diff options
Diffstat (limited to 'src/3rdparty/webkit/WebCore/bindings/js')
165 files changed, 17027 insertions, 0 deletions
diff --git a/src/3rdparty/webkit/WebCore/bindings/js/CachedScriptSourceProvider.h b/src/3rdparty/webkit/WebCore/bindings/js/CachedScriptSourceProvider.h new file mode 100644 index 0000000..e943fa5 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/CachedScriptSourceProvider.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 CachedScriptSourceProvider_h +#define CachedScriptSourceProvider_h + +#include "CachedResourceClient.h" +#include "CachedResourceHandle.h" +#include "CachedScript.h" +#include <parser/SourceCode.h> + +namespace WebCore { + + class CachedScriptSourceProvider : public JSC::SourceProvider, public CachedResourceClient { + public: + static PassRefPtr<CachedScriptSourceProvider> create(CachedScript* cachedScript) { return adoptRef(new CachedScriptSourceProvider(cachedScript)); } + + virtual ~CachedScriptSourceProvider() + { + m_cachedScript->removeClient(this); + } + + JSC::UString getRange(int start, int end) const { return JSC::UString(m_cachedScript->script().characters() + start, end - start); } + const UChar* data() const { return m_cachedScript->script().characters(); } + int length() const { return m_cachedScript->script().length(); } + + private: + CachedScriptSourceProvider(CachedScript* cachedScript) + : SourceProvider(cachedScript->url()) + , m_cachedScript(cachedScript) + { + m_cachedScript->addClient(this); + } + + CachedResourceHandle<CachedScript> m_cachedScript; + }; + + inline JSC::SourceCode makeSource(CachedScript* cachedScript) + { + return JSC::SourceCode(CachedScriptSourceProvider::create(cachedScript)); + } + +} // namespace WebCore + +#endif // CachedScriptSourceProvider_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/DOMTimer.cpp b/src/3rdparty/webkit/WebCore/bindings/js/DOMTimer.cpp new file mode 100644 index 0000000..911da71 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/DOMTimer.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "DOMTimer.h" + +#include "Document.h" +#include "ScheduledAction.h" +#include "ScriptExecutionContext.h" +#include <wtf/HashSet.h> +#include <wtf/StdLibExtras.h> + +using namespace std; + +namespace WebCore { + +static const int maxTimerNestingLevel = 5; +static const double oneMillisecond = 0.001; +static const double minTimerInterval = 0.010; // 10 milliseconds + +static int timerNestingLevel = 0; + +DOMTimer::DOMTimer(ScriptExecutionContext* context, ScheduledAction* action, int timeout, bool singleShot) + : ActiveDOMObject(context, this) + , m_action(action) + , m_nextFireInterval(0) + , m_repeatInterval(0) +{ + static int lastUsedTimeoutId = 0; + ++lastUsedTimeoutId; + // Avoid wraparound going negative on us. + if (lastUsedTimeoutId <= 0) + lastUsedTimeoutId = 1; + m_timeoutId = lastUsedTimeoutId; + + m_nestingLevel = timerNestingLevel + 1; + + // FIXME: Move the timeout map and API to ScriptExecutionContext to be able + // to create timeouts from Workers. + ASSERT(scriptExecutionContext() && scriptExecutionContext()->isDocument()); + static_cast<Document*>(scriptExecutionContext())->addTimeout(m_timeoutId, this); + + double intervalMilliseconds = max(oneMillisecond, timeout * oneMillisecond); + + // Use a minimum interval of 10 ms to match other browsers, but only once we've + // nested enough to notice that we're repeating. + // Faster timers might be "better", but they're incompatible. + if (intervalMilliseconds < minTimerInterval && m_nestingLevel >= maxTimerNestingLevel) + intervalMilliseconds = minTimerInterval; + if (singleShot) + startOneShot(intervalMilliseconds); + else + startRepeating(intervalMilliseconds); +} + +DOMTimer::~DOMTimer() +{ + if (scriptExecutionContext()) { + ASSERT(scriptExecutionContext()->isDocument()); + static_cast<Document*>(scriptExecutionContext())->removeTimeout(m_timeoutId); + } +} + +int DOMTimer::install(ScriptExecutionContext* context, ScheduledAction* action, int timeout, bool singleShot) +{ + // DOMTimer constructor links the new timer into a list of ActiveDOMObjects held by the 'context'. + // The timer is deleted when context is deleted (DOMTimer::contextDestroyed) or explicitly via DOMTimer::removeById(), + // or if it is a one-time timer and it has fired (DOMTimer::fired). + DOMTimer* timer = new DOMTimer(context, action, timeout, singleShot); + return timer->m_timeoutId; +} + +void DOMTimer::removeById(ScriptExecutionContext* context, int timeoutId) +{ + // timeout IDs have to be positive, and 0 and -1 are unsafe to + // even look up since they are the empty and deleted value + // respectively + if (timeoutId <= 0) + return; + ASSERT(context && context->isDocument()); + delete static_cast<Document*>(context)->findTimeout(timeoutId); +} + +void DOMTimer::fired() +{ + ScriptExecutionContext* context = scriptExecutionContext(); + timerNestingLevel = m_nestingLevel; + + // Simple case for non-one-shot timers. + if (isActive()) { + if (repeatInterval() && repeatInterval() < minTimerInterval) { + m_nestingLevel++; + if (m_nestingLevel >= maxTimerNestingLevel) + augmentRepeatInterval(minTimerInterval - repeatInterval()); + } + + // No access to member variables after this point, it can delete the timer. + m_action->execute(context); + return; + } + + // Delete timer before executing the action for one-shot timers. + ScheduledAction* action = m_action.release(); + + // No access to member variables after this point. + delete this; + + action->execute(context); + delete action; + timerNestingLevel = 0; +} + +bool DOMTimer::hasPendingActivity() const +{ + return isActive(); +} + +void DOMTimer::contextDestroyed() +{ + ActiveDOMObject::contextDestroyed(); + delete this; +} + +void DOMTimer::stop() +{ + TimerBase::stop(); + // Need to release JS objects potentially protected by ScheduledAction + // because they can form circular references back to the ScriptExecutionContext + // which will cause a memory leak. + m_action.clear(); +} + +void DOMTimer::suspend() +{ + ASSERT(m_nextFireInterval == 0 && m_repeatInterval == 0); + m_nextFireInterval = nextFireInterval(); + m_repeatInterval = repeatInterval(); + TimerBase::stop(); +} + +void DOMTimer::resume() +{ + start(m_nextFireInterval, m_repeatInterval); + m_nextFireInterval = 0; + m_repeatInterval = 0; +} + + +bool DOMTimer::canSuspend() const +{ + return true; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/DOMTimer.h b/src/3rdparty/webkit/WebCore/bindings/js/DOMTimer.h new file mode 100644 index 0000000..200b9b1 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/DOMTimer.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 DOMTimer_h +#define DOMTimer_h + +#include "ActiveDOMObject.h" +#include "Timer.h" +#include <wtf/OwnPtr.h> + +namespace WebCore { + +class ScheduledAction; + +class DOMTimer : public TimerBase, public ActiveDOMObject { +public: + virtual ~DOMTimer(); + // Creates a new timer owned by specified ScriptExecutionContext, starts it + // and returns its Id. + static int install(ScriptExecutionContext*, ScheduledAction*, int timeout, bool singleShot); + static void removeById(ScriptExecutionContext*, int timeoutId); + + // ActiveDOMObject + virtual bool hasPendingActivity() const; + virtual void contextDestroyed(); + virtual void stop(); + virtual bool canSuspend() const; + virtual void suspend(); + virtual void resume(); + +private: + DOMTimer(ScriptExecutionContext*, ScheduledAction*, int timeout, bool singleShot); + virtual void fired(); + + int m_timeoutId; + int m_nestingLevel; + OwnPtr<ScheduledAction> m_action; + double m_nextFireInterval; + double m_repeatInterval; +}; + +} // namespace WebCore + +#endif // DOMTimer_h + diff --git a/src/3rdparty/webkit/WebCore/bindings/js/GCController.cpp b/src/3rdparty/webkit/WebCore/bindings/js/GCController.cpp new file mode 100644 index 0000000..ceb7928 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/GCController.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2007 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "GCController.h" + +#include "JSDOMWindow.h" +#include <runtime/JSGlobalData.h> +#include <runtime/JSLock.h> +#include <runtime/Collector.h> +#include <wtf/StdLibExtras.h> + +#if USE(PTHREADS) +#include <pthread.h> +#endif + +using namespace JSC; + +namespace WebCore { + +#if USE(PTHREADS) + +static void* collect(void*) +{ + JSLock lock(false); + JSDOMWindow::commonJSGlobalData()->heap.collect(); + return 0; +} + +#endif + +GCController& gcController() +{ + DEFINE_STATIC_LOCAL(GCController, staticGCController, ()); + return staticGCController; +} + +GCController::GCController() + : m_GCTimer(this, &GCController::gcTimerFired) +{ +} + +void GCController::garbageCollectSoon() +{ + if (!m_GCTimer.isActive()) + m_GCTimer.startOneShot(0); +} + +void GCController::gcTimerFired(Timer<GCController>*) +{ + JSLock lock(false); + JSDOMWindow::commonJSGlobalData()->heap.collect(); +} + +void GCController::garbageCollectNow() +{ + JSLock lock(false); + JSDOMWindow::commonJSGlobalData()->heap.collect(); +} + +void GCController::garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone) +{ +#if USE(PTHREADS) + pthread_t thread; + pthread_create(&thread, NULL, collect, NULL); + + if (waitUntilDone) + pthread_join(thread, NULL); +#endif +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/GCController.h b/src/3rdparty/webkit/WebCore/bindings/js/GCController.h new file mode 100644 index 0000000..452019a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/GCController.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2007 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 GCController_h +#define GCController_h + +#include <wtf/Noncopyable.h> +#include "Timer.h" + +namespace WebCore { + + class GCController : Noncopyable { + friend GCController& gcController(); + + public: + void garbageCollectSoon(); + void garbageCollectNow(); // It's better to call garbageCollectSoon, unless you have a specific reason not to. + + void garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone); // Used for stress testing. + + private: + GCController(); // Use gcController() instead + void gcTimerFired(Timer<GCController>*); + + Timer<GCController> m_GCTimer; + }; + + // Function to obtain the global GC controller. + GCController& gcController(); + +} // namespace WebCore + +#endif // GCController_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSAttrCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSAttrCustom.cpp new file mode 100644 index 0000000..a97d039 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSAttrCustom.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSAttr.h" + +#include "CSSHelper.h" +#include "Document.h" +#include "HTMLFrameElementBase.h" +#include "HTMLNames.h" + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +void JSAttr::setValue(ExecState* exec, JSValuePtr value) +{ + Attr* imp = static_cast<Attr*>(impl()); + String attrValue = valueToStringWithNullCheck(exec, value); + + Element* ownerElement = imp->ownerElement(); + if (ownerElement && (ownerElement->hasTagName(iframeTag) || ownerElement->hasTagName(frameTag))) { + if (equalIgnoringCase(imp->name(), "src") && protocolIs(parseURL(attrValue), "javascript")) { + if (!checkNodeSecurity(exec, static_cast<HTMLFrameElementBase*>(ownerElement)->contentDocument())) + return; + } + } + + ExceptionCode ec = 0; + imp->setValue(attrValue, ec); + setDOMException(exec, ec); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSAudioConstructor.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSAudioConstructor.cpp new file mode 100644 index 0000000..eed5b2e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSAudioConstructor.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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(VIDEO) + +#include "JSAudioConstructor.h" + +#include "HTMLAudioElement.h" +#include "HTMLNames.h" +#include "JSHTMLAudioElement.h" +#include "ScriptExecutionContext.h" +#include "Text.h" + +using namespace JSC; + +namespace WebCore { + +const ClassInfo JSAudioConstructor::s_info = { "AudioConstructor", 0, 0, 0 }; + +JSAudioConstructor::JSAudioConstructor(ExecState* exec, ScriptExecutionContext* context) + : DOMObject(JSAudioConstructor::createStructure(exec->lexicalGlobalObject()->objectPrototype())) +{ + ASSERT(context->isDocument()); + m_document = static_cast<JSDocument*>(asObject(toJS(exec, static_cast<Document*>(context)))); + + putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum); +} + +static JSObject* constructAudio(ExecState* exec, JSObject* constructor, const ArgList& args) +{ + // FIXME: Why doesn't this need the call toJS on the document like JSImageConstructor? + + RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(HTMLNames::audioTag, static_cast<JSAudioConstructor*>(constructor)->document()); + if (args.size() > 0) { + audio->setSrc(args.at(exec, 0)->toString(exec)); + audio->scheduleLoad(); + } + return asObject(toJS(exec, audio.release())); +} + +ConstructType JSAudioConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructAudio; + return ConstructTypeHost; +} + +void JSAudioConstructor::mark() +{ + DOMObject::mark(); + if (!m_document->marked()) + m_document->mark(); +} + +} // namespace WebCore + +#endif // ENABLE(VIDEO) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSAudioConstructor.h b/src/3rdparty/webkit/WebCore/bindings/js/JSAudioConstructor.h new file mode 100644 index 0000000..cdff10f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSAudioConstructor.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSAudioConstructor_h +#define JSAudioConstructor_h + +#if ENABLE(VIDEO) + +#include "JSDOMBinding.h" +#include "JSDocument.h" +#include <wtf/RefPtr.h> + +namespace WebCore { + + class JSAudioConstructor : public DOMObject { + public: + JSAudioConstructor(JSC::ExecState*, ScriptExecutionContext*); + + Document* document() const { return m_document->impl(); } + + static const JSC::ClassInfo s_info; + + virtual void mark(); + private: + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + + JSDocument* m_document; + }; + +} // namespace WebCore + +#endif // ENABLE(VIDEO) + +#endif // JSAudioConstructor_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCSSRuleCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCSSRuleCustom.cpp new file mode 100644 index 0000000..32462fa --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCSSRuleCustom.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSCSSRule.h" + +#include "CSSCharsetRule.h" +#include "CSSFontFaceRule.h" +#include "CSSImportRule.h" +#include "CSSMediaRule.h" +#include "CSSPageRule.h" +#include "CSSStyleRule.h" +#include "CSSVariablesRule.h" +#include "JSCSSCharsetRule.h" +#include "JSCSSFontFaceRule.h" +#include "JSCSSImportRule.h" +#include "JSCSSMediaRule.h" +#include "JSCSSPageRule.h" +#include "JSCSSStyleRule.h" +#include "JSCSSVariablesRule.h" +#include "JSWebKitCSSKeyframeRule.h" +#include "JSWebKitCSSKeyframesRule.h" +#include "WebKitCSSKeyframeRule.h" +#include "WebKitCSSKeyframesRule.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr toJS(ExecState* exec, CSSRule* rule) +{ + if (!rule) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), rule); + + if (wrapper) + return wrapper; + + switch (rule->type()) { + case CSSRule::STYLE_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSStyleRule, rule); + break; + case CSSRule::MEDIA_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSMediaRule, rule); + break; + case CSSRule::FONT_FACE_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSFontFaceRule, rule); + break; + case CSSRule::PAGE_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSPageRule, rule); + break; + case CSSRule::IMPORT_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSImportRule, rule); + break; + case CSSRule::CHARSET_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSCharsetRule, rule); + break; + case CSSRule::VARIABLES_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSVariablesRule, rule); + break; + case CSSRule::WEBKIT_KEYFRAME_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, WebKitCSSKeyframeRule, rule); + break; + case CSSRule::WEBKIT_KEYFRAMES_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, WebKitCSSKeyframesRule, rule); + break; + default: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSRule, rule); + } + + return wrapper; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp new file mode 100644 index 0000000..6c46ae4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSCSSStyleDeclarationCustom.h" + +#include "AtomicString.h" +#include "CSSPrimitiveValue.h" +#include "CSSStyleDeclaration.h" +#include "CSSValue.h" +#include "PlatformString.h" +#include <runtime/StringObjectThatMasqueradesAsUndefined.h> +#include <runtime/StringPrototype.h> +#include <wtf/ASCIICType.h> + +using namespace JSC; +using namespace WTF; + +namespace WebCore { + +// Check for a CSS prefix. +// Passed prefix is all lowercase. +// First character of the prefix within the property name may be upper or lowercase. +// Other characters in the prefix within the property name must be lowercase. +// The prefix within the property name must be followed by a capital letter. +static bool hasCSSPropertyNamePrefix(const Identifier& propertyName, const char* prefix) +{ +#ifndef NDEBUG + ASSERT(*prefix); + for (const char* p = prefix; *p; ++p) + ASSERT(isASCIILower(*p)); + ASSERT(propertyName.size()); +#endif + + if (toASCIILower(propertyName.data()[0]) != prefix[0]) + return false; + + unsigned length = propertyName.size(); + for (unsigned i = 1; i < length; ++i) { + if (!prefix[i]) + return isASCIIUpper(propertyName.data()[i]); + if (propertyName.data()[i] != prefix[i]) + return false; + } + return false; +} + +static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0) +{ + if (hadPixelOrPosPrefix) + *hadPixelOrPosPrefix = false; + + unsigned length = propertyName.size(); + if (!length) + return String(); + + Vector<UChar> name; + name.reserveCapacity(length); + + unsigned i = 0; + + if (hasCSSPropertyNamePrefix(propertyName, "css")) + i += 3; + else if (hasCSSPropertyNamePrefix(propertyName, "pixel")) { + i += 5; + if (hadPixelOrPosPrefix) + *hadPixelOrPosPrefix = true; + } else if (hasCSSPropertyNamePrefix(propertyName, "pos")) { + i += 3; + if (hadPixelOrPosPrefix) + *hadPixelOrPosPrefix = true; + } else if (hasCSSPropertyNamePrefix(propertyName, "webkit") + || hasCSSPropertyNamePrefix(propertyName, "khtml") + || hasCSSPropertyNamePrefix(propertyName, "apple")) + name.append('-'); + else { + if (isASCIIUpper(propertyName.data()[0])) + return String(); + } + + name.append(toASCIILower(propertyName.data()[i++])); + + for (; i < length; ++i) { + UChar c = propertyName.data()[i]; + if (!isASCIIUpper(c)) + name.append(c); + else { + name.append('-'); + name.append(toASCIILower(c)); + } + } + + return String::adopt(name); +} + +static bool isCSSPropertyName(const Identifier& propertyName) +{ + return CSSStyleDeclaration::isPropertyName(cssPropertyName(propertyName)); +} + +bool JSCSSStyleDeclaration::canGetItemsForName(ExecState*, CSSStyleDeclaration*, const Identifier& propertyName) +{ + return isCSSPropertyName(propertyName); +} + +// FIXME: You can get these properties, and set them (see customPut below), +// but you should also be able to enumerate them. +JSValuePtr JSCSSStyleDeclaration::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSCSSStyleDeclaration* thisObj = static_cast<JSCSSStyleDeclaration*>(asObject(slot.slotBase())); + + // Set up pixelOrPos boolean to handle the fact that + // pixelTop returns "CSS Top" as number value in unit pixels + // posTop returns "CSS top" as number value in unit pixels _if_ its a + // positioned element. if it is not a positioned element, return 0 + // from MSIE documentation FIXME: IMPLEMENT THAT (Dirk) + bool pixelOrPos; + String prop = cssPropertyName(propertyName, &pixelOrPos); + RefPtr<CSSValue> v = thisObj->impl()->getPropertyCSSValue(prop); + if (v) { + if (pixelOrPos && v->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) + return jsNumber(exec, static_pointer_cast<CSSPrimitiveValue>(v)->getFloatValue(CSSPrimitiveValue::CSS_PX)); + return jsStringOrNull(exec, v->cssText()); + } + + // If the property is a shorthand property (such as "padding"), + // it can only be accessed using getPropertyValue. + + // Make the SVG 'filter' attribute undetectable, to avoid confusion with the IE 'filter' attribute. + if (propertyName == "filter") + return StringObjectThatMasqueradesAsUndefined::create(exec, thisObj->impl()->getPropertyValue(prop)); + + return jsString(exec, thisObj->impl()->getPropertyValue(prop)); +} + + +bool JSCSSStyleDeclaration::customPut(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot&) +{ + if (!isCSSPropertyName(propertyName)) + return false; + + bool pixelOrPos; + String prop = cssPropertyName(propertyName, &pixelOrPos); + String propValue = valueToStringWithNullCheck(exec, value); + if (pixelOrPos) + propValue += "px"; + ExceptionCode ec = 0; + impl()->setProperty(prop, propValue, ec); + setDOMException(exec, ec); + return true; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h new file mode 100644 index 0000000..32ecbe0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSCSSStyleDeclarationCustom_h +#define JSCSSStyleDeclarationCustom_h + +#include "JSCSSStyleDeclaration.h" + +#endif // JSCSSStyleDeclarationCustom_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCSSValueCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCSSValueCustom.cpp new file mode 100644 index 0000000..9e31304 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCSSValueCustom.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSCSSValue.h" + +#include "CSSPrimitiveValue.h" +#include "CSSValueList.h" +#include "JSCSSPrimitiveValue.h" +#include "JSCSSValueList.h" +#include "JSWebKitCSSTransformValue.h" +#include "WebKitCSSTransformValue.h" + +#if ENABLE(SVG) +#include "JSSVGColor.h" +#include "JSSVGPaint.h" +#include "SVGColor.h" +#include "SVGPaint.h" +#endif + +using namespace JSC; + +namespace WebCore { + +JSValuePtr toJS(ExecState* exec, CSSValue* value) +{ + if (!value) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), value); + + if (wrapper) + return wrapper; + + if (value->isWebKitCSSTransformValue()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, WebKitCSSTransformValue, value); + else if (value->isValueList()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSValueList, value); +#if ENABLE(SVG) + else if (value->isSVGPaint()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, SVGPaint, value); + else if (value->isSVGColor()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, SVGColor, value); +#endif + else if (value->isPrimitiveValue()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSPrimitiveValue, value); + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSValue, value); + + return wrapper; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp new file mode 100644 index 0000000..6eb4fc5 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp @@ -0,0 +1,389 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSCanvasRenderingContext2D.h" + +#include "CanvasGradient.h" +#include "CanvasPattern.h" +#include "CanvasRenderingContext2D.h" +#include "CanvasStyle.h" +#include "ExceptionCode.h" +#include "FloatRect.h" +#include "HTMLCanvasElement.h" +#include "HTMLImageElement.h" +#include "ImageData.h" +#include "JSCanvasGradient.h" +#include "JSCanvasPattern.h" +#include "JSHTMLCanvasElement.h" +#include "JSHTMLImageElement.h" +#include "JSImageData.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +static JSValuePtr toJS(ExecState* exec, CanvasStyle* style) +{ + if (style->canvasGradient()) + return toJS(exec, style->canvasGradient()); + if (style->canvasPattern()) + return toJS(exec, style->canvasPattern()); + return jsString(exec, style->color()); +} + +static PassRefPtr<CanvasStyle> toHTMLCanvasStyle(ExecState*, JSValuePtr value) +{ + if (value->isString()) + return CanvasStyle::create(asString(value)->value()); + if (!value->isObject()) + return 0; + JSObject* object = asObject(value); + if (object->inherits(&JSCanvasGradient::s_info)) + return CanvasStyle::create(static_cast<JSCanvasGradient*>(object)->impl()); + if (object->inherits(&JSCanvasPattern::s_info)) + return CanvasStyle::create(static_cast<JSCanvasPattern*>(object)->impl()); + return 0; +} + +JSValuePtr JSCanvasRenderingContext2D::strokeStyle(ExecState* exec) const +{ + return toJS(exec, impl()->strokeStyle()); +} + +void JSCanvasRenderingContext2D::setStrokeStyle(ExecState* exec, JSValuePtr value) +{ + impl()->setStrokeStyle(toHTMLCanvasStyle(exec, value)); +} + +JSValuePtr JSCanvasRenderingContext2D::fillStyle(ExecState* exec) const +{ + return toJS(exec, impl()->fillStyle()); +} + +void JSCanvasRenderingContext2D::setFillStyle(ExecState* exec, JSValuePtr value) +{ + impl()->setFillStyle(toHTMLCanvasStyle(exec, value)); +} + +JSValuePtr JSCanvasRenderingContext2D::setFillColor(ExecState* exec, const ArgList& args) +{ + CanvasRenderingContext2D* context = impl(); + + // string arg = named color + // number arg = gray color + // string arg, number arg = named color, alpha + // number arg, number arg = gray color, alpha + // 4 args = r, g, b, a + // 5 args = c, m, y, k, a + switch (args.size()) { + case 1: + if (args.at(exec, 0)->isString()) + context->setFillColor(asString(args.at(exec, 0))->value()); + else + context->setFillColor(args.at(exec, 0)->toFloat(exec)); + break; + case 2: + if (args.at(exec, 0)->isString()) + context->setFillColor(asString(args.at(exec, 0))->value(), args.at(exec, 1)->toFloat(exec)); + else + context->setFillColor(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec)); + break; + case 4: + context->setFillColor(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec)); + break; + case 5: + context->setFillColor(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec), args.at(exec, 4)->toFloat(exec)); + break; + default: + return throwError(exec, SyntaxError); + } + return jsUndefined(); +} + +JSValuePtr JSCanvasRenderingContext2D::setStrokeColor(ExecState* exec, const ArgList& args) +{ + CanvasRenderingContext2D* context = impl(); + + // string arg = named color + // number arg = gray color + // string arg, number arg = named color, alpha + // number arg, number arg = gray color, alpha + // 4 args = r, g, b, a + // 5 args = c, m, y, k, a + switch (args.size()) { + case 1: + if (args.at(exec, 0)->isString()) + context->setStrokeColor(asString(args.at(exec, 0))->value()); + else + context->setStrokeColor(args.at(exec, 0)->toFloat(exec)); + break; + case 2: + if (args.at(exec, 0)->isString()) + context->setStrokeColor(asString(args.at(exec, 0))->value(), args.at(exec, 1)->toFloat(exec)); + else + context->setStrokeColor(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec)); + break; + case 4: + context->setStrokeColor(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec)); + break; + case 5: + context->setStrokeColor(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec), args.at(exec, 4)->toFloat(exec)); + break; + default: + return throwError(exec, SyntaxError); + } + + return jsUndefined(); +} + +JSValuePtr JSCanvasRenderingContext2D::strokeRect(ExecState* exec, const ArgList& args) +{ + CanvasRenderingContext2D* context = impl(); + + if (args.size() <= 4) + context->strokeRect(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec)); + else + context->strokeRect(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec), args.at(exec, 4)->toFloat(exec)); + + return jsUndefined(); +} + +JSValuePtr JSCanvasRenderingContext2D::drawImage(ExecState* exec, const ArgList& args) +{ + CanvasRenderingContext2D* context = impl(); + + // DrawImage has three variants: + // drawImage(img, dx, dy) + // drawImage(img, dx, dy, dw, dh) + // drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh) + // Composite operation is specified with globalCompositeOperation. + // The img parameter can be a <img> or <canvas> element. + JSValuePtr value = args.at(exec, 0); + if (!value->isObject()) + return throwError(exec, TypeError); + JSObject* o = asObject(value); + + ExceptionCode ec = 0; + if (o->inherits(&JSHTMLImageElement::s_info)) { + HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl()); + switch (args.size()) { + case 3: + context->drawImage(imgElt, args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec)); + break; + case 5: + context->drawImage(imgElt, args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec), + args.at(exec, 3)->toFloat(exec), args.at(exec, 4)->toFloat(exec), ec); + setDOMException(exec, ec); + break; + case 9: + context->drawImage(imgElt, FloatRect(args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec), + args.at(exec, 3)->toFloat(exec), args.at(exec, 4)->toFloat(exec)), + FloatRect(args.at(exec, 5)->toFloat(exec), args.at(exec, 6)->toFloat(exec), + args.at(exec, 7)->toFloat(exec), args.at(exec, 8)->toFloat(exec)), ec); + setDOMException(exec, ec); + break; + default: + return throwError(exec, SyntaxError); + } + } else if (o->inherits(&JSHTMLCanvasElement::s_info)) { + HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(o)->impl()); + switch (args.size()) { + case 3: + context->drawImage(canvas, args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec)); + break; + case 5: + context->drawImage(canvas, args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec), + args.at(exec, 3)->toFloat(exec), args.at(exec, 4)->toFloat(exec), ec); + setDOMException(exec, ec); + break; + case 9: + context->drawImage(canvas, FloatRect(args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec), + args.at(exec, 3)->toFloat(exec), args.at(exec, 4)->toFloat(exec)), + FloatRect(args.at(exec, 5)->toFloat(exec), args.at(exec, 6)->toFloat(exec), + args.at(exec, 7)->toFloat(exec), args.at(exec, 8)->toFloat(exec)), ec); + setDOMException(exec, ec); + break; + default: + return throwError(exec, SyntaxError); + } + } else { + setDOMException(exec, TYPE_MISMATCH_ERR); + } + + return jsUndefined(); +} + +JSValuePtr JSCanvasRenderingContext2D::drawImageFromRect(ExecState* exec, const ArgList& args) +{ + CanvasRenderingContext2D* context = impl(); + + JSValuePtr value = args.at(exec, 0); + if (!value->isObject()) + return throwError(exec, TypeError); + JSObject* o = asObject(value); + + if (!o->inherits(&JSHTMLImageElement::s_info)) + return throwError(exec, TypeError); + context->drawImageFromRect(static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl()), + args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec), + args.at(exec, 3)->toFloat(exec), args.at(exec, 4)->toFloat(exec), + args.at(exec, 5)->toFloat(exec), args.at(exec, 6)->toFloat(exec), + args.at(exec, 7)->toFloat(exec), args.at(exec, 8)->toFloat(exec), + args.at(exec, 9)->toString(exec)); + return jsUndefined(); +} + +JSValuePtr JSCanvasRenderingContext2D::setShadow(ExecState* exec, const ArgList& args) +{ + CanvasRenderingContext2D* context = impl(); + + switch (args.size()) { + case 3: + context->setShadow(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec)); + break; + case 4: + if (args.at(exec, 3)->isString()) + context->setShadow(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), asString(args.at(exec, 3))->value()); + else + context->setShadow(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec)); + break; + case 5: + if (args.at(exec, 3)->isString()) + context->setShadow(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), asString(args.at(exec, 3))->value(), + args.at(exec, 4)->toFloat(exec)); + else + context->setShadow(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec), + args.at(exec, 4)->toFloat(exec)); + break; + case 7: + context->setShadow(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec), + args.at(exec, 4)->toFloat(exec), args.at(exec, 5)->toFloat(exec), + args.at(exec, 6)->toFloat(exec)); + break; + case 8: + context->setShadow(args.at(exec, 0)->toFloat(exec), args.at(exec, 1)->toFloat(exec), + args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec), + args.at(exec, 4)->toFloat(exec), args.at(exec, 5)->toFloat(exec), + args.at(exec, 6)->toFloat(exec), args.at(exec, 7)->toFloat(exec)); + break; + default: + return throwError(exec, SyntaxError); + } + + return jsUndefined(); +} + +JSValuePtr JSCanvasRenderingContext2D::createPattern(ExecState* exec, const ArgList& args) +{ + CanvasRenderingContext2D* context = impl(); + + JSValuePtr value = args.at(exec, 0); + if (!value->isObject()) + return throwError(exec, TypeError); + JSObject* o = asObject(value); + + if (o->inherits(&JSHTMLImageElement::s_info)) { + ExceptionCode ec; + JSValuePtr pattern = toJS(exec, + context->createPattern(static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl()), + valueToStringWithNullCheck(exec, args.at(exec, 1)), ec).get()); + setDOMException(exec, ec); + return pattern; + } + if (o->inherits(&JSHTMLCanvasElement::s_info)) { + ExceptionCode ec; + JSValuePtr pattern = toJS(exec, + context->createPattern(static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(o)->impl()), + valueToStringWithNullCheck(exec, args.at(exec, 1)), ec).get()); + setDOMException(exec, ec); + return pattern; + } + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); +} + +JSValuePtr JSCanvasRenderingContext2D::putImageData(ExecState* exec, const ArgList& args) +{ + // putImageData has two variants + // putImageData(ImageData, x, y) + // putImageData(ImageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) + CanvasRenderingContext2D* context = impl(); + + ExceptionCode ec = 0; + if (args.size() >= 7) + context->putImageData(toImageData(args.at(exec, 0)), args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec), + args.at(exec, 3)->toFloat(exec), args.at(exec, 4)->toFloat(exec), args.at(exec, 5)->toFloat(exec), args.at(exec, 6)->toFloat(exec), ec); + else + context->putImageData(toImageData(args.at(exec, 0)), args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec), ec); + + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValuePtr JSCanvasRenderingContext2D::fillText(ExecState* exec, const ArgList& args) +{ + CanvasRenderingContext2D* context = impl(); + + // string arg = text to draw + // number arg = x + // number arg = y + // optional number arg = maxWidth + if (args.size() < 3 || args.size() > 4) + return throwError(exec, SyntaxError); + + if (args.size() == 4) + context->fillText(args.at(exec, 0)->toString(exec), args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec)); + else + context->fillText(args.at(exec, 0)->toString(exec), args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec)); + return jsUndefined(); +} + +JSValuePtr JSCanvasRenderingContext2D::strokeText(ExecState* exec, const ArgList& args) +{ + CanvasRenderingContext2D* context = impl(); + + // string arg = text to draw + // number arg = x + // number arg = y + // optional number arg = maxWidth + if (args.size() < 3 || args.size() > 4) + return throwError(exec, SyntaxError); + + if (args.size() == 4) + context->strokeText(args.at(exec, 0)->toString(exec), args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec), args.at(exec, 3)->toFloat(exec)); + else + context->strokeText(args.at(exec, 0)->toString(exec), args.at(exec, 1)->toFloat(exec), args.at(exec, 2)->toFloat(exec)); + return jsUndefined(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSClipboardCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSClipboardCustom.cpp new file mode 100644 index 0000000..8ffb49e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSClipboardCustom.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSClipboard.h" + +#include "Clipboard.h" +#include "Element.h" +#include "HTMLImageElement.h" +#include "HTMLNames.h" +#include "IntPoint.h" +#include "JSNode.h" +#include "Node.h" +#include "PlatformString.h" +#include "StringHash.h" +#include <runtime/ArrayPrototype.h> +#include <runtime/Error.h> +#include <wtf/HashSet.h> + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +JSValuePtr JSClipboard::types(ExecState* exec) const +{ + Clipboard* clipboard = impl(); + + HashSet<String> types = clipboard->types(); + if (types.isEmpty()) + return jsNull(); + + ArgList list; + HashSet<String>::const_iterator end = types.end(); + for (HashSet<String>::const_iterator it = types.begin(); it != end; ++it) + list.append(jsString(exec, UString(*it))); + return constructArray(exec, list); +} + +JSValuePtr JSClipboard::clearData(ExecState* exec, const ArgList& args) +{ + Clipboard* clipboard = impl(); + + if (args.size() == 0) { + clipboard->clearAllData(); + return jsUndefined(); + } + + if (args.size() == 1) { + clipboard->clearData(args.at(exec, 0)->toString(exec)); + return jsUndefined(); + } + + // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. + return throwError(exec, SyntaxError, "clearData: Invalid number of arguments"); +} + +JSValuePtr JSClipboard::getData(ExecState* exec, const ArgList& args) +{ + // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. + if (args.size() != 1) + return throwError(exec, SyntaxError, "getData: Invalid number of arguments"); + + Clipboard* clipboard = impl(); + + bool success; + String result = clipboard->getData(args.at(exec, 0)->toString(exec), success); + if (!success) + return jsUndefined(); + + return jsString(exec, result); +} + +JSValuePtr JSClipboard::setData(ExecState* exec, const ArgList& args) +{ + Clipboard* clipboard = impl(); + + // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. + if (args.size() != 2) + return throwError(exec, SyntaxError, "setData: Invalid number of arguments"); + + return jsBoolean(clipboard->setData(args.at(exec, 0)->toString(exec), args.at(exec, 1)->toString(exec))); +} + +JSValuePtr JSClipboard::setDragImage(ExecState* exec, const ArgList& args) +{ + Clipboard* clipboard = impl(); + + if (!clipboard->isForDragging()) + return jsUndefined(); + + // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. + if (args.size() != 3) + return throwError(exec, SyntaxError, "setDragImage: Invalid number of arguments"); + + int x = args.at(exec, 1)->toInt32(exec); + int y = args.at(exec, 2)->toInt32(exec); + + // See if they passed us a node + Node* node = toNode(args.at(exec, 0)); + if (!node) + return throwError(exec, TypeError); + + // FIXME: This should probably be a TypeError. + if (!node->isElementNode()) + return throwError(exec, SyntaxError, "setDragImageFromElement: Invalid first argument"); + + if (static_cast<Element*>(node)->hasLocalName(imgTag) && !node->inDocument()) + clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y)); + else + clipboard->setDragImageElement(node, IntPoint(x, y)); + + return jsUndefined(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSConsoleCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSConsoleCustom.cpp new file mode 100644 index 0000000..ddfe4f7 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSConsoleCustom.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSConsole.h" +#include "JavaScriptProfile.h" +#include <runtime/JSArray.h> + +#include "Console.h" + +using namespace JSC; + +namespace WebCore { + +typedef Vector<RefPtr<JSC::Profile> > ProfilesArray; + +JSValuePtr JSConsole::profiles(ExecState* exec) const +{ + const ProfilesArray& profiles = impl()->profiles(); + ArgList list; + + ProfilesArray::const_iterator end = profiles.end(); + for (ProfilesArray::const_iterator iter = profiles.begin(); iter != end; ++iter) + list.append(toJS(exec, iter->get())); + + return constructArray(exec, list); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionCallback.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionCallback.cpp new file mode 100644 index 0000000..836ffb9 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionCallback.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSCustomPositionCallback.h" + +#include "CString.h" +#include "Frame.h" +#include "JSGeoposition.h" +#include "Page.h" +#include "ScriptController.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +JSCustomPositionCallback::JSCustomPositionCallback(JSObject* callback, Frame* frame) + : m_callback(callback) + , m_frame(frame) +{ +} + +void JSCustomPositionCallback::handleEvent(Geoposition* geoposition, bool& raisedException) +{ + ASSERT(m_callback); + ASSERT(m_frame); + + if (!m_frame->script()->isEnabled()) + return; + + JSGlobalObject* globalObject = m_frame->script()->globalObject(); + ExecState* exec = globalObject->globalExec(); + + JSC::JSLock lock(false); + + JSValuePtr function = m_callback->get(exec, Identifier(exec, "handleEvent")); + CallData callData; + CallType callType = function->getCallData(callData); + if (callType == CallTypeNone) { + callType = m_callback->getCallData(callData); + if (callType == CallTypeNone) { + // FIXME: Should an exception be thrown here? + return; + } + function = m_callback; + } + + RefPtr<JSCustomPositionCallback> protect(this); + + ArgList args; + args.append(toJS(exec, geoposition)); + + globalObject->startTimeoutCheck(); + call(exec, function, callType, callData, m_callback, args); + globalObject->stopTimeoutCheck(); + + if (exec->hadException()) { + reportCurrentException(exec); + raisedException = true; + } +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionCallback.h b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionCallback.h new file mode 100644 index 0000000..6c0d306 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionCallback.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSCustomPositionCallback_h +#define JSCustomPositionCallback_h + +#include "PositionCallback.h" +#include <runtime/JSObject.h> +#include <runtime/Protect.h> +#include <wtf/Forward.h> + +namespace JSC { + class JSObject; +} + +namespace WebCore { + +class Frame; +class Geoposition; + +class JSCustomPositionCallback : public PositionCallback { +public: + static PassRefPtr<JSCustomPositionCallback> create(JSC::JSObject* callback, Frame* frame) { return adoptRef(new JSCustomPositionCallback(callback, frame)); } + + virtual void handleEvent(Geoposition*, bool& raisedException); + +private: + JSCustomPositionCallback(JSC::JSObject* callback, Frame*); + + JSC::ProtectedPtr<JSC::JSObject> m_callback; + RefPtr<Frame> m_frame; +}; + +} // namespace WebCore + +#endif // JSCustomPositionCallback_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionErrorCallback.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionErrorCallback.cpp new file mode 100644 index 0000000..b4e9535 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionErrorCallback.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSCustomPositionErrorCallback.h" + +#include "CString.h" +#include "Frame.h" +#include "JSPositionError.h" +#include "Page.h" +#include "ScriptController.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +JSCustomPositionErrorCallback::JSCustomPositionErrorCallback(JSObject* callback, Frame* frame) + : m_callback(callback) + , m_frame(frame) +{ +} + +void JSCustomPositionErrorCallback::handleEvent(PositionError* positionError) +{ + ASSERT(m_callback); + ASSERT(m_frame); + + if (!m_frame->script()->isEnabled()) + return; + + JSGlobalObject* globalObject = m_frame->script()->globalObject(); + ExecState* exec = globalObject->globalExec(); + + JSC::JSLock lock(false); + + JSValuePtr function = m_callback->get(exec, Identifier(exec, "handleEvent")); + CallData callData; + CallType callType = function->getCallData(callData); + if (callType == CallTypeNone) { + callType = m_callback->getCallData(callData); + if (callType == CallTypeNone) { + // FIXME: Should an exception be thrown here? + return; + } + function = m_callback; + } + + RefPtr<JSCustomPositionErrorCallback> protect(this); + + ArgList args; + args.append(toJS(exec, positionError)); + + globalObject->startTimeoutCheck(); + call(exec, function, callType, callData, m_callback, args); + globalObject->stopTimeoutCheck(); + + if (exec->hadException()) + reportCurrentException(exec); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionErrorCallback.h b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionErrorCallback.h new file mode 100644 index 0000000..9f143a2 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomPositionErrorCallback.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSCustomPositionErrorCallback_h +#define JSCustomPositionErrorCallback_h + +#include "PositionErrorCallback.h" +#include <runtime/JSObject.h> +#include <runtime/Protect.h> +#include <wtf/Forward.h> + +namespace JSC { + class JSObject; +} + +namespace WebCore { + +class Frame; +class PositionError; + +class JSCustomPositionErrorCallback : public PositionErrorCallback { +public: + static PassRefPtr<JSCustomPositionErrorCallback> create(JSC::JSObject* callback, Frame* frame) { return adoptRef(new JSCustomPositionErrorCallback(callback, frame)); } + + virtual void handleEvent(PositionError*); + +private: + JSCustomPositionErrorCallback(JSC::JSObject* callback, Frame*); + + JSC::ProtectedPtr<JSC::JSObject> m_callback; + RefPtr<Frame> m_frame; +}; + +} // namespace WebCore + +#endif // JSCustomPositionErrorCallback_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementCallback.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementCallback.cpp new file mode 100644 index 0000000..2243564 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementCallback.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSCustomSQLStatementCallback.h" + +#include "CString.h" +#include "DOMWindow.h" +#include "Frame.h" +#include "ScriptController.h" +#include "JSSQLResultSet.h" +#include "JSSQLTransaction.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +JSCustomSQLStatementCallback::JSCustomSQLStatementCallback(JSObject* callback, Frame* frame) + : m_callback(callback) + , m_frame(frame) +{ +} + +void JSCustomSQLStatementCallback::handleEvent(SQLTransaction* transaction, SQLResultSet* resultSet, bool& raisedException) +{ + ASSERT(m_callback); + ASSERT(m_frame); + + if (!m_frame->script()->isEnabled()) + return; + + JSGlobalObject* globalObject = m_frame->script()->globalObject(); + ExecState* exec = globalObject->globalExec(); + + JSC::JSLock lock(false); + + JSValuePtr function = m_callback->get(exec, Identifier(exec, "handleEvent")); + CallData callData; + CallType callType = function->getCallData(callData); + if (callType == CallTypeNone) { + callType = m_callback->getCallData(callData); + if (callType == CallTypeNone) { + // FIXME: Should an exception be thrown here? + return; + } + function = m_callback; + } + + RefPtr<JSCustomSQLStatementCallback> protect(this); + + ArgList args; + args.append(toJS(exec, transaction)); + args.append(toJS(exec, resultSet)); + + globalObject->startTimeoutCheck(); + call(exec, function, callType, callData, m_callback, args); + globalObject->stopTimeoutCheck(); + + if (exec->hadException()) { + reportCurrentException(exec); + + raisedException = true; + } + + Document::updateDocumentsRendering(); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementCallback.h b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementCallback.h new file mode 100644 index 0000000..3a3ae21 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementCallback.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 JSCustomSQLStatementCallback_h +#define JSCustomSQLStatementCallback_h + +#include "SQLStatementCallback.h" + +#include <runtime/JSObject.h> +#include <runtime/Protect.h> +#include <wtf/Forward.h> + +namespace JSC { + class JSObject; +} + +namespace WebCore { + +class Frame; +class SQLResultSet; + +class JSCustomSQLStatementCallback : public SQLStatementCallback { +public: + static PassRefPtr<JSCustomSQLStatementCallback> create(JSC::JSObject* callback, Frame* frame) { return adoptRef(new JSCustomSQLStatementCallback(callback, frame)); } + + virtual void handleEvent(SQLTransaction*, SQLResultSet*, bool& raisedException); + +private: + JSCustomSQLStatementCallback(JSC::JSObject* callback, Frame*); + + JSC::ProtectedPtr<JSC::JSObject> m_callback; + RefPtr<Frame> m_frame; +}; + +} + +#endif // JSCustomSQLStatementCallback_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp new file mode 100644 index 0000000..14080ea --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSCustomSQLStatementErrorCallback.h" + +#include "CString.h" +#include "DOMWindow.h" +#include "Frame.h" +#include "ScriptController.h" +#include "JSSQLError.h" +#include "JSSQLTransaction.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +JSCustomSQLStatementErrorCallback::JSCustomSQLStatementErrorCallback(JSObject* callback, Frame* frame) + : m_callback(callback) + , m_frame(frame) +{ +} + +bool JSCustomSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error) +{ + ASSERT(m_callback); + ASSERT(m_frame); + + if (!m_frame->script()->isEnabled()) + return true; + + JSGlobalObject* globalObject = m_frame->script()->globalObject(); + ExecState* exec = globalObject->globalExec(); + + JSC::JSLock lock(false); + + JSValuePtr handleEventFunction = m_callback->get(exec, Identifier(exec, "handleEvent")); + CallData handleEventCallData; + CallType handleEventCallType = handleEventFunction->getCallData(handleEventCallData); + CallData callbackCallData; + CallType callbackCallType = CallTypeNone; + + if (handleEventCallType == CallTypeNone) { + callbackCallType = m_callback->getCallData(callbackCallData); + if (callbackCallType == CallTypeNone) { + // FIXME: Should an exception be thrown here? + return true; + } + } + + RefPtr<JSCustomSQLStatementErrorCallback> protect(this); + + ArgList args; + args.append(toJS(exec, transaction)); + args.append(toJS(exec, error)); + + JSValuePtr result; + globalObject->startTimeoutCheck(); + if (handleEventCallType != CallTypeNone) + result = call(exec, handleEventFunction, handleEventCallType, handleEventCallData, m_callback, args); + else + result = call(exec, m_callback, callbackCallType, callbackCallData, m_callback, args); + globalObject->stopTimeoutCheck(); + + if (exec->hadException()) { + reportCurrentException(exec); + + // The spec says: + // "If the error callback returns false, then move on to the next statement..." + // "Otherwise, the error callback did not return false, or there was no error callback" + // Therefore an exception and returning true are the same thing - so, return true on an exception + return true; + } + + Document::updateDocumentsRendering(); + + return result->toBoolean(exec); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.h b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.h new file mode 100644 index 0000000..2847114 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 JSCustomSQLStatementErrorCallback_h +#define JSCustomSQLStatementErrorCallback_h + +#include "SQLStatementErrorCallback.h" + +#include <runtime/JSObject.h> +#include <runtime/Protect.h> +#include <wtf/Forward.h> + +namespace JSC { + class JSObject; +} + +namespace WebCore { + +class Frame; +class SQLError; + +class JSCustomSQLStatementErrorCallback : public SQLStatementErrorCallback { +public: + static PassRefPtr<JSCustomSQLStatementErrorCallback> create(JSC::JSObject* callback, Frame* frame) { return adoptRef(new JSCustomSQLStatementErrorCallback(callback, frame)); } + + virtual bool handleEvent(SQLTransaction*, SQLError*); + +private: + JSCustomSQLStatementErrorCallback(JSC::JSObject* callback, Frame*); + + JSC::ProtectedPtr<JSC::JSObject> m_callback; + RefPtr<Frame> m_frame; +}; + +} + +#endif // JSCustomSQLStatementErrorCallback_h + diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp new file mode 100644 index 0000000..7910a88 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSCustomSQLTransactionCallback.h" + +#include "CString.h" +#include "DOMWindow.h" +#include "Frame.h" +#include "Logging.h" +#include "ScriptController.h" +#include "JSSQLTransaction.h" +#include "Page.h" +#include <runtime/JSLock.h> +#include <wtf/MainThread.h> +#include <wtf/RefCountedLeakCounter.h> + +namespace WebCore { + +using namespace JSC; + +#ifndef NDEBUG +static WTF::RefCountedLeakCounter counter("JSCustomSQLTransactionCallback"); +#endif + +// We have to clean up the data on the main thread for two reasons: +// +// 1) Can't deref a Frame on a non-main thread. +// 2) Unprotecting the JSObject on a non-main thread would register that thread +// for JavaScript garbage collection, which could unnecessarily slow things down. + +class JSCustomSQLTransactionCallback::Data { +public: + Data(JSObject* callback, Frame* frame) : m_callback(callback), m_frame(frame) { } + JSObject* callback() { return m_callback; } + Frame* frame() { return m_frame.get(); } + +private: + ProtectedPtr<JSObject> m_callback; + RefPtr<Frame> m_frame; +}; + +JSCustomSQLTransactionCallback::JSCustomSQLTransactionCallback(JSObject* callback, Frame* frame) + : m_data(new Data(callback, frame)) +{ +#ifndef NDEBUG + counter.increment(); +#endif +} + +void JSCustomSQLTransactionCallback::deleteData(void* context) +{ + delete static_cast<Data*>(context); +} + +JSCustomSQLTransactionCallback::~JSCustomSQLTransactionCallback() +{ + callOnMainThread(deleteData, m_data); +#ifndef NDEBUG + m_data = 0; + counter.decrement(); +#endif +} + +void JSCustomSQLTransactionCallback::handleEvent(SQLTransaction* transaction, bool& raisedException) +{ + ASSERT(m_data); + ASSERT(m_data->callback()); + ASSERT(m_data->frame()); + + if (!m_data->frame()->script()->isEnabled()) + return; + + JSGlobalObject* globalObject = m_data->frame()->script()->globalObject(); + ExecState* exec = globalObject->globalExec(); + + JSC::JSLock lock(false); + + JSValuePtr handleEventFunction = m_data->callback()->get(exec, Identifier(exec, "handleEvent")); + CallData handleEventCallData; + CallType handleEventCallType = handleEventFunction->getCallData(handleEventCallData); + CallData callbackCallData; + CallType callbackCallType = CallTypeNone; + + if (handleEventCallType == CallTypeNone) { + callbackCallType = m_data->callback()->getCallData(callbackCallData); + if (callbackCallType == CallTypeNone) { + // FIXME: Should an exception be thrown here? + return; + } + } + + RefPtr<JSCustomSQLTransactionCallback> protect(this); + + ArgList args; + args.append(toJS(exec, transaction)); + + globalObject->startTimeoutCheck(); + if (handleEventCallType != CallTypeNone) + call(exec, handleEventFunction, handleEventCallType, handleEventCallData, m_data->callback(), args); + else + call(exec, m_data->callback(), callbackCallType, callbackCallData, m_data->callback(), args); + globalObject->stopTimeoutCheck(); + + if (exec->hadException()) { + reportCurrentException(exec); + + raisedException = true; + } + + Document::updateDocumentsRendering(); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionCallback.h b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionCallback.h new file mode 100644 index 0000000..0a21c1a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionCallback.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 JSCustomSQLTransactionCallback_h +#define JSCustomSQLTransactionCallback_h + +#include "SQLTransactionCallback.h" + +#include <wtf/PassRefPtr.h> + +namespace JSC { + class JSObject; +} + +namespace WebCore { + +class Frame; + +class JSCustomSQLTransactionCallback : public SQLTransactionCallback { +public: + static PassRefPtr<JSCustomSQLTransactionCallback> create(JSC::JSObject* callback, Frame* frame) { return adoptRef(new JSCustomSQLTransactionCallback(callback, frame)); } + + virtual ~JSCustomSQLTransactionCallback(); + + virtual void handleEvent(SQLTransaction*, bool& raisedException); + +private: + JSCustomSQLTransactionCallback(JSC::JSObject* callback, Frame*); + + static void deleteData(void*); + + class Data; + Data* m_data; +}; + +} + +#endif // JSCustomSQLTransactionCallback_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp new file mode 100644 index 0000000..7f95d4c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSCustomSQLTransactionErrorCallback.h" + +#include "CString.h" +#include "DOMWindow.h" +#include "Frame.h" +#include "ScriptController.h" +#include "JSSQLError.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +JSCustomSQLTransactionErrorCallback::JSCustomSQLTransactionErrorCallback(JSObject* callback, Frame* frame) + : m_callback(callback) + , m_frame(frame) +{ +} + +bool JSCustomSQLTransactionErrorCallback::handleEvent(SQLError* error) +{ + ASSERT(m_callback); + ASSERT(m_frame); + + if (!m_frame->script()->isEnabled()) + return true; + + JSGlobalObject* globalObject = m_frame->script()->globalObject(); + ExecState* exec = globalObject->globalExec(); + + JSC::JSLock lock(false); + + JSValuePtr function = m_callback->get(exec, Identifier(exec, "handleEvent")); + CallData callData; + CallType callType = function->getCallData(callData); + if (callType == CallTypeNone) { + callType = m_callback->getCallData(callData); + if (callType == CallTypeNone) { + // FIXME: Should an exception be thrown here? + return true; + } + function = m_callback; + } + + RefPtr<JSCustomSQLTransactionErrorCallback> protect(this); + + ArgList args; + args.append(toJS(exec, error)); + + JSValuePtr result; + globalObject->startTimeoutCheck(); + result = call(exec, function, callType, callData, m_callback, args); + globalObject->stopTimeoutCheck(); + + if (exec->hadException()) + reportCurrentException(exec); + + Document::updateDocumentsRendering(); + + return result->toBoolean(exec); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.h b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.h new file mode 100644 index 0000000..122224f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 JSCustomSQLTransactionErrorCallback_h +#define JSCustomSQLTransactionErrorCallback_h + +#include "SQLTransactionErrorCallback.h" + +#include <runtime/JSObject.h> +#include <runtime/Protect.h> +#include <wtf/Forward.h> + +namespace JSC { + class JSObject; +} + +namespace WebCore { + +class Frame; +class SQLError; + +class JSCustomSQLTransactionErrorCallback : public SQLTransactionErrorCallback { +public: + static PassRefPtr<JSCustomSQLTransactionErrorCallback> create(JSC::JSObject* callback, Frame* frame) { return adoptRef(new JSCustomSQLTransactionErrorCallback(callback, frame)); } + + virtual bool handleEvent(SQLError*); + +private: + JSCustomSQLTransactionErrorCallback(JSC::JSObject* callback, Frame*); + + JSC::ProtectedPtr<JSC::JSObject> m_callback; + RefPtr<Frame> m_frame; +}; + +} + +#endif // JSCustomSQLTransactionErrorCallback_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomVoidCallback.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomVoidCallback.cpp new file mode 100644 index 0000000..527fa41 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomVoidCallback.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSCustomVoidCallback.h" + +#include "CString.h" +#include "DOMWindow.h" +#include "Frame.h" +#include "JSDOMWindowCustom.h" +#include "JSDOMBinding.h" +#include "ScriptController.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +JSCustomVoidCallback::JSCustomVoidCallback(JSObject* callback, Frame* frame) + : m_callback(callback) + , m_frame(frame) +{ +} + +void JSCustomVoidCallback::handleEvent() +{ + ASSERT(m_callback); + ASSERT(m_frame); + + if (!m_frame->script()->isEnabled()) + return; + + JSGlobalObject* globalObject = m_frame->script()->globalObject(); + ExecState* exec = globalObject->globalExec(); + + JSC::JSLock lock(false); + + JSValuePtr function = m_callback->get(exec, Identifier(exec, "handleEvent")); + CallData callData; + CallType callType = function->getCallData(callData); + if (callType == CallTypeNone) { + callType = m_callback->getCallData(callData); + if (callType == CallTypeNone) { + // FIXME: Should an exception be thrown here? + return; + } + function = m_callback; + } + + RefPtr<JSCustomVoidCallback> protect(this); + + ArgList args; + + globalObject->startTimeoutCheck(); + call(exec, function, callType, callData, m_callback, args); + globalObject->stopTimeoutCheck(); + + if (exec->hadException()) + reportCurrentException(exec); + + Document::updateDocumentsRendering(); +} + +PassRefPtr<VoidCallback> toVoidCallback(ExecState* exec, JSValuePtr value) +{ + JSObject* object = value->getObject(); + if (!object) + return 0; + + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!frame) + return 0; + + return JSCustomVoidCallback::create(object, frame); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomVoidCallback.h b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomVoidCallback.h new file mode 100644 index 0000000..f54ddb6 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomVoidCallback.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 JSCustomVoidCallback_h +#define JSCustomVoidCallback_h + +#include "VoidCallback.h" + +#include <runtime/JSObject.h> +#include <runtime/Protect.h> +#include <wtf/Forward.h> + +namespace WebCore { + + class Frame; + + class JSCustomVoidCallback : public VoidCallback { + public: + static PassRefPtr<JSCustomVoidCallback> create(JSC::JSObject* callback, Frame* frame) + { + return adoptRef(new JSCustomVoidCallback(callback, frame)); + } + + virtual void handleEvent(); + + private: + JSCustomVoidCallback(JSC::JSObject* callback, Frame*); + + JSC::ProtectedPtr<JSC::JSObject> m_callback; + RefPtr<Frame> m_frame; + }; + + PassRefPtr<VoidCallback> toVoidCallback(JSC::ExecState*, JSC::JSValuePtr); + +} // namespace WebCore + +#endif // JSCustomVoidCallback_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomXPathNSResolver.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomXPathNSResolver.cpp new file mode 100644 index 0000000..8451dd0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomXPathNSResolver.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2007 Alexey Proskuryakov (ap@nypop.com) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSCustomXPathNSResolver.h" + +#if ENABLE(XPATH) + +#include "CString.h" +#include "Console.h" +#include "DOMWindow.h" +#include "Document.h" +#include "ExceptionCode.h" +#include "Frame.h" +#include "JSDOMWindowCustom.h" +#include "JSDOMBinding.h" +#include "ScriptController.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +PassRefPtr<JSCustomXPathNSResolver> JSCustomXPathNSResolver::create(JSC::ExecState* exec, JSC::JSValuePtr value) +{ + if (value->isUndefinedOrNull()) + return 0; + + JSObject* resolverObject = value->getObject(); + if (!resolverObject) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return 0; + } + + return adoptRef(new JSCustomXPathNSResolver(resolverObject, asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame())); +} + +JSCustomXPathNSResolver::JSCustomXPathNSResolver(JSObject* customResolver, Frame* frame) + : m_customResolver(customResolver) + , m_frame(frame) +{ +} + +JSCustomXPathNSResolver::~JSCustomXPathNSResolver() +{ +} + +String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix) +{ + ASSERT(m_customResolver); + + if (!m_frame) + return String(); + if (!m_frame->script()->isEnabled()) + return String(); + + JSLock lock(false); + + JSGlobalObject* globalObject = m_frame->script()->globalObject(); + ExecState* exec = globalObject->globalExec(); + + JSValuePtr function = m_customResolver->get(exec, Identifier(exec, "lookupNamespaceURI")); + CallData callData; + CallType callType = function->getCallData(callData); + if (callType == CallTypeNone) { + callType = m_customResolver->getCallData(callData); + if (callType == CallTypeNone) { + // FIXME: Pass actual line number and source URL. + m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.", 0, String()); + return String(); + } + function = m_customResolver; + } + + RefPtr<JSCustomXPathNSResolver> selfProtector(this); + + ArgList args; + args.append(jsString(exec, prefix)); + + globalObject->startTimeoutCheck(); + JSValuePtr retval = call(exec, function, callType, callData, m_customResolver, args); + globalObject->stopTimeoutCheck(); + + String result; + if (exec->hadException()) + reportCurrentException(exec); + else { + if (!retval->isUndefinedOrNull()) + result = retval->toString(exec); + } + + Document::updateDocumentsRendering(); + + return result; +} + +} // namespace WebCore + +#endif // ENABLE(XPATH) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSCustomXPathNSResolver.h b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomXPathNSResolver.h new file mode 100644 index 0000000..fecbb61 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSCustomXPathNSResolver.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007 Alexey Proskuryakov (ap@nypop.com) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSCustomXPathNSResolver_h +#define JSCustomXPathNSResolver_h + +#if ENABLE(XPATH) + +#include "XPathNSResolver.h" +#include <runtime/JSValue.h> +#include <wtf/Forward.h> +#include <wtf/RefPtr.h> + +namespace JSC { + class ExecState; + class JSObject; +} + +namespace WebCore { + + class Frame; + + class JSCustomXPathNSResolver : public XPathNSResolver { + public: + static PassRefPtr<JSCustomXPathNSResolver> create(JSC::ExecState*, JSC::JSValuePtr); + + virtual ~JSCustomXPathNSResolver(); + + virtual String lookupNamespaceURI(const String& prefix); + + private: + JSCustomXPathNSResolver(JSC::JSObject*, Frame*); + + JSC::JSObject* m_customResolver; // JSCustomXPathNSResolvers are always temporary, thus no need to GC protect the object. + RefPtr<Frame> m_frame; + }; + +} // namespace WebCore + +#endif // ENABLE(XPATH) + +#endif // JSCustomXPathNSResolver_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMApplicationCacheCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMApplicationCacheCustom.cpp new file mode 100644 index 0000000..5e867a1 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMApplicationCacheCustom.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSDOMApplicationCache.h" + +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + +#include "AtomicString.h" +#include "DOMApplicationCache.h" +#include "DOMWindow.h" +#include "Event.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "JSDOMWindowCustom.h" +#include "JSEvent.h" +#include "JSEventListener.h" + +using namespace JSC; + +namespace WebCore { + +void JSDOMApplicationCache::mark() +{ + DOMObject::mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onchecking())) + listener->mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onerror())) + listener->mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onnoupdate())) + listener->mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->ondownloading())) + listener->mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onprogress())) + listener->mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onupdateready())) + listener->mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->oncached())) + listener->mark(); + + typedef DOMApplicationCache::EventListenersMap EventListenersMap; + typedef DOMApplicationCache::ListenerVector ListenerVector; + EventListenersMap& eventListeners = m_impl->eventListeners(); + for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) { + for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) { + JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(vecIter->get()); + listener->mark(); + } + } +} + +JSValuePtr JSDOMApplicationCache::hasItem(ExecState* exec, const ArgList& args) +{ + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!frame) + return jsUndefined(); + const KURL& url = frame->loader()->completeURL(args.at(exec, 0)->toString(exec)); + + ExceptionCode ec = 0; + bool result = impl()->hasItem(url, ec); + setDOMException(exec, ec); + return jsBoolean(result); +} + +JSValuePtr JSDOMApplicationCache::add(ExecState* exec, const ArgList& args) +{ + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!frame) + return jsUndefined(); + const KURL& url = frame->loader()->completeURL(args.at(exec, 0)->toString(exec)); + + ExceptionCode ec = 0; + impl()->add(url, ec); + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValuePtr JSDOMApplicationCache::remove(ExecState* exec, const ArgList& args) +{ + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!frame) + return jsUndefined(); + const KURL& url = frame->loader()->completeURL(args.at(exec, 0)->toString(exec)); + + ExceptionCode ec = 0; + impl()->remove(url, ec); + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValuePtr JSDOMApplicationCache::addEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + RefPtr<JSUnprotectedEventListener> listener = globalObject->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +JSValuePtr JSDOMApplicationCache::removeEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + JSUnprotectedEventListener* listener = globalObject->findJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(OFFLINE_WEB_APPLICATIONS) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.cpp new file mode 100644 index 0000000..4cf083a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.cpp @@ -0,0 +1,538 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +// gcc 3.x can't handle including the HashMap pointer specialization in this file +#if defined __GNUC__ && !defined __GLIBCXX__ // less than gcc 3.4 +#define HASH_MAP_PTR_SPEC_WORKAROUND 1 +#endif + +#include "config.h" +#include "JSDOMBinding.h" + +#include "ActiveDOMObject.h" +#include "DOMCoreException.h" +#include "Document.h" +#include "EventException.h" +#include "ExceptionCode.h" +#include "Frame.h" +#include "HTMLImageElement.h" +#include "HTMLNames.h" +#include "JSDOMCoreException.h" +#include "JSDOMWindowCustom.h" +#include "JSEventException.h" +#include "JSNode.h" +#include "JSRangeException.h" +#include "JSXMLHttpRequestException.h" +#include "KURL.h" +#include "MessagePort.h" +#include "RangeException.h" +#include "ScriptController.h" +#include "XMLHttpRequestException.h" +#include <runtime/PrototypeFunction.h> +#include <wtf/StdLibExtras.h> + +#if ENABLE(SVG) +#include "JSSVGException.h" +#include "SVGException.h" +#endif + +#if ENABLE(XPATH) +#include "JSXPathException.h" +#include "XPathException.h" +#endif + +#if ENABLE(WORKERS) +#include <wtf/ThreadSpecific.h> +using namespace WTF; +#endif + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +typedef Document::JSWrapperCache JSWrapperCache; + +// For debugging, keep a set of wrappers currently registered, and check that +// all are unregistered before they are destroyed. This has helped us fix at +// least one bug. + +static void addWrapper(DOMObject* wrapper); +static void removeWrapper(DOMObject* wrapper); +static void removeWrappers(const JSWrapperCache& wrappers); + +#ifdef NDEBUG + +static inline void addWrapper(DOMObject*) +{ +} + +static inline void removeWrapper(DOMObject*) +{ +} + +static inline void removeWrappers(const JSWrapperCache&) +{ +} + +#else + +static HashSet<DOMObject*>& wrapperSet() +{ +#if ENABLE(WORKERS) + DEFINE_STATIC_LOCAL(ThreadSpecific<HashSet<DOMObject*> >, staticWrapperSet, ()); + return *staticWrapperSet; +#else + DEFINE_STATIC_LOCAL(HashSet<DOMObject*>, staticWrapperSet, ()); + return staticWrapperSet; +#endif +} + +static void addWrapper(DOMObject* wrapper) +{ + ASSERT(!wrapperSet().contains(wrapper)); + wrapperSet().add(wrapper); +} + +static void removeWrapper(DOMObject* wrapper) +{ + if (!wrapper) + return; + ASSERT(wrapperSet().contains(wrapper)); + wrapperSet().remove(wrapper); +} + +static void removeWrappers(const JSWrapperCache& wrappers) +{ + for (JSWrapperCache::const_iterator it = wrappers.begin(); it != wrappers.end(); ++it) + removeWrapper(it->second); +} + +DOMObject::~DOMObject() +{ + ASSERT(!wrapperSet().contains(this)); +} + +#endif + +class DOMObjectWrapperMap { +public: + static DOMObjectWrapperMap& mapFor(JSGlobalData&); + + DOMObject* get(void* objectHandle) + { + return m_map.get(objectHandle); + } + + void set(void* objectHandle, DOMObject* wrapper) + { + addWrapper(wrapper); + m_map.set(objectHandle, wrapper); + } + + void remove(void* objectHandle) + { + removeWrapper(m_map.take(objectHandle)); + } + +private: + HashMap<void*, DOMObject*> m_map; +}; + +// Map from static HashTable instances to per-GlobalData ones. +class DOMObjectHashTableMap { +public: + static DOMObjectHashTableMap& mapFor(JSGlobalData&); + + ~DOMObjectHashTableMap() + { + HashMap<const JSC::HashTable*, JSC::HashTable>::iterator mapEnd = m_map.end(); + for (HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.begin(); iter != m_map.end(); ++iter) + iter->second.deleteTable(); + } + + const JSC::HashTable* get(const JSC::HashTable* staticTable) + { + HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.find(staticTable); + if (iter != m_map.end()) + return &iter->second; + return &m_map.set(staticTable, JSC::HashTable(*staticTable)).first->second; + } + +private: + HashMap<const JSC::HashTable*, JSC::HashTable> m_map; +}; + +class WebCoreJSClientData : public JSGlobalData::ClientData { +public: + DOMObjectHashTableMap hashTableMap; + DOMObjectWrapperMap wrapperMap; +}; + +DOMObjectHashTableMap& DOMObjectHashTableMap::mapFor(JSGlobalData& globalData) +{ + JSGlobalData::ClientData* clientData = globalData.clientData; + if (!clientData) { + clientData = new WebCoreJSClientData; + globalData.clientData = clientData; + } + return static_cast<WebCoreJSClientData*>(clientData)->hashTableMap; +} + +const JSC::HashTable* getHashTableForGlobalData(JSGlobalData& globalData, const JSC::HashTable* staticTable) +{ + return DOMObjectHashTableMap::mapFor(globalData).get(staticTable); +} + +inline DOMObjectWrapperMap& DOMObjectWrapperMap::mapFor(JSGlobalData& globalData) +{ + JSGlobalData::ClientData* clientData = globalData.clientData; + if (!clientData) { + clientData = new WebCoreJSClientData; + globalData.clientData = clientData; + } + return static_cast<WebCoreJSClientData*>(clientData)->wrapperMap; +} + +DOMObject* getCachedDOMObjectWrapper(JSGlobalData& globalData, void* objectHandle) +{ + return DOMObjectWrapperMap::mapFor(globalData).get(objectHandle); +} + +void cacheDOMObjectWrapper(JSGlobalData& globalData, void* objectHandle, DOMObject* wrapper) +{ + DOMObjectWrapperMap::mapFor(globalData).set(objectHandle, wrapper); +} + +void forgetDOMObject(JSGlobalData& globalData, void* objectHandle) +{ + DOMObjectWrapperMap::mapFor(globalData).remove(objectHandle); +} + +JSNode* getCachedDOMNodeWrapper(Document* document, Node* node) +{ + if (!document) + return static_cast<JSNode*>(DOMObjectWrapperMap::mapFor(*JSDOMWindow::commonJSGlobalData()).get(node)); + return document->wrapperCache().get(node); +} + +void forgetDOMNode(Document* document, Node* node) +{ + if (!document) { + DOMObjectWrapperMap::mapFor(*JSDOMWindow::commonJSGlobalData()).remove(node); + return; + } + removeWrapper(document->wrapperCache().take(node)); +} + +void cacheDOMNodeWrapper(Document* document, Node* node, JSNode* wrapper) +{ + if (!document) { + DOMObjectWrapperMap::mapFor(*JSDOMWindow::commonJSGlobalData()).set(node, wrapper); + return; + } + addWrapper(wrapper); + document->wrapperCache().set(node, wrapper); +} + +void forgetAllDOMNodesForDocument(Document* document) +{ + ASSERT(document); + removeWrappers(document->wrapperCache()); +} + +void markDOMNodesForDocument(Document* doc) +{ + // If a node's JS wrapper holds custom properties, those properties must + // persist every time the node is fetched from the DOM. So, we keep JS + // wrappers like that from being garbage collected. + + JSWrapperCache& nodeDict = doc->wrapperCache(); + JSWrapperCache::iterator nodeEnd = nodeDict.end(); + for (JSWrapperCache::iterator nodeIt = nodeDict.begin(); nodeIt != nodeEnd; ++nodeIt) { + JSNode* jsNode = nodeIt->second; + Node* node = jsNode->impl(); + + if (jsNode->marked()) + continue; + + // No need to preserve a wrapper that has no custom properties or is no + // longer fetchable through the DOM. + if (!jsNode->hasCustomProperties() || !node->inDocument()) { + //... unless the wrapper wraps a loading image, since the "new Image" + // syntax allows an orphan image wrapper to be the last reference + // to a loading image, whose load event might have important side-effects. + if (!node->hasTagName(imgTag) || static_cast<HTMLImageElement*>(node)->haveFiredLoadEvent()) + continue; + } + + jsNode->mark(); + } +} + +void markActiveObjectsForContext(JSGlobalData& globalData, ScriptExecutionContext* scriptExecutionContext) +{ + // If an element has pending activity that may result in event listeners being called + // (e.g. an XMLHttpRequest), we need to keep JS wrappers alive. + + const HashMap<ActiveDOMObject*, void*>& activeObjects = scriptExecutionContext->activeDOMObjects(); + HashMap<ActiveDOMObject*, void*>::const_iterator activeObjectsEnd = activeObjects.end(); + for (HashMap<ActiveDOMObject*, void*>::const_iterator iter = activeObjects.begin(); iter != activeObjectsEnd; ++iter) { + if (iter->first->hasPendingActivity()) { + DOMObject* wrapper = getCachedDOMObjectWrapper(globalData, iter->second); + // Generally, an active object with pending activity must have a wrapper to mark its listeners. + // However, some ActiveDOMObjects don't have JS wrappers (timers created by setTimeout is one example). + // FIXME: perhaps need to make sure even timers have a markable 'wrapper'. + if (wrapper && !wrapper->marked()) + wrapper->mark(); + } + } + + const HashSet<MessagePort*>& messagePorts = scriptExecutionContext->messagePorts(); + HashSet<MessagePort*>::const_iterator portsEnd = messagePorts.end(); + for (HashSet<MessagePort*>::const_iterator iter = messagePorts.begin(); iter != portsEnd; ++iter) { + if ((*iter)->hasPendingActivity()) { + DOMObject* wrapper = getCachedDOMObjectWrapper(globalData, *iter); + // A port with pending activity must have a wrapper to mark its listeners, so no null check. + if (!wrapper->marked()) + wrapper->mark(); + } + } +} + +void updateDOMNodeDocument(Node* node, Document* oldDocument, Document* newDocument) +{ + ASSERT(oldDocument != newDocument); + JSNode* wrapper = getCachedDOMNodeWrapper(oldDocument, node); + if (!wrapper) + return; + removeWrapper(wrapper); + cacheDOMNodeWrapper(newDocument, node, wrapper); + forgetDOMNode(oldDocument, node); + addWrapper(wrapper); +} + +void markDOMObjectWrapper(JSGlobalData& globalData, void* object) +{ + if (!object) + return; + DOMObject* wrapper = getCachedDOMObjectWrapper(globalData, object); + if (!wrapper || wrapper->marked()) + return; + wrapper->mark(); +} + +JSValuePtr jsStringOrNull(ExecState* exec, const String& s) +{ + if (s.isNull()) + return jsNull(); + return jsString(exec, s); +} + +JSValuePtr jsOwnedStringOrNull(ExecState* exec, const UString& s) +{ + if (s.isNull()) + return jsNull(); + return jsOwnedString(exec, s); +} + +JSValuePtr jsStringOrUndefined(ExecState* exec, const String& s) +{ + if (s.isNull()) + return jsUndefined(); + return jsString(exec, s); +} + +JSValuePtr jsStringOrFalse(ExecState* exec, const String& s) +{ + if (s.isNull()) + return jsBoolean(false); + return jsString(exec, s); +} + +JSValuePtr jsStringOrNull(ExecState* exec, const KURL& url) +{ + if (url.isNull()) + return jsNull(); + return jsString(exec, url.string()); +} + +JSValuePtr jsStringOrUndefined(ExecState* exec, const KURL& url) +{ + if (url.isNull()) + return jsUndefined(); + return jsString(exec, url.string()); +} + +JSValuePtr jsStringOrFalse(ExecState* exec, const KURL& url) +{ + if (url.isNull()) + return jsBoolean(false); + return jsString(exec, url.string()); +} + +UString valueToStringWithNullCheck(ExecState* exec, JSValuePtr value) +{ + if (value->isNull()) + return UString(); + return value->toString(exec); +} + +UString valueToStringWithUndefinedOrNullCheck(ExecState* exec, JSValuePtr value) +{ + if (value->isUndefinedOrNull()) + return UString(); + return value->toString(exec); +} + +void reportException(JSC::ExecState* exec, JSValuePtr exception) +{ + UString errorMessage = exception->toString(exec); + JSObject* exceptionObject = exception->toObject(exec); + int lineNumber = exceptionObject->get(exec, Identifier(exec, "line"))->toInt32(exec); + UString exceptionSourceURL = exceptionObject->get(exec, Identifier(exec, "sourceURL"))->toString(exec); + exec->clearException(); + + ScriptExecutionContext* scriptExecutionContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); + scriptExecutionContext->reportException(errorMessage, lineNumber, exceptionSourceURL); +} + +void reportCurrentException(JSC::ExecState* exec) +{ + JSValuePtr exception = exec->exception(); + exec->clearException(); + reportException(exec, exception); +} + +void setDOMException(ExecState* exec, ExceptionCode ec) +{ + if (!ec || exec->hadException()) + return; + + ExceptionCodeDescription description; + getExceptionCodeDescription(ec, description); + + JSValuePtr errorObject = noValue(); + switch (description.type) { + case DOMExceptionType: + errorObject = toJS(exec, DOMCoreException::create(description)); + break; + case RangeExceptionType: + errorObject = toJS(exec, RangeException::create(description)); + break; + case EventExceptionType: + errorObject = toJS(exec, EventException::create(description)); + break; + case XMLHttpRequestExceptionType: + errorObject = toJS(exec, XMLHttpRequestException::create(description)); + break; +#if ENABLE(SVG) + case SVGExceptionType: + errorObject = toJS(exec, SVGException::create(description).get(), 0); + break; +#endif +#if ENABLE(XPATH) + case XPathExceptionType: + errorObject = toJS(exec, XPathException::create(description)); + break; +#endif + } + + ASSERT(errorObject); + exec->setException(errorObject); +} + +bool checkNodeSecurity(ExecState* exec, Node* node) +{ + return node && allowsAccessFromFrame(exec, node->document()->frame()); +} + +bool allowsAccessFromFrame(ExecState* exec, Frame* frame) +{ + if (!frame) + return false; + JSDOMWindow* window = toJSDOMWindow(frame); + return window && window->allowsAccessFrom(exec); +} + +bool allowsAccessFromFrame(ExecState* exec, Frame* frame, String& message) +{ + if (!frame) + return false; + JSDOMWindow* window = toJSDOMWindow(frame); + return window && window->allowsAccessFrom(exec, message); +} + +void printErrorMessageForFrame(Frame* frame, const String& message) +{ + if (!frame) + return; + if (JSDOMWindow* window = toJSDOMWindow(frame)) + window->printErrorMessage(message); +} + +JSValuePtr objectToStringFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 0, propertyName, objectProtoFuncToString); +} + +ScriptState* scriptStateFromNode(Node* node) +{ + if (!node) + return 0; + Document* document = node->document(); + if (!document) + return 0; + Frame* frame = document->frame(); + if (!frame) + return 0; + if (!frame->script()->isEnabled()) + return 0; + return frame->script()->globalObject()->globalExec(); +} + +Structure* getCachedDOMStructure(ExecState* exec, const ClassInfo* classInfo) +{ + JSDOMStructureMap& structures = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->structures(); + return structures.get(classInfo).get(); +} + +Structure* cacheDOMStructure(ExecState* exec, PassRefPtr<Structure> structure, const ClassInfo* classInfo) +{ + JSDOMStructureMap& structures = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->structures(); + ASSERT(!structures.contains(classInfo)); + return structures.set(classInfo, structure).first->second.get(); +} + +JSObject* getCachedDOMConstructor(ExecState* exec, const ClassInfo* classInfo) +{ + JSDOMConstructorMap& constructors = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->constructors(); + return constructors.get(classInfo); +} + +void cacheDOMConstructor(ExecState* exec, const ClassInfo* classInfo, JSObject* constructor) +{ + JSDOMConstructorMap& constructors = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->constructors(); + ASSERT(!constructors.contains(classInfo)); + constructors.set(classInfo, constructor); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h new file mode 100644 index 0000000..71da21b --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMBinding.h @@ -0,0 +1,188 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSDOMBinding_h +#define JSDOMBinding_h + +#include "JSDOMGlobalObject.h" +#include <runtime/Completion.h> +#include <runtime/Lookup.h> +#include <runtime/JSFunction.h> +#include "ScriptState.h" +#include <wtf/Noncopyable.h> + +namespace JSC { + class JSGlobalData; +} + +namespace WebCore { + + class Document; + class Frame; + class KURL; + class Node; + class String; + class JSNode; + + typedef int ExceptionCode; + +#if ENABLE(SVG) + class SVGElement; +#endif + + // Base class for all objects in this binding except Window. + class DOMObject : public JSC::JSObject { + protected: + explicit DOMObject(PassRefPtr<JSC::Structure> structure) + : JSObject(structure) + { + } + +#ifndef NDEBUG + virtual ~DOMObject(); +#endif + }; + + DOMObject* getCachedDOMObjectWrapper(JSC::JSGlobalData&, void* objectHandle); + void cacheDOMObjectWrapper(JSC::JSGlobalData&, void* objectHandle, DOMObject* wrapper); + void forgetDOMObject(JSC::JSGlobalData&, void* objectHandle); + + JSNode* getCachedDOMNodeWrapper(Document*, Node*); + void cacheDOMNodeWrapper(Document*, Node*, JSNode* wrapper); + void forgetDOMNode(Document*, Node*); + void forgetAllDOMNodesForDocument(Document*); + void updateDOMNodeDocument(Node*, Document* oldDocument, Document* newDocument); + void markDOMNodesForDocument(Document*); + void markActiveObjectsForContext(JSC::JSGlobalData&, ScriptExecutionContext*); + void markDOMObjectWrapper(JSC::JSGlobalData& globalData, void* object); + + JSC::Structure* getCachedDOMStructure(JSC::ExecState*, const JSC::ClassInfo*); + JSC::Structure* cacheDOMStructure(JSC::ExecState*, PassRefPtr<JSC::Structure>, const JSC::ClassInfo*); + + JSC::JSObject* getCachedDOMConstructor(JSC::ExecState*, const JSC::ClassInfo*); + void cacheDOMConstructor(JSC::ExecState*, const JSC::ClassInfo*, JSC::JSObject* constructor); + + template<class WrapperClass> inline JSC::Structure* getDOMStructure(JSC::ExecState* exec) + { + if (JSC::Structure* structure = getCachedDOMStructure(exec, &WrapperClass::s_info)) + return structure; + return cacheDOMStructure(exec, WrapperClass::createStructure(WrapperClass::createPrototype(exec)), &WrapperClass::s_info); + } + template<class WrapperClass> inline JSC::JSObject* getDOMPrototype(JSC::ExecState* exec) + { + return static_cast<JSC::JSObject*>(asObject(getDOMStructure<WrapperClass>(exec)->storedPrototype())); + } + #define CREATE_DOM_OBJECT_WRAPPER(exec, className, object) createDOMObjectWrapper<JS##className>(exec, static_cast<className*>(object)) + template<class WrapperClass, class DOMClass> inline DOMObject* createDOMObjectWrapper(JSC::ExecState* exec, DOMClass* object) + { + ASSERT(object); + ASSERT(!getCachedDOMObjectWrapper(exec->globalData(), object)); + WrapperClass* wrapper = new (exec) WrapperClass(getDOMStructure<WrapperClass>(exec), object); + cacheDOMObjectWrapper(exec->globalData(), object, wrapper); + return wrapper; + } + template<class WrapperClass, class DOMClass> inline JSC::JSValuePtr getDOMObjectWrapper(JSC::ExecState* exec, DOMClass* object) + { + if (!object) + return JSC::jsNull(); + if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), object)) + return wrapper; + return createDOMObjectWrapper<WrapperClass>(exec, object); + } + +#if ENABLE(SVG) + #define CREATE_SVG_OBJECT_WRAPPER(exec, className, object, context) createDOMObjectWrapper<JS##className>(exec, static_cast<className*>(object), context) + template<class WrapperClass, class DOMClass> inline DOMObject* createDOMObjectWrapper(JSC::ExecState* exec, DOMClass* object, SVGElement* context) + { + ASSERT(object); + ASSERT(!getCachedDOMObjectWrapper(exec->globalData(), object)); + WrapperClass* wrapper = new (exec) WrapperClass(getDOMStructure<WrapperClass>(exec), object, context); + cacheDOMObjectWrapper(exec->globalData(), object, wrapper); + return wrapper; + } + template<class WrapperClass, class DOMClass> inline JSC::JSValuePtr getDOMObjectWrapper(JSC::ExecState* exec, DOMClass* object, SVGElement* context) + { + if (!object) + return JSC::jsNull(); + if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), object)) + return wrapper; + return createDOMObjectWrapper<WrapperClass>(exec, object, context); + } +#endif + + #define CREATE_DOM_NODE_WRAPPER(exec, className, object) createDOMNodeWrapper<JS##className>(exec, static_cast<className*>(object)) + template<class WrapperClass, class DOMClass> inline JSNode* createDOMNodeWrapper(JSC::ExecState* exec, DOMClass* node) + { + ASSERT(node); + ASSERT(!getCachedDOMNodeWrapper(node->document(), node)); + WrapperClass* wrapper = new (exec) WrapperClass(getDOMStructure<WrapperClass>(exec), node); + cacheDOMNodeWrapper(node->document(), node, wrapper); + return wrapper; + } + template<class WrapperClass, class DOMClass> inline JSC::JSValuePtr getDOMNodeWrapper(JSC::ExecState* exec, DOMClass* node) + { + if (!node) + return JSC::jsNull(); + if (JSNode* wrapper = getCachedDOMNodeWrapper(node->document(), node)) + return wrapper; + return createDOMNodeWrapper<WrapperClass>(exec, node); + } + + const JSC::HashTable* getHashTableForGlobalData(JSC::JSGlobalData&, const JSC::HashTable* staticTable); + + void reportException(JSC::ExecState*, JSC::JSValuePtr exception); + void reportCurrentException(JSC::ExecState*); + + // Convert a DOM implementation exception code into a JavaScript exception in the execution state. + void setDOMException(JSC::ExecState*, ExceptionCode); + + JSC::JSValuePtr jsStringOrNull(JSC::ExecState*, const String&); // null if the string is null + JSC::JSValuePtr jsStringOrNull(JSC::ExecState*, const KURL&); // null if the URL is null + + JSC::JSValuePtr jsStringOrUndefined(JSC::ExecState*, const String&); // undefined if the string is null + JSC::JSValuePtr jsStringOrUndefined(JSC::ExecState*, const KURL&); // undefined if the URL is null + + JSC::JSValuePtr jsStringOrFalse(JSC::ExecState*, const String&); // boolean false if the string is null + JSC::JSValuePtr jsStringOrFalse(JSC::ExecState*, const KURL&); // boolean false if the URL is null + + // See JavaScriptCore for explanation: Should be used for any UString that is already owned by another + // object, to let the engine know that collecting the JSString wrapper is unlikely to save memory. + JSC::JSValuePtr jsOwnedStringOrNull(JSC::ExecState*, const JSC::UString&); + + JSC::UString valueToStringWithNullCheck(JSC::ExecState*, JSC::JSValuePtr); // null if the value is null + JSC::UString valueToStringWithUndefinedOrNullCheck(JSC::ExecState*, JSC::JSValuePtr); // null if the value is null or undefined + + template <typename T> inline JSC::JSValuePtr toJS(JSC::ExecState* exec, PassRefPtr<T> ptr) { return toJS(exec, ptr.get()); } + + bool checkNodeSecurity(JSC::ExecState*, Node*); + + // Helpers for Window, History, and Location classes to implement cross-domain policy. + // Besides the cross-domain check, they need non-caching versions of staticFunctionGetter for + // because we do not want current property values involved at all. + bool allowsAccessFromFrame(JSC::ExecState*, Frame*); + bool allowsAccessFromFrame(JSC::ExecState*, Frame*, String& message); + void printErrorMessageForFrame(Frame*, const String& message); + JSC::JSValuePtr objectToStringFunctionGetter(JSC::ExecState*, const JSC::Identifier& propertyName, const JSC::PropertySlot&); + + ScriptState* scriptStateFromNode(Node*); + +} // namespace WebCore + +#endif // JSDOMBinding_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMGlobalObject.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMGlobalObject.cpp new file mode 100644 index 0000000..ae339ed --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMGlobalObject.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSDOMGlobalObject.h" + +#include "Document.h" +#include "JSDOMWindow.h" +#include "JSEventListener.h" +#include "JSWorkerContext.h" +#include "WorkerContext.h" + +using namespace JSC; + +namespace WebCore { + +JSDOMGlobalObject::JSDOMGlobalObjectData::JSDOMGlobalObjectData() + : evt(0) +{ +} + +JSDOMGlobalObject::JSDOMGlobalObject(PassRefPtr<Structure> structure, JSDOMGlobalObject::JSDOMGlobalObjectData* data, JSObject* thisValue) + : JSGlobalObject(structure, data, thisValue) +{ +} + +JSDOMGlobalObject::~JSDOMGlobalObject() +{ + // Clear any backpointers to the window + ListenersMap::iterator i1 = d()->jsEventListeners.begin(); + ListenersMap::iterator e1 = d()->jsEventListeners.end(); + for (; i1 != e1; ++i1) + i1->second->clearGlobalObject(); + + i1 = d()->jsInlineEventListeners.begin(); + e1 = d()->jsInlineEventListeners.end(); + for (; i1 != e1; ++i1) + i1->second->clearGlobalObject(); + + UnprotectedListenersMap::iterator i2 = d()->jsUnprotectedEventListeners.begin(); + UnprotectedListenersMap::iterator e2 = d()->jsUnprotectedEventListeners.end(); + for (; i2 != e2; ++i2) + i2->second->clearGlobalObject(); + + i2 = d()->jsUnprotectedInlineEventListeners.begin(); + e2 = d()->jsUnprotectedInlineEventListeners.end(); + for (; i2 != e2; ++i2) + i2->second->clearGlobalObject(); +} + +void JSDOMGlobalObject::mark() +{ + Base::mark(); + + JSDOMStructureMap::iterator end = structures().end(); + for (JSDOMStructureMap::iterator it = structures().begin(); it != end; ++it) + it->second->mark(); + + JSDOMConstructorMap::iterator end2 = constructors().end(); + for (JSDOMConstructorMap::iterator it2 = constructors().begin(); it2 != end2; ++it2) { + if (!it2->second->marked()) + it2->second->mark(); + } +} + +JSEventListener* JSDOMGlobalObject::findJSEventListener(JSValuePtr val, bool isInline) +{ + if (!val->isObject()) + return 0; + JSObject* object = asObject(val); + ListenersMap& listeners = isInline ? d()->jsInlineEventListeners : d()->jsEventListeners; + return listeners.get(object); +} + +PassRefPtr<JSEventListener> JSDOMGlobalObject::findOrCreateJSEventListener(ExecState*, JSValuePtr val, bool isInline) +{ + if (JSEventListener* listener = findJSEventListener(val, isInline)) + return listener; + + if (!val->isObject()) + return 0; + + // The JSEventListener constructor adds it to our jsEventListeners map. + return JSEventListener::create(asObject(val), this, isInline).get(); +} + +JSUnprotectedEventListener* JSDOMGlobalObject::findJSUnprotectedEventListener(ExecState*, JSValuePtr val, bool isInline) +{ + if (!val->isObject()) + return 0; + + UnprotectedListenersMap& listeners = isInline ? d()->jsUnprotectedInlineEventListeners : d()->jsUnprotectedEventListeners; + return listeners.get(asObject(val)); +} + +PassRefPtr<JSUnprotectedEventListener> JSDOMGlobalObject::findOrCreateJSUnprotectedEventListener(ExecState* exec, JSValuePtr val, bool isInline) +{ + if (JSUnprotectedEventListener* listener = findJSUnprotectedEventListener(exec, val, isInline)) + return listener; + + if (!val->isObject()) + return 0; + + // The JSUnprotectedEventListener constructor adds it to our jsUnprotectedEventListeners map. + return JSUnprotectedEventListener::create(asObject(val), this, isInline).get(); +} + +JSDOMGlobalObject::ListenersMap& JSDOMGlobalObject::jsEventListeners() +{ + return d()->jsEventListeners; +} + +JSDOMGlobalObject::ListenersMap& JSDOMGlobalObject::jsInlineEventListeners() +{ + return d()->jsInlineEventListeners; +} + +JSDOMGlobalObject::UnprotectedListenersMap& JSDOMGlobalObject::jsUnprotectedEventListeners() +{ + return d()->jsUnprotectedEventListeners; +} + +JSDOMGlobalObject::UnprotectedListenersMap& JSDOMGlobalObject::jsUnprotectedInlineEventListeners() +{ + return d()->jsUnprotectedInlineEventListeners; +} + +void JSDOMGlobalObject::setCurrentEvent(Event* evt) +{ + d()->evt = evt; +} + +Event* JSDOMGlobalObject::currentEvent() +{ + return d()->evt; +} + +JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext) +{ + if (scriptExecutionContext->isDocument()) + return toJSDOMWindow(static_cast<Document*>(scriptExecutionContext)->frame()); + +#if ENABLE(WORKERS) + if (scriptExecutionContext->isWorkerContext()) + return static_cast<WorkerContext*>(scriptExecutionContext)->script()->workerContextWrapper(); +#endif + + ASSERT_NOT_REACHED(); + return 0; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMGlobalObject.h b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMGlobalObject.h new file mode 100644 index 0000000..fbb3eb9 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMGlobalObject.h @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSDOMGlobalObject_h +#define JSDOMGlobalObject_h + +#include <runtime/JSGlobalObject.h> + +namespace WebCore { + + class Event; + class JSEventListener; + class JSUnprotectedEventListener; + class ScriptExecutionContext; + + typedef HashMap<const JSC::ClassInfo*, RefPtr<JSC::Structure> > JSDOMStructureMap; + typedef HashMap<const JSC::ClassInfo*, JSC::JSObject*> JSDOMConstructorMap; + + class JSDOMGlobalObject : public JSC::JSGlobalObject { + typedef JSC::JSGlobalObject Base; + protected: + struct JSDOMGlobalObjectData; + + JSDOMGlobalObject(PassRefPtr<JSC::Structure>, JSDOMGlobalObjectData*, JSC::JSObject* thisValue); + virtual ~JSDOMGlobalObject(); + + public: + JSDOMStructureMap& structures() { return d()->structures; } + JSDOMConstructorMap& constructors() const { return d()->constructors; } + + virtual ScriptExecutionContext* scriptExecutionContext() const = 0; + + // Finds a wrapper of a JS EventListener, returns 0 if no existing one. + JSEventListener* findJSEventListener(JSC::JSValuePtr, bool isInline = false); + + // Finds or creates a wrapper of a JS EventListener. JS EventListener object is GC-protected. + PassRefPtr<JSEventListener> findOrCreateJSEventListener(JSC::ExecState*, JSC::JSValuePtr, bool isInline = false); + + // Finds a wrapper of a GC-unprotected JS EventListener, returns 0 if no existing one. + JSUnprotectedEventListener* findJSUnprotectedEventListener(JSC::ExecState*, JSC::JSValuePtr, bool isInline = false); + + // Finds or creates a wrapper of a JS EventListener. JS EventListener object is *NOT* GC-protected. + PassRefPtr<JSUnprotectedEventListener> findOrCreateJSUnprotectedEventListener(JSC::ExecState*, JSC::JSValuePtr, bool isInline = false); + + typedef HashMap<JSC::JSObject*, JSEventListener*> ListenersMap; + typedef HashMap<JSC::JSObject*, JSUnprotectedEventListener*> UnprotectedListenersMap; + + ListenersMap& jsEventListeners(); + ListenersMap& jsInlineEventListeners(); + UnprotectedListenersMap& jsUnprotectedEventListeners(); + UnprotectedListenersMap& jsUnprotectedInlineEventListeners(); + + void setCurrentEvent(Event*); + Event* currentEvent(); + + virtual void mark(); + + protected: + struct JSDOMGlobalObjectData : public JSC::JSGlobalObject::JSGlobalObjectData { + JSDOMGlobalObjectData(); + + JSDOMStructureMap structures; + JSDOMConstructorMap constructors; + + JSDOMGlobalObject::ListenersMap jsEventListeners; + JSDOMGlobalObject::ListenersMap jsInlineEventListeners; + JSDOMGlobalObject::UnprotectedListenersMap jsUnprotectedEventListeners; + JSDOMGlobalObject::UnprotectedListenersMap jsUnprotectedInlineEventListeners; + + Event* evt; + }; + + private: + JSDOMGlobalObjectData* d() const { return static_cast<JSDOMGlobalObjectData*>(JSC::JSVariableObject::d); } + }; + + template<class ConstructorClass> + inline JSC::JSObject* getDOMConstructor(JSC::ExecState* exec) + { + if (JSC::JSObject* constructor = getCachedDOMConstructor(exec, &ConstructorClass::s_info)) + return constructor; + JSC::JSObject* constructor = new (exec) ConstructorClass(exec); + cacheDOMConstructor(exec, &ConstructorClass::s_info, constructor); + return constructor; + } + + template<class ConstructorClass> + inline JSC::JSObject* getDOMConstructor(JSC::ExecState* exec, JSDOMGlobalObject* globalObject) + { + if (JSC::JSObject* constructor = globalObject->constructors().get(&ConstructorClass::s_info)) + return constructor; + JSC::JSObject* constructor = new (exec) ConstructorClass(exec, globalObject->scriptExecutionContext()); + ASSERT(!globalObject->constructors().contains(&ConstructorClass::s_info)); + globalObject->constructors().set(&ConstructorClass::s_info, constructor); + return constructor; + } + + JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext*); + +} // namespace WebCore + +#endif // JSDOMGlobalObject_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMStringListCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMStringListCustom.cpp new file mode 100644 index 0000000..ccf0ce8 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMStringListCustom.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2009 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSDOMStringList.h" + +#include "DOMStringList.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSDOMStringList::getByIndex(ExecState* exec, unsigned index) +{ + return jsString(exec, impl()->item(index)); +} + +JSValuePtr JSDOMStringList::item(ExecState* exec, const ArgList& args) +{ + unsigned index = args.at(exec, 0)->toUInt32(exec); + if (index >= impl()->length()) + return jsNull(); + + return jsString(exec, impl()->item(index)); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowBase.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowBase.cpp new file mode 100644 index 0000000..10fc022 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowBase.cpp @@ -0,0 +1,875 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2006 Jon Shier (jshier@iastate.edu) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved. + * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include "config.h" +#include "JSDOMWindowBase.h" + +#include "CString.h" +#include "Console.h" +#include "DOMTimer.h" +#include "DOMWindow.h" +#include "Element.h" +#include "EventListener.h" +#include "ExceptionCode.h" +#include "FloatRect.h" +#include "Frame.h" +#include "FrameLoadRequest.h" +#include "FrameLoader.h" +#include "FrameTree.h" +#include "GCController.h" +#include "HTMLDocument.h" +#include "InspectorController.h" +#include "JSAudioConstructor.h" +#include "JSDOMWindowCustom.h" +#include "JSEvent.h" +#include "JSEventListener.h" +#include "JSHTMLCollection.h" +#include "JSImageConstructor.h" +#include "JSMessageChannelConstructor.h" +#include "JSNode.h" +#include "JSOptionConstructor.h" +#include "JSWorkerConstructor.h" +#include "JSXMLHttpRequestConstructor.h" +#include "JSXSLTProcessorConstructor.h" +#include "Logging.h" +#include "MediaPlayer.h" +#include "Page.h" +#include "PlatformScreen.h" +#include "PluginInfoStore.h" +#include "RenderView.h" +#include "ScheduledAction.h" +#include "ScriptController.h" +#include "SecurityOrigin.h" +#include "Settings.h" +#include "WindowFeatures.h" +#include "htmlediting.h" +#include <runtime/Error.h> +#include <runtime/JSLock.h> +#include <wtf/AlwaysInline.h> +#include <wtf/MathExtras.h> + +using namespace JSC; + +static JSValuePtr windowProtoFuncOpen(ExecState*, JSObject*, JSValuePtr, const ArgList&); +static JSValuePtr windowProtoFuncShowModalDialog(ExecState*, JSObject*, JSValuePtr, const ArgList&); +static JSValuePtr windowProtoFuncNotImplemented(ExecState*, JSObject*, JSValuePtr, const ArgList&); + +static JSValuePtr jsDOMWindowBaseCrypto(ExecState*, const Identifier&, const PropertySlot&); +static JSValuePtr jsDOMWindowBaseEvent(ExecState*, const Identifier&, const PropertySlot&); +static void setJSDOMWindowBaseEvent(ExecState*, JSObject*, JSValuePtr); + +// Constructors +static JSValuePtr jsDOMWindowBaseAudio(ExecState*, const Identifier&, const PropertySlot&); +static void setJSDOMWindowBaseAudio(ExecState*, JSObject*, JSValuePtr); +static JSValuePtr jsDOMWindowBaseImage(ExecState*, const Identifier&, const PropertySlot&); +static void setJSDOMWindowBaseImage(ExecState*, JSObject*, JSValuePtr); +static JSValuePtr jsDOMWindowBaseMessageChannel(ExecState*, const Identifier&, const PropertySlot&); +static void setJSDOMWindowBaseMessageChannel(ExecState*, JSObject*, JSValuePtr); +static JSValuePtr jsDOMWindowBaseWorker(ExecState*, const Identifier&, const PropertySlot&); +static void setJSDOMWindowBaseWorker(ExecState*, JSObject*, JSValuePtr); +static JSValuePtr jsDOMWindowBaseOption(ExecState*, const Identifier&, const PropertySlot&); +static void setJSDOMWindowBaseOption(ExecState*, JSObject*, JSValuePtr); +static JSValuePtr jsDOMWindowBaseXMLHttpRequest(ExecState*, const Identifier&, const PropertySlot&); +static void setJSDOMWindowBaseXMLHttpRequest(ExecState*, JSObject*, JSValuePtr); +static JSValuePtr jsDOMWindowBaseXSLTProcessor(ExecState*, const Identifier&, const PropertySlot&); +static void setJSDOMWindowBaseXSLTProcessor(ExecState*, JSObject*, JSValuePtr); + +#include "JSDOMWindowBase.lut.h" + +namespace WebCore { + +////////////////////// JSDOMWindowBase Object //////////////////////// + +const ClassInfo JSDOMWindowBase::s_info = { "Window", 0, &JSDOMWindowBaseTable, 0 }; + +/* +@begin JSDOMWindowBaseTable +# -- Functions -- + open windowProtoFuncOpen DontDelete|Function 3 + showModalDialog windowProtoFuncShowModalDialog DontDelete|Function 1 +# Not implemented + captureEvents windowProtoFuncNotImplemented DontDelete|Function 0 + releaseEvents windowProtoFuncNotImplemented DontDelete|Function 0 +# -- Attributes -- + crypto jsDOMWindowBaseCrypto DontDelete|ReadOnly + event jsDOMWindowBaseEvent DontDelete +# -- Constructors -- + Audio jsDOMWindowBaseAudio DontDelete + Image jsDOMWindowBaseImage DontDelete + MessageChannel jsDOMWindowBaseMessageChannel DontDelete + Option jsDOMWindowBaseOption DontDelete + Worker jsDOMWindowBaseWorker DontDelete + XMLHttpRequest jsDOMWindowBaseXMLHttpRequest DontDelete + XSLTProcessor jsDOMWindowBaseXSLTProcessor DontDelete +@end +*/ + +JSDOMWindowBase::JSDOMWindowBaseData::JSDOMWindowBaseData(PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell) + : impl(window) + , returnValueSlot(0) + , shell(shell) +{ +} + +JSDOMWindowBase::JSDOMWindowBase(PassRefPtr<Structure> structure, PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell) + : JSDOMGlobalObject(structure, new JSDOMWindowBaseData(window, shell), shell) +{ + // Time in milliseconds before the script timeout handler kicks in. + setTimeoutTime(10000); + + GlobalPropertyInfo staticGlobals[] = { + GlobalPropertyInfo(Identifier(globalExec(), "document"), jsNull(), DontDelete | ReadOnly), + GlobalPropertyInfo(Identifier(globalExec(), "window"), d()->shell, DontDelete | ReadOnly) + }; + + addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo)); +} + +void JSDOMWindowBase::updateDocument() +{ + ASSERT(d()->impl->document()); + ExecState* exec = globalExec(); + symbolTablePutWithAttributes(Identifier(exec, "document"), toJS(exec, d()->impl->document()), DontDelete | ReadOnly); +} + +JSDOMWindowBase::~JSDOMWindowBase() +{ + if (d()->impl->frame()) + d()->impl->frame()->script()->clearFormerWindow(asJSDOMWindow(this)); +} + +ScriptExecutionContext* JSDOMWindowBase::scriptExecutionContext() const +{ + return d()->impl->document(); +} + +static bool allowPopUp(ExecState* exec) +{ + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + + ASSERT(frame); + if (frame->script()->processingUserGesture()) + return true; + Settings* settings = frame->settings(); + return settings && settings->JavaScriptCanOpenWindowsAutomatically(); +} + +static HashMap<String, String> parseModalDialogFeatures(const String& featuresArg) +{ + HashMap<String, String> map; + + Vector<String> features; + featuresArg.split(';', features); + Vector<String>::const_iterator end = features.end(); + for (Vector<String>::const_iterator it = features.begin(); it != end; ++it) { + String s = *it; + int pos = s.find('='); + int colonPos = s.find(':'); + if (pos >= 0 && colonPos >= 0) + continue; // ignore any strings that have both = and : + if (pos < 0) + pos = colonPos; + if (pos < 0) { + // null string for value means key without value + map.set(s.stripWhiteSpace().lower(), String()); + } else { + String key = s.left(pos).stripWhiteSpace().lower(); + String val = s.substring(pos + 1).stripWhiteSpace().lower(); + int spacePos = val.find(' '); + if (spacePos != -1) + val = val.left(spacePos); + map.set(key, val); + } + } + + return map; +} + +static Frame* createWindow(ExecState* exec, Frame* openerFrame, const String& url, + const String& frameName, const WindowFeatures& windowFeatures, JSValuePtr dialogArgs) +{ + Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + ASSERT(activeFrame); + + ResourceRequest request; + + request.setHTTPReferrer(activeFrame->loader()->outgoingReferrer()); + FrameLoader::addHTTPOriginIfNeeded(request, activeFrame->loader()->outgoingOrigin()); + FrameLoadRequest frameRequest(request, frameName); + + // FIXME: It's much better for client API if a new window starts with a URL, here where we + // know what URL we are going to open. Unfortunately, this code passes the empty string + // for the URL, but there's a reason for that. Before loading we have to set up the opener, + // openedByDOM, and dialogArguments values. Also, to decide whether to use the URL we currently + // do an allowsAccessFrom call using the window we create, which can't be done before creating it. + // We'd have to resolve all those issues to pass the URL instead of "". + + bool created; + // We pass in the opener frame here so it can be used for looking up the frame name, in case the active frame + // is different from the opener frame, and the name references a frame relative to the opener frame, for example + // "_self" or "_parent". + Frame* newFrame = activeFrame->loader()->createWindow(openerFrame->loader(), frameRequest, windowFeatures, created); + if (!newFrame) + return 0; + + newFrame->loader()->setOpener(openerFrame); + newFrame->loader()->setOpenedByDOM(); + + JSDOMWindow* newWindow = toJSDOMWindow(newFrame); + + if (dialogArgs) + newWindow->putDirect(Identifier(exec, "dialogArguments"), dialogArgs); + + if (!protocolIs(url, "javascript") || newWindow->allowsAccessFrom(exec)) { + KURL completedURL = url.isEmpty() ? KURL("") : activeFrame->document()->completeURL(url); + bool userGesture = activeFrame->script()->processingUserGesture(); + + if (created) + newFrame->loader()->changeLocation(completedURL, activeFrame->loader()->outgoingReferrer(), false, userGesture); + else if (!url.isEmpty()) + newFrame->loader()->scheduleLocationChange(completedURL.string(), activeFrame->loader()->outgoingReferrer(), false, userGesture); + } + + return newFrame; +} + +static bool canShowModalDialog(const Frame* frame) +{ + if (!frame) + return false; + + Page* page = frame->page(); + if (!page) + return false; + + return page->chrome()->canRunModal(); +} + +static bool canShowModalDialogNow(const Frame* frame) +{ + if (!frame) + return false; + + Page* page = frame->page(); + if (!page) + return false; + + return page->chrome()->canRunModalNow(); +} + +static JSValuePtr showModalDialog(ExecState* exec, Frame* frame, const String& url, JSValuePtr dialogArgs, const String& featureArgs) +{ + if (!canShowModalDialogNow(frame) || !allowPopUp(exec)) + return jsUndefined(); + + const HashMap<String, String> features = parseModalDialogFeatures(featureArgs); + + const bool trusted = false; + + // The following features from Microsoft's documentation are not implemented: + // - default font settings + // - width, height, left, and top specified in units other than "px" + // - edge (sunken or raised, default is raised) + // - dialogHide: trusted && boolFeature(features, "dialoghide"), makes dialog hide when you print + // - help: boolFeature(features, "help", true), makes help icon appear in dialog (what does it do on Windows?) + // - unadorned: trusted && boolFeature(features, "unadorned"); + + if (!frame) + return jsUndefined(); + + FloatRect screenRect = screenAvailableRect(frame->view()); + + WindowFeatures wargs; + wargs.width = WindowFeatures::floatFeature(features, "dialogwidth", 100, screenRect.width(), 620); // default here came from frame size of dialog in MacIE + wargs.widthSet = true; + wargs.height = WindowFeatures::floatFeature(features, "dialogheight", 100, screenRect.height(), 450); // default here came from frame size of dialog in MacIE + wargs.heightSet = true; + + wargs.x = WindowFeatures::floatFeature(features, "dialogleft", screenRect.x(), screenRect.right() - wargs.width, -1); + wargs.xSet = wargs.x > 0; + wargs.y = WindowFeatures::floatFeature(features, "dialogtop", screenRect.y(), screenRect.bottom() - wargs.height, -1); + wargs.ySet = wargs.y > 0; + + if (WindowFeatures::boolFeature(features, "center", true)) { + if (!wargs.xSet) { + wargs.x = screenRect.x() + (screenRect.width() - wargs.width) / 2; + wargs.xSet = true; + } + if (!wargs.ySet) { + wargs.y = screenRect.y() + (screenRect.height() - wargs.height) / 2; + wargs.ySet = true; + } + } + + wargs.dialog = true; + wargs.resizable = WindowFeatures::boolFeature(features, "resizable"); + wargs.scrollbarsVisible = WindowFeatures::boolFeature(features, "scroll", true); + wargs.statusBarVisible = WindowFeatures::boolFeature(features, "status", !trusted); + wargs.menuBarVisible = false; + wargs.toolBarVisible = false; + wargs.locationBarVisible = false; + wargs.fullscreen = false; + + Frame* dialogFrame = createWindow(exec, frame, url, "", wargs, dialogArgs); + if (!dialogFrame) + return jsUndefined(); + + JSDOMWindow* dialogWindow = toJSDOMWindow(dialogFrame); + + // Get the return value either just before clearing the dialog window's + // properties (in JSDOMWindowBase::clear), or when on return from runModal. + JSValuePtr returnValue = noValue(); + dialogWindow->setReturnValueSlot(&returnValue); + dialogFrame->page()->chrome()->runModal(); + dialogWindow->setReturnValueSlot(0); + + // If we don't have a return value, get it now. + // Either JSDOMWindowBase::clear was not called yet, or there was no return value, + // and in that case, there's no harm in trying again (no benefit either). + if (!returnValue) + returnValue = dialogWindow->getDirect(Identifier(exec, "returnValue")); + + return returnValue ? returnValue : jsUndefined(); +} + +} // namespace WebCore + +using namespace WebCore; + +JSValuePtr jsDOMWindowBaseCrypto(ExecState*, const Identifier&, const PropertySlot&) +{ + return jsUndefined(); // FIXME: implement this +} + +JSValuePtr jsDOMWindowBaseEvent(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + if (!static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->allowsAccessFrom(exec)) + return jsUndefined(); + if (!static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->currentEvent()) + return jsUndefined(); + return toJS(exec, static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->currentEvent()); +} + +JSValuePtr jsDOMWindowBaseImage(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + if (!static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->allowsAccessFrom(exec)) + return jsUndefined(); + return getDOMConstructor<JSImageConstructor>(exec, static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))); +} + +JSValuePtr jsDOMWindowBaseMessageChannel(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ +#if ENABLE(CHANNEL_MESSAGING) + if (!static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->allowsAccessFrom(exec)) + return jsUndefined(); + return getDOMConstructor<JSMessageChannelConstructor>(exec, static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))); +#else + return jsUndefined(); +#endif +} + +JSValuePtr jsDOMWindowBaseOption(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + if (!static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->allowsAccessFrom(exec)) + return jsUndefined(); + return getDOMConstructor<JSOptionConstructor>(exec, static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))); +} + +JSValuePtr jsDOMWindowBaseXMLHttpRequest(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + if (!static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->allowsAccessFrom(exec)) + return jsUndefined(); + return getDOMConstructor<JSXMLHttpRequestConstructor>(exec, static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))); +} + +JSValuePtr jsDOMWindowBaseAudio(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ +#if ENABLE(VIDEO) + if (!static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->allowsAccessFrom(exec)) + return jsUndefined(); + if (!MediaPlayer::isAvailable()) + return jsUndefined(); + return getDOMConstructor<JSAudioConstructor>(exec, static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))); +#else + return jsUndefined(); +#endif +} + +JSValuePtr jsDOMWindowBaseWorker(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ +#if ENABLE(WORKERS) + if (!static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->allowsAccessFrom(exec)) + return jsUndefined(); + return getDOMConstructor<JSWorkerConstructor>(exec); +#else + return jsUndefined(); +#endif +} + +JSValuePtr jsDOMWindowBaseXSLTProcessor(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ +#if ENABLE(XSLT) + if (!static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->allowsAccessFrom(exec)) + return jsUndefined(); + return getDOMConstructor<JSXSLTProcessorConstructor>(exec); +#else + return jsUndefined(); +#endif +} + +void setJSDOMWindowBaseEvent(ExecState* exec, JSObject* thisObject, JSValuePtr value) +{ + if (!static_cast<JSDOMWindowBase*>(thisObject)->allowsAccessFrom(exec)) + return; + // Shadowing a built-in constructor + static_cast<JSDOMWindowBase*>(thisObject)->putDirect(Identifier(exec, "Event"), value); +} + +void setJSDOMWindowBaseAudio(ExecState* exec, JSObject* thisObject, JSValuePtr value) +{ + if (!static_cast<JSDOMWindowBase*>(thisObject)->allowsAccessFrom(exec)) + return; + // Shadowing a built-in constructor + static_cast<JSDOMWindowBase*>(thisObject)->putDirect(Identifier(exec, "Audio"), value); +} + +void setJSDOMWindowBaseImage(ExecState* exec, JSObject* thisObject, JSValuePtr value) +{ + if (!static_cast<JSDOMWindowBase*>(thisObject)->allowsAccessFrom(exec)) + return; + // Shadowing a built-in constructor + static_cast<JSDOMWindowBase*>(thisObject)->putDirect(Identifier(exec, "Image"), value); +} + +void setJSDOMWindowBaseMessageChannel(ExecState* exec, JSObject* thisObject, JSValuePtr value) +{ + if (!static_cast<JSDOMWindowBase*>(thisObject)->allowsAccessFrom(exec)) + return; + // Shadowing a built-in constructor + static_cast<JSDOMWindowBase*>(thisObject)->putDirect(Identifier(exec, "MessageChannel"), value); +} + +void setJSDOMWindowBaseOption(ExecState* exec, JSObject* thisObject, JSValuePtr value) +{ + if (!static_cast<JSDOMWindowBase*>(thisObject)->allowsAccessFrom(exec)) + return; + // Shadowing a built-in constructor + static_cast<JSDOMWindowBase*>(thisObject)->putDirect(Identifier(exec, "Option"), value); +} + +void setJSDOMWindowBaseWorker(ExecState* exec, JSObject* thisObject, JSValuePtr value) +{ + if (!static_cast<JSDOMWindowBase*>(thisObject)->allowsAccessFrom(exec)) + return; + // Shadowing a built-in constructor + static_cast<JSDOMWindowBase*>(thisObject)->putDirect(Identifier(exec, "Worker"), value); +} + +void setJSDOMWindowBaseXMLHttpRequest(ExecState* exec, JSObject* thisObject, JSValuePtr value) +{ + if (!static_cast<JSDOMWindowBase*>(thisObject)->allowsAccessFrom(exec)) + return; + // Shadowing a built-in constructor + static_cast<JSDOMWindowBase*>(thisObject)->putDirect(Identifier(exec, "XMLHttpRequest"), value); +} + +void setJSDOMWindowBaseXSLTProcessor(ExecState* exec, JSObject* thisObject, JSValuePtr value) +{ + if (!static_cast<JSDOMWindowBase*>(thisObject)->allowsAccessFrom(exec)) + return; + // Shadowing a built-in constructor + static_cast<JSDOMWindowBase*>(thisObject)->putDirect(Identifier(exec, "XSLTProcessor"), value); +} + +namespace WebCore { + +JSValuePtr JSDOMWindowBase::childFrameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + return toJS(exec, static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->impl()->frame()->tree()->child(AtomicString(propertyName))->domWindow()); +} + +JSValuePtr JSDOMWindowBase::indexGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + return toJS(exec, static_cast<JSDOMWindowBase*>(asObject(slot.slotBase()))->impl()->frame()->tree()->child(slot.index())->domWindow()); +} + +JSValuePtr JSDOMWindowBase::namedItemGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSDOMWindowBase* thisObj = static_cast<JSDOMWindowBase*>(asObject(slot.slotBase())); + Document* doc = thisObj->impl()->frame()->document(); + ASSERT(thisObj->allowsAccessFrom(exec)); + ASSERT(doc); + ASSERT(doc->isHTMLDocument()); + + RefPtr<HTMLCollection> collection = doc->windowNamedItems(propertyName); + if (collection->length() == 1) + return toJS(exec, collection->firstItem()); + return toJS(exec, collection.get()); +} + +bool JSDOMWindowBase::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + // Check for child frames by name before built-in properties to + // match Mozilla. This does not match IE, but some sites end up + // naming frames things that conflict with window properties that + // are in Moz but not IE. Since we have some of these, we have to do + // it the Moz way. + if (impl()->frame()->tree()->child(propertyName)) { + slot.setCustom(this, childFrameGetter); + return true; + } + + const HashEntry* entry = JSDOMWindowBaseTable.entry(exec, propertyName); + if (entry) { + if (entry->attributes() & Function) { + if (entry->function() == windowProtoFuncShowModalDialog) { + if (!canShowModalDialog(impl()->frame())) + return false; + } + if (allowsAccessFrom(exec)) + setUpStaticFunctionSlot(exec, entry, this, propertyName, slot); + else + slot.setUndefined(); + } else + slot.setCustom(this, entry->propertyGetter()); + return true; + } + + // Do prototype lookup early so that functions and attributes in the prototype can have + // precedence over the index and name getters. + JSValuePtr proto = prototype(); + if (proto->isObject()) { + if (asObject(proto)->getPropertySlot(exec, propertyName, slot)) { + if (!allowsAccessFrom(exec)) + slot.setUndefined(); + return true; + } + } + + // FIXME: Search the whole frame hierachy somewhere around here. + // We need to test the correct priority order. + + // allow window[1] or parent[1] etc. (#56983) + bool ok; + unsigned i = propertyName.toArrayIndex(&ok); + if (ok && i < impl()->frame()->tree()->childCount()) { + slot.setCustomIndex(this, i, indexGetter); + return true; + } + + if (!allowsAccessFrom(exec)) { + slot.setUndefined(); + return true; + } + + // Allow shortcuts like 'Image1' instead of document.images.Image1 + Document* document = impl()->frame()->document(); + if (document && document->isHTMLDocument()) { + AtomicStringImpl* atomicPropertyName = AtomicString::find(propertyName); + if (atomicPropertyName && (static_cast<HTMLDocument*>(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) { + slot.setCustom(this, namedItemGetter); + return true; + } + } + + return Base::getOwnPropertySlot(exec, propertyName, slot); +} + +void JSDOMWindowBase::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) +{ + const HashEntry* entry = JSDOMWindowBaseTable.entry(exec, propertyName); + if (entry) { + if (entry->attributes() & Function) { + if (allowsAccessFrom(exec)) + Base::put(exec, propertyName, value, slot); + return; + } + if (entry->attributes() & ReadOnly) + return; + } + + if (allowsAccessFrom(exec)) + Base::put(exec, propertyName, value, slot); +} + +String JSDOMWindowBase::crossDomainAccessErrorMessage(const JSGlobalObject* other) const +{ + KURL originURL = asJSDOMWindow(other)->impl()->url(); + KURL targetURL = impl()->frame()->document()->url(); + if (originURL.isNull() || targetURL.isNull()) + return String(); + + // FIXME: this error message should contain more specifics of why the same origin check has failed. + return String::format("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains, protocols and ports must match.\n", + targetURL.string().utf8().data(), originURL.string().utf8().data()); +} + +void JSDOMWindowBase::printErrorMessage(const String& message) const +{ + if (message.isEmpty()) + return; + + Frame* frame = impl()->frame(); + if (!frame) + return; + + Settings* settings = frame->settings(); + if (!settings) + return; + + if (settings->privateBrowsingEnabled()) + return; + + impl()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, 1, String()); // FIXME: provide a real line number and source URL. +} + +ExecState* JSDOMWindowBase::globalExec() +{ + // We need to make sure that any script execution happening in this + // frame does not destroy it + if (Frame *frame = impl()->frame()) + frame->keepAlive(); + return Base::globalExec(); +} + +bool JSDOMWindowBase::supportsProfiling() const +{ + Frame* frame = impl()->frame(); + if (!frame) + return false; + + Page* page = frame->page(); + if (!page) + return false; + + return page->inspectorController()->profilerEnabled(); +} + +bool JSDOMWindowBase::shouldInterruptScript() const +{ + ASSERT(impl()->frame()); + Page* page = impl()->frame()->page(); + + // See <rdar://problem/5479443>. We don't think that page can ever be NULL + // in this case, but if it is, we've gotten into a state where we may have + // hung the UI, with no way to ask the client whether to cancel execution. + // For now, our solution is just to cancel execution no matter what, + // ensuring that we never hang. We might want to consider other solutions + // if we discover problems with this one. + ASSERT(page); + if (!page) + return true; + + return page->chrome()->shouldInterruptJavaScript(); +} + +void JSDOMWindowBase::clearHelperObjectProperties() +{ + setCurrentEvent(0); +} + +void JSDOMWindowBase::clear() +{ + JSLock lock(false); + + if (d()->returnValueSlot && !*d()->returnValueSlot) + *d()->returnValueSlot = getDirect(Identifier(globalExec(), "returnValue")); + + clearHelperObjectProperties(); +} + +JSObject* JSDOMWindowBase::toThisObject(ExecState*) const +{ + return shell(); +} + +JSDOMWindowShell* JSDOMWindowBase::shell() const +{ + return d()->shell; +} + +JSGlobalData* JSDOMWindowBase::commonJSGlobalData() +{ + static JSGlobalData* globalData = JSGlobalData::createLeaked().releaseRef(); + return globalData; +} + +} // namespace WebCore + +using namespace WebCore; + +JSValuePtr windowProtoFuncOpen(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args) +{ + JSDOMWindow* window = toJSDOMWindow(thisValue); + if (!window) + return throwError(exec, TypeError); + if (!window->allowsAccessFrom(exec)) + return jsUndefined(); + + Frame* frame = window->impl()->frame(); + if (!frame) + return jsUndefined(); + Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!activeFrame) + return jsUndefined(); + + Page* page = frame->page(); + + String urlString = valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 0)); + AtomicString frameName = args.at(exec, 1)->isUndefinedOrNull() ? "_blank" : AtomicString(args.at(exec, 1)->toString(exec)); + + // Because FrameTree::find() returns true for empty strings, we must check for empty framenames. + // Otherwise, illegitimate window.open() calls with no name will pass right through the popup blocker. + if (!allowPopUp(exec) && (frameName.isEmpty() || !frame->tree()->find(frameName))) + return jsUndefined(); + + // Get the target frame for the special cases of _top and _parent. In those + // cases, we can schedule a location change right now and return early. + bool topOrParent = false; + if (frameName == "_top") { + frame = frame->tree()->top(); + topOrParent = true; + } else if (frameName == "_parent") { + if (Frame* parent = frame->tree()->parent()) + frame = parent; + topOrParent = true; + } + if (topOrParent) { + if (!activeFrame->loader()->shouldAllowNavigation(frame)) + return jsUndefined(); + + String completedURL; + if (!urlString.isEmpty()) + completedURL = activeFrame->document()->completeURL(urlString).string(); + + const JSDOMWindow* targetedWindow = toJSDOMWindow(frame); + if (!completedURL.isEmpty() && (!protocolIs(completedURL, "javascript") || (targetedWindow && targetedWindow->allowsAccessFrom(exec)))) { + bool userGesture = activeFrame->script()->processingUserGesture(); + frame->loader()->scheduleLocationChange(completedURL, activeFrame->loader()->outgoingReferrer(), false, userGesture); + } + return toJS(exec, frame->domWindow()); + } + + // In the case of a named frame or a new window, we'll use the createWindow() helper + WindowFeatures windowFeatures(valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 2))); + FloatRect windowRect(windowFeatures.xSet ? windowFeatures.x : 0, windowFeatures.ySet ? windowFeatures.y : 0, + windowFeatures.widthSet ? windowFeatures.width : 0, windowFeatures.heightSet ? windowFeatures.height : 0); + DOMWindow::adjustWindowRect(screenAvailableRect(page ? page->mainFrame()->view() : 0), windowRect, windowRect); + + windowFeatures.x = windowRect.x(); + windowFeatures.y = windowRect.y(); + windowFeatures.height = windowRect.height(); + windowFeatures.width = windowRect.width(); + + frame = createWindow(exec, frame, urlString, frameName, windowFeatures, noValue()); + + if (!frame) + return jsUndefined(); + + return toJS(exec, frame->domWindow()); // global object +} + +JSValuePtr windowProtoFuncShowModalDialog(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args) +{ + JSDOMWindow* window = toJSDOMWindow(thisValue); + if (!window) + return throwError(exec, TypeError); + if (!window->allowsAccessFrom(exec)) + return jsUndefined(); + + Frame* frame = window->impl()->frame(); + if (!frame) + return jsUndefined(); + + return showModalDialog(exec, frame, valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 0)), args.at(exec, 1), valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 2))); +} + +JSValuePtr windowProtoFuncNotImplemented(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&) +{ + if (!toJSDOMWindow(thisValue)) + return throwError(exec, TypeError); + return jsUndefined(); +} + +namespace WebCore { + +void JSDOMWindowBase::setReturnValueSlot(JSValuePtr* slot) +{ + d()->returnValueSlot = slot; +} + +////////////////////// timeouts //////////////////////// + +int JSDOMWindowBase::installTimeout(ScheduledAction* a, int t, bool singleShot) +{ + return DOMTimer::install(scriptExecutionContext(), a, t, singleShot); +} + +int JSDOMWindowBase::installTimeout(const UString& handler, int t, bool singleShot) +{ + return installTimeout(new ScheduledAction(handler), t, singleShot); +} + +int JSDOMWindowBase::installTimeout(ExecState* exec, JSValuePtr func, const ArgList& args, int t, bool singleShot) +{ + return installTimeout(new ScheduledAction(exec, func, args), t, singleShot); +} + +void JSDOMWindowBase::removeTimeout(int timeoutId) +{ + DOMTimer::removeById(scriptExecutionContext(), timeoutId); +} + +void JSDOMWindowBase::disconnectFrame() +{ +} + +JSValuePtr toJS(ExecState*, DOMWindow* domWindow) +{ + if (!domWindow) + return jsNull(); + Frame* frame = domWindow->frame(); + if (!frame) + return jsNull(); + return frame->script()->windowShell(); +} + +JSDOMWindow* toJSDOMWindow(Frame* frame) +{ + if (!frame) + return 0; + return frame->script()->windowShell()->window(); +} + +JSDOMWindow* toJSDOMWindow(JSValuePtr value) +{ + if (!value->isObject()) + return 0; + const ClassInfo* classInfo = asObject(value)->classInfo(); + if (classInfo == &JSDOMWindow::s_info) + return static_cast<JSDOMWindow*>(asObject(value)); + if (classInfo == &JSDOMWindowShell::s_info) + return static_cast<JSDOMWindowShell*>(asObject(value))->window(); + return 0; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowBase.h b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowBase.h new file mode 100644 index 0000000..2398172 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowBase.h @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSDOMWindowBase_h +#define JSDOMWindowBase_h + +#include "PlatformString.h" +#include "JSDOMBinding.h" +#include <runtime/Protect.h> +#include <wtf/HashMap.h> +#include <wtf/OwnPtr.h> + +namespace WebCore { + + class AtomicString; + class DOMWindow; + class Event; + class Frame; + class JSDOMWindow; + class JSDOMWindowShell; + class JSEventListener; + class JSLocation; + class JSUnprotectedEventListener; + class ScheduledAction; + class SecurityOrigin; + + class JSDOMWindowBasePrivate; + + // This is the only WebCore JS binding which does not inherit from DOMObject + class JSDOMWindowBase : public JSDOMGlobalObject { + typedef JSDOMGlobalObject Base; + + friend class ScheduledAction; + protected: + JSDOMWindowBase(PassRefPtr<JSC::Structure>, PassRefPtr<DOMWindow>, JSDOMWindowShell*); + + public: + virtual ~JSDOMWindowBase(); + + void updateDocument(); + + DOMWindow* impl() const { return d()->impl.get(); } + virtual ScriptExecutionContext* scriptExecutionContext() const; + + void disconnectFrame(); + + virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&); + virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValuePtr, JSC::PutPropertySlot&); + + int installTimeout(const JSC::UString& handler, int t, bool singleShot); + int installTimeout(JSC::ExecState*, JSC::JSValuePtr function, const JSC::ArgList& args, int t, bool singleShot); + void removeTimeout(int timeoutId); + + void clear(); + + // Set a place to put a dialog return value when the window is cleared. + void setReturnValueSlot(JSC::JSValuePtr* slot); + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + static const JSC::ClassInfo s_info; + + virtual JSC::ExecState* globalExec(); + + virtual bool supportsProfiling() const; + + virtual bool shouldInterruptScript() const; + + bool allowsAccessFrom(JSC::ExecState*) const; + bool allowsAccessFromNoErrorMessage(JSC::ExecState*) const; + bool allowsAccessFrom(JSC::ExecState*, String& message) const; + + void printErrorMessage(const String&) const; + + // Don't call this version of allowsAccessFrom -- it's a slightly incorrect implementation used only by WebScriptObject + virtual bool allowsAccessFrom(const JSC::JSGlobalObject*) const; + + virtual JSC::JSObject* toThisObject(JSC::ExecState*) const; + JSDOMWindowShell* shell() const; + + static JSC::JSGlobalData* commonJSGlobalData(); + + private: + struct JSDOMWindowBaseData : public JSDOMGlobalObjectData { + JSDOMWindowBaseData(PassRefPtr<DOMWindow>, JSDOMWindowShell*); + + RefPtr<DOMWindow> impl; + + JSC::JSValuePtr* returnValueSlot; + JSDOMWindowShell* shell; + }; + + static JSC::JSValuePtr childFrameGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); + static JSC::JSValuePtr indexGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); + static JSC::JSValuePtr namedItemGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); + + void clearHelperObjectProperties(); + int installTimeout(ScheduledAction*, int interval, bool singleShot); + + bool allowsAccessFromPrivate(const JSC::JSGlobalObject*) const; + String crossDomainAccessErrorMessage(const JSC::JSGlobalObject*) const; + + JSDOMWindowBaseData* d() const { return static_cast<JSDOMWindowBaseData*>(JSC::JSVariableObject::d); } + }; + + // Returns a JSDOMWindow or jsNull() + JSC::JSValuePtr toJS(JSC::ExecState*, DOMWindow*); + + // Returns JSDOMWindow or 0 + JSDOMWindow* toJSDOMWindow(Frame*); + JSDOMWindow* toJSDOMWindow(JSC::JSValuePtr); + +} // namespace WebCore + +#endif // JSDOMWindowBase_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowCustom.cpp new file mode 100644 index 0000000..2c5f882 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowCustom.cpp @@ -0,0 +1,325 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSDOMWindowCustom.h" + +#include "AtomicString.h" +#include "Base64.h" +#include "DOMWindow.h" +#include "Document.h" +#include "ExceptionCode.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "FrameTree.h" +#include "JSDOMWindowShell.h" +#include "JSEventListener.h" +#include "JSMessagePort.h" +#include "MessagePort.h" +#include "ScriptController.h" +#include "Settings.h" +#include <runtime/JSObject.h> +#include <runtime/PrototypeFunction.h> + +using namespace JSC; + +namespace WebCore { + +void JSDOMWindow::mark() +{ + Base::mark(); + + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + markDOMObjectWrapper(globalData, impl()->optionalConsole()); + markDOMObjectWrapper(globalData, impl()->optionalHistory()); + markDOMObjectWrapper(globalData, impl()->optionalLocationbar()); + markDOMObjectWrapper(globalData, impl()->optionalMenubar()); + markDOMObjectWrapper(globalData, impl()->optionalNavigator()); + markDOMObjectWrapper(globalData, impl()->optionalPersonalbar()); + markDOMObjectWrapper(globalData, impl()->optionalScreen()); + markDOMObjectWrapper(globalData, impl()->optionalScrollbars()); + markDOMObjectWrapper(globalData, impl()->optionalSelection()); + markDOMObjectWrapper(globalData, impl()->optionalStatusbar()); + markDOMObjectWrapper(globalData, impl()->optionalToolbar()); + markDOMObjectWrapper(globalData, impl()->optionalLocation()); +#if ENABLE(DOM_STORAGE) + markDOMObjectWrapper(globalData, impl()->optionalSessionStorage()); + markDOMObjectWrapper(globalData, impl()->optionalLocalStorage()); +#endif +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + markDOMObjectWrapper(globalData, impl()->optionalApplicationCache()); +#endif +} + +bool JSDOMWindow::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + // Only allow deleting properties by frames in the same origin. + if (!allowsAccessFrom(exec)) + return false; + return Base::deleteProperty(exec, propertyName); +} + +bool JSDOMWindow::customGetPropertyNames(ExecState* exec, PropertyNameArray&) +{ + // Only allow the window to enumerated by frames in the same origin. + if (!allowsAccessFrom(exec)) + return true; + return false; +} + +bool JSDOMWindow::getPropertyAttributes(JSC::ExecState* exec, const Identifier& propertyName, unsigned& attributes) const +{ + // Only allow getting property attributes properties by frames in the same origin. + if (!allowsAccessFrom(exec)) + return false; + return Base::getPropertyAttributes(exec, propertyName, attributes); +} + +void JSDOMWindow::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction) +{ + // Only allow defining getters by frames in the same origin. + if (!allowsAccessFrom(exec)) + return; + Base::defineGetter(exec, propertyName, getterFunction); +} + +void JSDOMWindow::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunction) +{ + // Only allow defining setters by frames in the same origin. + if (!allowsAccessFrom(exec)) + return; + Base::defineSetter(exec, propertyName, setterFunction); +} + +JSValuePtr JSDOMWindow::lookupGetter(ExecState* exec, const Identifier& propertyName) +{ + // Only allow looking-up getters by frames in the same origin. + if (!allowsAccessFrom(exec)) + return jsUndefined(); + return Base::lookupGetter(exec, propertyName); +} + +JSValuePtr JSDOMWindow::lookupSetter(ExecState* exec, const Identifier& propertyName) +{ + // Only allow looking-up setters by frames in the same origin. + if (!allowsAccessFrom(exec)) + return jsUndefined(); + return Base::lookupSetter(exec, propertyName); +} + +void JSDOMWindow::setLocation(ExecState* exec, JSValuePtr value) +{ + Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!activeFrame) + return; + +#if ENABLE(DASHBOARD_SUPPORT) + // To avoid breaking old widgets, make "var location =" in a top-level frame create + // a property named "location" instead of performing a navigation (<rdar://problem/5688039>). + if (Settings* settings = activeFrame->settings()) { + if (settings->usesDashboardBackwardCompatibilityMode() && !activeFrame->tree()->parent()) { + if (allowsAccessFrom(exec)) + putDirect(Identifier(exec, "location"), value); + return; + } + } +#endif + + if (!activeFrame->loader()->shouldAllowNavigation(impl()->frame())) + return; + String dstUrl = activeFrame->loader()->completeURL(value->toString(exec)).string(); + if (!protocolIs(dstUrl, "javascript") || allowsAccessFrom(exec)) { + bool userGesture = activeFrame->script()->processingUserGesture(); + // We want a new history item if this JS was called via a user gesture + impl()->frame()->loader()->scheduleLocationChange(dstUrl, activeFrame->loader()->outgoingReferrer(), false, userGesture); + } +} + +JSValuePtr JSDOMWindow::postMessage(ExecState* exec, const ArgList& args) +{ + DOMWindow* window = impl(); + + DOMWindow* source = asJSDOMWindow(exec->dynamicGlobalObject())->impl(); + String message = args.at(exec, 0)->toString(exec); + + if (exec->hadException()) + return jsUndefined(); + + MessagePort* messagePort = (args.size() == 2) ? 0 : toMessagePort(args.at(exec, 1)); + + String targetOrigin = valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, (args.size() == 2) ? 1 : 2)); + if (exec->hadException()) + return jsUndefined(); + + ExceptionCode ec = 0; + window->postMessage(message, messagePort, targetOrigin, source, ec); + setDOMException(exec, ec); + + return jsUndefined(); +} + +static JSValuePtr setTimeoutOrInterval(ExecState* exec, JSDOMWindow* window, const ArgList& args, bool timeout) +{ + JSValuePtr v = args.at(exec, 0); + int delay = args.at(exec, 1)->toInt32(exec); + if (v->isString()) + return jsNumber(exec, window->installTimeout(asString(v)->value(), delay, timeout)); + CallData callData; + if (v->getCallData(callData) == CallTypeNone) + return jsUndefined(); + ArgList argsTail; + args.getSlice(2, argsTail); + return jsNumber(exec, window->installTimeout(exec, v, argsTail, delay, timeout)); +} + +JSValuePtr JSDOMWindow::setTimeout(ExecState* exec, const ArgList& args) +{ + return setTimeoutOrInterval(exec, this, args, true); +} + +JSValuePtr JSDOMWindow::clearTimeout(ExecState* exec, const ArgList& args) +{ + removeTimeout(args.at(exec, 0)->toInt32(exec)); + return jsUndefined(); +} + +JSValuePtr JSDOMWindow::setInterval(ExecState* exec, const ArgList& args) +{ + return setTimeoutOrInterval(exec, this, args, false); +} + +JSValuePtr JSDOMWindow::clearInterval(ExecState* exec, const ArgList& args) +{ + removeTimeout(args.at(exec, 0)->toInt32(exec)); + return jsUndefined(); +} + +JSValuePtr JSDOMWindow::atob(ExecState* exec, const ArgList& args) +{ + if (args.size() < 1) + return throwError(exec, SyntaxError, "Not enough arguments"); + + JSValuePtr v = args.at(exec, 0); + if (v->isNull()) + return jsEmptyString(exec); + + UString s = v->toString(exec); + if (!s.is8Bit()) { + setDOMException(exec, INVALID_CHARACTER_ERR); + return jsUndefined(); + } + + Vector<char> in(s.size()); + for (int i = 0; i < s.size(); ++i) + in[i] = static_cast<char>(s.data()[i]); + Vector<char> out; + + if (!base64Decode(in, out)) + return throwError(exec, GeneralError, "Cannot decode base64"); + + return jsString(exec, String(out.data(), out.size())); +} + +JSValuePtr JSDOMWindow::btoa(ExecState* exec, const ArgList& args) +{ + if (args.size() < 1) + return throwError(exec, SyntaxError, "Not enough arguments"); + + JSValuePtr v = args.at(exec, 0); + if (v->isNull()) + return jsEmptyString(exec); + + UString s = v->toString(exec); + if (!s.is8Bit()) { + setDOMException(exec, INVALID_CHARACTER_ERR); + return jsUndefined(); + } + + Vector<char> in(s.size()); + for (int i = 0; i < s.size(); ++i) + in[i] = static_cast<char>(s.data()[i]); + Vector<char> out; + + base64Encode(in, out); + + return jsString(exec, String(out.data(), out.size())); +} + +JSValuePtr JSDOMWindow::addEventListener(ExecState* exec, const ArgList& args) +{ + Frame* frame = impl()->frame(); + if (!frame) + return jsUndefined(); + + if (RefPtr<JSEventListener> listener = findOrCreateJSEventListener(exec, args.at(exec, 1))) { + if (Document* doc = frame->document()) + doc->addWindowEventListener(AtomicString(args.at(exec, 0)->toString(exec)), listener.release(), args.at(exec, 2)->toBoolean(exec)); + } + + return jsUndefined(); +} + +JSValuePtr JSDOMWindow::removeEventListener(ExecState* exec, const ArgList& args) +{ + Frame* frame = impl()->frame(); + if (!frame) + return jsUndefined(); + + if (JSEventListener* listener = findJSEventListener(args.at(exec, 1))) { + if (Document* doc = frame->document()) + doc->removeWindowEventListener(AtomicString(args.at(exec, 0)->toString(exec)), listener, args.at(exec, 2)->toBoolean(exec)); + } + + return jsUndefined(); +} + +DOMWindow* toDOMWindow(JSValuePtr value) +{ + if (!value->isObject()) + return 0; + JSObject* object = asObject(value); + if (object->inherits(&JSDOMWindow::s_info)) + return static_cast<JSDOMWindow*>(object)->impl(); + if (object->inherits(&JSDOMWindowShell::s_info)) + return static_cast<JSDOMWindowShell*>(object)->impl(); + return 0; +} + +JSValuePtr nonCachingStaticCloseFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 0, propertyName, jsDOMWindowPrototypeFunctionClose); +} + +JSValuePtr nonCachingStaticBlurFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 0, propertyName, jsDOMWindowPrototypeFunctionBlur); +} + +JSValuePtr nonCachingStaticFocusFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 0, propertyName, jsDOMWindowPrototypeFunctionFocus); +} + +JSValuePtr nonCachingStaticPostMessageFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 2, propertyName, jsDOMWindowPrototypeFunctionPostMessage); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowCustom.h new file mode 100644 index 0000000..838abab --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowCustom.h @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reseved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSDOMWindowCustom_h +#define JSDOMWindowCustom_h + +#include "JSDOMWindow.h" +#include "JSDOMWindowShell.h" +#include <wtf/AlwaysInline.h> + +namespace WebCore { + +inline JSDOMWindow* asJSDOMWindow(JSC::JSGlobalObject* globalObject) +{ + return static_cast<JSDOMWindow*>(globalObject); +} + +inline const JSDOMWindow* asJSDOMWindow(const JSC::JSGlobalObject* globalObject) +{ + return static_cast<const JSDOMWindow*>(globalObject); +} + +JSC::JSValuePtr nonCachingStaticCloseFunctionGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); +JSC::JSValuePtr nonCachingStaticBlurFunctionGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); +JSC::JSValuePtr nonCachingStaticFocusFunctionGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); +JSC::JSValuePtr nonCachingStaticPostMessageFunctionGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); + +ALWAYS_INLINE bool JSDOMWindow::customGetOwnPropertySlot(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertySlot& slot) +{ + // When accessing a Window cross-domain, functions are always the native built-in ones, and they + // are not affected by properties changed on the Window or anything in its prototype chain. + // This is consistent with the behavior of Firefox. + + const JSC::HashEntry* entry; + + // We don't want any properties other than "close" and "closed" on a closed window. + if (!impl()->frame()) { + // The following code is safe for cross-domain and same domain use. + // It ignores any custom properties that might be set on the DOMWindow (including a custom prototype). + entry = s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry && !(entry->attributes() & JSC::Function) && entry->propertyGetter() == jsDOMWindowClosed) { + slot.setCustom(this, entry->propertyGetter()); + return true; + } + entry = JSDOMWindowPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry && (entry->attributes() & JSC::Function) && entry->function() == jsDOMWindowPrototypeFunctionClose) { + slot.setCustom(this, nonCachingStaticCloseFunctionGetter); + return true; + } + + // FIXME: We should have a message here that explains why the property access/function call was + // not allowed. + slot.setUndefined(); + return true; + } + + // We need to check for cross-domain access here without printing the generic warning message + // because we always allow access to some function, just different ones depending whether access + // is allowed. + bool allowsAccess = allowsAccessFromNoErrorMessage(exec); + + // Look for overrides before looking at any of our own properties. + if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot)) { + // But ignore overrides completely if this is cross-domain access. + if (allowsAccess) + return true; + } + + // We need this code here because otherwise JSC::Window will stop the search before we even get to the + // prototype due to the blanket same origin (allowsAccessFrom) check at the end of getOwnPropertySlot. + // Also, it's important to get the implementation straight out of the DOMWindow prototype regardless of + // what prototype is actually set on this object. + entry = JSDOMWindowPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry) { + if (entry->attributes() & JSC::Function) { + if (entry->function() == jsDOMWindowPrototypeFunctionBlur) { + if (!allowsAccess) { + slot.setCustom(this, nonCachingStaticBlurFunctionGetter); + return true; + } + } else if (entry->function() == jsDOMWindowPrototypeFunctionClose) { + if (!allowsAccess) { + slot.setCustom(this, nonCachingStaticCloseFunctionGetter); + return true; + } + } else if (entry->function() == jsDOMWindowPrototypeFunctionFocus) { + if (!allowsAccess) { + slot.setCustom(this, nonCachingStaticFocusFunctionGetter); + return true; + } + } else if (entry->function() == jsDOMWindowPrototypeFunctionPostMessage) { + if (!allowsAccess) { + slot.setCustom(this, nonCachingStaticPostMessageFunctionGetter); + return true; + } + } + } + } else { + // Allow access to toString() cross-domain, but always Object.prototype.toString. + if (propertyName == exec->propertyNames().toString) { + if (!allowsAccess) { + slot.setCustom(this, objectToStringFunctionGetter); + return true; + } + } + } + + return false; +} + +inline bool JSDOMWindow::customPut(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSValuePtr value, JSC::PutPropertySlot& slot) +{ + if (!impl()->frame()) + return true; + + // We have a local override (e.g. "var location"), save time and jump directly to JSGlobalObject. + JSC::PropertySlot getSlot; + bool slotIsWriteable; + if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, getSlot, slotIsWriteable)) { + if (allowsAccessFrom(exec)) { + if (slotIsWriteable) { + getSlot.putValue(value); + if (getSlot.isCacheable()) + slot.setExistingProperty(this, getSlot.cachedOffset()); + } else + JSGlobalObject::put(exec, propertyName, value, slot); + } + return true; + } + + return false; +} + + + +inline bool JSDOMWindowBase::allowsAccessFrom(const JSGlobalObject* other) const +{ + if (allowsAccessFromPrivate(other)) + return true; + printErrorMessage(crossDomainAccessErrorMessage(other)); + return false; +} + + inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec) const +{ + if (allowsAccessFromPrivate(exec->lexicalGlobalObject())) + return true; + printErrorMessage(crossDomainAccessErrorMessage(exec->lexicalGlobalObject())); + return false; +} + +inline bool JSDOMWindowBase::allowsAccessFromNoErrorMessage(JSC::ExecState* exec) const +{ + return allowsAccessFromPrivate(exec->lexicalGlobalObject()); +} + +inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec, String& message) const +{ + if (allowsAccessFromPrivate(exec->lexicalGlobalObject())) + return true; + message = crossDomainAccessErrorMessage(exec->lexicalGlobalObject()); + return false; +} + +ALWAYS_INLINE bool JSDOMWindowBase::allowsAccessFromPrivate(const JSGlobalObject* other) const +{ + const JSDOMWindow* originWindow = asJSDOMWindow(other); + const JSDOMWindow* targetWindow = d()->shell->window(); + + if (originWindow == targetWindow) + return true; + + // JS may be attempting to access the "window" object, which should be valid, + // even if the document hasn't been constructed yet. If the document doesn't + // exist yet allow JS to access the window object. + if (!originWindow->impl()->document()) + return true; + + const SecurityOrigin* originSecurityOrigin = originWindow->impl()->securityOrigin(); + const SecurityOrigin* targetSecurityOrigin = targetWindow->impl()->securityOrigin(); + + return originSecurityOrigin->canAccess(targetSecurityOrigin); +} + +} + +#endif // JSDOMWindowCustom_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowShell.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowShell.cpp new file mode 100644 index 0000000..d54611e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowShell.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSDOMWindowShell.h" + +#include "Frame.h" +#include "JSDOMWindow.h" +#include "DOMWindow.h" +#include "ScriptController.h" +#include <runtime/JSObject.h> + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSDOMWindowShell) + +const ClassInfo JSDOMWindowShell::s_info = { "JSDOMWindowShell", 0, 0, 0 }; + +JSDOMWindowShell::JSDOMWindowShell(PassRefPtr<DOMWindow> window) + : Base(JSDOMWindowShell::createStructure(jsNull())) + , m_window(0) +{ + setWindow(window); +} + +JSDOMWindowShell::~JSDOMWindowShell() +{ +} + +void JSDOMWindowShell::setWindow(PassRefPtr<DOMWindow> window) +{ + RefPtr<Structure> prototypeStructure = JSDOMWindowPrototype::createStructure(jsNull()); + RefPtr<Structure> structure = JSDOMWindow::createStructure(new JSDOMWindowPrototype(prototypeStructure.release())); + setWindow(new (JSDOMWindow::commonJSGlobalData()) JSDOMWindow(structure.release(), window, this)); +} + +// ---- +// JSObject methods +// ---- + +void JSDOMWindowShell::mark() +{ + Base::mark(); + if (m_window && !m_window->marked()) + m_window->mark(); +} + +UString JSDOMWindowShell::className() const +{ + return m_window->className(); +} + +bool JSDOMWindowShell::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return m_window->getOwnPropertySlot(exec, propertyName, slot); +} + +void JSDOMWindowShell::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) +{ + m_window->put(exec, propertyName, value, slot); +} + +void JSDOMWindowShell::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValuePtr value, unsigned attributes) +{ + m_window->putWithAttributes(exec, propertyName, value, attributes); +} + +bool JSDOMWindowShell::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + return m_window->deleteProperty(exec, propertyName); +} + +void JSDOMWindowShell::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) +{ + m_window->getPropertyNames(exec, propertyNames); +} + +bool JSDOMWindowShell::getPropertyAttributes(JSC::ExecState* exec, const Identifier& propertyName, unsigned& attributes) const +{ + return m_window->getPropertyAttributes(exec, propertyName, attributes); +} + +void JSDOMWindowShell::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction) +{ + m_window->defineGetter(exec, propertyName, getterFunction); +} + +void JSDOMWindowShell::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunction) +{ + m_window->defineSetter(exec, propertyName, setterFunction); +} + +JSValuePtr JSDOMWindowShell::lookupGetter(ExecState* exec, const Identifier& propertyName) +{ + return m_window->lookupGetter(exec, propertyName); +} + +JSValuePtr JSDOMWindowShell::lookupSetter(ExecState* exec, const Identifier& propertyName) +{ + return m_window->lookupSetter(exec, propertyName); +} + +JSObject* JSDOMWindowShell::unwrappedObject() +{ + return m_window; +} + +// ---- +// JSDOMWindow methods +// ---- + +DOMWindow* JSDOMWindowShell::impl() const +{ + return m_window->impl(); +} + +void JSDOMWindowShell::disconnectFrame() +{ + m_window->disconnectFrame(); +} + +void JSDOMWindowShell::clear() +{ + m_window->clear(); +} + +void* JSDOMWindowShell::operator new(size_t size) +{ + return JSDOMWindow::commonJSGlobalData()->heap.allocate(size); +} + +// ---- +// Conversion methods +// ---- + +JSValuePtr toJS(ExecState*, Frame* frame) +{ + if (!frame) + return jsNull(); + return frame->script()->windowShell(); +} + +JSDOMWindowShell* toJSDOMWindowShell(Frame* frame) +{ + if (!frame) + return 0; + return frame->script()->windowShell(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowShell.h b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowShell.h new file mode 100644 index 0000000..931a256 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDOMWindowShell.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 JSDOMWindowShell_h +#define JSDOMWindowShell_h + +#include "JSDOMWindow.h" +#include "JSDOMBinding.h" + +namespace WebCore { + + class DOMWindow; + class Frame; + + class JSDOMWindowShell : public DOMObject { + typedef DOMObject Base; + public: + JSDOMWindowShell(PassRefPtr<DOMWindow>); + virtual ~JSDOMWindowShell(); + + JSDOMWindow* window() const { return m_window; } + void setWindow(JSDOMWindow* window) + { + ASSERT_ARG(window, window); + m_window = window; + setPrototype(window->prototype()); + } + void setWindow(PassRefPtr<DOMWindow>); + + static const JSC::ClassInfo s_info; + + DOMWindow* impl() const; + void disconnectFrame(); + void clear(); + + void* operator new(size_t); + + static PassRefPtr<JSC::Structure> createStructure(JSC::JSValuePtr prototype) + { + return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType)); + } + + private: + virtual void mark(); + virtual JSC::UString className() const; + virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot&); + virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValuePtr, JSC::PutPropertySlot&); + virtual void putWithAttributes(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValuePtr, unsigned attributes); + virtual bool deleteProperty(JSC::ExecState*, const JSC::Identifier& propertyName); + virtual void getPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&); + virtual bool getPropertyAttributes(JSC::ExecState*, const JSC::Identifier& propertyName, unsigned& attributes) const; + virtual void defineGetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction); + virtual void defineSetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction); + virtual JSC::JSValuePtr lookupGetter(JSC::ExecState*, const JSC::Identifier& propertyName); + virtual JSC::JSValuePtr lookupSetter(JSC::ExecState*, const JSC::Identifier& propertyName); + virtual JSC::JSObject* unwrappedObject(); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + + JSDOMWindow* m_window; + }; + + JSC::JSValuePtr toJS(JSC::ExecState*, Frame*); + JSDOMWindowShell* toJSDOMWindowShell(Frame*); + +} // namespace WebCore + +#endif // JSDOMWindowShell_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDatabaseCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDatabaseCustom.cpp new file mode 100644 index 0000000..68639d5 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDatabaseCustom.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSDatabase.h" + +#include "DOMWindow.h" +#include "Database.h" +#include "Document.h" +#include "ExceptionCode.h" +#include "JSCustomSQLTransactionCallback.h" +#include "JSCustomSQLTransactionErrorCallback.h" +#include "JSCustomVoidCallback.h" +#include "JSDOMWindowCustom.h" +#include "PlatformString.h" +#include "SQLValue.h" +#include <runtime/JSArray.h> + +namespace WebCore { + +using namespace JSC; + +JSValuePtr JSDatabase::changeVersion(ExecState* exec, const ArgList& args) +{ + String oldVersion = args.at(exec, 0)->toString(exec); + String newVersion = args.at(exec, 1)->toString(exec); + + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!frame) + return jsUndefined(); + + JSObject *object; + if (!(object = args.at(exec, 2)->getObject())) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + RefPtr<SQLTransactionCallback> callback(JSCustomSQLTransactionCallback::create(object, frame)); + + RefPtr<SQLTransactionErrorCallback> errorCallback; + if (!args.at(exec, 3)->isNull()) { + if (!(object = args.at(exec, 3)->getObject())) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + errorCallback = JSCustomSQLTransactionErrorCallback::create(object, frame); + } + + RefPtr<VoidCallback> successCallback; + if (!args.at(exec, 4)->isNull()) { + successCallback = toVoidCallback(exec, args.at(exec, 4)); + if (!successCallback) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + } + + m_impl->changeVersion(oldVersion, newVersion, callback.release(), errorCallback.release(), successCallback.release()); + + return jsUndefined(); +} + +JSValuePtr JSDatabase::transaction(ExecState* exec, const ArgList& args) +{ + JSObject* object; + + if (!(object = args.at(exec, 0)->getObject())) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!frame) + return jsUndefined(); + + RefPtr<SQLTransactionCallback> callback(JSCustomSQLTransactionCallback::create(object, frame)); + RefPtr<SQLTransactionErrorCallback> errorCallback; + + if (args.size() > 1 && !args.at(exec, 1)->isNull()) { + if (!(object = args.at(exec, 1)->getObject())) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + errorCallback = JSCustomSQLTransactionErrorCallback::create(object, frame); + } + + RefPtr<VoidCallback> successCallback; + if (args.size() > 2 && !args.at(exec, 2)->isNull()) { + successCallback = toVoidCallback(exec, args.at(exec, 2)); + if (!successCallback) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + } + + m_impl->transaction(callback.release(), errorCallback.release(), successCallback.release()); + + return jsUndefined(); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDocumentCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDocumentCustom.cpp new file mode 100644 index 0000000..f292b38 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDocumentCustom.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSDocument.h" + +#include "DOMWindow.h" +#include "ExceptionCode.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "HTMLDocument.h" +#include "JSDOMWindowCustom.h" +#include "JSHTMLDocument.h" +#include "JSLocation.h" +#include "JSNodeList.h" +#include "Location.h" +#include "NodeList.h" +#include "ScriptController.h" + +#if ENABLE(SVG) +#include "JSSVGDocument.h" +#include "SVGDocument.h" +#endif + +using namespace JSC; + +namespace WebCore { + +void JSDocument::mark() +{ + JSEventTargetNode::mark(); + markDOMNodesForDocument(impl()); + markActiveObjectsForContext(*Heap::heap(this)->globalData(), impl()); +} + +JSValuePtr JSDocument::location(ExecState* exec) const +{ + Frame* frame = static_cast<Document*>(impl())->frame(); + if (!frame) + return jsNull(); + + return toJS(exec, frame->domWindow()->location()); +} + +void JSDocument::setLocation(ExecState* exec, JSValuePtr value) +{ + Frame* frame = static_cast<Document*>(impl())->frame(); + if (!frame) + return; + + String str = value->toString(exec); + + // IE and Mozilla both resolve the URL relative to the source frame, + // not the target frame. + Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (activeFrame) + str = activeFrame->document()->completeURL(str).string(); + + bool userGesture = activeFrame->script()->processingUserGesture(); + frame->loader()->scheduleLocationChange(str, activeFrame->loader()->outgoingReferrer(), false, userGesture); +} + +JSValuePtr toJS(ExecState* exec, Document* document) +{ + if (!document) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), document); + if (wrapper) + return wrapper; + + if (document->isHTMLDocument()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, HTMLDocument, document); +#if ENABLE(SVG) + else if (document->isSVGDocument()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, SVGDocument, document); +#endif + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, Document, document); + + // Make sure the document is kept around by the window object, and works right with the + // back/forward cache. + if (!document->frame()) { + size_t nodeCount = 0; + for (Node* n = document; n; n = n->traverseNextNode()) + nodeCount++; + + exec->heap()->reportExtraMemoryCost(nodeCount * sizeof(Node)); + } + + return wrapper; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSDocumentFragmentCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSDocumentFragmentCustom.cpp new file mode 100644 index 0000000..7bc7d68 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSDocumentFragmentCustom.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSDocumentFragment.h" + +#include "DocumentFragment.h" +#include "Element.h" +#include "ExceptionCode.h" +#include "JSElement.h" +#include "JSNodeList.h" +#include "NodeList.h" + +using namespace JSC; + +namespace WebCore { + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSElementCustom.cpp new file mode 100644 index 0000000..3effe85 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSElementCustom.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSElement.h" + +#include "CSSHelper.h" +#include "Document.h" +#include "ExceptionCode.h" +#include "HTMLFrameElementBase.h" +#include "HTMLNames.h" +#include "JSAttr.h" +#include "JSHTMLElementWrapperFactory.h" +#include "JSNodeList.h" +#include "NodeList.h" + +#if ENABLE(SVG) +#include "JSSVGElementWrapperFactory.h" +#include "SVGElement.h" +#endif + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +static inline bool allowSettingSrcToJavascriptURL(ExecState* exec, Element* element, const String& name, const String& value) +{ + if ((element->hasTagName(iframeTag) || element->hasTagName(frameTag)) && equalIgnoringCase(name, "src") && protocolIs(parseURL(value), "javascript")) { + HTMLFrameElementBase* frame = static_cast<HTMLFrameElementBase*>(element); + if (!checkNodeSecurity(exec, frame->contentDocument())) + return false; + } + return true; +} + +JSValuePtr JSElement::setAttribute(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + AtomicString name = args.at(exec, 0)->toString(exec); + AtomicString value = args.at(exec, 1)->toString(exec); + + Element* imp = impl(); + if (!allowSettingSrcToJavascriptURL(exec, imp, name, value)) + return jsUndefined(); + + imp->setAttribute(name, value, ec); + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValuePtr JSElement::setAttributeNode(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + Attr* newAttr = toAttr(args.at(exec, 0)); + if (!newAttr) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + Element* imp = impl(); + if (!allowSettingSrcToJavascriptURL(exec, imp, newAttr->name(), newAttr->value())) + return jsUndefined(); + + JSValuePtr result = toJS(exec, WTF::getPtr(imp->setAttributeNode(newAttr, ec))); + setDOMException(exec, ec); + return result; +} + +JSValuePtr JSElement::setAttributeNS(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + AtomicString namespaceURI = valueToStringWithNullCheck(exec, args.at(exec, 0)); + AtomicString qualifiedName = args.at(exec, 1)->toString(exec); + AtomicString value = args.at(exec, 2)->toString(exec); + + Element* imp = impl(); + if (!allowSettingSrcToJavascriptURL(exec, imp, qualifiedName, value)) + return jsUndefined(); + + imp->setAttributeNS(namespaceURI, qualifiedName, value, ec); + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValuePtr JSElement::setAttributeNodeNS(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + Attr* newAttr = toAttr(args.at(exec, 0)); + if (!newAttr) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + Element* imp = impl(); + if (!allowSettingSrcToJavascriptURL(exec, imp, newAttr->name(), newAttr->value())) + return jsUndefined(); + + JSValuePtr result = toJS(exec, WTF::getPtr(imp->setAttributeNodeNS(newAttr, ec))); + setDOMException(exec, ec); + return result; +} + +JSValuePtr toJSNewlyCreated(ExecState* exec, Element* element) +{ + if (!element) + return jsNull(); + + ASSERT(!getCachedDOMNodeWrapper(element->document(), element)); + + JSNode* wrapper; + if (element->isHTMLElement()) + wrapper = createJSHTMLWrapper(exec, static_cast<HTMLElement*>(element)); +#if ENABLE(SVG) + else if (element->isSVGElement()) + wrapper = createJSSVGWrapper(exec, static_cast<SVGElement*>(element)); +#endif + else + wrapper = CREATE_DOM_NODE_WRAPPER(exec, Element, element); + + return wrapper; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSEventCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSEventCustom.cpp new file mode 100644 index 0000000..1c59f9d --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSEventCustom.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSEvent.h" + +#include "Clipboard.h" +#include "Event.h" +#include "JSClipboard.h" +#include "JSKeyboardEvent.h" +#include "JSMessageEvent.h" +#include "JSMouseEvent.h" +#include "JSMutationEvent.h" +#include "JSOverflowEvent.h" +#include "JSProgressEvent.h" +#include "JSTextEvent.h" +#include "JSUIEvent.h" +#include "JSWebKitAnimationEvent.h" +#include "JSWebKitTransitionEvent.h" +#include "JSWheelEvent.h" +#include "JSXMLHttpRequestProgressEvent.h" +#include "KeyboardEvent.h" +#include "MessageEvent.h" +#include "MouseEvent.h" +#include "MutationEvent.h" +#include "OverflowEvent.h" +#include "ProgressEvent.h" +#include "TextEvent.h" +#include "UIEvent.h" +#include "WebKitAnimationEvent.h" +#include "WebKitTransitionEvent.h" +#include "WheelEvent.h" +#include "XMLHttpRequestProgressEvent.h" +#include <runtime/JSLock.h> + +#if ENABLE(DOM_STORAGE) +#include "JSStorageEvent.h" +#include "StorageEvent.h" +#endif + +#if ENABLE(SVG) +#include "JSSVGZoomEvent.h" +#include "SVGZoomEvent.h" +#endif + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSEvent::clipboardData(ExecState* exec) const +{ + return impl()->isClipboardEvent() ? toJS(exec, impl()->clipboardData()) : jsUndefined(); +} + +JSValuePtr toJS(ExecState* exec, Event* event) +{ + JSLock lock(false); + + if (!event) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), event); + if (wrapper) + return wrapper; + + if (event->isUIEvent()) { + if (event->isKeyboardEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, KeyboardEvent, event); + else if (event->isTextEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, TextEvent, event); + else if (event->isMouseEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, MouseEvent, event); + else if (event->isWheelEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, WheelEvent, event); +#if ENABLE(SVG) + else if (event->isSVGZoomEvent()) + wrapper = CREATE_SVG_OBJECT_WRAPPER(exec, SVGZoomEvent, event, 0); +#endif + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, UIEvent, event); + } else if (event->isMutationEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, MutationEvent, event); + else if (event->isOverflowEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, OverflowEvent, event); + else if (event->isMessageEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, MessageEvent, event); + else if (event->isProgressEvent()) { + if (event->isXMLHttpRequestProgressEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, XMLHttpRequestProgressEvent, event); + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, ProgressEvent, event); + } +#if ENABLE(DOM_STORAGE) + else if (event->isStorageEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, StorageEvent, event); +#endif + else if (event->isWebKitAnimationEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, WebKitAnimationEvent, event); + else if (event->isWebKitTransitionEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, WebKitTransitionEvent, event); + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, Event, event); + + return wrapper; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSEventListener.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSEventListener.cpp new file mode 100644 index 0000000..f84e537 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSEventListener.cpp @@ -0,0 +1,340 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSEventListener.h" + +#include "CString.h" +#include "Console.h" +#include "DOMWindow.h" +#include "Document.h" +#include "Event.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "JSDOMWindow.h" +#include "JSEvent.h" +#include "JSEventTarget.h" +#include "JSEventTargetNode.h" +#include "ScriptController.h" +#include <runtime/FunctionConstructor.h> +#include <runtime/JSLock.h> +#include <wtf/RefCountedLeakCounter.h> + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSAbstractEventListener) + +void JSAbstractEventListener::handleEvent(Event* event, bool isWindowEvent) +{ + JSLock lock(false); + + JSObject* listener = listenerObj(); + if (!listener) + return; + + JSDOMGlobalObject* globalObject = this->globalObject(); + // Null check as clearGlobalObject() can clear this and we still get called back by + // xmlhttprequest objects. See http://bugs.webkit.org/show_bug.cgi?id=13275 + // FIXME: Is this check still necessary? Requests are supposed to be stopped before clearGlobalObject() is called. + if (!globalObject) + return; + + ScriptExecutionContext* scriptExecutionContext = globalObject->scriptExecutionContext(); + if (!scriptExecutionContext) + return; + + if (scriptExecutionContext->isDocument()) { + JSDOMWindow* window = static_cast<JSDOMWindow*>(globalObject); + Frame* frame = window->impl()->frame(); + if (!frame) + return; + // The window must still be active in its frame. See <https://bugs.webkit.org/show_bug.cgi?id=21921>. + // FIXME: A better fix for this may be to change DOMWindow::frame() to not return a frame the detached window used to be in. + if (frame->domWindow() != window->impl()) + return; + // FIXME: Is this check needed for other contexts? + ScriptController* script = frame->script(); + if (!script->isEnabled() || script->isPaused()) + return; + } + + ExecState* exec = globalObject->globalExec(); + + JSValuePtr handleEventFunction = listener->get(exec, Identifier(exec, "handleEvent")); + CallData callData; + CallType callType = handleEventFunction->getCallData(callData); + if (callType == CallTypeNone) { + handleEventFunction = noValue(); + callType = listener->getCallData(callData); + } + + if (callType != CallTypeNone) { + ref(); + + ArgList args; + args.append(toJS(exec, event)); + + Event* savedEvent = globalObject->currentEvent(); + globalObject->setCurrentEvent(event); + + // If this event handler is the first JavaScript to execute, then the + // dynamic global object should be set to the global object of the + // window in which the event occurred. + JSGlobalData* globalData = globalObject->globalData(); + DynamicGlobalObjectScope globalObjectScope(exec, globalData->dynamicGlobalObject ? globalData->dynamicGlobalObject : globalObject); + + JSValuePtr retval; + if (handleEventFunction) { + globalObject->startTimeoutCheck(); + retval = call(exec, handleEventFunction, callType, callData, listener, args); + } else { + JSValuePtr thisValue; + if (isWindowEvent) + thisValue = globalObject->toThisObject(exec); + else + thisValue = toJS(exec, event->currentTarget()); + globalObject->startTimeoutCheck(); + retval = call(exec, listener, callType, callData, thisValue, args); + } + globalObject->stopTimeoutCheck(); + + globalObject->setCurrentEvent(savedEvent); + + if (exec->hadException()) + reportCurrentException(exec); + else { + if (!retval->isUndefinedOrNull() && event->storesResultAsString()) + event->storeResult(retval->toString(exec)); + if (m_isInline) { + bool retvalbool; + if (retval->getBoolean(retvalbool) && !retvalbool) + event->preventDefault(); + } + } + + if (scriptExecutionContext->isDocument()) + Document::updateDocumentsRendering(); + deref(); + } +} + +bool JSAbstractEventListener::isInline() const +{ + return m_isInline; +} + +// ------------------------------------------------------------------------- + +JSUnprotectedEventListener::JSUnprotectedEventListener(JSObject* listener, JSDOMGlobalObject* globalObject, bool isInline) + : JSAbstractEventListener(isInline) + , m_listener(listener) + , m_globalObject(globalObject) +{ + if (m_listener) { + JSDOMWindow::UnprotectedListenersMap& listeners = isInline + ? globalObject->jsUnprotectedInlineEventListeners() : globalObject->jsUnprotectedEventListeners(); + listeners.set(m_listener, this); + } +} + +JSUnprotectedEventListener::~JSUnprotectedEventListener() +{ + if (m_listener && m_globalObject) { + JSDOMWindow::UnprotectedListenersMap& listeners = isInline() + ? m_globalObject->jsUnprotectedInlineEventListeners() : m_globalObject->jsUnprotectedEventListeners(); + listeners.remove(m_listener); + } +} + +JSObject* JSUnprotectedEventListener::listenerObj() const +{ + return m_listener; +} + +JSDOMGlobalObject* JSUnprotectedEventListener::globalObject() const +{ + return m_globalObject; +} + +void JSUnprotectedEventListener::clearGlobalObject() +{ + m_globalObject = 0; +} + +void JSUnprotectedEventListener::mark() +{ + if (m_listener && !m_listener->marked()) + m_listener->mark(); +} + +#ifndef NDEBUG +static WTF::RefCountedLeakCounter eventListenerCounter("EventListener"); +#endif + +// ------------------------------------------------------------------------- + +JSEventListener::JSEventListener(JSObject* listener, JSDOMGlobalObject* globalObject, bool isInline) + : JSAbstractEventListener(isInline) + , m_listener(listener) + , m_globalObject(globalObject) +{ + if (m_listener) { + JSDOMWindow::ListenersMap& listeners = isInline + ? m_globalObject->jsInlineEventListeners() : m_globalObject->jsEventListeners(); + listeners.set(m_listener, this); + } +#ifndef NDEBUG + eventListenerCounter.increment(); +#endif +} + +JSEventListener::~JSEventListener() +{ + if (m_listener && m_globalObject) { + JSDOMWindow::ListenersMap& listeners = isInline() + ? m_globalObject->jsInlineEventListeners() : m_globalObject->jsEventListeners(); + listeners.remove(m_listener); + } +#ifndef NDEBUG + eventListenerCounter.decrement(); +#endif +} + +JSObject* JSEventListener::listenerObj() const +{ + return m_listener; +} + +JSDOMGlobalObject* JSEventListener::globalObject() const +{ + return m_globalObject; +} + +void JSEventListener::clearGlobalObject() +{ + m_globalObject = 0; +} + +// ------------------------------------------------------------------------- + +JSLazyEventListener::JSLazyEventListener(LazyEventListenerType type, const String& functionName, const String& code, JSDOMGlobalObject* globalObject, Node* node, int lineNumber) + : JSEventListener(0, globalObject, true) + , m_functionName(functionName) + , m_code(code) + , m_parsed(false) + , m_lineNumber(lineNumber) + , m_originalNode(node) + , m_type(type) +{ + // We don't retain the original node because we assume it + // will stay alive as long as this handler object is around + // and we need to avoid a reference cycle. If JS transfers + // this handler to another node, parseCode will be called and + // then originalNode is no longer needed. + + // A JSLazyEventListener can be created with a line number of zero when it is created with + // a setAttribute call from JavaScript, so make the line number 1 in that case. + if (m_lineNumber == 0) + m_lineNumber = 1; +} + +JSObject* JSLazyEventListener::listenerObj() const +{ + parseCode(); + return m_listener; +} + +// Helper function +inline JSValuePtr eventParameterName(JSLazyEventListener::LazyEventListenerType type, ExecState* exec) +{ + switch (type) { + case JSLazyEventListener::HTMLLazyEventListener: + return jsNontrivialString(exec, "event"); +#if ENABLE(SVG) + case JSLazyEventListener::SVGLazyEventListener: + return jsNontrivialString(exec, "evt"); +#endif + default: + ASSERT_NOT_REACHED(); + return jsUndefined(); + } +} + +void JSLazyEventListener::parseCode() const +{ + if (m_parsed) + return; + + if (globalObject()->scriptExecutionContext()->isDocument()) { + JSDOMWindow* window = static_cast<JSDOMWindow*>(globalObject()); + Frame* frame = window->impl()->frame(); + if (!frame) + return; + // FIXME: Is this check needed for non-Document contexts? + ScriptController* script = frame->script(); + if (!script->isEnabled() || script->isPaused()) + return; + } + + m_parsed = true; + + ExecState* exec = globalObject()->globalExec(); + + ArgList args; + UString sourceURL(globalObject()->scriptExecutionContext()->url().string()); + args.append(eventParameterName(m_type, exec)); + args.append(jsString(exec, m_code)); + + // FIXME: Passing the document's URL to construct is not always correct, since this event listener might + // have been added with setAttribute from a script, and we should pass String() in that case. + m_listener = constructFunction(exec, args, Identifier(exec, m_functionName), sourceURL, m_lineNumber); // FIXME: is globalExec ok? + + JSFunction* listenerAsFunction = static_cast<JSFunction*>(m_listener.get()); + + if (exec->hadException()) { + exec->clearException(); + + // failed to parse, so let's just make this listener a no-op + m_listener = 0; + } else if (m_originalNode) { + // Add the event's home element to the scope + // (and the document, and the form - see JSHTMLElement::eventHandlerScope) + ScopeChain scope = listenerAsFunction->scope(); + + JSValuePtr thisObj = toJS(exec, m_originalNode); + if (thisObj->isObject()) { + static_cast<JSEventTargetNode*>(asObject(thisObj))->pushEventHandlerScope(exec, scope); + listenerAsFunction->setScope(scope); + } + } + + // no more need to keep the unparsed code around + m_functionName = String(); + m_code = String(); + + if (m_listener) { + ASSERT(isInline()); + JSDOMWindow::ListenersMap& listeners = globalObject()->jsInlineEventListeners(); + listeners.set(m_listener, const_cast<JSLazyEventListener*>(this)); + } +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSEventListener.h b/src/3rdparty/webkit/WebCore/bindings/js/JSEventListener.h new file mode 100644 index 0000000..859d5d4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSEventListener.h @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2003, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSEventListener_h +#define JSEventListener_h + +#include "EventListener.h" +#include "PlatformString.h" +#include <runtime/Protect.h> + +namespace WebCore { + + class Event; + class JSDOMGlobalObject; + class Node; + + class JSAbstractEventListener : public EventListener { + public: + virtual void handleEvent(Event*, bool isWindowEvent); + virtual bool isInline() const; + virtual JSC::JSObject* listenerObj() const = 0; + virtual JSDOMGlobalObject* globalObject() const = 0; + + protected: + JSAbstractEventListener(bool isInline) + : m_isInline(isInline) + { + } + + private: + bool m_isInline; + }; + + class JSUnprotectedEventListener : public JSAbstractEventListener { + public: + static PassRefPtr<JSUnprotectedEventListener> create(JSC::JSObject* listener, JSDOMGlobalObject* globalObject, bool isInline) + { + return adoptRef(new JSUnprotectedEventListener(listener, globalObject, isInline)); + } + virtual ~JSUnprotectedEventListener(); + + virtual JSC::JSObject* listenerObj() const; + virtual JSDOMGlobalObject* globalObject() const; + void clearGlobalObject(); + void mark(); + + private: + JSUnprotectedEventListener(JSC::JSObject* listener, JSDOMGlobalObject*, bool isInline); + + JSC::JSObject* m_listener; + JSDOMGlobalObject* m_globalObject; + }; + + class JSEventListener : public JSAbstractEventListener { + public: + static PassRefPtr<JSEventListener> create(JSC::JSObject* listener, JSDOMGlobalObject* globalObject, bool isInline) + { + return adoptRef(new JSEventListener(listener, globalObject, isInline)); + } + virtual ~JSEventListener(); + + virtual JSC::JSObject* listenerObj() const; + virtual JSDOMGlobalObject* globalObject() const; + void clearGlobalObject(); + + protected: + JSEventListener(JSC::JSObject* listener, JSDOMGlobalObject*, bool isInline); + + mutable JSC::ProtectedPtr<JSC::JSObject> m_listener; + + private: + JSC::ProtectedPtr<JSDOMGlobalObject> m_globalObject; + }; + + class JSLazyEventListener : public JSEventListener { + public: + enum LazyEventListenerType { + HTMLLazyEventListener +#if ENABLE(SVG) + , SVGLazyEventListener +#endif + }; + + virtual bool wasCreatedFromMarkup() const { return true; } + + static PassRefPtr<JSLazyEventListener> create(LazyEventListenerType type, const String& functionName, const String& code, JSDOMGlobalObject* globalObject, Node* node, int lineNumber) + { + return adoptRef(new JSLazyEventListener(type, functionName, code, globalObject, node, lineNumber)); + } + virtual JSC::JSObject* listenerObj() const; + + protected: + JSLazyEventListener(LazyEventListenerType type, const String& functionName, const String& code, JSDOMGlobalObject*, Node*, int lineNumber); + + private: + void parseCode() const; + + mutable String m_functionName; + mutable String m_code; + mutable bool m_parsed; + int m_lineNumber; + Node* m_originalNode; + + LazyEventListenerType m_type; + }; + +} // namespace WebCore + +#endif // JSEventListener_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSEventTarget.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSEventTarget.cpp new file mode 100644 index 0000000..8239897 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSEventTarget.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSEventTarget.h" + +#include "Document.h" +#include "JSEventListener.h" +#include "JSEventTargetNode.h" +#include "JSMessagePort.h" +#include "JSWorker.h" +#include "JSWorkerContext.h" +#include "JSXMLHttpRequestUpload.h" +#include "Worker.h" +#include "WorkerContext.h" + +#if ENABLE(SVG) +#include "SVGElementInstance.h" +#include "JSSVGElementInstance.h" +#endif + +using namespace JSC; + +namespace WebCore { + +JSValuePtr toJS(ExecState* exec, EventTarget* target) +{ + if (!target) + return jsNull(); + +#if ENABLE(SVG) + // SVGElementInstance supports both toSVGElementInstance and toNode since so much mouse handling code depends on toNode returning a valid node. + if (SVGElementInstance* instance = target->toSVGElementInstance()) + return toJS(exec, instance); +#endif + + if (Node* node = target->toNode()) + return toJS(exec, node); + + if (XMLHttpRequest* xhr = target->toXMLHttpRequest()) + // XMLHttpRequest is always created via JS, so we don't need to use cacheDOMObject() here. + return getCachedDOMObjectWrapper(exec->globalData(), xhr); + + if (XMLHttpRequestUpload* upload = target->toXMLHttpRequestUpload()) + return toJS(exec, upload); + +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + if (DOMApplicationCache* cache = target->toDOMApplicationCache()) + // DOMApplicationCache is always created via JS, so we don't need to use cacheDOMObject() here. + return getCachedDOMObjectWrapper(exec->globalData(), cache); +#endif + + if (MessagePort* messagePort = target->toMessagePort()) + return toJS(exec, messagePort); + +#if ENABLE(WORKERS) + if (Worker* worker = target->toWorker()) + return toJS(exec, worker); + + if (WorkerContext* workerContext = target->toWorkerContext()) + return toJSDOMGlobalObject(workerContext); +#endif + + ASSERT_NOT_REACHED(); + return jsNull(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSEventTarget.h b/src/3rdparty/webkit/WebCore/bindings/js/JSEventTarget.h new file mode 100644 index 0000000..00dd848 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSEventTarget.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSEventTarget_h +#define JSEventTarget_h + +#include <runtime/JSValue.h> + +namespace JSC { + class ExecState; +} + +namespace WebCore { + + class EventTarget; + + JSC::JSValuePtr toJS(JSC::ExecState*, EventTarget*); + +} // namespace WebCore + +#endif // JSEventTarget_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSEventTargetBase.h b/src/3rdparty/webkit/WebCore/bindings/js/JSEventTargetBase.h new file mode 100644 index 0000000..2aa2bf2 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSEventTargetBase.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSEventTargetBase_h +#define JSEventTargetBase_h + +#include "Event.h" +#include "EventNames.h" +#include "JSEvent.h" + +#define JS_EVENT_LISTENER_FOR_EACH_LISTENER(specificEventTarget, macro) \ + macro(specificEventTarget, OnAbort, abortEvent) \ + macro(specificEventTarget, OnBlur, blurEvent) \ + macro(specificEventTarget, OnChange, changeEvent) \ + macro(specificEventTarget, OnClick, clickEvent) \ + macro(specificEventTarget, OnContextMenu, contextmenuEvent) \ + macro(specificEventTarget, OnDblClick, dblclickEvent) \ + macro(specificEventTarget, OnError, errorEvent) \ + macro(specificEventTarget, OnFocus, focusEvent) \ + macro(specificEventTarget, OnInput, inputEvent) \ + macro(specificEventTarget, OnKeyDown, keydownEvent) \ + macro(specificEventTarget, OnKeyPress, keypressEvent) \ + macro(specificEventTarget, OnKeyUp, keyupEvent) \ + macro(specificEventTarget, OnLoad, loadEvent) \ + macro(specificEventTarget, OnMouseDown, mousedownEvent) \ + macro(specificEventTarget, OnMouseMove, mousemoveEvent) \ + macro(specificEventTarget, OnMouseOut, mouseoutEvent) \ + macro(specificEventTarget, OnMouseOver, mouseoverEvent) \ + macro(specificEventTarget, OnMouseUp, mouseupEvent) \ + macro(specificEventTarget, OnMouseWheel, mousewheelEvent) \ + macro(specificEventTarget, OnBeforeCut, beforecutEvent) \ + macro(specificEventTarget, OnCut, cutEvent) \ + macro(specificEventTarget, OnBeforeCopy, beforecopyEvent) \ + macro(specificEventTarget, OnCopy, copyEvent) \ + macro(specificEventTarget, OnBeforePaste, beforepasteEvent) \ + macro(specificEventTarget, OnPaste, pasteEvent) \ + macro(specificEventTarget, OnDragEnter, dragenterEvent) \ + macro(specificEventTarget, OnDragOver, dragoverEvent) \ + macro(specificEventTarget, OnDragLeave, dragleaveEvent) \ + macro(specificEventTarget, OnDrop, dropEvent) \ + macro(specificEventTarget, OnDragStart, dragstartEvent) \ + macro(specificEventTarget, OnDrag, dragEvent) \ + macro(specificEventTarget, OnDragEnd, dragendEvent) \ + macro(specificEventTarget, OnReset, resetEvent) \ + macro(specificEventTarget, OnResize, resizeEvent) \ + macro(specificEventTarget, OnScroll, scrollEvent) \ + macro(specificEventTarget, OnSearch, searchEvent) \ + macro(specificEventTarget, OnSelect, selectEvent) \ + macro(specificEventTarget, OnSelectStart, selectstartEvent) \ + macro(specificEventTarget, OnSubmit, submitEvent) \ + macro(specificEventTarget, OnUnload, unloadEvent) \ + +#define EVENT_LISTENER_GETTER(specificEventTarget, name, event) \ +JSC::JSValuePtr js##specificEventTarget##name(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot& slot) \ +{ \ + return static_cast<JS##specificEventTarget*>(slot.slotBase())->getListener(event); \ +} \ + +#define EVENT_LISTENER_SETTER(specificEventTarget, name, event) \ +void setJS##specificEventTarget##name(JSC::ExecState* exec, JSC::JSObject* baseObject, JSC::JSValuePtr value) \ +{ \ + static_cast<JS##specificEventTarget*>(baseObject)->setListener(exec, event, value); \ +} \ + +#define DECLARE_JS_EVENT_LISTENERS(specificEventTarget) \ + JS_EVENT_LISTENER_FOR_EACH_LISTENER(specificEventTarget, EVENT_LISTENER_GETTER) \ + JS_EVENT_LISTENER_FOR_EACH_LISTENER(specificEventTarget, EVENT_LISTENER_SETTER) \ + +#endif // JSEventTargetBase_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSEventTargetNodeCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSEventTargetNodeCustom.cpp new file mode 100644 index 0000000..12fd98b --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSEventTargetNodeCustom.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSEventTargetNode.h" + +#include "AtomicString.h" +#include "Document.h" +#include "Event.h" +#include "EventTargetNode.h" +#include "ExceptionCode.h" +#include "Frame.h" +#include "JSDOMWindow.h" +#include "JSEvent.h" +#include "JSEventListener.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSEventTargetNode::addEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + + if (RefPtr<JSEventListener> listener = globalObject->findOrCreateJSEventListener(exec, args.at(exec, 1))) + impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec)); + + return jsUndefined(); +} + +JSValuePtr JSEventTargetNode::removeEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + + if (JSEventListener* listener = globalObject->findJSEventListener(args.at(exec, 1))) + impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec)); + + return jsUndefined(); +} + +void JSEventTargetNode::pushEventHandlerScope(ExecState*, ScopeChain&) const +{ +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSGeolocationCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSGeolocationCustom.cpp new file mode 100644 index 0000000..2b6fb20 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSGeolocationCustom.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSGeolocation.h" + +#include "DOMWindow.h" +#include "ExceptionCode.h" +#include "Geolocation.h" +#include "GeolocationService.h" +#include "JSCustomPositionCallback.h" +#include "JSCustomPositionErrorCallback.h" +#include "JSDOMWindow.h" +#include "PositionOptions.h" + +using namespace JSC; + +namespace WebCore { + +static PassRefPtr<PositionOptions> createPositionOptions(ExecState* exec, JSValuePtr value) +{ + if (!value->isObject()) + return 0; + + JSObject* object = asObject(value); + + JSValuePtr enableHighAccuracyValue = object->get(exec, Identifier(exec, "enableHighAccuracy")); + if (exec->hadException()) + return 0; + bool enableHighAccuracy = enableHighAccuracyValue->toBoolean(exec); + if (exec->hadException()) + return 0; + + JSValuePtr timeoutValue = object->get(exec, Identifier(exec, "timeout")); + if (exec->hadException()) + return 0; + unsigned timeout = timeoutValue->toUInt32(exec); + if (exec->hadException()) + return 0; + + return PositionOptions::create(enableHighAccuracy, timeout); +} + +JSValuePtr JSGeolocation::getCurrentPosition(ExecState* exec, const ArgList& args) +{ + // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions + RefPtr<PositionCallback> positionCallback; + JSObject* object = args.at(exec, 0)->getObject(); + if (exec->hadException()) + return jsUndefined(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame()) + positionCallback = JSCustomPositionCallback::create(object, frame); + + RefPtr<PositionErrorCallback> positionErrorCallback; + if (!args.at(exec, 1)->isUndefinedOrNull()) { + JSObject* object = args.at(exec, 1)->getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame()) + positionErrorCallback = JSCustomPositionErrorCallback::create(object, frame); + } + + RefPtr<PositionOptions> positionOptions; + if (!args.at(exec, 2)->isUndefinedOrNull()) { + positionOptions = createPositionOptions(exec, args.at(exec, 2)); + if (exec->hadException()) + return jsUndefined(); + } + + m_impl->getCurrentPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.get()); + + return jsUndefined(); +} + +JSValuePtr JSGeolocation::watchPosition(ExecState* exec, const ArgList& args) +{ + // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions + RefPtr<PositionCallback> positionCallback; + JSObject* object = args.at(exec, 0)->getObject(); + if (exec->hadException()) + return jsUndefined(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame()) + positionCallback = JSCustomPositionCallback::create(object, frame); + + RefPtr<PositionErrorCallback> positionErrorCallback; + if (!args.at(exec, 1)->isUndefinedOrNull()) { + JSObject* object = args.at(exec, 1)->getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame()) + positionErrorCallback = JSCustomPositionErrorCallback::create(object, frame); + } + + RefPtr<PositionOptions> positionOptions; + if (!args.at(exec, 2)->isUndefinedOrNull()) { + positionOptions = createPositionOptions(exec, args.at(exec, 2)); + if (exec->hadException()) + return jsUndefined(); + } + + int watchID = m_impl->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.get()); + return jsNumber(exec, watchID); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAllCollection.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAllCollection.cpp new file mode 100644 index 0000000..ce2609c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAllCollection.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSHTMLAllCollection.h" + +using namespace JSC; + +namespace WebCore { + +const ClassInfo JSHTMLAllCollection::s_info = { "HTMLAllCollection", 0, 0, 0 }; + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAllCollection.h b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAllCollection.h new file mode 100644 index 0000000..511c9d7 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAllCollection.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSHTMLAllCollection_h +#define JSHTMLAllCollection_h + +#include "HTMLCollection.h" +#include "JSHTMLCollection.h" + +namespace WebCore { + + class HTMLCollection; + + class JSHTMLAllCollection : public JSHTMLCollection { + public: + JSHTMLAllCollection(PassRefPtr<JSC::Structure> structure, PassRefPtr<HTMLCollection> collection) + : JSHTMLCollection(structure, collection) + { + } + + static PassRefPtr<JSC::Structure> createStructure(JSC::JSValuePtr proto) + { + return JSC::Structure::create(proto, JSC::TypeInfo(JSC::ObjectType, JSC::MasqueradesAsUndefined)); + } + + static const JSC::ClassInfo s_info; + + private: + virtual bool toBoolean(JSC::ExecState*) const { return false; } + }; + +} // namespace WebCore + +#endif // JSHTMLAllCollection_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp new file mode 100644 index 0000000..a99a36d --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSHTMLAppletElementCustom.h" + +#include "HTMLAppletElement.h" +#include "JSPluginElementFunctions.h" + +namespace WebCore { + +using namespace JSC; + +bool JSHTMLAppletElement::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return runtimeObjectCustomGetOwnPropertySlot(exec, propertyName, slot, this); +} + +bool JSHTMLAppletElement::customPut(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) +{ + return runtimeObjectCustomPut(exec, propertyName, value, impl(), slot); +} + +CallType JSHTMLAppletElement::getCallData(CallData& callData) +{ + return runtimeObjectGetCallData(impl(), callData); +} + +bool JSHTMLAppletElement::canGetItemsForName(ExecState*, HTMLAppletElement*, const Identifier& propertyName) +{ + return propertyName == "__apple_runtime_object"; +} + +JSValuePtr JSHTMLAppletElement::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + return runtimeObjectGetter(exec, propertyName, slot); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAppletElementCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAppletElementCustom.h new file mode 100644 index 0000000..5df9a66 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLAppletElementCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSHTMLAppletElementCustom_h +#define JSHTMLAppletElementCustom_h + +#include "JSHTMLAppletElement.h" + +#endif // JSHTMLAppletElementCustom_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLCollectionCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLCollectionCustom.cpp new file mode 100644 index 0000000..7ff5392 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLCollectionCustom.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSHTMLCollection.h" + +#include "AtomicString.h" +#include "HTMLCollection.h" +#include "HTMLOptionsCollection.h" +#include "JSHTMLAllCollection.h" +#include "JSHTMLOptionsCollection.h" +#include "JSNamedNodesCollection.h" +#include "JSNode.h" +#include "Node.h" +#include "JSDOMBinding.h" +#include <wtf/Vector.h> + +using namespace JSC; + +namespace WebCore { + +static JSValuePtr getNamedItems(ExecState* exec, HTMLCollection* impl, const Identifier& propertyName) +{ + Vector<RefPtr<Node> > namedItems; + impl->namedItems(propertyName, namedItems); + + if (namedItems.isEmpty()) + return jsUndefined(); + + if (namedItems.size() == 1) + return toJS(exec, namedItems[0].get()); + + return new (exec) JSNamedNodesCollection(exec, namedItems); +} + +// HTMLCollections are strange objects, they support both get and call, +// so that document.forms.item(0) and document.forms(0) both work. +static JSValuePtr callHTMLCollection(ExecState* exec, JSObject* function, JSValuePtr, const ArgList& args) +{ + if (args.size() < 1) + return jsUndefined(); + + // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case. + HTMLCollection* collection = static_cast<JSHTMLCollection*>(function)->impl(); + + // Also, do we need the TypeError test here ? + + if (args.size() == 1) { + // Support for document.all(<index>) etc. + bool ok; + UString string = args.at(exec, 0)->toString(exec); + unsigned index = string.toUInt32(&ok, false); + if (ok) + return toJS(exec, collection->item(index)); + + // Support for document.images('<name>') etc. + return getNamedItems(exec, collection, Identifier(exec, string)); + } + + // The second arg, if set, is the index of the item we want + bool ok; + UString string = args.at(exec, 0)->toString(exec); + unsigned index = args.at(exec, 1)->toString(exec).toUInt32(&ok, false); + if (ok) { + String pstr = string; + Node* node = collection->namedItem(pstr); + while (node) { + if (!index) + return toJS(exec, node); + node = collection->nextNamedItem(pstr); + --index; + } + } + + return jsUndefined(); +} + +CallType JSHTMLCollection::getCallData(CallData& callData) +{ + callData.native.function = callHTMLCollection; + return CallTypeHost; +} + +bool JSHTMLCollection::canGetItemsForName(ExecState* exec, HTMLCollection* thisObj, const Identifier& propertyName) +{ + return !getNamedItems(exec, thisObj, propertyName)->isUndefined(); +} + +JSValuePtr JSHTMLCollection::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSHTMLCollection* thisObj = static_cast<JSHTMLCollection*>(asObject(slot.slotBase())); + return getNamedItems(exec, thisObj->impl(), propertyName); +} + +JSValuePtr JSHTMLCollection::item(ExecState* exec, const ArgList& args) +{ + bool ok; + uint32_t index = args.at(exec, 0)->toString(exec).toUInt32(&ok, false); + if (ok) + return toJS(exec, impl()->item(index)); + return getNamedItems(exec, impl(), Identifier(exec, args.at(exec, 0)->toString(exec))); +} + +JSValuePtr JSHTMLCollection::namedItem(ExecState* exec, const ArgList& args) +{ + return getNamedItems(exec, impl(), Identifier(exec, args.at(exec, 0)->toString(exec))); +} + +JSValuePtr toJS(ExecState* exec, HTMLCollection* collection) +{ + if (!collection) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), collection); + + if (wrapper) + return wrapper; + + switch (collection->type()) { + case HTMLCollection::SelectOptions: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, HTMLOptionsCollection, collection); + break; + case HTMLCollection::DocAll: + typedef HTMLCollection HTMLAllCollection; + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, HTMLAllCollection, collection); + break; + default: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, HTMLCollection, collection); + break; + } + + return wrapper; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLDocumentCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLDocumentCustom.cpp new file mode 100644 index 0000000..e6abd29 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLDocumentCustom.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSHTMLDocument.h" + +#include "Frame.h" +#include "HTMLBodyElement.h" +#include "HTMLCollection.h" +#include "HTMLDocument.h" +#include "HTMLElement.h" +#include "HTMLIFrameElement.h" +#include "HTMLNames.h" +#include "JSDOMWindow.h" +#include "JSDOMWindowCustom.h" +#include "JSDOMWindowShell.h" +#include "JSHTMLCollection.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +bool JSHTMLDocument::canGetItemsForName(ExecState*, HTMLDocument* document, const Identifier& propertyName) +{ + AtomicStringImpl* atomicPropertyName = AtomicString::find(propertyName); + return atomicPropertyName && (document->hasNamedItem(atomicPropertyName) || document->hasExtraNamedItem(atomicPropertyName)); +} + +JSValuePtr JSHTMLDocument::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSHTMLDocument* thisObj = static_cast<JSHTMLDocument*>(asObject(slot.slotBase())); + HTMLDocument* document = static_cast<HTMLDocument*>(thisObj->impl()); + + String name = propertyName; + RefPtr<HTMLCollection> collection = document->documentNamedItems(name); + + unsigned length = collection->length(); + if (!length) + return jsUndefined(); + + if (length == 1) { + Node* node = collection->firstItem(); + + Frame* frame; + if (node->hasTagName(iframeTag) && (frame = static_cast<HTMLIFrameElement*>(node)->contentFrame())) + return toJS(exec, frame); + + return toJS(exec, node); + } + + return toJS(exec, collection.get()); +} + +// Custom attributes + +JSValuePtr JSHTMLDocument::all(ExecState* exec) const +{ + // If "all" has been overwritten, return the overwritten value + JSValuePtr v = getDirect(Identifier(exec, "all")); + if (v) + return v; + + return toJS(exec, static_cast<HTMLDocument*>(impl())->all().get()); +} + +void JSHTMLDocument::setAll(ExecState* exec, JSValuePtr value) +{ + // Add "all" to the property map. + putDirect(Identifier(exec, "all"), value); +} + +// Custom functions + +JSValuePtr JSHTMLDocument::open(ExecState* exec, const ArgList& args) +{ + // For compatibility with other browsers, pass open calls with more than 2 parameters to the window. + if (args.size() > 2) { + Frame* frame = static_cast<HTMLDocument*>(impl())->frame(); + if (frame) { + JSDOMWindowShell* wrapper = toJSDOMWindowShell(frame); + if (wrapper) { + JSValuePtr function = wrapper->get(exec, Identifier(exec, "open")); + CallData callData; + CallType callType = function->getCallData(callData); + if (callType == CallTypeNone) + return throwError(exec, TypeError); + return call(exec, function, callType, callData, wrapper, args); + } + } + return jsUndefined(); + } + + // document.open clobbers the security context of the document and + // aliases it with the active security context. + Document* activeDocument = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->document(); + + // In the case of two parameters or fewer, do a normal document open. + static_cast<HTMLDocument*>(impl())->open(activeDocument); + return this; +} + +static String writeHelper(ExecState* exec, const ArgList& args) +{ + // DOM only specifies single string argument, but NS & IE allow multiple + // or no arguments. + + unsigned size = args.size(); + if (size == 1) + return args.at(exec, 0)->toString(exec); + + Vector<UChar> result; + for (unsigned i = 0; i < size; ++i) + append(result, args.at(exec, i)->toString(exec)); + return String::adopt(result); +} + +JSValuePtr JSHTMLDocument::write(ExecState* exec, const ArgList& args) +{ + Document* activeDocument = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->document(); + static_cast<HTMLDocument*>(impl())->write(writeHelper(exec, args), activeDocument); + return jsUndefined(); +} + +JSValuePtr JSHTMLDocument::writeln(ExecState* exec, const ArgList& args) +{ + Document* activeDocument = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->document(); + static_cast<HTMLDocument*>(impl())->write(writeHelper(exec, args) + "\n", activeDocument); + return jsUndefined(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLElementCustom.cpp new file mode 100644 index 0000000..3345764 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLElementCustom.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSHTMLElement.h" + +#include "Document.h" +#include "HTMLFormElement.h" + +namespace WebCore { + +using namespace JSC; + +void JSHTMLElement::pushEventHandlerScope(ExecState* exec, ScopeChain& scope) const +{ + HTMLElement* element = impl(); + + // The document is put on first, fall back to searching it only after the element and form. + scope.push(asObject(toJS(exec, element->ownerDocument()))); + + // The form is next, searched before the document, but after the element itself. + if (HTMLFormElement* form = element->form()) + scope.push(asObject(toJS(exec, form))); + + // The element is on top, searched first. + scope.push(asObject(toJS(exec, element))); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp new file mode 100644 index 0000000..2856393 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSHTMLEmbedElementCustom.h" + +#include "HTMLEmbedElement.h" +#include "JSPluginElementFunctions.h" + +namespace WebCore { + +using namespace JSC; + +bool JSHTMLEmbedElement::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return runtimeObjectCustomGetOwnPropertySlot(exec, propertyName, slot, this); +} + +bool JSHTMLEmbedElement::customPut(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) +{ + return runtimeObjectCustomPut(exec, propertyName, value, impl(), slot); +} + +CallType JSHTMLEmbedElement::getCallData(CallData& callData) +{ + return runtimeObjectGetCallData(impl(), callData); +} + +bool JSHTMLEmbedElement::canGetItemsForName(ExecState*, HTMLEmbedElement*, const Identifier& propertyName) +{ + return propertyName == "__apple_runtime_object"; +} + +JSValuePtr JSHTMLEmbedElement::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + return runtimeObjectGetter(exec, propertyName, slot); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLEmbedElementCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLEmbedElementCustom.h new file mode 100644 index 0000000..58833ae --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLEmbedElementCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSHTMLEmbedElementCustom_h +#define JSHTMLEmbedElementCustom_h + +#include "JSHTMLEmbedElement.h" + +#endif // JSHTMLEmbedElementCustom_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLFormElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLFormElementCustom.cpp new file mode 100644 index 0000000..4e16cc5 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLFormElementCustom.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSHTMLFormElement.h" + +#include "HTMLCollection.h" +#include "HTMLFormElement.h" +#include "JSNamedNodesCollection.h" + +using namespace JSC; + +namespace WebCore { + +bool JSHTMLFormElement::canGetItemsForName(ExecState*, HTMLFormElement* form, const Identifier& propertyName) +{ + Vector<RefPtr<Node> > namedItems; + form->getNamedElements(propertyName, namedItems); + return namedItems.size(); +} + +JSValuePtr JSHTMLFormElement::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + HTMLFormElement* form = static_cast<HTMLFormElement*>(static_cast<JSHTMLElement*>(asObject(slot.slotBase()))->impl()); + + Vector<RefPtr<Node> > namedItems; + form->getNamedElements(propertyName, namedItems); + + if (namedItems.size() == 1) + return toJS(exec, namedItems[0].get()); + if (namedItems.size() > 1) + return new (exec) JSNamedNodesCollection(exec, namedItems); + return jsUndefined(); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLFrameElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLFrameElementCustom.cpp new file mode 100644 index 0000000..a97a72a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLFrameElementCustom.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSHTMLFrameElement.h" + +#include "CSSHelper.h" +#include "Document.h" +#include "HTMLFrameElement.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +static inline bool allowSettingJavascriptURL(ExecState* exec, HTMLFrameElement* imp, const String& value) +{ + if (protocolIs(parseURL(value), "javascript")) { + if (!checkNodeSecurity(exec, imp->contentDocument())) + return false; + } + return true; +} + +void JSHTMLFrameElement::setSrc(ExecState* exec, JSValuePtr value) +{ + HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); + String srcValue = valueToStringWithNullCheck(exec, value); + + if (!allowSettingJavascriptURL(exec, imp, srcValue)) + return; + + imp->setSrc(srcValue); + return; +} + +void JSHTMLFrameElement::setLocation(ExecState* exec, JSValuePtr value) +{ + HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); + String locationValue = valueToStringWithNullCheck(exec, value); + + if (!allowSettingJavascriptURL(exec, imp, locationValue)) + return; + + imp->setLocation(locationValue); + return; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp new file mode 100644 index 0000000..f17cb89 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSHTMLFrameSetElement.h" + +#include "Document.h" +#include "HTMLFrameElement.h" +#include "HTMLFrameSetElement.h" +#include "HTMLNames.h" +#include "JSDOMWindow.h" +#include "JSDOMWindowShell.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +bool JSHTMLFrameSetElement::canGetItemsForName(ExecState*, HTMLFrameSetElement* frameSet, const Identifier& propertyName) +{ + Node* frame = frameSet->children()->namedItem(propertyName); + return frame && frame->hasTagName(frameTag); +} + +JSValuePtr JSHTMLFrameSetElement::nameGetter(ExecState*, const Identifier& propertyName, const PropertySlot& slot) +{ + JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(asObject(slot.slotBase())); + HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl()); + + Node* frame = element->children()->namedItem(propertyName); + if (Document* doc = static_cast<HTMLFrameElement*>(frame)->contentDocument()) { + if (JSDOMWindowShell* window = toJSDOMWindowShell(doc->frame())) + return window; + } + + return jsUndefined(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLIFrameElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLIFrameElementCustom.cpp new file mode 100644 index 0000000..1a0fc1c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLIFrameElementCustom.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSHTMLIFrameElement.h" + +#include "CSSHelper.h" +#include "Document.h" +#include "HTMLIFrameElement.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +void JSHTMLIFrameElement::setSrc(ExecState* exec, JSValuePtr value) +{ + HTMLIFrameElement* imp = static_cast<HTMLIFrameElement*>(impl()); + + String srcValue = valueToStringWithNullCheck(exec, value); + + if (protocolIs(parseURL(srcValue), "javascript")) { + if (!checkNodeSecurity(exec, imp->contentDocument())) + return; + } + + imp->setSrc(srcValue); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLInputElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLInputElementCustom.cpp new file mode 100644 index 0000000..d59ef92 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLInputElementCustom.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSHTMLInputElement.h" + +#include "HTMLInputElement.h" + +using namespace JSC; + +namespace WebCore { + +bool JSHTMLInputElement::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + HTMLInputElement* input = static_cast<HTMLInputElement*>(impl()); + if (input->canHaveSelection()) + return false; + + const HashEntry* entry = JSHTMLInputElementPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry) { + if (entry->attributes() & Function) { + if (entry->function() == jsHTMLInputElementPrototypeFunctionSetSelectionRange) { + slot.setUndefined(); + return true; + } + } + } + + return false; +} + +JSValuePtr JSHTMLInputElement::selectionStart(ExecState* exec) const +{ + HTMLInputElement* input = static_cast<HTMLInputElement*>(impl()); + if (!input->canHaveSelection()) + return jsUndefined(); + + return jsNumber(exec, input->selectionStart()); +} + +JSValuePtr JSHTMLInputElement::selectionEnd(ExecState* exec) const +{ + HTMLInputElement* input = static_cast<HTMLInputElement*>(impl()); + if (!input->canHaveSelection()) + return jsUndefined(); + + return jsNumber(exec, input->selectionEnd()); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLInputElementCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLInputElementCustom.h new file mode 100644 index 0000000..f5222d2 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLInputElementCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSHTMLInputElementCustom_h +#define JSHTMLInputElementCustom_h + +#include "JSHTMLInputElement.h" + +#endif // JSHTMLInputElementCustom_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp new file mode 100644 index 0000000..5ad3454 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSHTMLObjectElementCustom.h" + +#include "HTMLObjectElement.h" +#include "JSPluginElementFunctions.h" + +namespace WebCore { + +using namespace JSC; + +bool JSHTMLObjectElement::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return runtimeObjectCustomGetOwnPropertySlot(exec, propertyName, slot, this); +} + +bool JSHTMLObjectElement::customPut(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) +{ + return runtimeObjectCustomPut(exec, propertyName, value, impl(), slot); +} + +CallType JSHTMLObjectElement::getCallData(CallData& callData) +{ + return runtimeObjectGetCallData(impl(), callData); +} + +bool JSHTMLObjectElement::canGetItemsForName(ExecState*, HTMLObjectElement*, const Identifier& propertyName) +{ + return propertyName == "__apple_runtime_object"; +} + +JSValuePtr JSHTMLObjectElement::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + return runtimeObjectGetter(exec, propertyName, slot); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLObjectElementCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLObjectElementCustom.h new file mode 100644 index 0000000..38659f9 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLObjectElementCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSHTMLObjectElementCustom_h +#define JSHTMLObjectElementCustom_h + +#include "JSHTMLObjectElement.h" + +#endif // JSHTMLObjectElementCustom_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp new file mode 100644 index 0000000..d60483d --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSHTMLOptionsCollection.h" + +#include "ExceptionCode.h" +#include "HTMLNames.h" +#include "HTMLOptionElement.h" +#include "HTMLOptionsCollection.h" +#include "HTMLSelectElement.h" +#include "JSHTMLOptionElement.h" +#include "JSHTMLSelectElement.h" +#include "JSHTMLSelectElementCustom.h" + +#include <wtf/MathExtras.h> + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSHTMLOptionsCollection::length(ExecState* exec) const +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + return jsNumber(exec, imp->length()); +} + +void JSHTMLOptionsCollection::setLength(ExecState* exec, JSValuePtr value) +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + ExceptionCode ec = 0; + unsigned newLength = 0; + double lengthValue = value->toNumber(exec); + if (!isnan(lengthValue) && !isinf(lengthValue)) { + if (lengthValue < 0.0) + ec = INDEX_SIZE_ERR; + else if (lengthValue > static_cast<double>(UINT_MAX)) + newLength = UINT_MAX; + else + newLength = static_cast<unsigned>(lengthValue); + } + if (!ec) + imp->setLength(newLength, ec); + setDOMException(exec, ec); +} + +void JSHTMLOptionsCollection::indexSetter(ExecState* exec, unsigned index, JSValuePtr value) +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + HTMLSelectElement* base = static_cast<HTMLSelectElement*>(imp->base()); + selectIndexSetter(base, exec, index, value); +} + +JSValuePtr JSHTMLOptionsCollection::add(ExecState* exec, const ArgList& args) +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + HTMLOptionElement* option = toHTMLOptionElement(args.at(exec, 0)); + ExceptionCode ec = 0; + if (args.size() < 2) + imp->add(option, ec); + else { + bool ok; + int index = args.at(exec, 1)->toInt32(exec, ok); + if (exec->hadException()) + return jsUndefined(); + if (!ok) + ec = TYPE_MISMATCH_ERR; + else + imp->add(option, index, ec); + } + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValuePtr JSHTMLOptionsCollection::remove(ExecState* exec, const ArgList& args) +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + JSHTMLSelectElement* base = static_cast<JSHTMLSelectElement*>(asObject(toJS(exec, imp->base()))); + return base->remove(exec, args); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp new file mode 100644 index 0000000..4094418 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2007 Apple, Inc. + * Copyright (C) 2007 Alexey Proskuryakov (ap@webkit.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSHTMLSelectElementCustom.h" + +#include "ExceptionCode.h" +#include "HTMLNames.h" +#include "HTMLOptionElement.h" +#include "HTMLSelectElement.h" +#include "JSHTMLOptionElement.h" + +namespace WebCore { + +using namespace JSC; +using namespace HTMLNames; + +JSValuePtr JSHTMLSelectElement::remove(ExecState* exec, const ArgList& args) +{ + HTMLSelectElement& select = *static_cast<HTMLSelectElement*>(impl()); + + // we support both options index and options objects + HTMLElement* element = toHTMLElement(args.at(exec, 0)); + if (element && element->hasTagName(optionTag)) + select.remove(static_cast<HTMLOptionElement*>(element)->index()); + else + select.remove(args.at(exec, 0)->toInt32(exec)); + + return jsUndefined(); +} + +void selectIndexSetter(HTMLSelectElement* select, JSC::ExecState* exec, unsigned index, JSC::JSValuePtr value) +{ + if (value->isUndefinedOrNull()) + select->remove(index); + else { + ExceptionCode ec = 0; + HTMLOptionElement* option = toHTMLOptionElement(value); + if (!option) + ec = TYPE_MISMATCH_ERR; + else + select->setOption(index, option, ec); + setDOMException(exec, ec); + } +} + +void JSHTMLSelectElement::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValuePtr value) +{ + selectIndexSetter(static_cast<HTMLSelectElement*>(impl()), exec, index, value); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLSelectElementCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLSelectElementCustom.h new file mode 100644 index 0000000..87344b5 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHTMLSelectElementCustom.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 JSHTMLSelectElementCustom_h +#define JSHTMLSelectElementCustom_h + +#include "JSHTMLSelectElement.h" + +namespace WebCore { + +void selectIndexSetter(HTMLSelectElement*, JSC::ExecState*, unsigned index, JSC::JSValuePtr); + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHistoryCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSHistoryCustom.cpp new file mode 100644 index 0000000..1baa6d4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHistoryCustom.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSHistoryCustom.h" + +#include "Frame.h" +#include "History.h" +#include <runtime/PrototypeFunction.h> + +using namespace JSC; + +namespace WebCore { + +JSValuePtr nonCachingStaticBackFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 0, propertyName, jsHistoryPrototypeFunctionBack); +} + +JSValuePtr nonCachingStaticForwardFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 0, propertyName, jsHistoryPrototypeFunctionForward); +} + +JSValuePtr nonCachingStaticGoFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 1, propertyName, jsHistoryPrototypeFunctionGo); +} + +bool JSHistory::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + // When accessing History cross-domain, functions are always the native built-in ones. + // See JSDOMWindow::customGetOwnPropertySlot for additional details. + + // Our custom code is only needed to implement the Window cross-domain scheme, so if access is + // allowed, return false so the normal lookup will take place. + String message; + if (allowsAccessFromFrame(exec, impl()->frame(), message)) + return false; + + // Check for the few functions that we allow, even when called cross-domain. + const HashEntry* entry = JSHistoryPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry) { + // Allow access to back(), forward() and go() from any frame. + if (entry->attributes() & Function) { + if (entry->function() == jsHistoryPrototypeFunctionBack) { + slot.setCustom(this, nonCachingStaticBackFunctionGetter); + return true; + } else if (entry->function() == jsHistoryPrototypeFunctionForward) { + slot.setCustom(this, nonCachingStaticForwardFunctionGetter); + return true; + } else if (entry->function() == jsHistoryPrototypeFunctionGo) { + slot.setCustom(this, nonCachingStaticGoFunctionGetter); + return true; + } + } + } else { + // Allow access to toString() cross-domain, but always Object.toString. + if (propertyName == exec->propertyNames().toString) { + slot.setCustom(this, objectToStringFunctionGetter); + return true; + } + } + + printErrorMessageForFrame(impl()->frame(), message); + slot.setUndefined(); + return true; +} + +bool JSHistory::customPut(ExecState* exec, const Identifier&, JSValuePtr, PutPropertySlot&) +{ + // Only allow putting by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return true; + return false; +} + +bool JSHistory::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + // Only allow deleting by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return false; + return Base::deleteProperty(exec, propertyName); +} + +bool JSHistory::customGetPropertyNames(ExecState* exec, PropertyNameArray&) +{ + // Only allow the history object to enumerated by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return true; + return false; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSHistoryCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSHistoryCustom.h new file mode 100644 index 0000000..40edc6f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSHistoryCustom.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSHistoryCustom_h +#define JSHistoryCustom_h + +#include "JSHistory.h" + +#endif // JSHistoryCustom_h + + diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSImageConstructor.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSImageConstructor.cpp new file mode 100644 index 0000000..2237c7a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSImageConstructor.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSImageConstructor.h" + +#include "HTMLImageElement.h" +#include "HTMLNames.h" +#include "JSNode.h" +#include "ScriptExecutionContext.h" + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSImageConstructor) + +const ClassInfo JSImageConstructor::s_info = { "ImageConstructor", 0, 0, 0 }; + +JSImageConstructor::JSImageConstructor(ExecState* exec, ScriptExecutionContext* context) + : DOMObject(JSImageConstructor::createStructure(exec->lexicalGlobalObject()->objectPrototype())) +{ + ASSERT(context->isDocument()); + m_document = static_cast<JSDocument*>(asObject(toJS(exec, static_cast<Document*>(context)))); +} + +static JSObject* constructImage(ExecState* exec, JSObject* constructor, const ArgList& args) +{ + bool widthSet = false; + bool heightSet = false; + int width = 0; + int height = 0; + if (args.size() > 0) { + widthSet = true; + width = args.at(exec, 0)->toInt32(exec); + } + if (args.size() > 1) { + heightSet = true; + height = args.at(exec, 1)->toInt32(exec); + } + + Document* document = static_cast<JSImageConstructor*>(constructor)->document(); + + // Calling toJS on the document causes the JS document wrapper to be + // added to the window object. This is done to ensure that JSDocument::mark + // will be called (which will cause the image element to be marked if necessary). + toJS(exec, document); + + RefPtr<HTMLImageElement> image = new HTMLImageElement(HTMLNames::imgTag, document); + if (widthSet) + image->setWidth(width); + if (heightSet) + image->setHeight(height); + return asObject(toJS(exec, image.release())); +} + +ConstructType JSImageConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructImage; + return ConstructTypeHost; +} + +void JSImageConstructor::mark() +{ + DOMObject::mark(); + if (!m_document->marked()) + m_document->mark(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSImageConstructor.h b/src/3rdparty/webkit/WebCore/bindings/js/JSImageConstructor.h new file mode 100644 index 0000000..13cce26 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSImageConstructor.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 1999 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSImageConstructor_h +#define JSImageConstructor_h + +#include "JSDOMBinding.h" +#include "JSDocument.h" + +namespace WebCore { + + class JSImageConstructor : public DOMObject { + public: + JSImageConstructor(JSC::ExecState*, ScriptExecutionContext*); + Document* document() const { return m_document->impl(); } + + static const JSC::ClassInfo s_info; + + virtual void mark(); + private: + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + + JSDocument* m_document; + }; + +} // namespace WebCore + +#endif // JSImageConstructor_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSImageDataCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSImageDataCustom.cpp new file mode 100644 index 0000000..920121e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSImageDataCustom.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSImageData.h" + +#include "ImageData.h" +#include "PlatformString.h" + +#include <runtime/JSByteArray.h> +#include <wtf/StdLibExtras.h> + +using namespace JSC; + +namespace WebCore { + +JSValuePtr toJS(ExecState* exec, ImageData* imageData) +{ + if (!imageData) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), imageData); + if (wrapper) + return wrapper; + + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, ImageData, imageData); + Identifier dataName(exec, "data"); + DEFINE_STATIC_LOCAL(RefPtr<Structure>, cpaStructure, (JSByteArray::createStructure(jsNull()))); + static const ClassInfo cpaClassInfo = { "CanvasPixelArray", 0, 0, 0 }; + wrapper->putDirect(dataName, new (exec) JSByteArray(exec, cpaStructure, imageData->data(), &cpaClassInfo), DontDelete | ReadOnly); + exec->heap()->reportExtraMemoryCost(imageData->data()->length()); + + return wrapper; +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSInspectedObjectWrapper.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSInspectedObjectWrapper.cpp new file mode 100644 index 0000000..80c35df --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSInspectedObjectWrapper.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSInspectedObjectWrapper.h" + +#include "JSInspectorCallbackWrapper.h" +#include <runtime/JSGlobalObject.h> +#include <wtf/StdLibExtras.h> + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSInspectedObjectWrapper) + +typedef HashMap<JSObject*, JSInspectedObjectWrapper*> WrapperMap; +typedef HashMap<JSGlobalObject*, WrapperMap*> GlobalObjectWrapperMap; + +static GlobalObjectWrapperMap& wrappers() +{ + DEFINE_STATIC_LOCAL(GlobalObjectWrapperMap, map, ()); + return map; +} + +const ClassInfo JSInspectedObjectWrapper::s_info = { "JSInspectedObjectWrapper", &JSQuarantinedObjectWrapper::s_info, 0, 0 }; + +JSValuePtr JSInspectedObjectWrapper::wrap(ExecState* unwrappedExec, JSValuePtr unwrappedValue) +{ + if (!unwrappedValue->isObject()) + return unwrappedValue; + + JSObject* unwrappedObject = asObject(unwrappedValue); + + if (unwrappedObject->inherits(&JSInspectedObjectWrapper::s_info)) + return unwrappedObject; + + if (WrapperMap* wrapperMap = wrappers().get(unwrappedExec->dynamicGlobalObject())) + if (JSInspectedObjectWrapper* wrapper = wrapperMap->get(unwrappedObject)) + return wrapper; + + JSValuePtr prototype = unwrappedObject->prototype(); + ASSERT(prototype->isNull() || prototype->isObject()); + + if (prototype->isNull()) + return new (unwrappedExec) JSInspectedObjectWrapper(unwrappedExec, unwrappedObject, JSQuarantinedObjectWrapper::createStructure(jsNull())); + return new (unwrappedExec) JSInspectedObjectWrapper(unwrappedExec, unwrappedObject, JSQuarantinedObjectWrapper::createStructure(asObject(wrap(unwrappedExec, prototype)))); +} + +JSInspectedObjectWrapper::JSInspectedObjectWrapper(ExecState* unwrappedExec, JSObject* unwrappedObject, PassRefPtr<Structure> structure) + : JSQuarantinedObjectWrapper(unwrappedExec, unwrappedObject, structure) +{ + WrapperMap* wrapperMap = wrappers().get(unwrappedGlobalObject()); + if (!wrapperMap) { + wrapperMap = new WrapperMap; + wrappers().set(unwrappedGlobalObject(), wrapperMap); + } + + ASSERT(!wrapperMap->contains(unwrappedObject)); + wrapperMap->set(unwrappedObject, this); +} + +JSInspectedObjectWrapper::~JSInspectedObjectWrapper() +{ + ASSERT(wrappers().contains(unwrappedGlobalObject())); + WrapperMap* wrapperMap = wrappers().get(unwrappedGlobalObject()); + + ASSERT(wrapperMap->contains(unwrappedObject())); + wrapperMap->remove(unwrappedObject()); + + if (wrapperMap->isEmpty()) { + wrappers().remove(unwrappedGlobalObject()); + delete wrapperMap; + } +} + +JSValuePtr JSInspectedObjectWrapper::prepareIncomingValue(ExecState*, JSValuePtr value) const +{ + // The Inspector is only allowed to pass primitive values and wrapped objects to objects from the inspected page. + + if (!value->isObject()) + return value; + + JSQuarantinedObjectWrapper* wrapper = asWrapper(value); + ASSERT_WITH_MESSAGE(wrapper, "Objects passed to JSInspectedObjectWrapper must be wrapped"); + if (!wrapper) + return jsUndefined(); + + if (wrapper->allowsUnwrappedAccessFrom(unwrappedExecState())) { + ASSERT_WITH_MESSAGE(wrapper->inherits(&s_info), "A wrapper contains an object from the inspected page but is not a JSInspectedObjectWrapper"); + if (!wrapper->inherits(&s_info)) + return jsUndefined(); + + // Return the unwrapped object so the inspected page never sees one of its own objects in wrapped form. + return wrapper->unwrappedObject(); + } + + ASSERT_WITH_MESSAGE(wrapper->inherits(&JSInspectorCallbackWrapper::s_info), "A wrapper that was not from the inspected page and is not an Inspector callback was passed to a JSInspectedObjectWrapper"); + if (!wrapper->inherits(&JSInspectorCallbackWrapper::s_info)) + return jsUndefined(); + + return wrapper; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSInspectedObjectWrapper.h b/src/3rdparty/webkit/WebCore/bindings/js/JSInspectedObjectWrapper.h new file mode 100644 index 0000000..273c0b0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSInspectedObjectWrapper.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSInspectedObjectWrapper_h +#define JSInspectedObjectWrapper_h + +#include "JSQuarantinedObjectWrapper.h" + +namespace WebCore { + + class JSInspectedObjectWrapper : public JSQuarantinedObjectWrapper { + public: + static JSC::JSValuePtr wrap(JSC::ExecState* unwrappedExec, JSC::JSValuePtr unwrappedValue); + virtual ~JSInspectedObjectWrapper(); + + static const JSC::ClassInfo s_info; + + private: + JSInspectedObjectWrapper(JSC::ExecState* unwrappedExec, JSC::JSObject* unwrappedObject, PassRefPtr<JSC::Structure>); + + virtual bool allowsGetProperty() const { return true; } + virtual bool allowsSetProperty() const { return true; } + virtual bool allowsDeleteProperty() const { return true; } + virtual bool allowsConstruct() const { return true; } + virtual bool allowsHasInstance() const { return true; } + virtual bool allowsCallAsFunction() const { return true; } + virtual bool allowsGetPropertyNames() const { return true; } + + virtual JSC::JSValuePtr prepareIncomingValue(JSC::ExecState* unwrappedExec, JSC::JSValuePtr unwrappedValue) const; + virtual JSC::JSValuePtr wrapOutgoingValue(JSC::ExecState* unwrappedExec, JSC::JSValuePtr unwrappedValue) const { return wrap(unwrappedExec, unwrappedValue); } + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + }; + +} // namespace WebCore + +#endif // JSInspectedObjectWrapper_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSInspectorCallbackWrapper.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSInspectorCallbackWrapper.cpp new file mode 100644 index 0000000..8e13e42 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSInspectorCallbackWrapper.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSInspectorCallbackWrapper.h" + +#include "JSInspectedObjectWrapper.h" +#include <wtf/StdLibExtras.h> + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSInspectorCallbackWrapper) + +typedef HashMap<JSObject*, JSInspectorCallbackWrapper*> WrapperMap; + +static WrapperMap& wrappers() +{ + DEFINE_STATIC_LOCAL(WrapperMap, map, ()); + return map; +} + +const ClassInfo JSInspectorCallbackWrapper::s_info = { "JSInspectorCallbackWrapper", &JSQuarantinedObjectWrapper::s_info, 0, 0 }; + +static Structure* leakInspectorCallbackWrapperStructure() +{ + Structure::startIgnoringLeaks(); + Structure* structure = JSInspectorCallbackWrapper::createStructure(jsNull()).releaseRef(); + Structure::stopIgnoringLeaks(); + return structure; +} + +JSValuePtr JSInspectorCallbackWrapper::wrap(ExecState* unwrappedExec, JSValuePtr unwrappedValue) +{ + if (!unwrappedValue->isObject()) + return unwrappedValue; + + JSObject* unwrappedObject = asObject(unwrappedValue); + + if (unwrappedObject->inherits(&JSInspectorCallbackWrapper::s_info)) + return unwrappedObject; + + if (JSInspectorCallbackWrapper* wrapper = wrappers().get(unwrappedObject)) + return wrapper; + + JSValuePtr prototype = unwrappedObject->prototype(); + ASSERT(prototype->isNull() || prototype->isObject()); + + if (prototype->isNull()) { + static Structure* structure = leakInspectorCallbackWrapperStructure(); + return new (unwrappedExec) JSInspectorCallbackWrapper(unwrappedExec, unwrappedObject, structure); + } + return new (unwrappedExec) JSInspectorCallbackWrapper(unwrappedExec, unwrappedObject, asObject(wrap(unwrappedExec, prototype))->inheritorID()); +} + +JSInspectorCallbackWrapper::JSInspectorCallbackWrapper(ExecState* unwrappedExec, JSObject* unwrappedObject, PassRefPtr<Structure> structure) + : JSQuarantinedObjectWrapper(unwrappedExec, unwrappedObject, structure) +{ + ASSERT(!wrappers().contains(unwrappedObject)); + wrappers().set(unwrappedObject, this); +} + +JSInspectorCallbackWrapper::~JSInspectorCallbackWrapper() +{ + wrappers().remove(unwrappedObject()); +} + +JSValuePtr JSInspectorCallbackWrapper::prepareIncomingValue(ExecState* unwrappedExec, JSValuePtr unwrappedValue) const +{ + if (JSQuarantinedObjectWrapper* wrapper = asWrapper(unwrappedValue)) { + // The only time a wrapper should be passed into a JSInspectorCallbackWrapper is when a client-side storage callback + // is called. (The client-side storage API calls the callback with the `this` object set to the callback itself.) + ASSERT_WITH_MESSAGE(wrapper == this, "A different wrapper was passed into a JSInspectorCallbackWrapper"); + if (wrapper != this) + return jsUndefined(); + + return wrapper->unwrappedObject(); + } + + // Any value being passed to the Inspector from the inspected page should be wrapped in a JSInspectedObjectWrapper. + return JSInspectedObjectWrapper::wrap(unwrappedExec, unwrappedValue); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSInspectorCallbackWrapper.h b/src/3rdparty/webkit/WebCore/bindings/js/JSInspectorCallbackWrapper.h new file mode 100644 index 0000000..49157c0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSInspectorCallbackWrapper.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSInspectorCallbackWrapper_h +#define JSInspectorCallbackWrapper_h + +#include "JSQuarantinedObjectWrapper.h" + +namespace WebCore { + + class JSInspectorCallbackWrapper : public JSQuarantinedObjectWrapper { + public: + static JSC::JSValuePtr wrap(JSC::ExecState* unwrappedExec, JSC::JSValuePtr unwrappedValue); + + virtual ~JSInspectorCallbackWrapper(); + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + static const JSC::ClassInfo s_info; + + protected: + JSInspectorCallbackWrapper(JSC::ExecState* unwrappedExec, JSC::JSObject* unwrappedObject, PassRefPtr<JSC::Structure>); + + virtual bool allowsCallAsFunction() const { return true; } + + virtual JSC::JSValuePtr prepareIncomingValue(JSC::ExecState* unwrappedExec, JSC::JSValuePtr unwrappedValue) const; + virtual JSC::JSValuePtr wrapOutgoingValue(JSC::ExecState* unwrappedExec, JSC::JSValuePtr unwrappedValue) const { return wrap(unwrappedExec, unwrappedValue); } + }; + +} // namespace WebCore + +#endif // JSInspectorCallbackWrapper_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp new file mode 100644 index 0000000..c3f89c3 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSJavaScriptCallFrame.h" + +#include "JavaScriptCallFrame.h" +#include <runtime/ArrayPrototype.h> + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSJavaScriptCallFrame::evaluate(ExecState* exec, const ArgList& args) +{ + JSValuePtr exception = noValue(); + JSValuePtr result = impl()->evaluate(args.at(exec, 0)->toString(exec), exception); + + if (exception) + exec->setException(exception); + + return result; +} + +JSValuePtr JSJavaScriptCallFrame::thisObject(ExecState*) const +{ + return impl()->thisObject() ? impl()->thisObject() : jsNull(); +} + +JSValuePtr JSJavaScriptCallFrame::type(ExecState* exec) const +{ + switch (impl()->type()) { + case DebuggerCallFrame::FunctionType: + return jsString(exec, "function"); + case DebuggerCallFrame::ProgramType: + return jsString(exec, "program"); + } + + ASSERT_NOT_REACHED(); + return jsNull(); +} + +JSValuePtr JSJavaScriptCallFrame::scopeChain(ExecState* exec) const +{ + if (!impl()->scopeChain()) + return jsNull(); + + const ScopeChainNode* scopeChain = impl()->scopeChain(); + ScopeChainIterator iter = scopeChain->begin(); + ScopeChainIterator end = scopeChain->end(); + + // we must always have something in the scope chain + ASSERT(iter != end); + + ArgList list; + do { + list.append(*iter); + ++iter; + } while (iter != end); + + return constructArray(exec, list); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSLocationCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSLocationCustom.cpp new file mode 100644 index 0000000..b24a62c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSLocationCustom.cpp @@ -0,0 +1,309 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2006 Jon Shier (jshier@iastate.edu) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved. + * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include "config.h" +#include "JSLocationCustom.h" + +#include "DOMWindow.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "JSDOMBinding.h" +#include "JSDOMWindowCustom.h" +#include "KURL.h" +#include "Location.h" +#include "ScriptController.h" +#include <runtime/PrototypeFunction.h> + +using namespace JSC; + +namespace WebCore { + +JSValuePtr nonCachingStaticReplaceFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 1, propertyName, jsLocationPrototypeFunctionReplace); +} + +JSValuePtr nonCachingStaticReloadFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 0, propertyName, jsLocationPrototypeFunctionReload); +} + +JSValuePtr nonCachingStaticAssignFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot&) +{ + return new (exec) PrototypeFunction(exec, 1, propertyName, jsLocationPrototypeFunctionAssign); +} + +bool JSLocation::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + Frame* frame = impl()->frame(); + if (!frame) { + slot.setUndefined(); + return true; + } + + // When accessing Location cross-domain, functions are always the native built-in ones. + // See JSDOMWindow::customGetOwnPropertySlot for additional details. + + // Our custom code is only needed to implement the Window cross-domain scheme, so if access is + // allowed, return false so the normal lookup will take place. + String message; + if (allowsAccessFromFrame(exec, frame, message)) + return false; + + // Check for the few functions that we allow, even when called cross-domain. + const HashEntry* entry = JSLocationPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry && (entry->attributes() & Function)) { + if (entry->function() == jsLocationPrototypeFunctionReplace) { + slot.setCustom(this, nonCachingStaticReplaceFunctionGetter); + return true; + } else if (entry->function() == jsLocationPrototypeFunctionReload) { + slot.setCustom(this, nonCachingStaticReplaceFunctionGetter); + return true; + } else if (entry->function() == jsLocationPrototypeFunctionAssign) { + slot.setCustom(this, nonCachingStaticAssignFunctionGetter); + return true; + } + } + + // FIXME: Other implementers of the Window cross-domain scheme (Window, History) allow toString, + // but for now we have decided not to, partly because it seems silly to return "[Object Location]" in + // such cases when normally the string form of Location would be the URL. + + printErrorMessageForFrame(frame, message); + slot.setUndefined(); + return true; +} + +bool JSLocation::customPut(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) +{ + Frame* frame = impl()->frame(); + if (!frame) + return true; + + bool sameDomainAccess = allowsAccessFromFrame(exec, frame); + + const HashEntry* entry = JSLocation::s_info.propHashTable(exec)->entry(exec, propertyName); + if (!entry) { + if (sameDomainAccess) + JSObject::put(exec, propertyName, value, slot); + return true; + } + + // Cross-domain access to the location is allowed when assigning the whole location, + // but not when assigning the individual pieces, since that might inadvertently + // disclose other parts of the original location. + if (entry->propertyPutter() != setJSLocationHref && !sameDomainAccess) + return true; + + return false; +} + +bool JSLocation::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + // Only allow deleting by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return false; + return Base::deleteProperty(exec, propertyName); +} + +bool JSLocation::customGetPropertyNames(ExecState* exec, PropertyNameArray&) +{ + // Only allow the location object to enumerated by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return true; + return false; +} + +static void navigateIfAllowed(ExecState* exec, Frame* frame, const KURL& url, bool lockHistory) +{ + Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!url.protocolIs("javascript") || allowsAccessFromFrame(exec, frame)) { + bool userGesture = activeFrame->script()->processingUserGesture(); + frame->loader()->scheduleLocationChange(url.string(), activeFrame->loader()->outgoingReferrer(), lockHistory, userGesture); + } +} + +void JSLocation::setHref(ExecState* exec, JSValuePtr value) +{ + Frame* frame = impl()->frame(); + ASSERT(frame); + + Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!activeFrame) + return; + if (!activeFrame->loader()->shouldAllowNavigation(frame)) + return; + + KURL url = activeFrame->loader()->completeURL(value->toString(exec)); + navigateIfAllowed(exec, frame, url, false); +} + +void JSLocation::setProtocol(ExecState* exec, JSValuePtr value) +{ + Frame* frame = impl()->frame(); + ASSERT(frame); + + KURL url = frame->loader()->url(); + url.setProtocol(value->toString(exec)); + + navigateIfAllowed(exec, frame, url, false); +} + +void JSLocation::setHost(ExecState* exec, JSValuePtr value) +{ + Frame* frame = impl()->frame(); + ASSERT(frame); + + KURL url = frame->loader()->url(); + url.setHostAndPort(value->toString(exec)); + + navigateIfAllowed(exec, frame, url, false); +} + +void JSLocation::setHostname(ExecState* exec, JSValuePtr value) +{ + Frame* frame = impl()->frame(); + ASSERT(frame); + + KURL url = frame->loader()->url(); + url.setHost(value->toString(exec)); + + navigateIfAllowed(exec, frame, url, false); +} + +void JSLocation::setPort(ExecState* exec, JSValuePtr value) +{ + Frame* frame = impl()->frame(); + ASSERT(frame); + + KURL url = frame->loader()->url(); + // FIXME: Could make this a little less ugly if String provided a toUnsignedShort function. + const UString& portString = value->toString(exec); + int port = charactersToInt(portString.data(), portString.size()); + if (port < 0 || port > 0xFFFF) + port = 0; + url.setPort(port); + + navigateIfAllowed(exec, frame, url, false); +} + +void JSLocation::setPathname(ExecState* exec, JSValuePtr value) +{ + Frame* frame = impl()->frame(); + ASSERT(frame); + + KURL url = frame->loader()->url(); + url.setPath(value->toString(exec)); + + navigateIfAllowed(exec, frame, url, false); +} + +void JSLocation::setSearch(ExecState* exec, JSValuePtr value) +{ + Frame* frame = impl()->frame(); + ASSERT(frame); + + KURL url = frame->loader()->url(); + url.setQuery(value->toString(exec)); + + navigateIfAllowed(exec, frame, url, false); +} + +void JSLocation::setHash(ExecState* exec, JSValuePtr value) +{ + Frame* frame = impl()->frame(); + ASSERT(frame); + + KURL url = frame->loader()->url(); + String oldRef = url.ref(); + String str = value->toString(exec); + if (str.startsWith("#")) + str = str.substring(1); + if (oldRef == str || (oldRef.isNull() && str.isEmpty())) + return; + url.setRef(str); + + navigateIfAllowed(exec, frame, url, false); +} + +JSValuePtr JSLocation::replace(ExecState* exec, const ArgList& args) +{ + Frame* frame = impl()->frame(); + if (!frame) + return jsUndefined(); + + Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!activeFrame) + return jsUndefined(); + if (!activeFrame->loader()->shouldAllowNavigation(frame)) + return jsUndefined(); + + navigateIfAllowed(exec, frame, activeFrame->loader()->completeURL(args.at(exec, 0)->toString(exec)), true); + return jsUndefined(); +} + +JSValuePtr JSLocation::reload(ExecState* exec, const ArgList&) +{ + Frame* frame = impl()->frame(); + if (!frame) + return jsUndefined(); + + JSDOMWindow* window = toJSDOMWindow(frame); + if (!window->allowsAccessFrom(exec)) + return jsUndefined(); + + if (!frame->loader()->url().protocolIs("javascript") || (window && window->allowsAccessFrom(exec))) { + bool userGesture = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame()->script()->processingUserGesture(); + frame->loader()->scheduleRefresh(userGesture); + } + return jsUndefined(); +} + +JSValuePtr JSLocation::assign(ExecState* exec, const ArgList& args) +{ + Frame* frame = impl()->frame(); + if (!frame) + return jsUndefined(); + + Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!activeFrame) + return jsUndefined(); + if (!activeFrame->loader()->shouldAllowNavigation(frame)) + return jsUndefined(); + + // We want a new history item if this JS was called via a user gesture + navigateIfAllowed(exec, frame, activeFrame->loader()->completeURL(args.at(exec, 0)->toString(exec)), false); + return jsUndefined(); +} + +JSValuePtr JSLocation::toString(ExecState* exec, const ArgList&) +{ + Frame* frame = impl()->frame(); + if (!frame) + return jsUndefined(); + if (!allowsAccessFromFrame(exec, frame)) + return jsUndefined(); + + return jsString(exec, impl()->toString()); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSLocationCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSLocationCustom.h new file mode 100644 index 0000000..127871e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSLocationCustom.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSLocationCustom_h +#define JSLocationCustom_h + +#include "JSLocation.h" + +#endif // JSLocationCustom_h + + diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSMessageChannelConstructor.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSMessageChannelConstructor.cpp new file mode 100644 index 0000000..6c11bea --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSMessageChannelConstructor.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSMessageChannelConstructor.h" + +#include "Document.h" +#include "JSDocument.h" +#include "JSMessageChannel.h" +#include "JSWorkerContext.h" +#include "MessageChannel.h" + +using namespace JSC; + +namespace WebCore { + +const ClassInfo JSMessageChannelConstructor::s_info = { "MessageChannelConstructor", 0, 0, 0 }; + +JSMessageChannelConstructor::JSMessageChannelConstructor(ExecState* exec, ScriptExecutionContext* scriptExecutionContext) + : DOMObject(JSMessageChannelConstructor::createStructure(exec->lexicalGlobalObject()->objectPrototype())) + , m_scriptExecutionContext(scriptExecutionContext) +{ + if (m_scriptExecutionContext->isDocument()) + m_contextWrapper = toJS(exec, static_cast<Document*>(scriptExecutionContext)); +#if ENABLE(WORKERS) + else if (m_scriptExecutionContext->isWorkerContext()) + m_contextWrapper = toJSDOMGlobalObject(scriptExecutionContext); +#endif + else + ASSERT_NOT_REACHED(); + + putDirect(exec->propertyNames().prototype, JSMessageChannelPrototype::self(exec), None); +} + +JSMessageChannelConstructor::~JSMessageChannelConstructor() +{ +} + +ConstructType JSMessageChannelConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = construct; + return ConstructTypeHost; +} + +JSObject* JSMessageChannelConstructor::construct(ExecState* exec, JSObject* constructor, const ArgList&) +{ + return asObject(toJS(exec, MessageChannel::create(static_cast<JSMessageChannelConstructor*>(constructor)->scriptExecutionContext()))); +} + +void JSMessageChannelConstructor::mark() +{ + DOMObject::mark(); + if (!m_contextWrapper->marked()) + m_contextWrapper->mark(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSMessageChannelConstructor.h b/src/3rdparty/webkit/WebCore/bindings/js/JSMessageChannelConstructor.h new file mode 100644 index 0000000..614f6ae --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSMessageChannelConstructor.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSMessageChannelConstructor_h +#define JSMessageChannelConstructor_h + +#include "JSDOMBinding.h" + +namespace WebCore { + + class JSMessageChannelConstructor : public DOMObject { + public: + JSMessageChannelConstructor(JSC::ExecState*, ScriptExecutionContext*); + virtual ~JSMessageChannelConstructor(); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + static const JSC::ClassInfo s_info; + + ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext; } + + virtual bool implementsHasInstance() const { return true; } + static JSC::JSObject* construct(JSC::ExecState*, JSC::JSObject*, const JSC::ArgList&); + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + + virtual void mark(); + + private: + ScriptExecutionContext* m_scriptExecutionContext; + JSC::JSValuePtr m_contextWrapper; + }; + +} // namespace WebCore + +#endif // JSMessageChannelConstructor_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSMessageChannelCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSMessageChannelCustom.cpp new file mode 100644 index 0000000..70329e2 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSMessageChannelCustom.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSMessageChannel.h" + +#include "MessageChannel.h" + +using namespace JSC; + +namespace WebCore { + +void JSMessageChannel::mark() +{ + DOMObject::mark(); + + if (MessagePort* port = m_impl->port1()) { + DOMObject* wrapper = getCachedDOMObjectWrapper(*Heap::heap(this)->globalData(), port); + if (wrapper && !wrapper->marked()) + wrapper->mark(); + } + + if (MessagePort* port = m_impl->port2()) { + DOMObject* wrapper = getCachedDOMObjectWrapper(*Heap::heap(this)->globalData(), port); + if (wrapper && !wrapper->marked()) + wrapper->mark(); + } +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSMessagePortCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSMessagePortCustom.cpp new file mode 100644 index 0000000..d0615de --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSMessagePortCustom.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSMessagePort.h" + +#include "AtomicString.h" +#include "Event.h" +#include "Frame.h" +#include "JSDOMGlobalObject.h" +#include "JSEvent.h" +#include "JSEventListener.h" +#include "MessagePort.h" + +using namespace JSC; + +namespace WebCore { + +void JSMessagePort::mark() +{ + DOMObject::mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onmessage())) + listener->mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onclose())) + listener->mark(); + + if (MessagePort* entangledPort = m_impl->entangledPort()) { + DOMObject* wrapper = getCachedDOMObjectWrapper(*Heap::heap(this)->globalData(), entangledPort); + if (wrapper && !wrapper->marked()) + wrapper->mark(); + } + + typedef MessagePort::EventListenersMap EventListenersMap; + typedef MessagePort::ListenerVector ListenerVector; + EventListenersMap& eventListeners = m_impl->eventListeners(); + for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) { + for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) { + JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(vecIter->get()); + listener->mark(); + } + } +} + +JSValuePtr JSMessagePort::startConversation(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()); + const UString& message = args.at(exec, 0)->toString(exec); + + return toJS(exec, impl()->startConversation(globalObject->scriptExecutionContext(), message).get()); +} + +JSValuePtr JSMessagePort::addEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + RefPtr<JSUnprotectedEventListener> listener = globalObject->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +JSValuePtr JSMessagePort::removeEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + JSUnprotectedEventListener* listener = globalObject->findJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSMimeTypeArrayCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSMimeTypeArrayCustom.cpp new file mode 100644 index 0000000..5338d5b --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSMimeTypeArrayCustom.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSMimeTypeArray.h" + +#include "AtomicString.h" +#include "JSMimeType.h" +#include "MimeTypeArray.h" + +namespace WebCore { + +using namespace JSC; + +bool JSMimeTypeArray::canGetItemsForName(ExecState*, MimeTypeArray* mimeTypeArray, const Identifier& propertyName) +{ + return mimeTypeArray->canGetItemsForName(propertyName); +} + +JSValuePtr JSMimeTypeArray::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSMimeTypeArray* thisObj = static_cast<JSMimeTypeArray*>(asObject(slot.slotBase())); + return toJS(exec, thisObj->impl()->namedItem(propertyName)); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNamedNodeMapCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSNamedNodeMapCustom.cpp new file mode 100644 index 0000000..e7b0764 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNamedNodeMapCustom.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSNamedNodeMap.h" + +#include "JSNode.h" +#include "NamedNodeMap.h" +#include "Node.h" +#include "PlatformString.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +bool JSNamedNodeMap::canGetItemsForName(ExecState*, NamedNodeMap* impl, const Identifier& propertyName) +{ + return impl->getNamedItem(propertyName); +} + +JSValuePtr JSNamedNodeMap::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSNamedNodeMap* thisObj = static_cast<JSNamedNodeMap*>(asObject(slot.slotBase())); + return toJS(exec, thisObj->impl()->getNamedItem(propertyName)); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNamedNodesCollection.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSNamedNodesCollection.cpp new file mode 100644 index 0000000..8a7ee0e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNamedNodesCollection.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSNamedNodesCollection.h" + +#include "AtomicString.h" +#include "Element.h" +#include "JSNode.h" +#include "NamedAttrMap.h" + +namespace WebCore { + +using namespace JSC; + +ASSERT_CLASS_FITS_IN_CELL(JSNamedNodesCollection) + +const ClassInfo JSNamedNodesCollection::s_info = { "Collection", 0, 0, 0 }; + +// Such a collection is usually very short-lived, it only exists +// for constructs like document.forms.<name>[1], +// so it shouldn't be a problem that it's storing all the nodes (with the same name). (David) +JSNamedNodesCollection::JSNamedNodesCollection(ExecState* exec, const Vector<RefPtr<Node> >& nodes) + : DOMObject(getDOMStructure<JSNamedNodesCollection>(exec)) + , m_nodes(new Vector<RefPtr<Node> >(nodes)) +{ +} + +JSValuePtr JSNamedNodesCollection::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + JSNamedNodesCollection* thisObj = static_cast<JSNamedNodesCollection*>(asObject(slot.slotBase())); + return jsNumber(exec, thisObj->m_nodes->size()); +} + +JSValuePtr JSNamedNodesCollection::indexGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + JSNamedNodesCollection *thisObj = static_cast<JSNamedNodesCollection*>(asObject(slot.slotBase())); + return toJS(exec, (*thisObj->m_nodes)[slot.index()].get()); +} + +bool JSNamedNodesCollection::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + if (propertyName == exec->propertyNames().length) { + slot.setCustom(this, lengthGetter); + return true; + } + + bool ok; + unsigned index = propertyName.toUInt32(&ok); + if (ok && index < m_nodes->size()) { + slot.setCustomIndex(this, index, indexGetter); + return true; + } + + // For IE compatibility, we need to be able to look up elements in a + // document.formName.name result by id as well as be index. + + AtomicString atomicPropertyName = propertyName; + for (unsigned i = 0; i < m_nodes->size(); i++) { + Node* node = (*m_nodes)[i].get(); + if (node->hasAttributes() && node->attributes()->id() == atomicPropertyName) { + slot.setCustomIndex(this, i, indexGetter); + return true; + } + } + + return DOMObject::getOwnPropertySlot(exec, propertyName, slot); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNamedNodesCollection.h b/src/3rdparty/webkit/WebCore/bindings/js/JSNamedNodesCollection.h new file mode 100644 index 0000000..19f194b --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNamedNodesCollection.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSNamedNodesCollection_h +#define JSNamedNodesCollection_h + +#include "JSDOMBinding.h" +#include <wtf/Vector.h> + +namespace WebCore { + + class Node; + + // Internal class, used for the collection return by e.g. document.forms.myinput + // when multiple nodes have the same name. + class JSNamedNodesCollection : public DOMObject { + public: + JSNamedNodesCollection(JSC::ExecState*, const Vector<RefPtr<Node> >&); + + virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&); + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + static const JSC::ClassInfo s_info; + + static JSC::ObjectPrototype* createPrototype(JSC::ExecState* exec) + { + return exec->lexicalGlobalObject()->objectPrototype(); + } + + static PassRefPtr<JSC::Structure> createStructure(JSC::JSValuePtr prototype) + { + return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType)); + } + + private: + static JSC::JSValuePtr lengthGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); + static JSC::JSValuePtr indexGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); + + OwnPtr<Vector<RefPtr<Node> > > m_nodes; + }; + +} // namespace WebCore + +#endif // JSNamedNodesCollection_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNavigatorCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSNavigatorCustom.cpp new file mode 100644 index 0000000..2287426 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNavigatorCustom.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org) + * Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All Rights Reserved. + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSNavigator.h" + +#include "Frame.h" +#include "FrameLoader.h" +#include "KURL.h" +#include "Navigator.h" +#include "Settings.h" + +namespace WebCore { + +using namespace JSC; + +static bool needsYouTubeQuirk(ExecState*, Frame*); + +#if 1 + +static inline bool needsYouTubeQuirk(ExecState*, Frame*) +{ + return false; +} + +#else + +static bool needsYouTubeQuirk(ExecState* exec, Frame* frame) +{ + // This quirk works around a mistaken check in an ad at youtube.com. + // There's a function called isSafari that returns false if the function + // called isWindows returns true; thus the site malfunctions with Windows Safari. + + // Do the quirk only if the function's name is "isWindows". + JSFunction* function = exec->function(); + if (!function) + return false; + DEFINE_STATIC_LOCAL(const Identifier, isWindowsFunctionName, (exec, "isWindows")); + if (function->functionName() != isWindowsFunctionName) + return false; + + // Do the quirk only if the function is called by an "isSafari" function. + // However, that function is not itself named -- it is stored in the isSafari + // property, though, so that's how we recognize it. + ExecState* callingExec = exec->callingExecState(); + if (!callingExec) + return false; + JSFunction* callingFunction = callingExec->function(); + if (!callingFunction) + return false; + JSObject* thisObject = callingExec->thisValue(); + if (!thisObject) + return false; + DEFINE_STATIC_LOCAL(const Identifier, isSafariFunction, (exec, "isSafari")); + JSValuePtr isSafariFunction = thisObject->getDirect(isSafariFunctionName); + if (isSafariFunction != callingFunction) + return false; + + Document* document = frame->document(); + // FIXME: The document is never null, so we should remove this check along with the + // other similar ones in this file when we are absolutely sure it's safe. + if (!document) + return false; + + // Do the quirk only on the front page of the global version of YouTube. + const KURL& url = document->url(); + if (url.host() != "youtube.com" && url.host() != "www.youtube.com") + return false; + if (url.path() != "/") + return false; + + // As with other site-specific quirks, allow website developers to turn this off. + // In theory, this allows website developers to check if their fixes are effective. + Settings* settings = frame->settings(); + if (!settings) + return false; + if (!settings->needsSiteSpecificQuirks()) + return false; + + return true; +} + +#endif + +JSValuePtr JSNavigator::appVersion(ExecState* exec) const +{ + Navigator* imp = static_cast<Navigator*>(impl()); + Frame* frame = imp->frame(); + if (!frame) + return jsString(exec, ""); + + if (needsYouTubeQuirk(exec, frame)) + return jsString(exec, ""); + return jsString(exec, imp->appVersion()); +} + +void JSNavigator::mark() +{ + Base::mark(); + + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + markDOMObjectWrapper(globalData, impl()->optionalGeolocation()); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNodeCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeCustom.cpp new file mode 100644 index 0000000..2b4d6d4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeCustom.cpp @@ -0,0 +1,241 @@ +/* + * Copyright (C) 2007 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSNode.h" + +#include "Attr.h" +#include "CDATASection.h" +#include "Comment.h" +#include "Document.h" +#include "DocumentFragment.h" +#include "DocumentType.h" +#include "Entity.h" +#include "EntityReference.h" +#include "HTMLElement.h" +#include "JSAttr.h" +#include "JSCDATASection.h" +#include "JSComment.h" +#include "JSDocument.h" +#include "JSDocumentFragment.h" +#include "JSDocumentType.h" +#include "JSEntity.h" +#include "JSEntityReference.h" +#include "JSHTMLElement.h" +#include "JSHTMLElementWrapperFactory.h" +#include "JSNotation.h" +#include "JSProcessingInstruction.h" +#include "JSText.h" +#include "Node.h" +#include "Notation.h" +#include "ProcessingInstruction.h" +#include "Text.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +#if ENABLE(SVG) +#include "JSSVGElementWrapperFactory.h" +#include "SVGElement.h" +#endif + +using namespace JSC; + +namespace WebCore { + +typedef int ExpectionCode; + +JSValuePtr JSNode::insertBefore(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + bool ok = impl()->insertBefore(toNode(args.at(exec, 0)), toNode(args.at(exec, 1)), ec, true); + setDOMException(exec, ec); + if (ok) + return args.at(exec, 0); + return jsNull(); +} + +JSValuePtr JSNode::replaceChild(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + bool ok = impl()->replaceChild(toNode(args.at(exec, 0)), toNode(args.at(exec, 1)), ec, true); + setDOMException(exec, ec); + if (ok) + return args.at(exec, 1); + return jsNull(); +} + +JSValuePtr JSNode::removeChild(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + bool ok = impl()->removeChild(toNode(args.at(exec, 0)), ec); + setDOMException(exec, ec); + if (ok) + return args.at(exec, 0); + return jsNull(); +} + +JSValuePtr JSNode::appendChild(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + bool ok = impl()->appendChild(toNode(args.at(exec, 0)), ec, true); + setDOMException(exec, ec); + if (ok) + return args.at(exec, 0); + return jsNull(); +} + +void JSNode::mark() +{ + ASSERT(!marked()); + + Node* node = m_impl.get(); + + // Nodes in the document are kept alive by JSDocument::mark, + // so we have no special responsibilities and can just call the base class here. + if (node->inDocument()) { + // But if the document isn't marked we have to mark it to ensure that + // nodes reachable from this one are also marked + if (Document* doc = node->ownerDocument()) + if (DOMObject* docWrapper = getCachedDOMObjectWrapper(*Heap::heap(this)->globalData(), doc)) + if (!docWrapper->marked()) + docWrapper->mark(); + DOMObject::mark(); + return; + } + + // This is a node outside the document, so find the root of the tree it is in, + // and start marking from there. + Node* root = node; + for (Node* current = m_impl.get(); current; current = current->parentNode()) + root = current; + + // If we're already marking this tree, then we can simply mark this wrapper + // by calling the base class; our caller is iterating the tree. + if (root->inSubtreeMark()) { + DOMObject::mark(); + return; + } + + // Mark the whole tree; use the global set of roots to avoid reentering. + root->setInSubtreeMark(true); + for (Node* nodeToMark = root; nodeToMark; nodeToMark = nodeToMark->traverseNextNode()) { + JSNode* wrapper = getCachedDOMNodeWrapper(m_impl->document(), nodeToMark); + if (wrapper) { + if (!wrapper->marked()) + wrapper->mark(); + } else if (nodeToMark == node) { + // This is the case where the map from the document to wrappers has + // been cleared out, but a wrapper is being marked. For now, we'll + // let the rest of the tree of wrappers get collected, because we have + // no good way of finding them. Later we should test behavior of other + // browsers and see if we need to preserve other wrappers in this case. + if (!marked()) + mark(); + } + } + root->setInSubtreeMark(false); + + // Double check that we actually ended up marked. This assert caught problems in the past. + ASSERT(marked()); +} + +static ALWAYS_INLINE JSValuePtr createWrapper(ExecState* exec, Node* node) +{ + ASSERT(node); + ASSERT(!getCachedDOMNodeWrapper(node->document(), node)); + + JSNode* wrapper; + switch (node->nodeType()) { + case Node::ELEMENT_NODE: + if (node->isHTMLElement()) + wrapper = createJSHTMLWrapper(exec, static_cast<HTMLElement*>(node)); +#if ENABLE(SVG) + else if (node->isSVGElement()) + wrapper = createJSSVGWrapper(exec, static_cast<SVGElement*>(node)); +#endif + else + wrapper = CREATE_DOM_NODE_WRAPPER(exec, Element, node); + break; + case Node::ATTRIBUTE_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, Attr, node); + break; + case Node::TEXT_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, Text, node); + break; + case Node::CDATA_SECTION_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, CDATASection, node); + break; + case Node::ENTITY_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, Entity, node); + break; + case Node::PROCESSING_INSTRUCTION_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, ProcessingInstruction, node); + break; + case Node::COMMENT_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, Comment, node); + break; + case Node::DOCUMENT_NODE: + // we don't want to cache the document itself in the per-document dictionary + return toJS(exec, static_cast<Document*>(node)); + case Node::DOCUMENT_TYPE_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, DocumentType, node); + break; + case Node::NOTATION_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, Notation, node); + break; + case Node::DOCUMENT_FRAGMENT_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, DocumentFragment, node); + break; + case Node::ENTITY_REFERENCE_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, EntityReference, node); + break; + default: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, Node, node); + } + + return wrapper; +} + +JSValuePtr toJSNewlyCreated(ExecState* exec, Node* node) +{ + if (!node) + return jsNull(); + + return createWrapper(exec, node); +} + +JSValuePtr toJS(ExecState* exec, Node* node) +{ + if (!node) + return jsNull(); + + JSNode* wrapper = getCachedDOMNodeWrapper(node->document(), node); + if (wrapper) + return wrapper; + + return createWrapper(exec, node); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNodeFilterCondition.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeFilterCondition.cpp new file mode 100644 index 0000000..55a282e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeFilterCondition.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSNodeFilterCondition.h" + +#include "JSNode.h" +#include "JSNodeFilter.h" +#include "NodeFilter.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +ASSERT_CLASS_FITS_IN_CELL(JSNodeFilterCondition) + +JSNodeFilterCondition::JSNodeFilterCondition(JSValuePtr filter) + : m_filter(filter) +{ +} + +void JSNodeFilterCondition::mark() +{ + if (!m_filter->marked()) + m_filter->mark(); +} + +short JSNodeFilterCondition::acceptNode(JSC::ExecState* exec, Node* filterNode) const +{ + JSLock lock(false); + + CallData callData; + CallType callType = m_filter->getCallData(callData); + if (callType == CallTypeNone) + return NodeFilter::FILTER_ACCEPT; + + // The exec argument here should only be null if this was called from a + // non-JavaScript language, and this is a JavaScript filter, and the document + // in question is not associated with the frame. In that case, we're going to + // behave incorrectly, and just reject nodes instead of calling the filter function. + // To fix that we'd need to come up with a way to find a suitable JavaScript + // execution context for the filter function to run in. + if (!exec) + return NodeFilter::FILTER_REJECT; + + ArgList args; + args.append(toJS(exec, filterNode)); + if (exec->hadException()) + return NodeFilter::FILTER_REJECT; + + JSValuePtr result = call(exec, m_filter, callType, callData, m_filter, args); + if (exec->hadException()) + return NodeFilter::FILTER_REJECT; + + int intResult = result->toInt32(exec); + if (exec->hadException()) + return NodeFilter::FILTER_REJECT; + + return intResult; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNodeFilterCondition.h b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeFilterCondition.h new file mode 100644 index 0000000..2600d90 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeFilterCondition.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSNodeFilterCondition_h +#define JSNodeFilterCondition_h + +#include "NodeFilterCondition.h" +#include <runtime/JSValue.h> +#include <wtf/PassRefPtr.h> + +namespace WebCore { + + class Node; + + class JSNodeFilterCondition : public NodeFilterCondition { + public: + static PassRefPtr<JSNodeFilterCondition> create(JSC::JSValuePtr filter) + { + return adoptRef(new JSNodeFilterCondition(filter)); + } + + private: + JSNodeFilterCondition(JSC::JSValuePtr filter); + + virtual short acceptNode(ScriptState*, Node*) const; + virtual void mark(); + + JSC::JSValuePtr m_filter; + }; + +} // namespace WebCore + +#endif // JSNodeFilterCondition_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNodeFilterCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeFilterCustom.cpp new file mode 100644 index 0000000..bca6e3a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeFilterCustom.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSNodeFilter.h" + +#include "JSNode.h" +#include "JSNodeFilterCondition.h" +#include "NodeFilter.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +void JSNodeFilter::mark() +{ + impl()->mark(); + DOMObject::mark(); +} + +JSValuePtr JSNodeFilter::acceptNode(ExecState* exec, const ArgList& args) +{ + return jsNumber(exec, impl()->acceptNode(exec, toNode(args.at(exec, 0)))); +} + +PassRefPtr<NodeFilter> toNodeFilter(JSValuePtr value) +{ + if (value->isObject(&JSNodeFilter::s_info)) + return static_cast<JSNodeFilter*>(asObject(value))->impl(); + + return NodeFilter::create(JSNodeFilterCondition::create(value)); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNodeIteratorCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeIteratorCustom.cpp new file mode 100644 index 0000000..6498a7c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeIteratorCustom.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSNodeIterator.h" + +#include "JSNode.h" +#include "Node.h" +#include "NodeFilter.h" +#include "NodeIterator.h" + +using namespace JSC; + +namespace WebCore { + +void JSNodeIterator::mark() +{ + if (NodeFilter* filter = m_impl->filter()) + filter->mark(); + + DOMObject::mark(); +} + +JSValuePtr JSNodeIterator::nextNode(ExecState* exec, const ArgList&) +{ + ExceptionCode ec = 0; + RefPtr<Node> node = impl()->nextNode(exec, ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + + if (exec->hadException()) + return jsUndefined(); + + return toJS(exec, node.get()); +} + +JSValuePtr JSNodeIterator::previousNode(ExecState* exec, const ArgList&) +{ + ExceptionCode ec = 0; + RefPtr<Node> node = impl()->previousNode(exec, ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + + if (exec->hadException()) + return jsUndefined(); + + return toJS(exec, node.get()); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSNodeListCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeListCustom.cpp new file mode 100644 index 0000000..a67887e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSNodeListCustom.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSNodeList.h" + +#include "AtomicString.h" +#include "JSNode.h" +#include "Node.h" +#include "NodeList.h" + +using namespace JSC; + +namespace WebCore { + +// Need to support call so that list(0) works. +static JSValuePtr callNodeList(ExecState* exec, JSObject* function, JSValuePtr, const ArgList& args) +{ + bool ok; + unsigned index = args.at(exec, 0)->toString(exec).toUInt32(&ok); + if (!ok) + return jsUndefined(); + return toJS(exec, static_cast<JSNodeList*>(function)->impl()->item(index)); +} + +CallType JSNodeList::getCallData(CallData& callData) +{ + callData.native.function = callNodeList; + return CallTypeHost; +} + +bool JSNodeList::canGetItemsForName(ExecState*, NodeList* impl, const Identifier& propertyName) +{ + return impl->itemWithName(propertyName); +} + +JSValuePtr JSNodeList::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSNodeList* thisObj = static_cast<JSNodeList*>(asObject(slot.slotBase())); + return toJS(exec, thisObj->impl()->itemWithName(propertyName)); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSOptionConstructor.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSOptionConstructor.cpp new file mode 100644 index 0000000..42136e5 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSOptionConstructor.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSOptionConstructor.h" + +#include "HTMLOptionElement.h" +#include "JSHTMLOptionElement.h" +#include "ScriptExecutionContext.h" +#include "Text.h" + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSOptionConstructor) + +const ClassInfo JSOptionConstructor::s_info = { "OptionConstructor", 0, 0, 0 }; + +JSOptionConstructor::JSOptionConstructor(ExecState* exec, ScriptExecutionContext* context) + : DOMObject(JSOptionConstructor::createStructure(exec->lexicalGlobalObject()->objectPrototype())) +{ + ASSERT(context->isDocument()); + m_document = static_cast<JSDocument*>(asObject(toJS(exec, static_cast<Document*>(context)))); + + putDirect(exec->propertyNames().length, jsNumber(exec, 4), ReadOnly|DontDelete|DontEnum); +} + +static JSObject* constructHTMLOptionElement(ExecState* exec, JSObject* constructor, const ArgList& args) +{ + Document* document = static_cast<JSOptionConstructor*>(constructor)->document(); + + ExceptionCode ec = 0; + + RefPtr<HTMLOptionElement> element = static_pointer_cast<HTMLOptionElement>(document->createElement("option", ec)); + RefPtr<Text> text; + if (ec == 0) + text = document->createTextNode(""); + if (ec == 0 && !args.at(exec, 0)->isUndefined()) + text->setData(args.at(exec, 0)->toString(exec), ec); + if (ec == 0) + element->appendChild(text.release(), ec); + if (ec == 0 && !args.at(exec, 1)->isUndefined()) + element->setValue(args.at(exec, 1)->toString(exec)); + if (ec == 0) + element->setDefaultSelected(args.at(exec, 2)->toBoolean(exec)); + if (ec == 0) + element->setSelected(args.at(exec, 3)->toBoolean(exec)); + + if (ec) { + setDOMException(exec, ec); + return 0; + } + + return asObject(toJS(exec, element.release())); +} + +ConstructType JSOptionConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructHTMLOptionElement; + return ConstructTypeHost; +} + +void JSOptionConstructor::mark() +{ + DOMObject::mark(); + if (!m_document->marked()) + m_document->mark(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSOptionConstructor.h b/src/3rdparty/webkit/WebCore/bindings/js/JSOptionConstructor.h new file mode 100644 index 0000000..5234c49 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSOptionConstructor.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef JSOptionConstructor_h +#define JSOptionConstructor_h + +#include "JSDOMBinding.h" +#include "JSDocument.h" +#include <wtf/RefPtr.h> + +namespace WebCore { + + class JSOptionConstructor : public DOMObject { + public: + JSOptionConstructor(JSC::ExecState*, ScriptExecutionContext*); + Document* document() const { return m_document->impl(); } + + static const JSC::ClassInfo s_info; + + virtual void mark(); + private: + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + + JSDocument* m_document; + }; + +} // namespace WebCore + +#endif // JSOptionConstructor_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSPluginArrayCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSPluginArrayCustom.cpp new file mode 100644 index 0000000..5e82942 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSPluginArrayCustom.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSPluginArray.h" + +#include "AtomicString.h" +#include "JSPlugin.h" +#include "PluginArray.h" + +namespace WebCore { + +using namespace JSC; + +bool JSPluginArray::canGetItemsForName(ExecState*, PluginArray* pluginArray, const Identifier& propertyName) +{ + return pluginArray->canGetItemsForName(propertyName); +} + +JSValuePtr JSPluginArray::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSPluginArray* thisObj = static_cast<JSPluginArray*>(asObject(slot.slotBase())); + return toJS(exec, thisObj->impl()->namedItem(propertyName)); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSPluginCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSPluginCustom.cpp new file mode 100644 index 0000000..2cc3bae --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSPluginCustom.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSPlugin.h" + +#include "AtomicString.h" +#include "JSMimeType.h" +#include "Plugin.h" + +namespace WebCore { + +using namespace JSC; + +bool JSPlugin::canGetItemsForName(ExecState*, Plugin* plugin, const Identifier& propertyName) +{ + return plugin->canGetItemsForName(propertyName); +} + +JSValuePtr JSPlugin::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSPlugin* thisObj = static_cast<JSPlugin*>(asObject(slot.slotBase())); + return toJS(exec, thisObj->impl()->namedItem(propertyName)); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSPluginElementFunctions.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSPluginElementFunctions.cpp new file mode 100644 index 0000000..4d1b8fb --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSPluginElementFunctions.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSPluginElementFunctions.h" + +#include "Frame.h" +#include "FrameLoader.h" +#include "HTMLDocument.h" +#include "HTMLNames.h" +#include "HTMLPlugInElement.h" +#include "JSHTMLElement.h" +#include "ScriptController.h" +#include "runtime.h" +#include "runtime_object.h" + +using namespace JSC; + +namespace WebCore { + +using namespace Bindings; +using namespace HTMLNames; + +// Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement. + +static Instance* pluginInstance(Node* node) +{ + if (!node) + return 0; + if (!(node->hasTagName(objectTag) || node->hasTagName(embedTag) || node->hasTagName(appletTag))) + return 0; + HTMLPlugInElement* plugInElement = static_cast<HTMLPlugInElement*>(node); + // The plugin element holds an owning reference, so we don't have to. + Instance* instance = plugInElement->getInstance().get(); + if (!instance || !instance->rootObject()) + return 0; + return instance; +} + +static RuntimeObjectImp* getRuntimeObject(ExecState* exec, Node* node) +{ + Instance* instance = pluginInstance(node); + if (!instance) + return 0; + return JSC::Bindings::Instance::createRuntimeObject(exec, instance); +} + +JSValuePtr runtimeObjectGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(asObject(slot.slotBase())); + HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl()); + RuntimeObjectImp* runtimeObject = getRuntimeObject(exec, element); + return runtimeObject ? runtimeObject : jsUndefined(); +} + +JSValuePtr runtimeObjectPropertyGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(asObject(slot.slotBase())); + HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl()); + RuntimeObjectImp* runtimeObject = getRuntimeObject(exec, element); + if (!runtimeObject) + return jsUndefined(); + return runtimeObject->get(exec, propertyName); +} + +bool runtimeObjectCustomGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, JSHTMLElement* element) +{ + RuntimeObjectImp* runtimeObject = getRuntimeObject(exec, element->impl()); + if (!runtimeObject) + return false; + if (!runtimeObject->hasProperty(exec, propertyName)) + return false; + slot.setCustom(element, runtimeObjectPropertyGetter); + return true; +} + +bool runtimeObjectCustomPut(ExecState* exec, const Identifier& propertyName, JSValuePtr value, HTMLElement* element, PutPropertySlot& slot) +{ + RuntimeObjectImp* runtimeObject = getRuntimeObject(exec, element); + if (!runtimeObject) + return 0; + if (!runtimeObject->hasProperty(exec, propertyName)) + return false; + runtimeObject->put(exec, propertyName, value, slot); + return true; +} + +static JSValuePtr callPlugin(ExecState* exec, JSObject* function, JSValuePtr, const ArgList& args) +{ + Instance* instance = pluginInstance(static_cast<JSHTMLElement*>(function)->impl()); + instance->begin(); + JSValuePtr result = instance->invokeDefaultMethod(exec, args); + instance->end(); + return result; +} + +CallType runtimeObjectGetCallData(HTMLElement* element, CallData& callData) +{ + Instance* instance = pluginInstance(element); + if (!instance || !instance->supportsInvokeDefaultMethod()) + return CallTypeNone; + callData.native.function = callPlugin; + return CallTypeHost; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSPluginElementFunctions.h b/src/3rdparty/webkit/WebCore/bindings/js/JSPluginElementFunctions.h new file mode 100644 index 0000000..a1a86c0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSPluginElementFunctions.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 1999 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSPluginElementFunctions_h +#define JSPluginElementFunctions_h + +#include "JSDOMBinding.h" + +namespace WebCore { + + class HTMLElement; + class JSHTMLElement; + class Node; + + // Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement. + + JSC::JSValuePtr runtimeObjectGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); + JSC::JSValuePtr runtimeObjectPropertyGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); + bool runtimeObjectCustomGetOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&, JSHTMLElement*); + bool runtimeObjectCustomPut(JSC::ExecState*, const JSC::Identifier&, JSC::JSValuePtr, HTMLElement*, JSC::PutPropertySlot&); + JSC::CallType runtimeObjectGetCallData(HTMLElement*, JSC::CallData&); + +} // namespace WebCore + +#endif // JSPluginElementFunctions_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSQuarantinedObjectWrapper.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSQuarantinedObjectWrapper.cpp new file mode 100644 index 0000000..cec0dab --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSQuarantinedObjectWrapper.cpp @@ -0,0 +1,278 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSQuarantinedObjectWrapper.h" + +#include <runtime/JSGlobalObject.h> + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSQuarantinedObjectWrapper) + +const ClassInfo JSQuarantinedObjectWrapper::s_info = { "JSQuarantinedObjectWrapper", 0, 0, 0 }; + +JSQuarantinedObjectWrapper* JSQuarantinedObjectWrapper::asWrapper(JSValuePtr value) +{ + if (!value->isObject()) + return 0; + + JSObject* object = asObject(value); + + if (!object->inherits(&JSQuarantinedObjectWrapper::s_info)) + return 0; + + return static_cast<JSQuarantinedObjectWrapper*>(object); +} + +JSValuePtr JSQuarantinedObjectWrapper::cachedValueGetter(ExecState*, const Identifier&, const PropertySlot& slot) +{ + JSValuePtr v = slot.slotBase(); + ASSERT(v); + return v; +} + +JSQuarantinedObjectWrapper::JSQuarantinedObjectWrapper(ExecState* unwrappedExec, JSObject* unwrappedObject, PassRefPtr<Structure> structure) + : JSObject(structure) + , m_unwrappedGlobalObject(unwrappedExec->dynamicGlobalObject()) + , m_unwrappedObject(unwrappedObject) +{ + ASSERT_ARG(unwrappedExec, unwrappedExec); + ASSERT_ARG(unwrappedObject, unwrappedObject); + ASSERT(this->structure()); +} + +JSQuarantinedObjectWrapper::~JSQuarantinedObjectWrapper() +{ +} + +bool JSQuarantinedObjectWrapper::allowsUnwrappedAccessFrom(ExecState* exec) const +{ + return m_unwrappedGlobalObject->profileGroup() == exec->dynamicGlobalObject()->profileGroup(); +} + +ExecState* JSQuarantinedObjectWrapper::unwrappedExecState() const +{ + return m_unwrappedGlobalObject->globalExec(); +} + +void JSQuarantinedObjectWrapper::transferExceptionToExecState(ExecState* exec) const +{ + ASSERT(exec != unwrappedExecState()); + + if (!unwrappedExecState()->hadException()) + return; + + exec->setException(wrapOutgoingValue(unwrappedExecState(), unwrappedExecState()->exception())); + unwrappedExecState()->clearException(); +} + +void JSQuarantinedObjectWrapper::mark() +{ + JSObject::mark(); + + if (!m_unwrappedObject->marked()) + m_unwrappedObject->mark(); + if (!m_unwrappedGlobalObject->marked()) + m_unwrappedGlobalObject->mark(); +} + +bool JSQuarantinedObjectWrapper::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot) +{ + if (!allowsGetProperty()) { + slot.setUndefined(); + return true; + } + + PropertySlot unwrappedSlot(m_unwrappedObject); + bool result = m_unwrappedObject->getOwnPropertySlot(unwrappedExecState(), identifier, unwrappedSlot); + if (result) { + JSValuePtr unwrappedValue = unwrappedSlot.getValue(unwrappedExecState(), identifier); + slot.setCustom(wrapOutgoingValue(unwrappedExecState(), unwrappedValue), cachedValueGetter); + } + + transferExceptionToExecState(exec); + + return result; +} + +bool JSQuarantinedObjectWrapper::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot) +{ + if (!allowsGetProperty()) { + slot.setUndefined(); + return true; + } + + PropertySlot unwrappedSlot(m_unwrappedObject); + bool result = m_unwrappedObject->getOwnPropertySlot(unwrappedExecState(), identifier, unwrappedSlot); + if (result) { + JSValuePtr unwrappedValue = unwrappedSlot.getValue(unwrappedExecState(), identifier); + slot.setCustom(wrapOutgoingValue(unwrappedExecState(), unwrappedValue), cachedValueGetter); + } + + transferExceptionToExecState(exec); + + return result; +} + +void JSQuarantinedObjectWrapper::put(ExecState* exec, const Identifier& identifier, JSValuePtr value, PutPropertySlot& slot) +{ + if (!allowsSetProperty()) + return; + + m_unwrappedObject->put(unwrappedExecState(), identifier, prepareIncomingValue(exec, value), slot); + + transferExceptionToExecState(exec); +} + +void JSQuarantinedObjectWrapper::put(ExecState* exec, unsigned identifier, JSValuePtr value) +{ + if (!allowsSetProperty()) + return; + + m_unwrappedObject->put(unwrappedExecState(), identifier, prepareIncomingValue(exec, value)); + + transferExceptionToExecState(exec); +} + +bool JSQuarantinedObjectWrapper::deleteProperty(ExecState* exec, const Identifier& identifier) +{ + if (!allowsDeleteProperty()) + return false; + + bool result = m_unwrappedObject->deleteProperty(unwrappedExecState(), identifier); + + transferExceptionToExecState(exec); + + return result; +} + +bool JSQuarantinedObjectWrapper::deleteProperty(ExecState* exec, unsigned identifier) +{ + if (!allowsDeleteProperty()) + return false; + + bool result = m_unwrappedObject->deleteProperty(unwrappedExecState(), identifier); + + transferExceptionToExecState(exec); + + return result; +} + +JSObject* JSQuarantinedObjectWrapper::construct(ExecState* exec, JSObject* constructor, const ArgList& args) +{ + JSQuarantinedObjectWrapper* wrapper = static_cast<JSQuarantinedObjectWrapper*>(constructor); + + ArgList preparedArgs; + for (size_t i = 0; i < args.size(); ++i) + preparedArgs.append(wrapper->prepareIncomingValue(exec, args.at(exec, i))); + + // FIXME: Would be nice to find a way to reuse the result of m_unwrappedObject->getConstructData + // from when we called it in JSQuarantinedObjectWrapper::getConstructData. + ConstructData unwrappedConstructData; + ConstructType unwrappedConstructType = wrapper->m_unwrappedObject->getConstructData(unwrappedConstructData); + ASSERT(unwrappedConstructType != ConstructTypeNone); + + JSValuePtr unwrappedResult = JSC::construct(wrapper->unwrappedExecState(), wrapper->m_unwrappedObject, unwrappedConstructType, unwrappedConstructData, preparedArgs); + + JSValuePtr resultValue = wrapper->wrapOutgoingValue(wrapper->unwrappedExecState(), unwrappedResult); + ASSERT(resultValue->isObject()); + JSObject* result = asObject(resultValue); + + wrapper->transferExceptionToExecState(exec); + + return result; +} + +ConstructType JSQuarantinedObjectWrapper::getConstructData(ConstructData& constructData) +{ + if (!allowsConstruct()) + return ConstructTypeNone; + ConstructData unwrappedConstructData; + if (m_unwrappedObject->getConstructData(unwrappedConstructData) == ConstructTypeNone) + return ConstructTypeNone; + constructData.native.function = construct; + return ConstructTypeHost; +} + +bool JSQuarantinedObjectWrapper::hasInstance(ExecState* exec, JSValuePtr value, JSValuePtr proto) +{ + if (!allowsHasInstance()) + return false; + + bool result = m_unwrappedObject->hasInstance(unwrappedExecState(), prepareIncomingValue(exec, value), prepareIncomingValue(exec, proto)); + + transferExceptionToExecState(exec); + + return result; +} + +JSValuePtr JSQuarantinedObjectWrapper::call(ExecState* exec, JSObject* function, JSValuePtr thisValue, const ArgList& args) +{ + JSQuarantinedObjectWrapper* wrapper = static_cast<JSQuarantinedObjectWrapper*>(function); + + JSValuePtr preparedThisValue = wrapper->prepareIncomingValue(exec, thisValue); + + ArgList preparedArgs; + for (size_t i = 0; i < args.size(); ++i) + preparedArgs.append(wrapper->prepareIncomingValue(exec, args.at(exec, i))); + + // FIXME: Would be nice to find a way to reuse the result of m_unwrappedObject->getCallData + // from when we called it in JSQuarantinedObjectWrapper::getCallData. + CallData unwrappedCallData; + CallType unwrappedCallType = wrapper->m_unwrappedObject->getCallData(unwrappedCallData); + ASSERT(unwrappedCallType != CallTypeNone); + + JSValuePtr unwrappedResult = JSC::call(wrapper->unwrappedExecState(), wrapper->m_unwrappedObject, unwrappedCallType, unwrappedCallData, preparedThisValue, preparedArgs); + + JSValuePtr result = wrapper->wrapOutgoingValue(wrapper->unwrappedExecState(), unwrappedResult); + + wrapper->transferExceptionToExecState(exec); + + return result; +} + +CallType JSQuarantinedObjectWrapper::getCallData(CallData& callData) +{ + if (!allowsCallAsFunction()) + return CallTypeNone; + CallData unwrappedCallData; + if (m_unwrappedObject->getCallData(unwrappedCallData) == CallTypeNone) + return CallTypeNone; + callData.native.function = call; + return CallTypeHost; +} + +void JSQuarantinedObjectWrapper::getPropertyNames(ExecState*, PropertyNameArray& array) +{ + if (!allowsGetPropertyNames()) + return; + + m_unwrappedObject->getPropertyNames(unwrappedExecState(), array); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSQuarantinedObjectWrapper.h b/src/3rdparty/webkit/WebCore/bindings/js/JSQuarantinedObjectWrapper.h new file mode 100644 index 0000000..d66dc46 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSQuarantinedObjectWrapper.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSQuarantinedObjectWrapper_h +#define JSQuarantinedObjectWrapper_h + +#include <runtime/JSObject.h> + +namespace WebCore { + + class JSQuarantinedObjectWrapper : public JSC::JSObject { + public: + static JSQuarantinedObjectWrapper* asWrapper(JSC::JSValuePtr); + + virtual ~JSQuarantinedObjectWrapper(); + + virtual JSC::JSObject* unwrappedObject() { return m_unwrappedObject; } + + JSC::JSGlobalObject* unwrappedGlobalObject() const { return m_unwrappedGlobalObject; }; + JSC::ExecState* unwrappedExecState() const; + + bool allowsUnwrappedAccessFrom(JSC::ExecState*) const; + + static const JSC::ClassInfo s_info; + + static PassRefPtr<JSC::Structure> createStructure(JSC::JSValuePtr proto) + { + return JSC::Structure::create(proto, JSC::TypeInfo(JSC::ObjectType, JSC::ImplementsHasInstance | JSC::OverridesHasInstance)); + } + + protected: + JSQuarantinedObjectWrapper(JSC::ExecState* unwrappedExec, JSC::JSObject* unwrappedObject, PassRefPtr<JSC::Structure>); + + virtual void mark(); + + private: + virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&); + virtual bool getOwnPropertySlot(JSC::ExecState*, unsigned, JSC::PropertySlot&); + + virtual void put(JSC::ExecState*, const JSC::Identifier&, JSC::JSValuePtr, JSC::PutPropertySlot&); + virtual void put(JSC::ExecState*, unsigned, JSC::JSValuePtr); + + virtual bool deleteProperty(JSC::ExecState*, const JSC::Identifier&); + virtual bool deleteProperty(JSC::ExecState*, unsigned); + + virtual JSC::CallType getCallData(JSC::CallData&); + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + + virtual bool hasInstance(JSC::ExecState*, JSC::JSValuePtr, JSC::JSValuePtr proto); + + virtual void getPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&); + + virtual JSC::UString className() const { return m_unwrappedObject->className(); } + + virtual bool allowsGetProperty() const { return false; } + virtual bool allowsSetProperty() const { return false; } + virtual bool allowsDeleteProperty() const { return false; } + virtual bool allowsConstruct() const { return false; } + virtual bool allowsHasInstance() const { return false; } + virtual bool allowsCallAsFunction() const { return false; } + virtual bool allowsGetPropertyNames() const { return false; } + + virtual JSC::JSValuePtr prepareIncomingValue(JSC::ExecState* unwrappedExec, JSC::JSValuePtr unwrappedValue) const = 0; + virtual JSC::JSValuePtr wrapOutgoingValue(JSC::ExecState* unwrappedExec, JSC::JSValuePtr unwrappedValue) const = 0; + + static JSC::JSValuePtr cachedValueGetter(JSC::ExecState*, const JSC::Identifier&, const JSC::PropertySlot&); + + void transferExceptionToExecState(JSC::ExecState*) const; + + static JSC::JSValuePtr call(JSC::ExecState*, JSC::JSObject* function, JSC::JSValuePtr thisValue, const JSC::ArgList&); + static JSC::JSObject* construct(JSC::ExecState*, JSC::JSObject*, const JSC::ArgList&); + + JSC::JSGlobalObject* m_unwrappedGlobalObject; + JSC::JSObject* m_unwrappedObject; + }; + +} // namespace WebCore + +#endif // JSQuarantinedObjectWrapper_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSRGBColor.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSRGBColor.cpp new file mode 100644 index 0000000..91fe4b3 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSRGBColor.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006 James G. Speth (speth@end.com) + * Copyright (C) 2006 Samuel Weinig (sam@webkit.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSRGBColor.h" + +#include "CSSPrimitiveValue.h" +#include "JSCSSPrimitiveValue.h" + +using namespace JSC; + +static JSValuePtr jsRGBColorRed(ExecState*, const Identifier&, const PropertySlot&); +static JSValuePtr jsRGBColorGreen(ExecState*, const Identifier&, const PropertySlot&); +static JSValuePtr jsRGBColorBlue(ExecState*, const Identifier&, const PropertySlot&); + +/* +@begin JSRGBColorTable + red jsRGBColorRed DontDelete|ReadOnly + green jsRGBColorGreen DontDelete|ReadOnly + blue jsRGBColorBlue DontDelete|ReadOnly +@end +*/ + +#include "JSRGBColor.lut.h" + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSRGBColor) + +const ClassInfo JSRGBColor::s_info = { "RGBColor", 0, &JSRGBColorTable, 0 }; + +JSRGBColor::JSRGBColor(ExecState* exec, unsigned color) + : DOMObject(getDOMStructure<JSRGBColor>(exec)) + , m_color(color) +{ +} + +bool JSRGBColor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return getStaticValueSlot<JSRGBColor, DOMObject>(exec, &JSRGBColorTable, this, propertyName, slot); +} + +JSValuePtr getJSRGBColor(ExecState* exec, unsigned color) +{ + return new (exec) JSRGBColor(exec, color); +} + +} // namespace WebCore + +using namespace WebCore; + +JSValuePtr jsRGBColorRed(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + return toJS(exec, CSSPrimitiveValue::create((static_cast<JSRGBColor*>(asObject(slot.slotBase()))->impl() >> 16) & 0xFF, CSSPrimitiveValue::CSS_NUMBER)); +} + +JSValuePtr jsRGBColorGreen(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + return toJS(exec, CSSPrimitiveValue::create((static_cast<JSRGBColor*>(asObject(slot.slotBase()))->impl() >> 8) & 0xFF, CSSPrimitiveValue::CSS_NUMBER)); +} + +JSValuePtr jsRGBColorBlue(ExecState* exec, const Identifier&, const PropertySlot& slot) +{ + return toJS(exec, CSSPrimitiveValue::create(static_cast<JSRGBColor*>(asObject(slot.slotBase()))->impl() & 0xFF, CSSPrimitiveValue::CSS_NUMBER)); +} + diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSRGBColor.h b/src/3rdparty/webkit/WebCore/bindings/js/JSRGBColor.h new file mode 100644 index 0000000..d5acff3 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSRGBColor.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSRGBColor_h +#define JSRGBColor_h + +#include "Color.h" +#include "JSDOMBinding.h" + +namespace WebCore { + + // FIXME: JSRGBColor should have a proper prototype and a constructor. + class JSRGBColor : public DOMObject { + public: + JSRGBColor(JSC::ExecState*, unsigned color); + + virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&); + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + static const JSC::ClassInfo s_info; + + unsigned impl() const { return m_color; } + + static JSC::ObjectPrototype* createPrototype(JSC::ExecState* exec) + { + return exec->lexicalGlobalObject()->objectPrototype(); + } + + static PassRefPtr<JSC::Structure> createStructure(JSC::JSValuePtr prototype) + { + return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType)); + } + + private: + unsigned m_color; + }; + + JSC::JSValuePtr getJSRGBColor(JSC::ExecState*, unsigned color); + +} // namespace WebCore + +#endif // JSRGBColor_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp new file mode 100644 index 0000000..8c01d0c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSSQLResultSetRowList.h" + +#include "ExceptionCode.h" +#include "SQLValue.h" +#include "SQLResultSetRowList.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSSQLResultSetRowList::item(ExecState* exec, const ArgList& args) +{ + bool indexOk; + int index = args.at(exec, 0)->toInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + if (index < 0 || (unsigned)index >= m_impl->length()) { + setDOMException(exec, INDEX_SIZE_ERR); + return jsUndefined(); + } + + JSObject* object = constructEmptyObject(exec); + + unsigned numColumns = m_impl->columnNames().size(); + unsigned valuesIndex = index * numColumns; + for (unsigned i = 0; i < numColumns; i++) { + const SQLValue& value = m_impl->values()[valuesIndex + i]; + JSValuePtr jsValue = noValue(); + + switch (value.type()) { + case SQLValue::StringValue: + jsValue = jsString(exec, value.string()); + break; + case SQLValue::NullValue: + jsValue = jsNull(); + break; + case SQLValue::NumberValue: + jsValue = jsNumber(exec, value.number()); + break; + default: + ASSERT_NOT_REACHED(); + } + + object->putDirect(Identifier(exec, m_impl->columnNames()[i]), jsValue, DontDelete | ReadOnly); + } + + return object; +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSQLTransactionCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSSQLTransactionCustom.cpp new file mode 100644 index 0000000..3cab8c4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSQLTransactionCustom.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2007 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSSQLTransaction.h" + +#include "DOMWindow.h" +#include "ExceptionCode.h" +#include "JSCustomSQLStatementCallback.h" +#include "JSCustomSQLStatementErrorCallback.h" +#include "JSDOMWindowCustom.h" +#include "SQLTransaction.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSSQLTransaction::executeSql(ExecState* exec, const ArgList& args) +{ + String sqlStatement = args.at(exec, 0)->toString(exec); + if (exec->hadException()) + return jsUndefined(); + + // Now assemble the list of SQL arguments + Vector<SQLValue> sqlValues; + if (!args.at(exec, 1)->isUndefinedOrNull()) { + JSObject* object = args.at(exec, 1)->getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + JSValuePtr lengthValue = object->get(exec, exec->propertyNames().length); + if (exec->hadException()) + return jsUndefined(); + unsigned length = lengthValue->toUInt32(exec); + if (exec->hadException()) + return jsUndefined(); + + for (unsigned i = 0 ; i < length; ++i) { + JSValuePtr value = object->get(exec, i); + if (exec->hadException()) + return jsUndefined(); + + if (value->isNull()) + sqlValues.append(SQLValue()); + else if (value->isNumber()) + sqlValues.append(value->getNumber()); + else { + // Convert the argument to a string and append it + sqlValues.append(value->toString(exec)); + if (exec->hadException()) + return jsUndefined(); + } + } + } + + RefPtr<SQLStatementCallback> callback; + if (!args.at(exec, 2)->isUndefinedOrNull()) { + JSObject* object = args.at(exec, 2)->getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + if (Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame()) + callback = JSCustomSQLStatementCallback::create(object, frame); + } + + RefPtr<SQLStatementErrorCallback> errorCallback; + if (!args.at(exec, 3)->isUndefinedOrNull()) { + JSObject* object = args.at(exec, 3)->getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + if (Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame()) + errorCallback = JSCustomSQLStatementErrorCallback::create(object, frame); + } + + ExceptionCode ec = 0; + m_impl->executeSQL(sqlStatement, sqlValues, callback.release(), errorCallback.release(), ec); + setDOMException(exec, ec); + + return jsUndefined(); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGElementInstanceCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGElementInstanceCustom.cpp new file mode 100644 index 0000000..ea2471e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGElementInstanceCustom.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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(SVG) +#include "SVGElementInstance.h" +#include "JSSVGElementInstance.h" + +#include "JSEventListener.h" +#include "JSDOMWindow.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSSVGElementInstance::addEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + + if (RefPtr<JSEventListener> listener = globalObject->findOrCreateJSEventListener(exec, args.at(exec, 1))) + impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec)); + + return jsUndefined(); +} + +JSValuePtr JSSVGElementInstance::removeEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + + if (JSEventListener* listener = globalObject->findJSEventListener(args.at(exec, 1))) + impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec)); + + return jsUndefined(); +} + +void JSSVGElementInstance::pushEventHandlerScope(ExecState*, ScopeChain&) const +{ +} + +} + +#endif diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGLengthCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGLengthCustom.cpp new file mode 100644 index 0000000..6dd8507 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGLengthCustom.cpp @@ -0,0 +1,48 @@ +/* + Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "JSSVGLength.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSSVGLength::value(ExecState* exec) const +{ + SVGLength imp(*impl()); + return jsNumber(exec, imp.value(context())); +} + +JSValuePtr JSSVGLength::convertToSpecifiedUnits(ExecState* exec, const ArgList& args) +{ + JSSVGPODTypeWrapper<SVGLength>* wrapper = impl(); + + SVGLength imp(*wrapper); + imp.convertToSpecifiedUnits(args.at(exec, 0)->toInt32(exec), context()); + + wrapper->commitChange(imp, context()); + return jsUndefined(); +} + +} + +#endif // ENABLE(SVG) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGMatrixCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGMatrixCustom.cpp new file mode 100644 index 0000000..fdf9d5e --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGMatrixCustom.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "JSSVGMatrix.h" + +#include "TransformationMatrix.h" +#include "SVGException.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSSVGMatrix::multiply(ExecState* exec, const ArgList& args) +{ + TransformationMatrix imp(*impl()); + + TransformationMatrix secondMatrix = toSVGMatrix(args.at(exec, 0)); + return toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.multiply(secondMatrix)).get(), m_context.get()); +} + +JSValuePtr JSSVGMatrix::inverse(ExecState* exec, const ArgList&) +{ + TransformationMatrix imp(*impl()); + JSC::JSValuePtr result = toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.inverse()).get(), m_context.get()); + + if (!imp.isInvertible()) + setDOMException(exec, SVGException::SVG_MATRIX_NOT_INVERTABLE); + + return result; +} + +JSValuePtr JSSVGMatrix::translate(ExecState* exec, const ArgList& args) +{ + TransformationMatrix imp(*impl()); + + float x = args.at(exec, 0)->toFloat(exec); + float y = args.at(exec, 1)->toFloat(exec); + + return toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.translate(x, y)).get(), m_context.get()); +} + +JSValuePtr JSSVGMatrix::scale(ExecState* exec, const ArgList& args) +{ + TransformationMatrix imp(*impl()); + + float scaleFactor = args.at(exec, 0)->toFloat(exec); + return toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.scale(scaleFactor)).get(), m_context.get()); +} + +JSValuePtr JSSVGMatrix::scaleNonUniform(ExecState* exec, const ArgList& args) +{ + TransformationMatrix imp(*impl()); + + float scaleFactorX = args.at(exec, 0)->toFloat(exec); + float scaleFactorY = args.at(exec, 1)->toFloat(exec); + + return toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.scaleNonUniform(scaleFactorX, scaleFactorY)).get(), m_context.get()); +} + +JSValuePtr JSSVGMatrix::rotate(ExecState* exec, const ArgList& args) +{ + TransformationMatrix imp(*impl()); + + float angle = args.at(exec, 0)->toFloat(exec); + return toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.rotate(angle)).get(), m_context.get()); +} + +JSValuePtr JSSVGMatrix::rotateFromVector(ExecState* exec, const ArgList& args) +{ + TransformationMatrix imp(*impl()); + + float x = args.at(exec, 0)->toFloat(exec); + float y = args.at(exec, 1)->toFloat(exec); + + JSC::JSValuePtr result = toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.rotateFromVector(x, y)).get(), m_context.get()); + + if (x == 0.0 || y == 0.0) + setDOMException(exec, SVGException::SVG_INVALID_VALUE_ERR); + + return result; +} + +JSValuePtr JSSVGMatrix::flipX(ExecState* exec, const ArgList&) +{ + TransformationMatrix imp(*impl()); + return toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.flipX()).get(), m_context.get()); +} + +JSValuePtr JSSVGMatrix::flipY(ExecState* exec, const ArgList&) +{ + TransformationMatrix imp(*impl()); + return toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.flipY()).get(), m_context.get()); +} + +JSValuePtr JSSVGMatrix::skewX(ExecState* exec, const ArgList& args) +{ + TransformationMatrix imp(*impl()); + + float angle = args.at(exec, 0)->toFloat(exec); + return toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.skewX(angle)).get(), m_context.get()); +} + +JSValuePtr JSSVGMatrix::skewY(ExecState* exec, const ArgList& args) +{ + TransformationMatrix imp(*impl()); + + float angle = args.at(exec, 0)->toFloat(exec); + return toJS(exec, JSSVGStaticPODTypeWrapper<TransformationMatrix>::create(imp.skewY(angle)).get(), m_context.get()); +} + +} + +#endif // ENABLE(SVG) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h new file mode 100644 index 0000000..c30f97f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPODTypeWrapper.h @@ -0,0 +1,411 @@ +/* + * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSSVGPODTypeWrapper_h +#define JSSVGPODTypeWrapper_h + +#if ENABLE(SVG) +#include "Frame.h" +#include "SVGElement.h" +#include <wtf/StdLibExtras.h> + +namespace WebCore { + +template<typename PODType> +class JSSVGPODTypeWrapper : public RefCounted<JSSVGPODTypeWrapper<PODType> > { +public: + virtual ~JSSVGPODTypeWrapper() { } + + virtual operator PODType() = 0; + virtual void commitChange(PODType, SVGElement*) = 0; +}; + +// This file contains JS wrapper objects for SVG datatypes, that are passed around by value +// in WebCore/svg (aka. 'POD types'). For instance SVGMatrix is mapped to TransformationMatrix, and +// passed around as const reference. SVG DOM demands these objects to be "live", changes to any +// of the writable attributes of SVGMatrix need to be reflected in the object which exposed the +// SVGMatrix object (ie. 'someElement.transform.matrix.a = 50.0', in that case 'SVGTransform'). +// The SVGTransform class stores its "TransformationMatrix m_matrix" object on the stack. If it would +// be stored as pointer we could just build an auto-generated JSSVG* wrapper object around it +// and all changes to that object would automatically affect the TransformationMatrix* object stored +// in the SVGTransform object. For the sake of efficiency and memory we don't pass around any +// primitive values as pointers, so a custom JS wrapper object is needed for all SVG types, that +// are internally represented by POD types (SVGRect <-> FloatRect, SVGPoint <-> FloatPoint, ...). +// Those custom wrappers are called JSSVGPODTypeWrapper and are capable of updating the POD types +// by taking function pointers to the getter & setter functions of the "creator object", the object +// which exposed a SVG POD type. For example, the JSSVGPODTypeWrapper object wrapping a SVGMatrix +// object takes (SVGTransform*, &SVGTransform::matrix, &SVGTransform::setMatrix). A JS call like +// "someElement.transform.matrix.a = 50.0' causes the JSSVGMatrix object to call SVGTransform::setMatrix, +// method, which in turn notifies 'someElement' that the 'SVGNames::transformAttr' has changed. +// That's a short sketch of our SVG DOM implementation. + +// Represents a JS wrapper object for SVGAnimated* classes, exposing SVG POD types that contain writable properties +// (Two cases: SVGAnimatedLength exposing SVGLength, SVGAnimatedRect exposing SVGRect) + +#if COMPILER(MSVC) +// GetterMethod and SetterMethod are each 12 bytes. We have to pack to a size +// greater than or equal to that to avoid an alignment warning (C4121). 16 is +// the next-largest size allowed for packing, so we use that. +#pragma pack(16) +#endif +template<typename PODType, typename PODTypeCreator> +class JSSVGDynamicPODTypeWrapper : public JSSVGPODTypeWrapper<PODType> { +public: + typedef PODType (PODTypeCreator::*GetterMethod)() const; + typedef void (PODTypeCreator::*SetterMethod)(PODType); + + static PassRefPtr<JSSVGDynamicPODTypeWrapper> create(PassRefPtr<PODTypeCreator> creator, GetterMethod getter, SetterMethod setter) + { + return adoptRef(new JSSVGDynamicPODTypeWrapper(creator, getter, setter)); + } + + virtual operator PODType() + { + return (m_creator.get()->*m_getter)(); + } + + virtual void commitChange(PODType type, SVGElement* context) + { + (m_creator.get()->*m_setter)(type); + + if (context) + context->svgAttributeChanged(m_creator->associatedAttributeName()); + } + +private: + JSSVGDynamicPODTypeWrapper(PassRefPtr<PODTypeCreator> creator, GetterMethod getter, SetterMethod setter) + : m_creator(creator) + , m_getter(getter) + , m_setter(setter) + { + ASSERT(m_creator); + ASSERT(m_getter); + ASSERT(m_setter); + } + + // Update callbacks + RefPtr<PODTypeCreator> m_creator; + GetterMethod m_getter; + SetterMethod m_setter; +}; + +// Represents a JS wrapper object for SVG POD types (not for SVGAnimated* clases). Any modification to the SVG POD +// types don't cause any updates unlike JSSVGDynamicPODTypeWrapper. This class is used for return values (ie. getBBox()) +// and for properties where SVG specification explicitely states, that the contents of the POD type are immutable. + +template<typename PODType> +class JSSVGStaticPODTypeWrapper : public JSSVGPODTypeWrapper<PODType> { +public: + static PassRefPtr<JSSVGStaticPODTypeWrapper> create(PODType type) + { + return adoptRef(new JSSVGStaticPODTypeWrapper(type)); + } + + virtual operator PODType() + { + return m_podType; + } + + virtual void commitChange(PODType type, SVGElement*) + { + m_podType = type; + } + +protected: + JSSVGStaticPODTypeWrapper(PODType type) + : m_podType(type) + { + } + + PODType m_podType; +}; + +template<typename PODType, typename ParentTypeArg> +class JSSVGStaticPODTypeWrapperWithPODTypeParent : public JSSVGStaticPODTypeWrapper<PODType> { +public: + typedef JSSVGPODTypeWrapper<ParentTypeArg> ParentType; + + static PassRefPtr<JSSVGStaticPODTypeWrapperWithPODTypeParent> create(PODType type, PassRefPtr<ParentType> parent) + { + return adoptRef(new JSSVGStaticPODTypeWrapperWithPODTypeParent(type, parent)); + } + + virtual void commitChange(PODType type, SVGElement* context) + { + JSSVGStaticPODTypeWrapper<PODType>::commitChange(type, context); + m_parentType->commitChange(ParentTypeArg(type), context); + } + +private: + JSSVGStaticPODTypeWrapperWithPODTypeParent(PODType type, PassRefPtr<ParentType> parent) + : JSSVGStaticPODTypeWrapper<PODType>(type) + , m_parentType(parent) + { + } + + RefPtr<ParentType> m_parentType; +}; + +#if COMPILER(MSVC) +// GetterMethod and SetterMethod are each 12 bytes. We have to pack to a size +// greater than or equal to that to avoid an alignment warning (C4121). 16 is +// the next-largest size allowed for packing, so we use that. +#pragma pack(16) +#endif +template<typename PODType, typename ParentType> +class JSSVGStaticPODTypeWrapperWithParent : public JSSVGPODTypeWrapper<PODType> { +public: + typedef PODType (ParentType::*GetterMethod)() const; + typedef void (ParentType::*SetterMethod)(const PODType&); + + static PassRefPtr<JSSVGStaticPODTypeWrapperWithParent> create(PassRefPtr<ParentType> parent, GetterMethod getter, SetterMethod setter) + { + return adoptRef(new JSSVGStaticPODTypeWrapperWithParent(parent, getter, setter)); + } + + virtual operator PODType() + { + return (m_parent.get()->*m_getter)(); + } + + virtual void commitChange(PODType type, SVGElement*) + { + (m_parent.get()->*m_setter)(type); + } + +private: + JSSVGStaticPODTypeWrapperWithParent(PassRefPtr<ParentType> parent, GetterMethod getter, SetterMethod setter) + : m_parent(parent) + , m_getter(getter) + , m_setter(setter) + { + ASSERT(m_parent); + ASSERT(m_getter); + ASSERT(m_setter); + } + + // Update callbacks + RefPtr<ParentType> m_parent; + GetterMethod m_getter; + SetterMethod m_setter; +}; + +template<typename PODType> +class SVGPODListItem; + +// Just like JSSVGDynamicPODTypeWrapper, but only used for SVGList* objects wrapping around POD values. + +template<typename PODType> +class JSSVGPODTypeWrapperCreatorForList : public JSSVGPODTypeWrapper<PODType> { +public: + typedef SVGPODListItem<PODType> PODListItemPtrType; + + typedef PODType (SVGPODListItem<PODType>::*GetterMethod)() const; + typedef void (SVGPODListItem<PODType>::*SetterMethod)(PODType); + + static PassRefPtr<JSSVGPODTypeWrapperCreatorForList> create(PassRefPtr<PODListItemPtrType> creator, const QualifiedName& attributeName) + { + return adoptRef(new JSSVGPODTypeWrapperCreatorForList(creator, attributeName)); + } + + virtual operator PODType() + { + return (m_creator.get()->*m_getter)(); + } + + virtual void commitChange(PODType type, SVGElement* context) + { + if (!m_setter) + return; + + (m_creator.get()->*m_setter)(type); + + if (context) + context->svgAttributeChanged(m_associatedAttributeName); + } + +private: + JSSVGPODTypeWrapperCreatorForList(PassRefPtr<PODListItemPtrType> creator, const QualifiedName& attributeName) + : m_creator(creator) + , m_getter(&PODListItemPtrType::value) + , m_setter(&PODListItemPtrType::setValue) + , m_associatedAttributeName(attributeName) + { + ASSERT(m_creator); + ASSERT(m_getter); + ASSERT(m_setter); + } + + // Update callbacks + RefPtr<PODListItemPtrType> m_creator; + GetterMethod m_getter; + SetterMethod m_setter; + const QualifiedName& m_associatedAttributeName; +}; + +// Caching facilities +template<typename PODType, typename PODTypeCreator> +struct PODTypeWrapperCacheInfo { + typedef PODType (PODTypeCreator::*GetterMethod)() const; + typedef void (PODTypeCreator::*SetterMethod)(PODType); + + // Empty value + PODTypeWrapperCacheInfo() + : creator(0) + , getter(0) + , setter(0) + { + } + + // Deleted value + PODTypeWrapperCacheInfo(WTF::HashTableDeletedValueType) + : creator(reinterpret_cast<PODTypeCreator*>(-1)) + , getter(0) + , setter(0) + { + } + bool isHashTableDeletedValue() const + { + return creator == reinterpret_cast<PODTypeCreator*>(-1); + } + + PODTypeWrapperCacheInfo(PODTypeCreator* _creator, GetterMethod _getter, SetterMethod _setter) + : creator(_creator) + , getter(_getter) + , setter(_setter) + { + ASSERT(creator); + ASSERT(getter); + } + + bool operator==(const PODTypeWrapperCacheInfo& other) const + { + return creator == other.creator && getter == other.getter && setter == other.setter; + } + + PODTypeCreator* creator; + GetterMethod getter; + SetterMethod setter; +}; + +template<typename PODType, typename PODTypeCreator> +struct PODTypeWrapperCacheInfoHash { + typedef PODTypeWrapperCacheInfo<PODType, PODTypeCreator> CacheInfo; + + static unsigned hash(const CacheInfo& info) + { + return StringImpl::computeHash(reinterpret_cast<const UChar*>(&info), sizeof(CacheInfo) / sizeof(UChar)); + } + + static bool equal(const CacheInfo& a, const CacheInfo& b) + { + return a == b; + } + + static const bool safeToCompareToEmptyOrDeleted = true; +}; + +template<typename PODType, typename PODTypeCreator> +struct PODTypeWrapperCacheInfoTraits : WTF::GenericHashTraits<PODTypeWrapperCacheInfo<PODType, PODTypeCreator> > { + typedef PODTypeWrapperCacheInfo<PODType, PODTypeCreator> CacheInfo; + + static const bool emptyValueIsZero = true; + static const bool needsDestruction = false; + + static const CacheInfo& emptyValue() + { + DEFINE_STATIC_LOCAL(CacheInfo, key, ()); + return key; + } + + static void constructDeletedValue(CacheInfo& slot) + { + new (&slot) CacheInfo(WTF::HashTableDeletedValue); + } + + static bool isDeletedValue(const CacheInfo& value) + { + return value.isHashTableDeletedValue(); + } +}; + +template<typename PODType, typename PODTypeCreator> +class JSSVGDynamicPODTypeWrapperCache { +public: + typedef PODType (PODTypeCreator::*GetterMethod)() const; + typedef void (PODTypeCreator::*SetterMethod)(PODType); + + typedef PODTypeWrapperCacheInfo<PODType, PODTypeCreator> CacheInfo; + typedef PODTypeWrapperCacheInfoHash<PODType, PODTypeCreator> CacheInfoHash; + typedef PODTypeWrapperCacheInfoTraits<PODType, PODTypeCreator> CacheInfoTraits; + + typedef JSSVGPODTypeWrapper<PODType> WrapperBase; + typedef JSSVGDynamicPODTypeWrapper<PODType, PODTypeCreator> DynamicWrapper; + typedef HashMap<CacheInfo, DynamicWrapper*, CacheInfoHash, CacheInfoTraits> DynamicWrapperHashMap; + typedef typename DynamicWrapperHashMap::const_iterator DynamicWrapperHashMapIterator; + + static DynamicWrapperHashMap& dynamicWrapperHashMap() + { + DEFINE_STATIC_LOCAL(DynamicWrapperHashMap, s_dynamicWrapperHashMap, ()); + return s_dynamicWrapperHashMap; + } + + // Used for readwrite attributes only + static PassRefPtr<WrapperBase> lookupOrCreateWrapper(PODTypeCreator* creator, GetterMethod getter, SetterMethod setter) + { + DynamicWrapperHashMap& map(dynamicWrapperHashMap()); + CacheInfo info(creator, getter, setter); + + if (map.contains(info)) + return map.get(info); + + RefPtr<DynamicWrapper> wrapper = DynamicWrapper::create(creator, getter, setter); + map.set(info, wrapper.get()); + return wrapper.release(); + } + + static void forgetWrapper(WrapperBase* wrapper) + { + DynamicWrapperHashMap& map(dynamicWrapperHashMap()); + + DynamicWrapperHashMapIterator it = map.begin(); + DynamicWrapperHashMapIterator end = map.end(); + + for (; it != end; ++it) { + if (it->second != wrapper) + continue; + + // It's guaranteed that there's just one object we need to take care of. + map.remove(it->first); + break; + } + } +}; + +}; + +#endif // ENABLE(SVG) +#endif // JSSVGPODTypeWrapper_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPathSegCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPathSegCustom.cpp new file mode 100644 index 0000000..b7490e7 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPathSegCustom.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "JSSVGPathSeg.h" +#include "JSSVGPathSegArcAbs.h" +#include "JSSVGPathSegArcRel.h" +#include "JSSVGPathSegClosePath.h" +#include "JSSVGPathSegCurvetoCubicAbs.h" +#include "JSSVGPathSegCurvetoCubicRel.h" +#include "JSSVGPathSegCurvetoCubicSmoothAbs.h" +#include "JSSVGPathSegCurvetoCubicSmoothRel.h" +#include "JSSVGPathSegCurvetoQuadraticAbs.h" +#include "JSSVGPathSegCurvetoQuadraticRel.h" +#include "JSSVGPathSegCurvetoQuadraticSmoothAbs.h" +#include "JSSVGPathSegCurvetoQuadraticSmoothRel.h" +#include "JSSVGPathSegLinetoAbs.h" +#include "JSSVGPathSegLinetoRel.h" +#include "JSSVGPathSegLinetoHorizontalAbs.h" +#include "JSSVGPathSegLinetoHorizontalRel.h" +#include "JSSVGPathSegLinetoVerticalAbs.h" +#include "JSSVGPathSegLinetoVerticalRel.h" +#include "JSSVGPathSegMovetoAbs.h" +#include "JSSVGPathSegMovetoRel.h" + +#include "JSDOMBinding.h" + +#include "SVGPathSeg.h" +#include "SVGPathSegArc.h" +#include "SVGPathSegClosePath.h" +#include "SVGPathSegCurvetoCubic.h" +#include "SVGPathSegCurvetoCubicSmooth.h" +#include "SVGPathSegCurvetoQuadratic.h" +#include "SVGPathSegCurvetoQuadraticSmooth.h" +#include "SVGPathSegLineto.h" +#include "SVGPathSegLinetoHorizontal.h" +#include "SVGPathSegLinetoVertical.h" +#include "SVGPathSegMoveto.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr toJS(ExecState* exec, SVGPathSeg* object, SVGElement* context) +{ + if (!object) + return jsNull(); + + if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), object)) + return wrapper; + + switch (object->pathSegType()) { + case SVGPathSeg::PATHSEG_CLOSEPATH: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegClosePath, object, context); + case SVGPathSeg::PATHSEG_MOVETO_ABS: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegMovetoAbs, object, context); + case SVGPathSeg::PATHSEG_MOVETO_REL: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegMovetoRel, object, context); + case SVGPathSeg::PATHSEG_LINETO_ABS: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegLinetoAbs, object, context); + case SVGPathSeg::PATHSEG_LINETO_REL: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegLinetoRel, object, context); + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegCurvetoCubicAbs, object, context); + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_REL: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegCurvetoCubicRel, object, context); + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_ABS: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegCurvetoQuadraticAbs, object, context); + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_REL: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegCurvetoQuadraticRel, object, context); + case SVGPathSeg::PATHSEG_ARC_ABS: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegArcAbs, object, context); + case SVGPathSeg::PATHSEG_ARC_REL: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegArcRel, object, context); + case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_ABS: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegLinetoHorizontalAbs, object, context); + case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_REL: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegLinetoHorizontalRel, object, context); + case SVGPathSeg::PATHSEG_LINETO_VERTICAL_ABS: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegLinetoVerticalAbs, object, context); + case SVGPathSeg::PATHSEG_LINETO_VERTICAL_REL: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegLinetoVerticalRel, object, context); + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_ABS: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegCurvetoCubicSmoothAbs, object, context); + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_REL: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegCurvetoCubicSmoothRel, object, context); + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegCurvetoQuadraticSmoothAbs, object, context); + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSegCurvetoQuadraticSmoothRel, object, context); + case SVGPathSeg::PATHSEG_UNKNOWN: + default: + return CREATE_SVG_OBJECT_WRAPPER(exec, SVGPathSeg, object, context); + } +} + +} + +#endif // ENABLE(SVG) + +// vim:ts=4:noet diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPathSegListCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPathSegListCustom.cpp new file mode 100644 index 0000000..6197b48 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPathSegListCustom.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "JSSVGPathSegList.h" + +#include "Document.h" +#include "Frame.h" +#include "JSSVGPathSeg.h" +#include "SVGDocumentExtensions.h" +#include "SVGElement.h" +#include "SVGPathSegList.h" + +#include <wtf/Assertions.h> + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSSVGPathSegList::clear(ExecState* exec, const ArgList&) +{ + ExceptionCode ec = 0; + + SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl()); + imp->clear(ec); + + setDOMException(exec, ec); + + m_context->svgAttributeChanged(imp->associatedAttributeName()); + return jsUndefined(); +} + +JSValuePtr JSSVGPathSegList::initialize(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + SVGPathSeg* newItem = toSVGPathSeg(args.at(exec, 0)); + + SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl()); + + SVGPathSeg* obj = WTF::getPtr(imp->initialize(newItem, ec)); + + JSC::JSValuePtr result = toJS(exec, obj, m_context.get()); + setDOMException(exec, ec); + + m_context->svgAttributeChanged(imp->associatedAttributeName()); + return result; +} + +JSValuePtr JSSVGPathSegList::getItem(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + + bool indexOk; + unsigned index = args.at(exec, 0)->toInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl()); + SVGPathSeg* obj = WTF::getPtr(imp->getItem(index, ec)); + + JSC::JSValuePtr result = toJS(exec, obj, m_context.get()); + setDOMException(exec, ec); + return result; +} + +JSValuePtr JSSVGPathSegList::insertItemBefore(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + SVGPathSeg* newItem = toSVGPathSeg(args.at(exec, 0)); + + bool indexOk; + unsigned index = args.at(exec, 1)->toInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl()); + + JSC::JSValuePtr result = toJS(exec, WTF::getPtr(imp->insertItemBefore(newItem, index, ec)), m_context.get()); + setDOMException(exec, ec); + + m_context->svgAttributeChanged(imp->associatedAttributeName()); + return result; +} + +JSValuePtr JSSVGPathSegList::replaceItem(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + SVGPathSeg* newItem = toSVGPathSeg(args.at(exec, 0)); + + bool indexOk; + unsigned index = args.at(exec, 1)->toInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl()); + + JSC::JSValuePtr result = toJS(exec, WTF::getPtr(imp->replaceItem(newItem, index, ec)), m_context.get()); + setDOMException(exec, ec); + + m_context->svgAttributeChanged(imp->associatedAttributeName()); + return result; +} + +JSValuePtr JSSVGPathSegList::removeItem(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + + bool indexOk; + unsigned index = args.at(exec, 0)->toInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl()); + + RefPtr<SVGPathSeg> obj(imp->removeItem(index, ec)); + + JSC::JSValuePtr result = toJS(exec, obj.get(), m_context.get()); + setDOMException(exec, ec); + + m_context->svgAttributeChanged(imp->associatedAttributeName()); + return result; +} + +JSValuePtr JSSVGPathSegList::appendItem(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + SVGPathSeg* newItem = toSVGPathSeg(args.at(exec, 0)); + + SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl()); + + JSC::JSValuePtr result = toJS(exec, WTF::getPtr(imp->appendItem(newItem, ec)), m_context.get()); + setDOMException(exec, ec); + + m_context->svgAttributeChanged(imp->associatedAttributeName()); + return result; +} + +} + +#endif // ENABLE(SVG) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPointListCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPointListCustom.cpp new file mode 100644 index 0000000..a2e74ae --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGPointListCustom.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "JSSVGPointList.h" + +#include "JSSVGPoint.h" +#include "SVGPointList.h" + +using namespace JSC; + +namespace WebCore { + +typedef SVGPODListItem<FloatPoint> PODListItem; +typedef SVGList<RefPtr<PODListItem> > SVGPointListBase; + +static JSValuePtr finishGetter(ExecState* exec, ExceptionCode& ec, SVGElement* context, SVGPointList* list, PassRefPtr<PODListItem > item) +{ + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, JSSVGPODTypeWrapperCreatorForList<FloatPoint>::create(item.get(), list->associatedAttributeName()).get(), context); +} + +static JSValuePtr finishSetter(ExecState* exec, ExceptionCode& ec, SVGElement* context, SVGPointList* list, PassRefPtr<PODListItem > item) +{ + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + const QualifiedName& attributeName = list->associatedAttributeName(); + context->svgAttributeChanged(attributeName); + return toJS(exec, JSSVGPODTypeWrapperCreatorForList<FloatPoint>::create(item.get(), attributeName).get(), context); +} + +static JSValuePtr finishSetterReadOnlyResult(ExecState* exec, ExceptionCode& ec, SVGElement* context, SVGPointList* list, PassRefPtr<PODListItem> item) +{ + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + context->svgAttributeChanged(list->associatedAttributeName()); + return toJS(exec, JSSVGStaticPODTypeWrapper<FloatPoint>::create(*item).get(), context); +} + +JSValuePtr JSSVGPointList::clear(ExecState* exec, const ArgList&) +{ + ExceptionCode ec = 0; + impl()->clear(ec); + setDOMException(exec, ec); + m_context->svgAttributeChanged(impl()->associatedAttributeName()); + return jsUndefined(); +} + +JSValuePtr JSSVGPointList::initialize(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + SVGPointListBase* listImp = impl(); + return finishSetter(exec, ec, context(), impl(), + listImp->initialize(PODListItem::copy(toSVGPoint(args.at(exec, 0))), ec)); +} + +JSValuePtr JSSVGPointList::getItem(ExecState* exec, const ArgList& args) +{ + bool indexOk; + unsigned index = args.at(exec, 0)->toUInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + ExceptionCode ec = 0; + SVGPointListBase* listImp = impl(); + return finishGetter(exec, ec, context(), impl(), + listImp->getItem(index, ec)); +} + +JSValuePtr JSSVGPointList::insertItemBefore(ExecState* exec, const ArgList& args) +{ + bool indexOk; + unsigned index = args.at(exec, 1)->toUInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + ExceptionCode ec = 0; + SVGPointListBase* listImp = impl(); + return finishSetter(exec, ec, context(), impl(), + listImp->insertItemBefore(PODListItem::copy(toSVGPoint(args.at(exec, 0))), index, ec)); +} + +JSValuePtr JSSVGPointList::replaceItem(ExecState* exec, const ArgList& args) +{ + bool indexOk; + unsigned index = args.at(exec, 1)->toInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + ExceptionCode ec = 0; + SVGPointListBase* listImp = impl(); + return finishSetter(exec, ec, context(), impl(), + listImp->replaceItem(PODListItem::copy(toSVGPoint(args.at(exec, 0))), index, ec)); +} + +JSValuePtr JSSVGPointList::removeItem(ExecState* exec, const ArgList& args) +{ + bool indexOk; + unsigned index = args.at(exec, 0)->toInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + ExceptionCode ec = 0; + SVGPointListBase* listImp = impl(); + return finishSetterReadOnlyResult(exec, ec, context(), impl(), + listImp->removeItem(index, ec)); +} + +JSValuePtr JSSVGPointList::appendItem(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + SVGPointListBase* listImp = impl(); + return finishSetter(exec, ec, context(), impl(), + listImp->appendItem(PODListItem::copy(toSVGPoint(args.at(exec, 0))), ec)); +} + +} + +#endif // ENABLE(SVG) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSSVGTransformListCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGTransformListCustom.cpp new file mode 100644 index 0000000..b29b259 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSSVGTransformListCustom.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "JSSVGTransformList.h" + +#include "JSSVGTransform.h" +#include "SVGTransformList.h" + +using namespace JSC; + +namespace WebCore { + +typedef SVGPODListItem<SVGTransform> PODListItem; +typedef SVGList<RefPtr<PODListItem> > SVGTransformListBase; + +static JSValuePtr finishGetter(ExecState* exec, ExceptionCode& ec, SVGElement* context, SVGTransformList* list, PassRefPtr<PODListItem> item) +{ + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, JSSVGPODTypeWrapperCreatorForList<SVGTransform>::create(item.get(), list->associatedAttributeName()).get(), context); +} + +static JSValuePtr finishSetter(ExecState* exec, ExceptionCode& ec, SVGElement* context, SVGTransformList* list, PassRefPtr<PODListItem> item) +{ + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + const QualifiedName& attributeName = list->associatedAttributeName(); + context->svgAttributeChanged(attributeName); + return toJS(exec, JSSVGPODTypeWrapperCreatorForList<SVGTransform>::create(item.get(), attributeName).get(), context); +} + +static JSValuePtr finishSetterReadOnlyResult(ExecState* exec, ExceptionCode& ec, SVGElement* context, SVGTransformList* list, PassRefPtr<PODListItem> item) +{ + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + context->svgAttributeChanged(list->associatedAttributeName()); + return toJS(exec, JSSVGStaticPODTypeWrapper<SVGTransform>::create(*item).get(), context); +} + +JSValuePtr JSSVGTransformList::clear(ExecState* exec, const ArgList&) +{ + ExceptionCode ec = 0; + impl()->clear(ec); + setDOMException(exec, ec); + m_context->svgAttributeChanged(impl()->associatedAttributeName()); + return jsUndefined(); +} + +JSValuePtr JSSVGTransformList::initialize(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + SVGTransformListBase* listImp = impl(); + return finishSetter(exec, ec, context(), impl(), + listImp->initialize(PODListItem::copy(toSVGTransform(args.at(exec, 0))), ec)); +} + +JSValuePtr JSSVGTransformList::getItem(ExecState* exec, const ArgList& args) +{ + bool indexOk; + unsigned index = args.at(exec, 0)->toUInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + ExceptionCode ec = 0; + SVGTransformListBase* listImp = impl(); + return finishGetter(exec, ec, context(), impl(), + listImp->getItem(index, ec)); +} + +JSValuePtr JSSVGTransformList::insertItemBefore(ExecState* exec, const ArgList& args) +{ + bool indexOk; + unsigned index = args.at(exec, 1)->toUInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + ExceptionCode ec = 0; + SVGTransformListBase* listImp = impl(); + return finishSetter(exec, ec, context(), impl(), + listImp->insertItemBefore(PODListItem::copy(toSVGTransform(args.at(exec, 0))), index, ec)); +} + +JSValuePtr JSSVGTransformList::replaceItem(ExecState* exec, const ArgList& args) +{ + bool indexOk; + unsigned index = args.at(exec, 1)->toUInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + ExceptionCode ec = 0; + SVGTransformListBase* listImp = impl(); + return finishSetter(exec, ec, context(), impl(), + listImp->replaceItem(PODListItem::copy(toSVGTransform(args.at(exec, 0))), index, ec)); +} + +JSValuePtr JSSVGTransformList::removeItem(ExecState* exec, const ArgList& args) +{ + bool indexOk; + unsigned index = args.at(exec, 0)->toUInt32(exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + ExceptionCode ec = 0; + SVGTransformListBase* listImp = impl(); + return finishSetterReadOnlyResult(exec, ec, context(), impl(), + listImp->removeItem(index, ec)); +} + +JSValuePtr JSSVGTransformList::appendItem(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + SVGTransformListBase* listImp = impl(); + return finishSetter(exec, ec, context(), impl(), + listImp->appendItem(PODListItem::copy(toSVGTransform(args.at(exec, 0))), ec)); +} + +} + +#endif // ENABLE(SVG) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSStorageCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSStorageCustom.cpp new file mode 100644 index 0000000..a92da25 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSStorageCustom.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSStorageCustom.h" + +#if ENABLE(DOM_STORAGE) + +#include "PlatformString.h" +#include <runtime/PropertyNameArray.h> +#include "Storage.h" + +using namespace JSC; + +namespace WebCore { + +bool JSStorage::canGetItemsForName(ExecState*, Storage* impl, const Identifier& propertyName) +{ + return impl->contains(propertyName); +} + +JSValuePtr JSStorage::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSStorage* thisObj = static_cast<JSStorage*>(asObject(slot.slotBase())); + return jsStringOrNull(exec, thisObj->impl()->getItem(propertyName)); +} + +bool JSStorage::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + // Only perform the custom delete if the object doesn't have a native property by this name. + // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check + // the native property slots manually. + PropertySlot slot; + if (getStaticValueSlot<JSStorage, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot)) + return false; + + JSValuePtr prototype = this->prototype(); + if (prototype->isObject() && asObject(prototype)->hasProperty(exec, propertyName)) + return false; + + m_impl->removeItem(propertyName); + return true; +} + +bool JSStorage::customGetPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) +{ + ExceptionCode ec; + unsigned length = m_impl->length(); + for (unsigned i = 0; i < length; ++i) + propertyNames.add(Identifier(exec, m_impl->key(i, ec))); + + return false; +} + +bool JSStorage::customPut(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot&) +{ + // Only perform the custom put if the object doesn't have a native property by this name. + // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check + // the native property slots manually. + PropertySlot slot; + if (getStaticValueSlot<JSStorage, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot)) + return false; + + JSValuePtr prototype = this->prototype(); + if (prototype->isObject() && asObject(prototype)->hasProperty(exec, propertyName)) + return false; + + String stringValue = valueToStringWithNullCheck(exec, value); + if (exec->hadException()) + return true; + + ExceptionCode ec = 0; + impl()->setItem(propertyName, stringValue, ec); + setDOMException(exec, ec); + + return true; +} + +} // namespace WebCore + +#endif // ENABLE(DOM_STORAGE) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSStorageCustom.h b/src/3rdparty/webkit/WebCore/bindings/js/JSStorageCustom.h new file mode 100644 index 0000000..45f62df --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSStorageCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 JSStorageCustom_h +#define JSStorageCustom_h + +#include "JSStorage.h" + +#endif // JSStorageCustom_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSStyleSheetCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSStyleSheetCustom.cpp new file mode 100644 index 0000000..04dabf0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSStyleSheetCustom.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSStyleSheet.h" + +#include "CSSStyleSheet.h" +#include "JSCSSStyleSheet.h" +#include "JSNode.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr toJS(ExecState* exec, StyleSheet* styleSheet) +{ + if (!styleSheet) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), styleSheet); + if (wrapper) + return wrapper; + + if (styleSheet->isCSSStyleSheet()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, CSSStyleSheet, styleSheet); + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, StyleSheet, styleSheet); + + return wrapper; +} + +void JSStyleSheet::mark() +{ + Base::mark(); + + // This prevents us from having a style sheet with a dangling ownerNode pointer. + // A better solution would be to handle this on the DOM side -- if the style sheet + // is kept around, then we want the node to stay around too. One possibility would + // be to make ref/deref on the style sheet ref/deref the node instead, but there's + // a lot of disentangling of the CSS DOM objects that would need to happen first. + if (Node* ownerNode = impl()->ownerNode()) { + if (JSNode* ownerNodeWrapper = getCachedDOMNodeWrapper(ownerNode->document(), ownerNode)) { + if (!ownerNodeWrapper->marked()) + ownerNodeWrapper->mark(); + } + } +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSStyleSheetListCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSStyleSheetListCustom.cpp new file mode 100644 index 0000000..ea41687 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSStyleSheetListCustom.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "JSStyleSheetList.h" + +#include "HTMLStyleElement.h" +#include "JSStyleSheet.h" +#include "StyleSheet.h" +#include "StyleSheetList.h" + +using namespace JSC; + +namespace WebCore { + +bool JSStyleSheetList::canGetItemsForName(ExecState*, StyleSheetList* styleSheetList, const Identifier& propertyName) +{ + return styleSheetList->getNamedItem(propertyName); +} + +JSValuePtr JSStyleSheetList::nameGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot) +{ + JSStyleSheetList* thisObj = static_cast<JSStyleSheetList*>(asObject(slot.slotBase())); + HTMLStyleElement* element = thisObj->impl()->getNamedItem(propertyName); + ASSERT(element); + return toJS(exec, element->sheet()); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSTextCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSTextCustom.cpp new file mode 100644 index 0000000..8118aef --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSTextCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSText.h" + +#include "Text.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr toJSNewlyCreated(ExecState* exec, Text* text) +{ + if (!text) + return jsNull(); + + return CREATE_DOM_NODE_WRAPPER(exec, Text, text); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSTreeWalkerCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSTreeWalkerCustom.cpp new file mode 100644 index 0000000..aca0f93 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSTreeWalkerCustom.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSTreeWalker.h" + +#include "JSNode.h" +#include "Node.h" +#include "NodeFilter.h" +#include "TreeWalker.h" + +using namespace JSC; + +namespace WebCore { + +void JSTreeWalker::mark() +{ + if (NodeFilter* filter = m_impl->filter()) + filter->mark(); + + DOMObject::mark(); +} + +JSValuePtr JSTreeWalker::parentNode(ExecState* exec, const ArgList&) +{ + Node* node = impl()->parentNode(exec); + if (exec->hadException()) + return jsUndefined(); + return toJS(exec, node); +} + +JSValuePtr JSTreeWalker::firstChild(ExecState* exec, const ArgList&) +{ + Node* node = impl()->firstChild(exec); + if (exec->hadException()) + return jsUndefined(); + return toJS(exec, node); +} + +JSValuePtr JSTreeWalker::lastChild(ExecState* exec, const ArgList&) +{ + Node* node = impl()->lastChild(exec); + if (exec->hadException()) + return jsUndefined(); + return toJS(exec, node); +} + +JSValuePtr JSTreeWalker::nextSibling(ExecState* exec, const ArgList&) +{ + Node* node = impl()->nextSibling(exec); + if (exec->hadException()) + return jsUndefined(); + return toJS(exec, node); +} + +JSValuePtr JSTreeWalker::previousSibling(ExecState* exec, const ArgList&) +{ + Node* node = impl()->previousSibling(exec); + if (exec->hadException()) + return jsUndefined(); + return toJS(exec, node); +} + +JSValuePtr JSTreeWalker::previousNode(ExecState* exec, const ArgList&) +{ + Node* node = impl()->previousNode(exec); + if (exec->hadException()) + return jsUndefined(); + return toJS(exec, node); +} + +JSValuePtr JSTreeWalker::nextNode(ExecState* exec, const ArgList&) +{ + Node* node = impl()->nextNode(exec); + if (exec->hadException()) + return jsUndefined(); + return toJS(exec, node); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerConstructor.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerConstructor.cpp new file mode 100644 index 0000000..2c964c3 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerConstructor.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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(WORKERS) + +#include "JSWorkerConstructor.h" + +#include "Document.h" +#include "ExceptionCode.h" +#include "JSDOMWindowCustom.h" +#include "JSWorker.h" +#include "Worker.h" + +using namespace JSC; + +namespace WebCore { + +const ClassInfo JSWorkerConstructor::s_info = { "WorkerConstructor", 0, 0, 0 }; + +JSWorkerConstructor::JSWorkerConstructor(ExecState* exec) + : DOMObject(JSWorkerConstructor::createStructure(exec->lexicalGlobalObject()->objectPrototype())) +{ + putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum); +} + +static JSObject* constructWorker(ExecState* exec, JSObject*, const ArgList& args) +{ + if (args.size() == 0) + return throwError(exec, SyntaxError, "Not enough arguments"); + + UString scriptURL = args.at(exec, 0)->toString(exec); + if (exec->hadException()) + return 0; + + DOMWindow* window = asJSDOMWindow(exec->lexicalGlobalObject())->impl(); + + ExceptionCode ec = 0; + RefPtr<Worker> worker = Worker::create(scriptURL, window->document(), ec); + setDOMException(exec, ec); + + return asObject(toJS(exec, worker.release())); +} + +ConstructType JSWorkerConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructWorker; + return ConstructTypeHost; +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerConstructor.h b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerConstructor.h new file mode 100644 index 0000000..d1df7eb --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerConstructor.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSWorkerConstructor_h +#define JSWorkerConstructor_h + +#if ENABLE(WORKERS) + +#include "JSDOMBinding.h" + +namespace WebCore { + + class JSWorkerConstructor : public DOMObject { + public: + JSWorkerConstructor(JSC::ExecState*); + + static const JSC::ClassInfo s_info; + + private: + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + }; + +} // namespace WebCore + +#endif // ENABLE(WORKERS) + +#endif // JSWorkerConstructor_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerContextBase.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerContextBase.cpp new file mode 100644 index 0000000..24dd50f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerContextBase.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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(WORKERS) + +#include "JSWorkerContextBase.h" + +#include "Event.h" +#include "JSDOMBinding.h" +#include "JSEventListener.h" +#include "JSMessageChannelConstructor.h" +#include "JSMessageEvent.h" +#include "JSMessagePort.h" +#include "JSWorkerLocation.h" +#include "JSWorkerNavigator.h" +#include "WorkerContext.h" +#include "WorkerLocation.h" + +using namespace JSC; + +/* +@begin JSWorkerContextBaseTable +@end +*/ + +#include "JSWorkerContextBase.lut.h" + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSWorkerContextBase) + +JSWorkerContextBase::JSWorkerContextBase(PassRefPtr<JSC::Structure> structure, PassRefPtr<WorkerContext> impl) + : JSDOMGlobalObject(structure, new JSDOMGlobalObjectData, this) + , m_impl(impl) +{ +} + +JSWorkerContextBase::~JSWorkerContextBase() +{ +} + +ScriptExecutionContext* JSWorkerContextBase::scriptExecutionContext() const +{ + return m_impl.get(); +} + +static const HashTable* getJSWorkerContextBaseTable(ExecState* exec) +{ + return getHashTableForGlobalData(exec->globalData(), &JSWorkerContextBaseTable); +} + +const ClassInfo JSWorkerContextBase::s_info = { "WorkerContext", 0, 0, getJSWorkerContextBaseTable }; + +void JSWorkerContextBase::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) +{ + lookupPut<JSWorkerContextBase, Base>(exec, propertyName, value, getJSWorkerContextBaseTable(exec), this, slot); +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerContextBase.h b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerContextBase.h new file mode 100644 index 0000000..d2d5bd2 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerContextBase.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSWorkerContextBase_h +#define JSWorkerContextBase_h + +#if ENABLE(WORKERS) + +#include "JSDOMGlobalObject.h" + +namespace WebCore { + + class WorkerContext; + + class JSWorkerContextBase : public JSDOMGlobalObject { + typedef JSDOMGlobalObject Base; + public: + JSWorkerContextBase(PassRefPtr<JSC::Structure>, PassRefPtr<WorkerContext>); + virtual ~JSWorkerContextBase(); + + virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValuePtr, JSC::PutPropertySlot&); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + static const JSC::ClassInfo s_info; + + WorkerContext* impl() const { return m_impl.get(); } + virtual ScriptExecutionContext* scriptExecutionContext() const; + + private: + RefPtr<WorkerContext> m_impl; + }; + +} // namespace WebCore + +#endif // ENABLE(WORKERS) + +#endif // JSWorkerContextBase_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerContextCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerContextCustom.cpp new file mode 100644 index 0000000..2bf4dbc --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerContextCustom.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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(WORKERS) + +#include "JSWorkerContext.h" + +#include "JSDOMBinding.h" +#include "JSEventListener.h" +#include "WorkerContext.h" + +using namespace JSC; + +namespace WebCore { + +bool JSWorkerContext::customGetOwnPropertySlot(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertySlot& slot) +{ + // Look for overrides before looking at any of our own properties. + if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot)) + return true; + return false; +} + +void JSWorkerContext::mark() +{ + Base::mark(); + + markActiveObjectsForContext(*globalData(), scriptExecutionContext()); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(impl()->onmessage())) + listener->mark(); + + typedef WorkerContext::EventListenersMap EventListenersMap; + typedef WorkerContext::ListenerVector ListenerVector; + EventListenersMap& eventListeners = impl()->eventListeners(); + for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) { + for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) { + JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(vecIter->get()); + listener->mark(); + } + } +} + +JSValuePtr JSWorkerContext::self(ExecState*) const +{ + return asValue(); +} + +void JSWorkerContext::setSelf(ExecState* exec, JSValuePtr value) +{ + putDirect(Identifier(exec, "self"), value); +} + +JSValuePtr JSWorkerContext::addEventListener(ExecState* exec, const ArgList& args) +{ + RefPtr<JSUnprotectedEventListener> listener = findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +JSValuePtr JSWorkerContext::removeEventListener(ExecState* exec, const ArgList& args) +{ + JSUnprotectedEventListener* listener = findJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerCustom.cpp new file mode 100644 index 0000000..bb40705 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSWorkerCustom.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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(WORKERS) + +#include "JSWorker.h" + +#include "JSDOMGlobalObject.h" +#include "JSEventListener.h" +#include "Worker.h" + +using namespace JSC; + +namespace WebCore { + +void JSWorker::mark() +{ + DOMObject::mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onmessage())) + listener->mark(); + + if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onerror())) + listener->mark(); + + typedef Worker::EventListenersMap EventListenersMap; + typedef Worker::ListenerVector ListenerVector; + EventListenersMap& eventListeners = m_impl->eventListeners(); + for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) { + for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) { + JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(vecIter->get()); + listener->mark(); + } + } +} + +JSValuePtr JSWorker::addEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + RefPtr<JSUnprotectedEventListener> listener = globalObject->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +JSValuePtr JSWorker::removeEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + JSUnprotectedEventListener* listener = globalObject->findJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestConstructor.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestConstructor.cpp new file mode 100644 index 0000000..d7f54de --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestConstructor.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2004, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2005, 2006 Alexey Proskuryakov <ap@nypop.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSXMLHttpRequestConstructor.h" + +#include "JSXMLHttpRequest.h" +#include "ScriptExecutionContext.h" +#include "XMLHttpRequest.h" + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSXMLHttpRequestConstructor) + +const ClassInfo JSXMLHttpRequestConstructor::s_info = { "XMLHttpRequestConstructor", 0, 0, 0 }; + +JSXMLHttpRequestConstructor::JSXMLHttpRequestConstructor(ExecState* exec, ScriptExecutionContext* context) + : DOMObject(JSXMLHttpRequestConstructor::createStructure(exec->lexicalGlobalObject()->objectPrototype())) +{ + ASSERT(context->isDocument()); + m_document = static_cast<JSDocument*>(asObject(toJS(exec, static_cast<Document*>(context)))); + + putDirect(exec->propertyNames().prototype, JSXMLHttpRequestPrototype::self(exec), None); +} + +static JSObject* constructXMLHttpRequest(ExecState* exec, JSObject* constructor, const ArgList&) +{ + RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(static_cast<JSXMLHttpRequestConstructor*>(constructor)->document()); + return CREATE_DOM_OBJECT_WRAPPER(exec, XMLHttpRequest, xmlHttpRequest.get()); +} + +ConstructType JSXMLHttpRequestConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructXMLHttpRequest; + return ConstructTypeHost; +} + +void JSXMLHttpRequestConstructor::mark() +{ + DOMObject::mark(); + if (!m_document->marked()) + m_document->mark(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestConstructor.h b/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestConstructor.h new file mode 100644 index 0000000..f235af6 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestConstructor.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2003, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2005, 2006 Alexey Proskuryakov <ap@nypop.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSXMLHttpRequestConstructor_h +#define JSXMLHttpRequestConstructor_h + +#include "JSDOMBinding.h" +#include "JSDocument.h" + +namespace WebCore { + +class JSXMLHttpRequestConstructor : public DOMObject { +public: + JSXMLHttpRequestConstructor(JSC::ExecState*, ScriptExecutionContext*); + Document* document() const { return m_document->impl(); } + static const JSC::ClassInfo s_info; + + virtual void mark(); +private: + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + + JSDocument* m_document; +}; + +} // namespace WebCore + +#endif // JSXMLHttpRequestConstructor_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp new file mode 100644 index 0000000..49813c4 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "JSXMLHttpRequest.h" + +#include "DOMWindow.h" +#include "Document.h" +#include "Event.h" +#include "File.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "HTMLDocument.h" +#include "JSDOMWindowCustom.h" +#include "JSDocument.h" +#include "JSEvent.h" +#include "JSEventListener.h" +#include "JSFile.h" +#include "XMLHttpRequest.h" +#include <runtime/Error.h> +#include <interpreter/Interpreter.h> + +using namespace JSC; + +namespace WebCore { + +void JSXMLHttpRequest::mark() +{ + Base::mark(); + + if (XMLHttpRequestUpload* upload = m_impl->optionalUpload()) { + DOMObject* wrapper = getCachedDOMObjectWrapper(*Heap::heap(this)->globalData(), upload); + if (wrapper && !wrapper->marked()) + wrapper->mark(); + } + + if (JSUnprotectedEventListener* onReadyStateChangeListener = static_cast<JSUnprotectedEventListener*>(m_impl->onreadystatechange())) + onReadyStateChangeListener->mark(); + + if (JSUnprotectedEventListener* onAbortListener = static_cast<JSUnprotectedEventListener*>(m_impl->onabort())) + onAbortListener->mark(); + + if (JSUnprotectedEventListener* onErrorListener = static_cast<JSUnprotectedEventListener*>(m_impl->onerror())) + onErrorListener->mark(); + + if (JSUnprotectedEventListener* onLoadListener = static_cast<JSUnprotectedEventListener*>(m_impl->onload())) + onLoadListener->mark(); + + if (JSUnprotectedEventListener* onLoadStartListener = static_cast<JSUnprotectedEventListener*>(m_impl->onloadstart())) + onLoadStartListener->mark(); + + if (JSUnprotectedEventListener* onProgressListener = static_cast<JSUnprotectedEventListener*>(m_impl->onprogress())) + onProgressListener->mark(); + + typedef XMLHttpRequest::EventListenersMap EventListenersMap; + typedef XMLHttpRequest::ListenerVector ListenerVector; + EventListenersMap& eventListeners = m_impl->eventListeners(); + for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) { + for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) { + JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(vecIter->get()); + listener->mark(); + } + } +} + +// Custom functions +JSValuePtr JSXMLHttpRequest::open(ExecState* exec, const ArgList& args) +{ + if (args.size() < 2) + return throwError(exec, SyntaxError, "Not enough arguments"); + + const KURL& url = impl()->scriptExecutionContext()->completeURL(args.at(exec, 1)->toString(exec)); + String method = args.at(exec, 0)->toString(exec); + bool async = true; + if (args.size() >= 3) + async = args.at(exec, 2)->toBoolean(exec); + + ExceptionCode ec = 0; + if (args.size() >= 4 && !args.at(exec, 3)->isUndefined()) { + String user = valueToStringWithNullCheck(exec, args.at(exec, 3)); + + if (args.size() >= 5 && !args.at(exec, 4)->isUndefined()) { + String password = valueToStringWithNullCheck(exec, args.at(exec, 4)); + impl()->open(method, url, async, user, password, ec); + } else + impl()->open(method, url, async, user, ec); + } else + impl()->open(method, url, async, ec); + + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValuePtr JSXMLHttpRequest::setRequestHeader(ExecState* exec, const ArgList& args) +{ + if (args.size() < 2) + return throwError(exec, SyntaxError, "Not enough arguments"); + + ExceptionCode ec = 0; + impl()->setRequestHeader(args.at(exec, 0)->toString(exec), args.at(exec, 1)->toString(exec), ec); + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValuePtr JSXMLHttpRequest::send(ExecState* exec, const ArgList& args) +{ + ExceptionCode ec = 0; + if (args.isEmpty()) + impl()->send(ec); + else { + JSValuePtr val = args.at(exec, 0); + if (val->isUndefinedOrNull()) + impl()->send(ec); + else if (val->isObject(&JSDocument::s_info)) + impl()->send(toDocument(val), ec); + else if (val->isObject(&JSFile::s_info)) + impl()->send(toFile(val), ec); + else + impl()->send(val->toString(exec), ec); + } + + int signedLineNumber; + intptr_t sourceID; + UString sourceURL; + JSValuePtr function; + exec->interpreter()->retrieveLastCaller(exec, signedLineNumber, sourceID, sourceURL, function); + impl()->setLastSendLineNumber(signedLineNumber >= 0 ? signedLineNumber : 0); + impl()->setLastSendURL(sourceURL); + + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValuePtr JSXMLHttpRequest::getResponseHeader(ExecState* exec, const ArgList& args) +{ + if (args.size() < 1) + return throwError(exec, SyntaxError, "Not enough arguments"); + + ExceptionCode ec = 0; + JSValuePtr header = jsStringOrNull(exec, impl()->getResponseHeader(args.at(exec, 0)->toString(exec), ec)); + setDOMException(exec, ec); + return header; +} + +JSValuePtr JSXMLHttpRequest::overrideMimeType(ExecState* exec, const ArgList& args) +{ + if (args.size() < 1) + return throwError(exec, SyntaxError, "Not enough arguments"); + + impl()->overrideMimeType(args.at(exec, 0)->toString(exec)); + return jsUndefined(); +} + +JSValuePtr JSXMLHttpRequest::addEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + RefPtr<JSUnprotectedEventListener> listener = globalObject->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +JSValuePtr JSXMLHttpRequest::removeEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + JSUnprotectedEventListener* listener = globalObject->findJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +JSValuePtr JSXMLHttpRequest::responseText(ExecState* exec) const +{ + return jsOwnedStringOrNull(exec, impl()->responseText()); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestUploadCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestUploadCustom.cpp new file mode 100644 index 0000000..5d094db --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSXMLHttpRequestUploadCustom.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE INC. ``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 APPLE INC. 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 "JSXMLHttpRequestUpload.h" + +#include "DOMWindow.h" +#include "Document.h" +#include "Event.h" +#include "Frame.h" +#include "JSDOMWindowCustom.h" +#include "JSEvent.h" +#include "JSEventListener.h" +#include "XMLHttpRequest.h" +#include "XMLHttpRequestUpload.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +void JSXMLHttpRequestUpload::mark() +{ + Base::mark(); + + if (XMLHttpRequest* xmlHttpRequest = m_impl->associatedXMLHttpRequest()) { + DOMObject* wrapper = getCachedDOMObjectWrapper(*Heap::heap(this)->globalData(), xmlHttpRequest); + if (wrapper && !wrapper->marked()) + wrapper->mark(); + } + + if (JSUnprotectedEventListener* onAbortListener = static_cast<JSUnprotectedEventListener*>(m_impl->onabort())) + onAbortListener->mark(); + + if (JSUnprotectedEventListener* onErrorListener = static_cast<JSUnprotectedEventListener*>(m_impl->onerror())) + onErrorListener->mark(); + + if (JSUnprotectedEventListener* onLoadListener = static_cast<JSUnprotectedEventListener*>(m_impl->onload())) + onLoadListener->mark(); + + if (JSUnprotectedEventListener* onLoadStartListener = static_cast<JSUnprotectedEventListener*>(m_impl->onloadstart())) + onLoadStartListener->mark(); + + if (JSUnprotectedEventListener* onProgressListener = static_cast<JSUnprotectedEventListener*>(m_impl->onprogress())) + onProgressListener->mark(); + + typedef XMLHttpRequestUpload::EventListenersMap EventListenersMap; + typedef XMLHttpRequestUpload::ListenerVector ListenerVector; + EventListenersMap& eventListeners = m_impl->eventListeners(); + for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) { + for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) { + JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(vecIter->get()); + listener->mark(); + } + } +} + +JSValuePtr JSXMLHttpRequestUpload::addEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + RefPtr<JSUnprotectedEventListener> listener = globalObject->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->addEventListener(args.at(exec, 0)->toString(exec), listener.release(), args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +JSValuePtr JSXMLHttpRequestUpload::removeEventListener(ExecState* exec, const ArgList& args) +{ + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext()); + if (!globalObject) + return jsUndefined(); + JSUnprotectedEventListener* listener = globalObject->findJSUnprotectedEventListener(exec, args.at(exec, 1)); + if (!listener) + return jsUndefined(); + impl()->removeEventListener(args.at(exec, 0)->toString(exec), listener, args.at(exec, 2)->toBoolean(exec)); + return jsUndefined(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSXSLTProcessorConstructor.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSXSLTProcessorConstructor.cpp new file mode 100644 index 0000000..ed456e1 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSXSLTProcessorConstructor.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2005, 2006, 2007, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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(XSLT) + +#include "JSXSLTProcessorConstructor.h" + +#include "JSXSLTProcessor.h" +#include "XSLTProcessor.h" +#include <wtf/RefPtr.h> + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSXSLTProcessorConstructor) + +const ClassInfo JSXSLTProcessorConstructor::s_info = { "XSLTProcessorConsructor", 0, 0, 0 }; + +JSXSLTProcessorConstructor::JSXSLTProcessorConstructor(ExecState* exec) + : DOMObject(JSXSLTProcessorConstructor::createStructure(exec->lexicalGlobalObject()->objectPrototype())) +{ + putDirect(exec->propertyNames().prototype, JSXSLTProcessorPrototype::self(exec), None); +} + +static JSObject* constructXSLTProcessor(ExecState* exec, JSObject*, const ArgList&) +{ + return CREATE_DOM_OBJECT_WRAPPER(exec, XSLTProcessor, XSLTProcessor::create().get()); +} + +ConstructType JSXSLTProcessorConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructXSLTProcessor; + return ConstructTypeHost; +} + +} // namespace WebCore + +#endif // ENABLE(XSLT) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSXSLTProcessorConstructor.h b/src/3rdparty/webkit/WebCore/bindings/js/JSXSLTProcessorConstructor.h new file mode 100644 index 0000000..64ef944 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSXSLTProcessorConstructor.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2005, 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSXSLTProcessorConstructor_h +#define JSXSLTProcessorConstructor_h + +#if ENABLE(XSLT) + +#include "JSDOMBinding.h" + +namespace WebCore { + + class JSXSLTProcessorConstructor : public DOMObject { + public: + JSXSLTProcessorConstructor(JSC::ExecState*); + static const JSC::ClassInfo s_info; + + private: + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + }; + +} // namespace WebCore + +#endif // ENABLE(XSLT) + +#endif // JSXSLTProcessorConstructor_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/JSXSLTProcessorCustom.cpp b/src/3rdparty/webkit/WebCore/bindings/js/JSXSLTProcessorCustom.cpp new file mode 100644 index 0000000..cdd5d1f --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/JSXSLTProcessorCustom.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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(XSLT) + +#include "JSXSLTProcessor.h" + +#include "Document.h" +#include "DocumentFragment.h" +#include "JSDocument.h" +#include "JSDocumentFragment.h" +#include "JSNode.h" +#include "Node.h" +#include "PlatformString.h" +#include "XSLTProcessor.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +JSValuePtr JSXSLTProcessor::importStylesheet(ExecState* exec, const ArgList& args) +{ + JSValuePtr nodeVal = args.at(exec, 0); + if (nodeVal->isObject(&JSNode::s_info)) { + JSNode* node = static_cast<JSNode*>(asObject(nodeVal)); + impl()->importStylesheet(node->impl()); + return jsUndefined(); + } + // Throw exception? + return jsUndefined(); +} + +JSValuePtr JSXSLTProcessor::transformToFragment(ExecState* exec, const ArgList& args) +{ + JSValuePtr nodeVal = args.at(exec, 0); + JSValuePtr docVal = args.at(exec, 1); + if (nodeVal->isObject(&JSNode::s_info) && docVal->isObject(&JSDocument::s_info)) { + WebCore::Node* node = static_cast<JSNode*>(asObject(nodeVal))->impl(); + Document* doc = static_cast<Document*>(static_cast<JSDocument*>(asObject(docVal))->impl()); + return toJS(exec, impl()->transformToFragment(node, doc).get()); + } + // Throw exception? + return jsUndefined(); +} + +JSValuePtr JSXSLTProcessor::transformToDocument(ExecState* exec, const ArgList& args) +{ + JSValuePtr nodeVal = args.at(exec, 0); + if (nodeVal->isObject(&JSNode::s_info)) { + JSNode* node = static_cast<JSNode*>(asObject(nodeVal)); + RefPtr<Document> resultDocument = impl()->transformToDocument(node->impl()); + if (resultDocument) + return toJS(exec, resultDocument.get()); + return jsUndefined(); + } + // Throw exception? + return jsUndefined(); +} + +JSValuePtr JSXSLTProcessor::setParameter(ExecState* exec, const ArgList& args) +{ + if (args.at(exec, 1)->isUndefinedOrNull() || args.at(exec, 2)->isUndefinedOrNull()) + return jsUndefined(); // Throw exception? + String namespaceURI = args.at(exec, 0)->toString(exec); + String localName = args.at(exec, 1)->toString(exec); + String value = args.at(exec, 2)->toString(exec); + impl()->setParameter(namespaceURI, localName, value); + return jsUndefined(); +} + +JSValuePtr JSXSLTProcessor::getParameter(ExecState* exec, const ArgList& args) +{ + if (args.at(exec, 1)->isUndefinedOrNull()) + return jsUndefined(); + String namespaceURI = args.at(exec, 0)->toString(exec); + String localName = args.at(exec, 1)->toString(exec); + String value = impl()->getParameter(namespaceURI, localName); + return jsStringOrUndefined(exec, value); +} + +JSValuePtr JSXSLTProcessor::removeParameter(ExecState* exec, const ArgList& args) +{ + if (args.at(exec, 1)->isUndefinedOrNull()) + return jsUndefined(); + String namespaceURI = args.at(exec, 0)->toString(exec); + String localName = args.at(exec, 1)->toString(exec); + impl()->removeParameter(namespaceURI, localName); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(XSLT) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScheduledAction.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScheduledAction.cpp new file mode 100644 index 0000000..d247194 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScheduledAction.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2006 Jon Shier (jshier@iastate.edu) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved. + * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include "config.h" +#include "ScheduledAction.h" + +#include "CString.h" +#include "DOMWindow.h" +#include "Document.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "JSDOMBinding.h" +#include "JSDOMWindow.h" +#include "ScriptController.h" +#include "ScriptExecutionContext.h" +#include "ScriptValue.h" +#include <runtime/JSLock.h> + +using namespace JSC; + +namespace WebCore { + +ScheduledAction::ScheduledAction(ExecState* exec, JSValuePtr function, const ArgList& args) + : m_function(function) +{ + ArgList::const_iterator end = args.end(); + for (ArgList::const_iterator it = args.begin(); it != end; ++it) { + m_args.append((*it).jsValue(exec)); + } +} + +void ScheduledAction::execute(ScriptExecutionContext* context) +{ + // FIXME: make it work with Workers SEC too. + ASSERT(context->isDocument()); + Document* document = static_cast<Document*>(context); + if (JSDOMWindow* window = toJSDOMWindow(document->frame())) + execute(window->shell()); +} + +void ScheduledAction::execute(JSDOMWindowShell* windowShell) +{ + RefPtr<Frame> frame = windowShell->window()->impl()->frame(); + if (!frame) + return; + + if (!frame->script()->isEnabled()) + return; + + frame->script()->setProcessingTimerCallback(true); + + JSLock lock(false); + + if (m_function) { + CallData callData; + CallType callType = m_function->getCallData(callData); + if (callType != CallTypeNone) { + JSDOMWindow* window = windowShell->window(); + ExecState* exec = window->globalExec(); + + ArgList args; + size_t size = m_args.size(); + for (size_t i = 0; i < size; ++i) + args.append(m_args[i]); + + window->startTimeoutCheck(); + call(exec, m_function, callType, callData, windowShell, args); + window->stopTimeoutCheck(); + if (exec->hadException()) + reportCurrentException(exec); + } + } else + frame->loader()->executeScript(m_code); + + // Update our document's rendering following the execution of the timeout callback. + // FIXME: Why not use updateDocumentsRendering to update rendering of all documents? + // FIXME: Is this really the right point to do the update? We need a place that works + // for all possible entry points that might possibly execute script, but this seems + // to be a bit too low-level. + if (Document* document = frame->document()) + document->updateRendering(); + + frame->script()->setProcessingTimerCallback(false); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScheduledAction.h b/src/3rdparty/webkit/WebCore/bindings/js/ScheduledAction.h new file mode 100644 index 0000000..9bf83ad --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScheduledAction.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ScheduledAction_h +#define ScheduledAction_h + +#include "PlatformString.h" +#include <runtime/Protect.h> +#include <wtf/Vector.h> + +namespace WebCore { + + class JSDOMWindowShell; + class ScriptExecutionContext; + + /* An action (either function or string) to be executed after a specified + * time interval, either once or repeatedly. Used for window.setTimeout() + * and window.setInterval() + */ + class ScheduledAction { + public: + ScheduledAction(JSC::ExecState* exec, JSC::JSValuePtr function, const JSC::ArgList&); + ScheduledAction(const String& code) + : m_code(code) + { + } + + void execute(ScriptExecutionContext*); + + private: + void execute(JSDOMWindowShell*); + + JSC::ProtectedJSValuePtr m_function; + Vector<JSC::ProtectedJSValuePtr> m_args; + String m_code; + }; + +} // namespace WebCore + +#endif // ScheduledAction_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptCachedPageData.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCachedPageData.cpp new file mode 100644 index 0000000..eeccf43 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCachedPageData.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2008, 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 "ScriptCachedPageData.h" + +#include "Frame.h" +#include "GCController.h" +#include "Page.h" +#include "PageGroup.h" +#include <runtime/JSLock.h> +#include "ScriptController.h" + +using namespace JSC; + +namespace WebCore { + +ScriptCachedPageData::ScriptCachedPageData(Page* page) +{ + JSLock lock(false); + + ScriptController* scriptController = page->mainFrame()->script(); + if (scriptController->haveWindowShell()) { + m_window = scriptController->windowShell()->window(); + } +} + +DOMWindow* ScriptCachedPageData::domWindow() const { + return m_window ? m_window->impl() : 0; +} + +ScriptCachedPageData::~ScriptCachedPageData() +{ + clear(); +} + +void ScriptCachedPageData::restore(Page* page) +{ + Frame* mainFrame = page->mainFrame(); + + JSLock lock(false); + + ScriptController* scriptController = mainFrame->script(); + if (scriptController->haveWindowShell()) { + JSDOMWindowShell* windowShell = scriptController->windowShell(); + if (m_window) { + windowShell->setWindow(m_window.get()); + } else { + windowShell->setWindow(mainFrame->domWindow()); + scriptController->attachDebugger(page->debugger()); + windowShell->window()->setProfileGroup(page->group().identifier()); + } + } +} + +void ScriptCachedPageData::clear() +{ + JSLock lock(false); + + if (!m_window) { + m_window = 0; + gcController().garbageCollectSoon(); + } +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptCachedPageData.h b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCachedPageData.h new file mode 100644 index 0000000..91e47d0 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCachedPageData.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2008, 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 ScriptCachedPageData_h +#define ScriptCachedPageData_h + +#include <runtime/Protect.h> + +namespace WebCore { + class JSDOMWindow; + class Page; + class DOMWindow; + + class ScriptCachedPageData { + public: + ScriptCachedPageData(Page*); + ~ScriptCachedPageData(); + + void restore(Page*); + void clear(); + DOMWindow* domWindow() const; + + private: + JSC::ProtectedPtr<JSDOMWindow> m_window; + }; + +} // namespace WebCore + +#endif // ScriptCachedPageData_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallFrame.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallFrame.cpp new file mode 100644 index 0000000..29f380a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallFrame.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2008, 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 "ScriptCallFrame.h" + +#include <interpreter/CallFrame.h> +#include <runtime/UString.h> + +using namespace JSC; + +namespace WebCore { + +ScriptCallFrame::ScriptCallFrame(const UString& functionName, const UString& urlString, int lineNumber, ExecState* exec, const ArgList& args, unsigned skipArgumentCount) + : m_functionName(functionName) + , m_sourceURL(urlString) + , m_lineNumber(lineNumber) +{ + size_t argumentCount = args.size(); + for (size_t i = skipArgumentCount; i < argumentCount; ++i) + m_arguments.append(ScriptValue(args.at(exec, i))); +} + +ScriptCallFrame::~ScriptCallFrame() +{ +} + +const ScriptValue &ScriptCallFrame::argumentAt(unsigned index) const +{ + ASSERT(m_arguments.size() > index); + return m_arguments[index]; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallFrame.h b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallFrame.h new file mode 100644 index 0000000..64a1a08 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallFrame.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008, 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 ScriptCallFrame_h +#define ScriptCallFrame_h + +#include "KURL.h" +#include <runtime/ArgList.h> +#include "ScriptString.h" +#include "ScriptValue.h" +#include <wtf/Vector.h> + +namespace JSC { + class ExecState; + class InternalFunction; +} + +namespace WebCore { + + // FIXME: Implement retrieving line number and source URL and storing here + // for all call frames, not just the first one. + // See <https://bugs.webkit.org/show_bug.cgi?id=22556> and + // <https://bugs.webkit.org/show_bug.cgi?id=21180> + class ScriptCallFrame { + public: + ScriptCallFrame(const JSC::UString& functionName, const JSC::UString& urlString, int lineNumber, JSC::ExecState*, const JSC::ArgList&, unsigned skipArgumentCount); + ~ScriptCallFrame(); + + const ScriptString& functionName() const { return m_functionName; } + const KURL& sourceURL() const { return m_sourceURL; } + unsigned lineNumber() const { return m_lineNumber; } + + // argument retrieval methods + const ScriptValue& argumentAt(unsigned) const; + unsigned argumentCount() const { return m_arguments.size(); } + + private: + ScriptString m_functionName; + KURL m_sourceURL; + unsigned m_lineNumber; + + Vector<ScriptValue> m_arguments; + }; + +} // namespace WebCore + +#endif // ScriptCallFrame_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallStack.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallStack.cpp new file mode 100644 index 0000000..88acadb --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallStack.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2008, 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 "ScriptCallStack.h" + +#include <interpreter/CallFrame.h> +#include <interpreter/Interpreter.h> +#include <runtime/InternalFunction.h> +#include <runtime/JSValue.h> +#include <runtime/UString.h> +#include <runtime/JSGlobalData.h> + +using namespace JSC; + +namespace WebCore { + +ScriptCallStack::ScriptCallStack(ExecState* exec, const ArgList& args, unsigned skipArgumentCount) + : m_initialized(false) + , m_exec(exec) + , m_caller(0) +{ + int signedLineNumber; + intptr_t sourceID; + UString urlString; + JSValuePtr function; + + exec->interpreter()->retrieveLastCaller(exec, signedLineNumber, sourceID, urlString, function); + + if (function) { + m_caller = asInternalFunction(function); + unsigned lineNumber = signedLineNumber >= 0 ? signedLineNumber : 0; + m_frames.append(ScriptCallFrame(m_caller->name(&m_exec->globalData()), urlString, lineNumber, exec, args, skipArgumentCount)); + } else { + // Caller is unknown, but we should still add the frame, because + // something called us, and gave us arguments. + m_frames.append(ScriptCallFrame(UString(), UString(), 0, exec, args, skipArgumentCount)); + } +} + +ScriptCallStack::~ScriptCallStack() +{ +} + +const ScriptCallFrame &ScriptCallStack::at(unsigned index) +{ + // First frame is pre-populated in constructor, so don't trigger + // initialization unless looking beyond the first frame. + if (index > 0) + initialize(); + ASSERT(m_frames.size() > index); + return m_frames[index]; +} + +unsigned ScriptCallStack::size() +{ + initialize(); + return m_frames.size(); +} + +void ScriptCallStack::initialize() +{ + if (!m_caller || m_initialized) + return; + + JSValuePtr func = m_exec->interpreter()->retrieveCaller(m_exec, m_caller); + while (!func->isNull()) { + InternalFunction* internalFunction = asInternalFunction(func); + ArgList emptyArgList; + m_frames.append(ScriptCallFrame(internalFunction->name(&m_exec->globalData()), UString(), 0, 0, emptyArgList, 0)); + func = m_exec->interpreter()->retrieveCaller(m_exec, internalFunction); + } + m_initialized = true; +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallStack.h b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallStack.h new file mode 100644 index 0000000..1907564 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptCallStack.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008, 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 ScriptCallStack_h +#define ScriptCallStack_h + +#include "ScriptCallFrame.h" +#include "ScriptState.h" +#include "ScriptString.h" +#include <wtf/Noncopyable.h> + +namespace JSC { + class ExecState; + class JSValue; +} + +namespace WebCore { + + class ScriptCallStack : public Noncopyable { + public: + ScriptCallStack(JSC::ExecState*, const JSC::ArgList&, unsigned skipArgumentCount = 0); + ~ScriptCallStack(); + + ScriptState* state() const { return m_exec; } + // frame retrieval methods + const ScriptCallFrame &at(unsigned); + unsigned size(); + + private: + void initialize(); + bool m_initialized; + + JSC::ExecState* m_exec; + Vector<ScriptCallFrame> m_frames; + JSC::InternalFunction* m_caller; + }; + +} // namespace WebCore + +#endif // ScriptCallStack_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptController.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScriptController.cpp new file mode 100644 index 0000000..ebed71d --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptController.cpp @@ -0,0 +1,355 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "ScriptController.h" + +#include "Console.h" +#include "DOMWindow.h" +#include "Document.h" +#include "Event.h" +#include "EventNames.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "GCController.h" +#include "JSDOMWindow.h" +#include "JSDocument.h" +#include "JSEventListener.h" +#include "npruntime_impl.h" +#include "NP_jsobject.h" +#include "Page.h" +#include "PageGroup.h" +#include "runtime_root.h" +#include "ScriptSourceCode.h" +#include "ScriptValue.h" +#include "Settings.h" + +#include <runtime/Completion.h> +#include <debugger/Debugger.h> +#include <runtime/JSLock.h> + +#if ENABLE(NETSCAPE_PLUGIN_API) +#include "HTMLPlugInElement.h" +#endif + +using namespace JSC; + +namespace WebCore { + +ScriptController::ScriptController(Frame* frame) + : m_frame(frame) + , m_handlerLineno(0) + , m_sourceURL(0) + , m_processingTimerCallback(false) + , m_paused(false) +#if ENABLE(NETSCAPE_PLUGIN_API) + , m_windowScriptNPObject(0) +#endif +#if PLATFORM(MAC) + , m_windowScriptObject(0) +#endif +{ +#if PLATFORM(MAC) && ENABLE(MAC_JAVA_BRIDGE) + static bool initializedJavaJSBindings; + if (!initializedJavaJSBindings) { + initializedJavaJSBindings = true; + initJavaJSBindings(); + } +#endif +} + +ScriptController::~ScriptController() +{ + if (m_windowShell) { + m_windowShell = 0; + + // It's likely that releasing the global object has created a lot of garbage. + gcController().garbageCollectSoon(); + } + + disconnectPlatformScriptObjects(); +} + +ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode) +{ + // evaluate code. Returns the JS return value or 0 + // if there was none, an error occured or the type couldn't be converted. + + const SourceCode& jsSourceCode = sourceCode.jsSourceCode(); + + initScriptIfNeeded(); + // inlineCode is true for <a href="javascript:doSomething()"> + // and false for <script>doSomething()</script>. Check if it has the + // expected value in all cases. + // See smart window.open policy for where this is used. + ExecState* exec = m_windowShell->window()->globalExec(); + const String* savedSourceURL = m_sourceURL; + String sourceURL = jsSourceCode.provider()->url(); + m_sourceURL = &sourceURL; + + JSLock lock(false); + + // Evaluating the JavaScript could cause the frame to be deallocated + // so we start the keep alive timer here. + m_frame->keepAlive(); + + m_windowShell->window()->startTimeoutCheck(); + Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), jsSourceCode, m_windowShell); + m_windowShell->window()->stopTimeoutCheck(); + + if (comp.complType() == Normal || comp.complType() == ReturnValue) { + m_sourceURL = savedSourceURL; + return comp.value(); + } + + if (comp.complType() == Throw) + reportException(exec, comp.value()); + + m_sourceURL = savedSourceURL; + return noValue(); +} + +void ScriptController::clearWindowShell() +{ + if (!m_windowShell) + return; + + JSLock lock(false); + m_windowShell->window()->clear(); + m_liveFormerWindows.add(m_windowShell->window()); + m_windowShell->setWindow(m_frame->domWindow()); + if (Page* page = m_frame->page()) { + attachDebugger(page->debugger()); + m_windowShell->window()->setProfileGroup(page->group().identifier()); + } + + // There is likely to be a lot of garbage now. + gcController().garbageCollectSoon(); +} + +PassRefPtr<EventListener> ScriptController::createInlineEventListener(const String& functionName, const String& code, Node* node) +{ + initScriptIfNeeded(); + JSLock lock(false); + return JSLazyEventListener::create(JSLazyEventListener::HTMLLazyEventListener, functionName, code, m_windowShell->window(), node, m_handlerLineno); +} + +#if ENABLE(SVG) +PassRefPtr<EventListener> ScriptController::createSVGEventHandler(const String& functionName, const String& code, Node* node) +{ + initScriptIfNeeded(); + JSLock lock(false); + return JSLazyEventListener::create(JSLazyEventListener::SVGLazyEventListener, functionName, code, m_windowShell->window(), node, m_handlerLineno); +} +#endif + +void ScriptController::initScript() +{ + if (m_windowShell) + return; + + JSLock lock(false); + + m_windowShell = new JSDOMWindowShell(m_frame->domWindow()); + updateDocument(); + + if (Page* page = m_frame->page()) { + attachDebugger(page->debugger()); + m_windowShell->window()->setProfileGroup(page->group().identifier()); + } + + m_frame->loader()->dispatchWindowObjectAvailable(); +} + +bool ScriptController::processingUserGesture() const +{ + if (!m_windowShell) + return false; + + if (Event* event = m_windowShell->window()->currentEvent()) { + const AtomicString& type = event->type(); + if ( // mouse events + type == eventNames().clickEvent || type == eventNames().mousedownEvent || + type == eventNames().mouseupEvent || type == eventNames().dblclickEvent || + // keyboard events + type == eventNames().keydownEvent || type == eventNames().keypressEvent || + type == eventNames().keyupEvent || + // other accepted events + type == eventNames().selectEvent || type == eventNames().changeEvent || + type == eventNames().focusEvent || type == eventNames().blurEvent || + type == eventNames().submitEvent) + return true; + } else { // no event + if (m_sourceURL && m_sourceURL->isNull() && !m_processingTimerCallback) { + // This is the <a href="javascript:window.open('...')> case -> we let it through + return true; + } + // This is the <script>window.open(...)</script> case or a timer callback -> block it + } + return false; +} + +bool ScriptController::isEnabled() +{ + Settings* settings = m_frame->settings(); + return (settings && settings->isJavaScriptEnabled()); +} + +void ScriptController::attachDebugger(JSC::Debugger* debugger) +{ + if (!m_windowShell) + return; + + if (debugger) + debugger->attach(m_windowShell->window()); + else if (JSC::Debugger* currentDebugger = m_windowShell->window()->debugger()) + currentDebugger->detach(m_windowShell->window()); +} + +void ScriptController::updateDocument() +{ + if (!m_frame->document()) + return; + + JSLock lock(false); + if (m_windowShell) + m_windowShell->window()->updateDocument(); + HashSet<JSDOMWindow*>::iterator end = m_liveFormerWindows.end(); + for (HashSet<JSDOMWindow*>::iterator it = m_liveFormerWindows.begin(); it != end; ++it) + (*it)->updateDocument(); +} + +void ScriptController::updateSecurityOrigin() +{ + // Our bindings do not do anything in this case. +} + +Bindings::RootObject* ScriptController::bindingRootObject() +{ + if (!isEnabled()) + return 0; + + if (!m_bindingRootObject) { + JSLock lock(false); + m_bindingRootObject = Bindings::RootObject::create(0, globalObject()); + } + return m_bindingRootObject.get(); +} + +PassRefPtr<Bindings::RootObject> ScriptController::createRootObject(void* nativeHandle) +{ + RootObjectMap::iterator it = m_rootObjects.find(nativeHandle); + if (it != m_rootObjects.end()) + return it->second; + + RefPtr<Bindings::RootObject> rootObject = Bindings::RootObject::create(nativeHandle, globalObject()); + + m_rootObjects.set(nativeHandle, rootObject); + return rootObject.release(); +} + +#if ENABLE(NETSCAPE_PLUGIN_API) +NPObject* ScriptController::windowScriptNPObject() +{ + if (!m_windowScriptNPObject) { + if (isEnabled()) { + // JavaScript is enabled, so there is a JavaScript window object. + // Return an NPObject bound to the window object. + JSC::JSLock lock(false); + JSObject* win = windowShell()->window(); + ASSERT(win); + Bindings::RootObject* root = bindingRootObject(); + m_windowScriptNPObject = _NPN_CreateScriptObject(0, win, root); + } else { + // JavaScript is not enabled, so we cannot bind the NPObject to the JavaScript window object. + // Instead, we create an NPObject of a different class, one which is not bound to a JavaScript object. + m_windowScriptNPObject = _NPN_CreateNoScriptObject(); + } + } + + return m_windowScriptNPObject; +} + +NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement* plugin) +{ + // Can't create NPObjects when JavaScript is disabled + if (!isEnabled()) + return _NPN_CreateNoScriptObject(); + + // Create a JSObject bound to this element + JSLock lock(false); + ExecState* exec = globalObject()->globalExec(); + JSValuePtr jsElementValue = toJS(exec, plugin); + if (!jsElementValue || !jsElementValue->isObject()) + return _NPN_CreateNoScriptObject(); + + // Wrap the JSObject in an NPObject + return _NPN_CreateScriptObject(0, jsElementValue->getObject(), bindingRootObject()); +} +#endif + +#if !PLATFORM(MAC) +void ScriptController::updatePlatformScriptObjects() +{ +} + +void ScriptController::disconnectPlatformScriptObjects() +{ +} +#endif + +void ScriptController::cleanupScriptObjectsForPlugin(void* nativeHandle) +{ + RootObjectMap::iterator it = m_rootObjects.find(nativeHandle); + + if (it == m_rootObjects.end()) + return; + + it->second->invalidate(); + m_rootObjects.remove(it); +} + +void ScriptController::clearScriptObjects() +{ + JSLock lock(false); + + RootObjectMap::const_iterator end = m_rootObjects.end(); + for (RootObjectMap::const_iterator it = m_rootObjects.begin(); it != end; ++it) + it->second->invalidate(); + + m_rootObjects.clear(); + + if (m_bindingRootObject) { + m_bindingRootObject->invalidate(); + m_bindingRootObject = 0; + } + +#if ENABLE(NETSCAPE_PLUGIN_API) + if (m_windowScriptNPObject) { + // Call _NPN_DeallocateObject() instead of _NPN_ReleaseObject() so that we don't leak if a plugin fails to release the window + // script object properly. + // This shouldn't cause any problems for plugins since they should have already been stopped and destroyed at this point. + _NPN_DeallocateObject(m_windowScriptNPObject); + m_windowScriptNPObject = 0; + } +#endif +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptController.h b/src/3rdparty/webkit/WebCore/bindings/js/ScriptController.h new file mode 100644 index 0000000..c952cc2 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptController.h @@ -0,0 +1,166 @@ +/* + * Copyright (C) 1999 Harri Porten (porten@kde.org) + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ScriptController_h +#define ScriptController_h + +#include "JSDOMWindowShell.h" +#include "ScriptInstance.h" +#include <runtime/Protect.h> +#include <wtf/RefPtr.h> + +#if PLATFORM(MAC) +#include <wtf/RetainPtr.h> + +#ifdef __OBJC__ +@class WebScriptObject; +#else +class WebScriptObject; +#endif +#endif + +struct NPObject; + +namespace JSC { + class JSGlobalObject; + + namespace Bindings { + class RootObject; + } +} + +namespace WebCore { + +class Event; +class EventListener; +class HTMLPlugInElement; +class Frame; +class Node; +class ScriptSourceCode; +class ScriptValue; +class String; +class Widget; + +typedef HashMap<void*, RefPtr<JSC::Bindings::RootObject> > RootObjectMap; + +class ScriptController { +public: + ScriptController(Frame*); + ~ScriptController(); + + bool haveWindowShell() const { return m_windowShell; } + JSDOMWindowShell* windowShell() + { + initScriptIfNeeded(); + return m_windowShell; + } + + JSDOMWindow* globalObject() + { + initScriptIfNeeded(); + return m_windowShell->window(); + } + + ScriptValue evaluate(const ScriptSourceCode&); + + PassRefPtr<EventListener> createInlineEventListener(const String& functionName, const String& code, Node*); +#if ENABLE(SVG) + PassRefPtr<EventListener> createSVGEventHandler(const String& functionName, const String& code, Node*); +#endif + void setEventHandlerLineno(int lineno) { m_handlerLineno = lineno; } + + void setProcessingTimerCallback(bool b) { m_processingTimerCallback = b; } + bool processingUserGesture() const; + + bool isEnabled(); + + void attachDebugger(JSC::Debugger*); + + void setPaused(bool b) { m_paused = b; } + bool isPaused() const { return m_paused; } + + const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script + + void clearWindowShell(); + void clearFormerWindow(JSDOMWindow* window) { m_liveFormerWindows.remove(window); } + void updateDocument(); + + // Notifies the ScriptController that the securityOrigin of the current + // document was modified. For example, this method is called when + // document.domain is set. This method is *not* called when a new document + // is attached to a frame because updateDocument() is called instead. + void updateSecurityOrigin(); + + void clearScriptObjects(); + void cleanupScriptObjectsForPlugin(void*); + + void updatePlatformScriptObjects(); + + PassScriptInstance createScriptInstanceForWidget(Widget*); + JSC::Bindings::RootObject* bindingRootObject(); + + PassRefPtr<JSC::Bindings::RootObject> createRootObject(void* nativeHandle); + +#if PLATFORM(MAC) +#if ENABLE(MAC_JAVA_BRIDGE) + static void initJavaJSBindings(); +#endif + WebScriptObject* windowScriptObject(); +#endif + +#if ENABLE(NETSCAPE_PLUGIN_API) + NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*); + NPObject* windowScriptNPObject(); +#endif + +private: + void initScriptIfNeeded() + { + if (!m_windowShell) + initScript(); + } + void initScript(); + + void disconnectPlatformScriptObjects(); + + JSC::ProtectedPtr<JSDOMWindowShell> m_windowShell; + HashSet<JSDOMWindow*> m_liveFormerWindows; + Frame* m_frame; + int m_handlerLineno; + const String* m_sourceURL; + + bool m_processingTimerCallback; + bool m_paused; + + // The root object used for objects bound outside the context of a plugin. + RefPtr<JSC::Bindings::RootObject> m_bindingRootObject; + RootObjectMap m_rootObjects; +#if ENABLE(NETSCAPE_PLUGIN_API) + NPObject* m_windowScriptNPObject; +#endif +#if PLATFORM(MAC) + RetainPtr<WebScriptObject> m_windowScriptObject; +#endif +}; + +} // namespace WebCore + +#endif // ScriptController_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerGtk.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerGtk.cpp new file mode 100644 index 0000000..c906034 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerGtk.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2008 Collabora Ltd. All rights reserved. + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "ScriptController.h" + +#include "PluginView.h" +#include "runtime_root.h" +#include "runtime.h" + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + if (!widget->isPluginView()) + return 0; + + return static_cast<PluginView*>(widget)->bindingInstance(); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerMac.mm b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerMac.mm new file mode 100644 index 0000000..39fcc67 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerMac.mm @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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. + */ + +#import "config.h" +#import "ScriptController.h" + +#import "DOMAbstractViewFrame.h" +#import "DOMWindow.h" +#import "Frame.h" +#import "FrameLoader.h" +#import "FrameLoaderClient.h" +#import "JSDOMWindow.h" +#import "WebScriptObjectPrivate.h" +#import "Widget.h" +#import <JavaScriptCore/APICast.h> +#import <runtime/JSLock.h> + +#if ENABLE(NETSCAPE_PLUGIN_API) +#import "c_instance.h" +#import "NP_jsobject.h" +#import "npruntime_impl.h" +#endif + +#import "objc_instance.h" +#import "runtime_root.h" +#import "runtime.h" + +#if ENABLE(MAC_JAVA_BRIDGE) +#import "jni_instance.h" +#endif + +@interface NSObject (WebPlugin) +- (id)objectForWebScript; +- (NPObject *)createPluginScriptableObject; +@end + +using namespace JSC::Bindings; + +namespace WebCore { + +PassScriptInstance ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + NSView* widgetView = widget->platformWidget(); + if (!widgetView) + return 0; + + RefPtr<RootObject> rootObject = createRootObject(widgetView); + + if ([widgetView respondsToSelector:@selector(objectForWebScript)]) { + id objectForWebScript = [widgetView objectForWebScript]; + if (!objectForWebScript) + return 0; + return JSC::Bindings::ObjcInstance::create(objectForWebScript, rootObject.release()); + } + + if ([widgetView respondsToSelector:@selector(createPluginScriptableObject)]) { +#if !ENABLE(NETSCAPE_PLUGIN_API) + return 0; +#else + NPObject* npObject = [widgetView createPluginScriptableObject]; + if (!npObject) + return 0; + RefPtr<Instance> instance = JSC::Bindings::CInstance::create(npObject, rootObject.release()); + // -createPluginScriptableObject returns a retained NPObject. The caller is expected to release it. + _NPN_ReleaseObject(npObject); + return instance.release(); +#endif + } + +#if ENABLE(MAC_JAVA_BRIDGE) + jobject applet = m_frame->loader()->client()->javaApplet(widgetView); + if (!applet) + return 0; + return JSC::Bindings::JavaInstance::create(applet, rootObject.release()); +#else + return 0; +#endif +} + +WebScriptObject* ScriptController::windowScriptObject() +{ + if (!isEnabled()) + return 0; + + if (!m_windowScriptObject) { + JSC::JSLock lock(false); + JSC::Bindings::RootObject* root = bindingRootObject(); + m_windowScriptObject = [WebScriptObject scriptObjectForJSObject:toRef(windowShell()) originRootObject:root rootObject:root]; + } + + ASSERT([m_windowScriptObject.get() isKindOfClass:[DOMAbstractView class]]); + return m_windowScriptObject.get(); +} + +void ScriptController::updatePlatformScriptObjects() +{ + if (m_windowScriptObject) { + JSC::Bindings::RootObject* root = bindingRootObject(); + [m_windowScriptObject.get() _setOriginRootObject:root andRootObject:root]; + } +} + +void ScriptController::disconnectPlatformScriptObjects() +{ + if (m_windowScriptObject) { + ASSERT([m_windowScriptObject.get() isKindOfClass:[DOMAbstractView class]]); + [(DOMAbstractView *)m_windowScriptObject.get() _disconnectFrame]; + } +} + +#if ENABLE(MAC_JAVA_BRIDGE) + +static pthread_t mainThread; + +static void updateRenderingForBindings(JSC::ExecState*, JSC::JSObject* rootObject) +{ + if (pthread_self() != mainThread) + return; + + if (!rootObject) + return; + + JSDOMWindow* window = static_cast<JSDOMWindow*>(rootObject); + if (!window) + return; + + Frame* frame = window->impl()->frame(); + if (!frame) + return; + + Document* document = frame->document(); + if (!document) + return; + + document->updateRendering(); +} + +void ScriptController::initJavaJSBindings() +{ + mainThread = pthread_self(); + JSC::Bindings::JavaJSObject::initializeJNIThreading(); + JSC::Bindings::Instance::setDidExecuteFunction(updateRenderingForBindings); +} + +#endif + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerQt.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerQt.cpp new file mode 100644 index 0000000..6b14190 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerQt.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> + * Copyright (C) 2006 Zack Rusin <zack@kde.org> + * Copyright (C) 2006 George Staikos <staikos@kde.org> + * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> + * Copyright (C) 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Collabora Ltd. All rights reserved. + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "ScriptController.h" + +#include "DOMWindow.h" +#include "PluginView.h" +#include "qt_instance.h" +#include "runtime_root.h" +#include "runtime.h" + +#include <QWidget> + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(WebCore::Widget* widget) +{ + if (widget->isPluginView()) { + PluginView* pluginView = static_cast<PluginView*>(widget); + return pluginView->bindingInstance(); + } + + QWidget* platformWidget = widget->platformWidget(); + if (!platformWidget) + return 0; + return JSC::Bindings::QtInstance::getQtInstance(platformWidget, bindingRootObject(), QScriptEngine::QtOwnership); +} + +} +// vim: ts=4 sw=4 et diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerWin.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerWin.cpp new file mode 100644 index 0000000..703cf7c --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerWin.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "ScriptController.h" + +#include "PluginView.h" +#include "runtime.h" + +using namespace JSC::Bindings; + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + if (!widget->isPluginView()) + return 0; + + return static_cast<PluginView*>(widget)->bindingInstance(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerWx.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerWx.cpp new file mode 100644 index 0000000..1c14928 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptControllerWx.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2008 Apple Computer, Inc. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 "ScriptController.h" + +#include "PluginView.h" +#include "runtime_root.h" +#include "runtime.h" + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + if (!widget->isPluginView()) + return 0; + + return static_cast<PluginView*>(widget)->bindingInstance(); +} + +} diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptInstance.h b/src/3rdparty/webkit/WebCore/bindings/js/ScriptInstance.h new file mode 100644 index 0000000..3095df9 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptInstance.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2008, 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 ScriptInstance_h +#define ScriptInstance_h + +#include <wtf/RefPtr.h> +#include "runtime.h" + +namespace WebCore { + +typedef RefPtr<JSC::Bindings::Instance> ScriptInstance; +typedef PassRefPtr<JSC::Bindings::Instance> PassScriptInstance; + +} // namespace WebCore + +#endif // ScriptInstance_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptSourceCode.h b/src/3rdparty/webkit/WebCore/bindings/js/ScriptSourceCode.h new file mode 100644 index 0000000..4a2403d --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptSourceCode.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008, 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 ScriptSourceCode_h +#define ScriptSourceCode_h + +#include "CachedScriptSourceProvider.h" +#include "StringSourceProvider.h" +#include "KURL.h" + +namespace WebCore { + +class ScriptSourceCode { +public: + ScriptSourceCode(const String& source, const KURL& url = KURL(), int startLine = 1) + : m_code(makeSource(source, url.isNull() ? String() : url.string(), startLine)) + { + } + + ScriptSourceCode(CachedScript* cs) + : m_code(makeSource(cs)) + { + } + + bool isEmpty() const { return m_code.length() == 0; } + + const JSC::SourceCode& jsSourceCode() const { return m_code; } + +private: + JSC::SourceCode m_code; +}; + +} // namespace WebCore + +#endif // ScriptSourceCode_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptState.h b/src/3rdparty/webkit/WebCore/bindings/js/ScriptState.h new file mode 100644 index 0000000..3cce093 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptState.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2008, 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 ScriptState_h +#define ScriptState_h + +namespace JSC { + class ExecState; +} + +namespace WebCore { + + // The idea is to expose "state-like" methods (hadException, and any other + // methods where ExecState just dips into globalData) of JSC::ExecState as a + // separate abstraction. + // For now, the separation is purely by convention. + typedef JSC::ExecState ScriptState; + +} // namespace WebCore + +#endif // ScriptState_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptString.h b/src/3rdparty/webkit/WebCore/bindings/js/ScriptString.h new file mode 100644 index 0000000..3efa160 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptString.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008, 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 ScriptString_h +#define ScriptString_h + +#include "PlatformString.h" +#include <runtime/JSLock.h> +#include <runtime/UString.h> + +namespace WebCore { + +class String; + +class ScriptString { +public: + ScriptString() {} + ScriptString(const char* s) : m_str(s) {} + ScriptString(const JSC::UString& s) : m_str(s) {} + + operator JSC::UString() const { return m_str; } + + bool isNull() const { return m_str.isNull(); } + size_t size() const { return m_str.size(); } + + ScriptString& operator=(const char* s) + { + JSC::JSLock lock(false); + m_str = s; + return *this; + } + + ScriptString& operator+=(const String& s) + { + JSC::JSLock lock(false); + m_str += s; + return *this; + } + + bool operator==(const ScriptString& s) const + { + JSC::JSLock lock(false); + return m_str == s.m_str; + } + + bool operator!=(const ScriptString& s) const + { + JSC::JSLock lock(false); + // Avoid exporting an extra symbol by re-using "==" operator. + return !(m_str == s.m_str); + } + +private: + JSC::UString m_str; +}; + +} // namespace WebCore + +#endif // ScriptString_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptValue.cpp b/src/3rdparty/webkit/WebCore/bindings/js/ScriptValue.cpp new file mode 100644 index 0000000..f462e21 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptValue.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "ScriptValue.h" + +#include "PlatformString.h" +#include <runtime/JSLock.h> +#include <runtime/Protect.h> +#include <runtime/UString.h> + +using namespace JSC; + +namespace WebCore { + +bool ScriptValue::getString(String& result) const +{ + if (!m_value) + return false; + JSLock lock(false); + UString ustring; + if (!m_value->getString(ustring)) + return false; + result = ustring; + return true; +} + +bool ScriptValue::isNull() const +{ + if (!m_value) + return false; + return m_value->isNull(); +} + +bool ScriptValue::isUndefined() const +{ + if (!m_value) + return false; + return m_value->isUndefined(); +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/bindings/js/ScriptValue.h b/src/3rdparty/webkit/WebCore/bindings/js/ScriptValue.h new file mode 100644 index 0000000..855509a --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/ScriptValue.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2008, 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 ScriptValue_h +#define ScriptValue_h + +#include <runtime/Protect.h> + +namespace WebCore { + +class String; + +class ScriptValue { +public: + ScriptValue(JSC::JSValuePtr value = JSC::noValue()) : m_value(value) {} + + JSC::JSValuePtr jsValue() const { return m_value.get(); } + bool getString(String& result) const; + bool isNull() const; + bool isUndefined() const; + +private: + JSC::ProtectedJSValuePtr m_value; +}; + +} // namespace WebCore + +#endif // ScriptValue_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/StringSourceProvider.h b/src/3rdparty/webkit/WebCore/bindings/js/StringSourceProvider.h new file mode 100644 index 0000000..ab37a56 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/StringSourceProvider.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2008 Apple 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: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 StringSourceProvider_h +#define StringSourceProvider_h + +#include <parser/SourceCode.h> + +namespace WebCore { + + class StringSourceProvider : public JSC::SourceProvider { + public: + static PassRefPtr<StringSourceProvider> create(const String& source, const String& url) { return adoptRef(new StringSourceProvider(source, url)); } + + JSC::UString getRange(int start, int end) const { return JSC::UString(m_source.characters() + start, end - start); } + const UChar* data() const { return m_source.characters(); } + int length() const { return m_source.length(); } + + private: + StringSourceProvider(const String& source, const String& url) + : SourceProvider(url) + , m_source(source) + { + } + + String m_source; + }; + + inline JSC::SourceCode makeSource(const String& source, const String& url = String(), int firstLine = 1) + { + return JSC::SourceCode(StringSourceProvider::create(source, url), firstLine); + } + +} // namespace WebCore + +#endif // StringSourceProvider_h diff --git a/src/3rdparty/webkit/WebCore/bindings/js/WorkerScriptController.cpp b/src/3rdparty/webkit/WebCore/bindings/js/WorkerScriptController.cpp new file mode 100644 index 0000000..0727510 --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/WorkerScriptController.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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(WORKERS) + +#include "WorkerScriptController.h" + +#include "JSDOMBinding.h" +#include "JSWorkerContext.h" +#include "ScriptSourceCode.h" +#include "ScriptValue.h" +#include "WorkerContext.h" +#include "WorkerMessagingProxy.h" +#include "WorkerThread.h" +#include <interpreter/Interpreter.h> +#include <runtime/Completion.h> +#include <runtime/Completion.h> +#include <runtime/JSLock.h> + +using namespace JSC; + +namespace WebCore { + +WorkerScriptController::WorkerScriptController(WorkerContext* workerContext) + : m_globalData(JSGlobalData::create()) + , m_workerContext(workerContext) + , m_executionForbidden(false) +{ +} + +WorkerScriptController::~WorkerScriptController() +{ + m_workerContextWrapper = 0; // Unprotect the global object. + + ASSERT(!m_globalData->heap.protectedObjectCount()); + ASSERT(!m_globalData->heap.isBusy()); + m_globalData->heap.destroy(); +} + +void WorkerScriptController::initScript() +{ + ASSERT(!m_workerContextWrapper); + + JSLock lock(false); + + RefPtr<Structure> prototypeStructure = JSWorkerContextPrototype::createStructure(jsNull()); + RefPtr<Structure> structure = JSWorkerContext::createStructure(new (m_globalData.get()) JSWorkerContextPrototype(prototypeStructure.release())); + m_workerContextWrapper = new (m_globalData.get()) JSWorkerContext(structure.release(), m_workerContext); +} + +ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode) +{ + { + MutexLocker lock(m_sharedDataMutex); + if (m_executionForbidden) + return noValue(); + } + + initScriptIfNeeded(); + JSLock lock(false); + + ExecState* exec = m_workerContextWrapper->globalExec(); + m_workerContextWrapper->startTimeoutCheck(); + Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), sourceCode.jsSourceCode(), m_workerContextWrapper); + m_workerContextWrapper->stopTimeoutCheck(); + + m_workerContext->thread()->messagingProxy()->reportWorkerThreadActivity(m_workerContext->hasPendingActivity()); + + if (comp.complType() == Normal || comp.complType() == ReturnValue) + return comp.value(); + + if (comp.complType() == Throw) + reportException(exec, comp.value()); + return noValue(); +} + +void WorkerScriptController::forbidExecution() +{ + // This function is called from another thread. + // Mutex protection for m_executionForbidden is needed to guarantee that the value is synchronized between processors, because + // if it were not, the worker could re-enter JSC::evaluate(), but with timeout already reset. + // It is not critical for Interpreter::m_timeoutTime to be synchronized, we just rely on it reaching the worker thread's processor sooner or later. + MutexLocker lock(m_sharedDataMutex); + m_executionForbidden = true; + m_globalData->interpreter->setTimeoutTime(1); // 1 ms is the smallest timeout that can be set. +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/src/3rdparty/webkit/WebCore/bindings/js/WorkerScriptController.h b/src/3rdparty/webkit/WebCore/bindings/js/WorkerScriptController.h new file mode 100644 index 0000000..1dda5da --- /dev/null +++ b/src/3rdparty/webkit/WebCore/bindings/js/WorkerScriptController.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2008 Apple 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: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 WorkerScriptController_h +#define WorkerScriptController_h + +#if ENABLE(WORKERS) + +#include <runtime/Protect.h> +#include <wtf/Noncopyable.h> +#include <wtf/Threading.h> + +namespace JSC { + class JSGlobalData; +} + +namespace WebCore { + + class JSWorkerContext; + class ScriptSourceCode; + class ScriptValue; + class String; + class WorkerContext; + + class WorkerScriptController : Noncopyable { + public: + WorkerScriptController(WorkerContext*); + ~WorkerScriptController(); + + JSWorkerContext* workerContextWrapper() + { + initScriptIfNeeded(); + return m_workerContextWrapper; + } + + ScriptValue evaluate(const ScriptSourceCode&); + + void forbidExecution(); + + private: + void initScriptIfNeeded() + { + if (!m_workerContextWrapper) + initScript(); + } + void initScript(); + + RefPtr<JSC::JSGlobalData> m_globalData; + WorkerContext* m_workerContext; + JSC::ProtectedPtr<JSWorkerContext> m_workerContextWrapper; + + Mutex m_sharedDataMutex; + bool m_executionForbidden; + }; + +} // namespace WebCore + +#endif // ENABLE(WORKERS) + +#endif // WorkerScriptController_h |