~jconti/ubuntu/oneiric/webkit/fix_doc_path

« back to all changes in this revision

Viewing changes to WebCore/bindings/js/kjs_window.h

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2008-09-27 08:57:48 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080927085748-yhzld00w0rekp961
Tags: 1.0.1-4
WebCore/dom/Document.*, WebCore/loader/DocLoader.*: Avoid DoS via
crafted CSS import statements. Fixes: CVE-2008-3632. Closes: #499771.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2000 Harri Porten (porten@kde.org)
3
 
 *  Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reseved.
4
 
 *
5
 
 *  This library is free software; you can redistribute it and/or
6
 
 *  modify it under the terms of the GNU Lesser General Public
7
 
 *  License as published by the Free Software Foundation; either
8
 
 *  version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 *  This library is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 *  Lesser General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU Lesser General Public
16
 
 *  License along with this library; if not, write to the Free Software
17
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 */
19
 
 
20
 
#ifndef kjs_window_h
21
 
#define kjs_window_h
22
 
 
23
 
#include "PlatformString.h"
24
 
#include "kjs_binding.h"
25
 
#include <wtf/HashMap.h>
26
 
#include <wtf/OwnPtr.h>
27
 
 
28
 
namespace WebCore {
29
 
    class AtomicString;
30
 
    class DOMWindow;
31
 
    class Frame;
32
 
    class FrameView;
33
 
    class JSDOMWindow;
34
 
    class JSEventListener;
35
 
    class JSUnprotectedEventListener;
36
 
    class Node;
37
 
}
38
 
 
39
 
namespace KJS {
40
 
 
41
 
    class Location;
42
 
    class PausedTimeout;
43
 
    class ScheduledAction;
44
 
    class Window;
45
 
    class WindowFunc;
46
 
 
47
 
    class PausedTimeouts {
48
 
    public:
49
 
        PausedTimeouts(PausedTimeout *a, size_t length) : m_array(a), m_length(length) { }
50
 
        ~PausedTimeouts();
51
 
 
52
 
        size_t numTimeouts() const { return m_length; }
53
 
        PausedTimeout *takeTimeouts()
54
 
            { PausedTimeout *a = m_array; m_array = 0; return a; }
55
 
 
56
 
    private:
57
 
        PausedTimeout *m_array;
58
 
        size_t m_length;
59
 
 
60
 
        PausedTimeouts(const PausedTimeouts&);
61
 
        PausedTimeouts& operator=(const PausedTimeouts&);
62
 
    };
63
 
 
64
 
    class DOMWindowTimer;
65
 
 
66
 
  class WindowPrivate;
67
 
 
68
 
  class Window : public DOMObject {
69
 
    friend class Location;
70
 
    friend class WindowFunc;
71
 
    friend class ScheduledAction;
72
 
  protected:
73
 
    Window(WebCore::DOMWindow*);
74
 
  public:
75
 
    ~Window();
76
 
    WebCore::DOMWindow* impl() const { return m_impl.get(); }
77
 
    void disconnectFrame();
78
 
    /**
79
 
     * Returns and registers a window object. In case there's already a Window
80
 
     * for the specified frame p this will be returned in order to have unique
81
 
     * bindings.
82
 
     */
83
 
    static JSValue* retrieve(WebCore::Frame*);
84
 
    /**
85
 
     * Returns the Window object for a given HTML frame
86
 
     */
87
 
    static Window* retrieveWindow(WebCore::Frame*);
88
 
    /**
89
 
     * returns a pointer to the Window object this javascript interpreting instance
90
 
     * was called from.
91
 
     */
92
 
    static Window* retrieveActive(ExecState*);
93
 
    virtual void mark();
94
 
    virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
95
 
    JSValue *getValueProperty(ExecState *exec, int token) const;
96
 
    virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
97
 
 
98
 
    int installTimeout(const UString& handler, int t, bool singleShot);
99
 
    int installTimeout(JSValue* function, const List& args, int t, bool singleShot);
100
 
    void clearTimeout(int timerId, bool delAction = true);
101
 
    PausedTimeouts* pauseTimeouts();
102
 
    void resumeTimeouts(PausedTimeouts*);
103
 
 
104
 
    void timerFired(DOMWindowTimer*);
105
 
    
106
 
    KJS::ScriptInterpreter *interpreter() const;
107
 
        
108
 
    bool isSafeScript(ExecState*) const;
109
 
    static bool isSafeScript(const ScriptInterpreter *origin, const ScriptInterpreter *target);
110
 
 
111
 
    Location* location() const;
112
 
 
113
 
    // Finds a wrapper of a JS EventListener, returns 0 if no existing one.
114
 
    WebCore::JSEventListener* findJSEventListener(JSValue*, bool html = false);
115
 
 
116
 
    // Finds or creates a wrapper of a JS EventListener. JS EventListener object is GC-protected.
117
 
    WebCore::JSEventListener *findOrCreateJSEventListener(JSValue*, bool html = false);
118
 
 
119
 
    // Finds a wrapper of a GC-unprotected JS EventListener, returns 0 if no existing one.
120
 
    WebCore::JSUnprotectedEventListener* findJSUnprotectedEventListener(JSValue*, bool html = false);
121
 
 
122
 
    // Finds or creates a wrapper of a JS EventListener. JS EventListener object is *NOT* GC-protected.
123
 
    WebCore::JSUnprotectedEventListener *findOrCreateJSUnprotectedEventListener(JSValue*, bool html = false);
124
 
 
125
 
    void clear();
126
 
 
127
 
    // Set the current "event" object
128
 
    void setCurrentEvent(WebCore::Event*);
129
 
 
130
 
    // Set a place to put a dialog return value when the window is cleared.
131
 
    void setReturnValueSlot(JSValue **slot);
132
 
 
133
 
    typedef HashMap<JSObject*, WebCore::JSEventListener*> ListenersMap;
134
 
    typedef HashMap<JSObject*, WebCore::JSUnprotectedEventListener*> UnprotectedListenersMap;
135
 
    
136
 
    ListenersMap& jsEventListeners();
137
 
    ListenersMap& jsHTMLEventListeners();
138
 
    UnprotectedListenersMap& jsUnprotectedEventListeners();
139
 
    UnprotectedListenersMap& jsUnprotectedHTMLEventListeners();
140
 
    
141
 
    virtual const ClassInfo* classInfo() const { return &info; }
142
 
    static const ClassInfo info;
143
 
 
144
 
    enum {
145
 
        // Functions
146
 
        AToB, BToA, Open, SetTimeout,
147
 
        ClearTimeout, SetInterval, ClearInterval, CaptureEvents, 
148
 
        ReleaseEvents, AddEventListener, RemoveEventListener, Scroll,
149
 
        ScrollBy, ScrollTo, MoveBy, MoveTo,
150
 
        ResizeBy, ResizeTo, ShowModalDialog,
151
 
 
152
 
        // Attributes
153
 
        Crypto, Event_, Location_, Navigator_,
154
 
        ClientInformation,
155
 
 
156
 
        // Event Listeners
157
 
        Onabort, Onblur, Onchange, Onclick,
158
 
        Ondblclick, Onerror, Onfocus, Onkeydown,
159
 
        Onkeypress, Onkeyup, Onload, Onmousedown,
160
 
        Onmousemove, Onmouseout, Onmouseover, Onmouseup,
161
 
        OnWindowMouseWheel, Onreset, Onresize, Onscroll,
162
 
        Onsearch, Onselect, Onsubmit, Onunload,
163
 
        Onbeforeunload,
164
 
 
165
 
        // Constructors
166
 
        DOMException, Image, Option, XMLHttpRequest,
167
 
        XSLTProcessor_
168
 
    };
169
 
 
170
 
  private:
171
 
    JSValue* getListener(ExecState*, const WebCore::AtomicString& eventType) const;
172
 
    void setListener(ExecState*, const WebCore::AtomicString& eventType, JSValue* func);
173
 
 
174
 
    static JSValue *childFrameGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);
175
 
    static JSValue *namedFrameGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);
176
 
    static JSValue *indexGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);
177
 
    static JSValue *namedItemGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);
178
 
 
179
 
    void updateLayout() const;
180
 
 
181
 
    void clearHelperObjectProperties();
182
 
    void clearAllTimeouts();
183
 
    int installTimeout(ScheduledAction*, int interval, bool singleShot);
184
 
 
185
 
    RefPtr<WebCore::DOMWindow> m_impl;
186
 
    OwnPtr<WindowPrivate> d;
187
 
  };
188
 
 
189
 
  KJS_IMPLEMENT_PROTOTYPE_FUNCTION(WindowFunc)
190
 
 
191
 
  /**
192
 
   * An action (either function or string) to be executed after a specified
193
 
   * time interval, either once or repeatedly. Used for window.setTimeout()
194
 
   * and window.setInterval()
195
 
   */
196
 
    class ScheduledAction {
197
 
    public:
198
 
        ScheduledAction(JSValue *func, const List& args)
199
 
            : m_func(func), m_args(args) { }
200
 
        ScheduledAction(const WebCore::String& code)
201
 
            : m_code(code) { }
202
 
        void execute(Window *);
203
 
 
204
 
    private:
205
 
        ProtectedPtr<JSValue> m_func;
206
 
        List m_args;
207
 
        WebCore::String m_code;
208
 
    };
209
 
 
210
 
  class Location : public DOMObject {
211
 
  public:
212
 
    virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
213
 
    JSValue *getValueProperty(ExecState *exec, int token) const;
214
 
    virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
215
 
    enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, 
216
 
           Replace, Reload, ToString, Assign };
217
 
    WebCore::Frame* frame() const { return m_frame; }
218
 
    virtual const ClassInfo* classInfo() const { return &info; }
219
 
    static const ClassInfo info;
220
 
  private:
221
 
    friend class Window;
222
 
    Location(WebCore::Frame*);
223
 
    WebCore::Frame* m_frame;
224
 
  };
225
 
 
226
 
} // namespace
227
 
 
228
 
namespace WebCore {
229
 
    KJS::JSValue* toJS(KJS::ExecState*, DOMWindow*);
230
 
} // namespace WebCore
231
 
 
232
 
#endif