• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "JSXMLHttpRequestUpload.h"
28 
29 #include "DOMWindow.h"
30 #include "Document.h"
31 #include "Event.h"
32 #include "Frame.h"
33 #include "JSDOMWindowCustom.h"
34 #include "JSEvent.h"
35 #include "JSEventListener.h"
36 #include "XMLHttpRequest.h"
37 #include "XMLHttpRequestUpload.h"
38 #include <runtime/Error.h>
39 
40 using namespace JSC;
41 
42 namespace WebCore {
43 
mark()44 void JSXMLHttpRequestUpload::mark()
45 {
46     Base::mark();
47 
48     if (XMLHttpRequest* xmlHttpRequest = m_impl->associatedXMLHttpRequest()) {
49         DOMObject* wrapper = getCachedDOMObjectWrapper(*Heap::heap(this)->globalData(), xmlHttpRequest);
50         if (wrapper && !wrapper->marked())
51             wrapper->mark();
52     }
53 
54     if (JSUnprotectedEventListener* onAbortListener = static_cast<JSUnprotectedEventListener*>(m_impl->onabort()))
55         onAbortListener->mark();
56 
57     if (JSUnprotectedEventListener* onErrorListener = static_cast<JSUnprotectedEventListener*>(m_impl->onerror()))
58         onErrorListener->mark();
59 
60     if (JSUnprotectedEventListener* onLoadListener = static_cast<JSUnprotectedEventListener*>(m_impl->onload()))
61         onLoadListener->mark();
62 
63     if (JSUnprotectedEventListener* onLoadStartListener = static_cast<JSUnprotectedEventListener*>(m_impl->onloadstart()))
64         onLoadStartListener->mark();
65 
66     if (JSUnprotectedEventListener* onProgressListener = static_cast<JSUnprotectedEventListener*>(m_impl->onprogress()))
67         onProgressListener->mark();
68 
69     typedef XMLHttpRequestUpload::EventListenersMap EventListenersMap;
70     typedef XMLHttpRequestUpload::ListenerVector ListenerVector;
71     EventListenersMap& eventListeners = m_impl->eventListeners();
72     for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) {
73         for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) {
74             JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(vecIter->get());
75             listener->mark();
76         }
77     }
78 }
79 
addEventListener(ExecState * exec,const ArgList & args)80 JSValuePtr JSXMLHttpRequestUpload::addEventListener(ExecState* exec, const ArgList& args)
81 {
82     JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
83     if (!globalObject)
84         return jsUndefined();
85     RefPtr<JSUnprotectedEventListener> listener = globalObject->findOrCreateJSUnprotectedEventListener(exec, args.at(exec, 1));
86     if (!listener)
87         return jsUndefined();
88     impl()->addEventListener(args.at(exec, 0).toString(exec), listener.release(), args.at(exec, 2).toBoolean(exec));
89     return jsUndefined();
90 }
91 
removeEventListener(ExecState * exec,const ArgList & args)92 JSValuePtr JSXMLHttpRequestUpload::removeEventListener(ExecState* exec, const ArgList& args)
93 {
94     JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(impl()->scriptExecutionContext());
95     if (!globalObject)
96         return jsUndefined();
97     JSUnprotectedEventListener* listener = globalObject->findJSUnprotectedEventListener(exec, args.at(exec, 1));
98     if (!listener)
99         return jsUndefined();
100     impl()->removeEventListener(args.at(exec, 0).toString(exec), listener, args.at(exec, 2).toBoolean(exec));
101     return jsUndefined();
102 }
103 
104 } // namespace WebCore
105