author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 2006, 2007, 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 COMPUTER, 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 COMPUTER, 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 "DOMWindow.h" |
|
28 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
29 |
#include "Base64.h" |
0 | 30 |
#include "BarInfo.h" |
31 |
#include "BeforeUnloadEvent.h" |
|
32 |
#include "CSSComputedStyleDeclaration.h" |
|
33 |
#include "CSSRuleList.h" |
|
34 |
#include "CSSStyleSelector.h" |
|
35 |
#include "CString.h" |
|
36 |
#include "Chrome.h" |
|
37 |
#include "Console.h" |
|
38 |
#include "Database.h" |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
39 |
#include "DatabaseCallback.h" |
0 | 40 |
#include "DOMApplicationCache.h" |
41 |
#include "DOMSelection.h" |
|
42 |
#include "DOMTimer.h" |
|
43 |
#include "PageTransitionEvent.h" |
|
44 |
#include "Document.h" |
|
45 |
#include "Element.h" |
|
46 |
#include "EventException.h" |
|
47 |
#include "EventListener.h" |
|
48 |
#include "EventNames.h" |
|
49 |
#include "ExceptionCode.h" |
|
50 |
#include "FloatRect.h" |
|
51 |
#include "Frame.h" |
|
52 |
#include "FrameLoader.h" |
|
53 |
#include "FrameTree.h" |
|
54 |
#include "FrameView.h" |
|
55 |
#include "HTMLFrameOwnerElement.h" |
|
56 |
#include "History.h" |
|
57 |
#include "InspectorController.h" |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
58 |
#include "InspectorTimelineAgent.h" |
0 | 59 |
#include "Location.h" |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
#include "StyleMedia.h" |
0 | 61 |
#include "MessageEvent.h" |
62 |
#include "Navigator.h" |
|
63 |
#include "NotificationCenter.h" |
|
64 |
#include "Page.h" |
|
65 |
#include "PageGroup.h" |
|
66 |
#include "PlatformScreen.h" |
|
67 |
#include "PlatformString.h" |
|
68 |
#include "Screen.h" |
|
69 |
#include "SecurityOrigin.h" |
|
70 |
#include "SerializedScriptValue.h" |
|
71 |
#include "Settings.h" |
|
72 |
#include "Storage.h" |
|
73 |
#include "StorageArea.h" |
|
74 |
#include "StorageNamespace.h" |
|
75 |
#include "SuddenTermination.h" |
|
76 |
#include "WebKitPoint.h" |
|
77 |
#include <algorithm> |
|
78 |
#include <wtf/MathExtras.h> |
|
79 |
||
80 |
using std::min; |
|
81 |
using std::max; |
|
82 |
||
83 |
namespace WebCore { |
|
84 |
||
85 |
class PostMessageTimer : public TimerBase { |
|
86 |
public: |
|
87 |
PostMessageTimer(DOMWindow* window, PassRefPtr<SerializedScriptValue> message, const String& sourceOrigin, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortChannelArray> channels, SecurityOrigin* targetOrigin) |
|
88 |
: m_window(window) |
|
89 |
, m_message(message) |
|
90 |
, m_origin(sourceOrigin) |
|
91 |
, m_source(source) |
|
92 |
, m_channels(channels) |
|
93 |
, m_targetOrigin(targetOrigin) |
|
94 |
{ |
|
95 |
} |
|
96 |
||
97 |
PassRefPtr<MessageEvent> event(ScriptExecutionContext* context) |
|
98 |
{ |
|
99 |
OwnPtr<MessagePortArray> messagePorts = MessagePort::entanglePorts(*context, m_channels.release()); |
|
100 |
return MessageEvent::create(messagePorts.release(), m_message, m_origin, "", m_source); |
|
101 |
} |
|
102 |
SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); } |
|
103 |
||
104 |
private: |
|
105 |
virtual void fired() |
|
106 |
{ |
|
107 |
m_window->postMessageTimerFired(this); |
|
108 |
} |
|
109 |
||
110 |
RefPtr<DOMWindow> m_window; |
|
111 |
RefPtr<SerializedScriptValue> m_message; |
|
112 |
String m_origin; |
|
113 |
RefPtr<DOMWindow> m_source; |
|
114 |
OwnPtr<MessagePortChannelArray> m_channels; |
|
115 |
RefPtr<SecurityOrigin> m_targetOrigin; |
|
116 |
}; |
|
117 |
||
118 |
typedef HashCountedSet<DOMWindow*> DOMWindowSet; |
|
119 |
||
120 |
static DOMWindowSet& windowsWithUnloadEventListeners() |
|
121 |
{ |
|
122 |
DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithUnloadEventListeners, ()); |
|
123 |
return windowsWithUnloadEventListeners; |
|
124 |
} |
|
125 |
||
126 |
static DOMWindowSet& windowsWithBeforeUnloadEventListeners() |
|
127 |
{ |
|
128 |
DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithBeforeUnloadEventListeners, ()); |
|
129 |
return windowsWithBeforeUnloadEventListeners; |
|
130 |
} |
|
131 |
||
132 |
static void addUnloadEventListener(DOMWindow* domWindow) |
|
133 |
{ |
|
134 |
DOMWindowSet& set = windowsWithUnloadEventListeners(); |
|
135 |
if (set.isEmpty()) |
|
136 |
disableSuddenTermination(); |
|
137 |
set.add(domWindow); |
|
138 |
} |
|
139 |
||
140 |
static void removeUnloadEventListener(DOMWindow* domWindow) |
|
141 |
{ |
|
142 |
DOMWindowSet& set = windowsWithUnloadEventListeners(); |
|
143 |
DOMWindowSet::iterator it = set.find(domWindow); |
|
144 |
if (it == set.end()) |
|
145 |
return; |
|
146 |
set.remove(it); |
|
147 |
if (set.isEmpty()) |
|
148 |
enableSuddenTermination(); |
|
149 |
} |
|
150 |
||
151 |
static void removeAllUnloadEventListeners(DOMWindow* domWindow) |
|
152 |
{ |
|
153 |
DOMWindowSet& set = windowsWithUnloadEventListeners(); |
|
154 |
DOMWindowSet::iterator it = set.find(domWindow); |
|
155 |
if (it == set.end()) |
|
156 |
return; |
|
157 |
set.removeAll(it); |
|
158 |
if (set.isEmpty()) |
|
159 |
enableSuddenTermination(); |
|
160 |
} |
|
161 |
||
162 |
static void addBeforeUnloadEventListener(DOMWindow* domWindow) |
|
163 |
{ |
|
164 |
DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); |
|
165 |
if (set.isEmpty()) |
|
166 |
disableSuddenTermination(); |
|
167 |
set.add(domWindow); |
|
168 |
} |
|
169 |
||
170 |
static void removeBeforeUnloadEventListener(DOMWindow* domWindow) |
|
171 |
{ |
|
172 |
DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); |
|
173 |
DOMWindowSet::iterator it = set.find(domWindow); |
|
174 |
if (it == set.end()) |
|
175 |
return; |
|
176 |
set.remove(it); |
|
177 |
if (set.isEmpty()) |
|
178 |
enableSuddenTermination(); |
|
179 |
} |
|
180 |
||
181 |
static void removeAllBeforeUnloadEventListeners(DOMWindow* domWindow) |
|
182 |
{ |
|
183 |
DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); |
|
184 |
DOMWindowSet::iterator it = set.find(domWindow); |
|
185 |
if (it == set.end()) |
|
186 |
return; |
|
187 |
set.removeAll(it); |
|
188 |
if (set.isEmpty()) |
|
189 |
enableSuddenTermination(); |
|
190 |
} |
|
191 |
||
192 |
static bool allowsBeforeUnloadListeners(DOMWindow* window) |
|
193 |
{ |
|
194 |
ASSERT_ARG(window, window); |
|
195 |
Frame* frame = window->frame(); |
|
196 |
if (!frame) |
|
197 |
return false; |
|
198 |
Page* page = frame->page(); |
|
199 |
if (!page) |
|
200 |
return false; |
|
201 |
return frame == page->mainFrame(); |
|
202 |
} |
|
203 |
||
204 |
bool DOMWindow::dispatchAllPendingBeforeUnloadEvents() |
|
205 |
{ |
|
206 |
DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); |
|
207 |
if (set.isEmpty()) |
|
208 |
return true; |
|
209 |
||
210 |
static bool alreadyDispatched = false; |
|
211 |
ASSERT(!alreadyDispatched); |
|
212 |
if (alreadyDispatched) |
|
213 |
return true; |
|
214 |
||
215 |
Vector<RefPtr<DOMWindow> > windows; |
|
216 |
DOMWindowSet::iterator end = set.end(); |
|
217 |
for (DOMWindowSet::iterator it = set.begin(); it != end; ++it) |
|
218 |
windows.append(it->first); |
|
219 |
||
220 |
size_t size = windows.size(); |
|
221 |
for (size_t i = 0; i < size; ++i) { |
|
222 |
DOMWindow* window = windows[i].get(); |
|
223 |
if (!set.contains(window)) |
|
224 |
continue; |
|
225 |
||
226 |
Frame* frame = window->frame(); |
|
227 |
if (!frame) |
|
228 |
continue; |
|
229 |
||
230 |
if (!frame->shouldClose()) |
|
231 |
return false; |
|
232 |
} |
|
233 |
||
234 |
enableSuddenTermination(); |
|
235 |
||
236 |
alreadyDispatched = true; |
|
237 |
||
238 |
return true; |
|
239 |
} |
|
240 |
||
241 |
unsigned DOMWindow::pendingUnloadEventListeners() const |
|
242 |
{ |
|
243 |
return windowsWithUnloadEventListeners().count(const_cast<DOMWindow*>(this)); |
|
244 |
} |
|
245 |
||
246 |
void DOMWindow::dispatchAllPendingUnloadEvents() |
|
247 |
{ |
|
248 |
DOMWindowSet& set = windowsWithUnloadEventListeners(); |
|
249 |
if (set.isEmpty()) |
|
250 |
return; |
|
251 |
||
252 |
static bool alreadyDispatched = false; |
|
253 |
ASSERT(!alreadyDispatched); |
|
254 |
if (alreadyDispatched) |
|
255 |
return; |
|
256 |
||
257 |
Vector<RefPtr<DOMWindow> > windows; |
|
258 |
DOMWindowSet::iterator end = set.end(); |
|
259 |
for (DOMWindowSet::iterator it = set.begin(); it != end; ++it) |
|
260 |
windows.append(it->first); |
|
261 |
||
262 |
size_t size = windows.size(); |
|
263 |
for (size_t i = 0; i < size; ++i) { |
|
264 |
DOMWindow* window = windows[i].get(); |
|
265 |
if (!set.contains(window)) |
|
266 |
continue; |
|
267 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
window->dispatchEvent(PageTransitionEvent::create(eventNames().pagehideEvent, false), window->document()); |
0 | 269 |
window->dispatchEvent(Event::create(eventNames().unloadEvent, false, false), window->document()); |
270 |
} |
|
271 |
||
272 |
enableSuddenTermination(); |
|
273 |
||
274 |
alreadyDispatched = true; |
|
275 |
} |
|
276 |
||
277 |
// This function: |
|
278 |
// 1) Validates the pending changes are not changing to NaN |
|
279 |
// 2) Constrains the window rect to no smaller than 100 in each dimension and no |
|
280 |
// bigger than the the float rect's dimensions. |
|
281 |
// 3) Constrain window rect to within the top and left boundaries of the screen rect |
|
282 |
// 4) Constraint the window rect to within the bottom and right boundaries of the |
|
283 |
// screen rect. |
|
284 |
// 5) Translate the window rect coordinates to be within the coordinate space of |
|
285 |
// the screen rect. |
|
286 |
void DOMWindow::adjustWindowRect(const FloatRect& screen, FloatRect& window, const FloatRect& pendingChanges) |
|
287 |
{ |
|
288 |
// Make sure we're in a valid state before adjusting dimensions. |
|
289 |
ASSERT(isfinite(screen.x())); |
|
290 |
ASSERT(isfinite(screen.y())); |
|
291 |
ASSERT(isfinite(screen.width())); |
|
292 |
ASSERT(isfinite(screen.height())); |
|
293 |
ASSERT(isfinite(window.x())); |
|
294 |
ASSERT(isfinite(window.y())); |
|
295 |
ASSERT(isfinite(window.width())); |
|
296 |
ASSERT(isfinite(window.height())); |
|
297 |
||
298 |
// Update window values if new requested values are not NaN. |
|
299 |
if (!isnan(pendingChanges.x())) |
|
300 |
window.setX(pendingChanges.x()); |
|
301 |
if (!isnan(pendingChanges.y())) |
|
302 |
window.setY(pendingChanges.y()); |
|
303 |
if (!isnan(pendingChanges.width())) |
|
304 |
window.setWidth(pendingChanges.width()); |
|
305 |
if (!isnan(pendingChanges.height())) |
|
306 |
window.setHeight(pendingChanges.height()); |
|
307 |
||
308 |
// Resize the window to between 100 and the screen width and height. |
|
309 |
window.setWidth(min(max(100.0f, window.width()), screen.width())); |
|
310 |
window.setHeight(min(max(100.0f, window.height()), screen.height())); |
|
311 |
||
312 |
// Constrain the window position to the screen. |
|
313 |
window.setX(max(screen.x(), min(window.x(), screen.right() - window.width()))); |
|
314 |
window.setY(max(screen.y(), min(window.y(), screen.bottom() - window.height()))); |
|
315 |
} |
|
316 |
||
317 |
void DOMWindow::parseModalDialogFeatures(const String& featuresArg, HashMap<String, String>& map) |
|
318 |
{ |
|
319 |
Vector<String> features; |
|
320 |
featuresArg.split(';', features); |
|
321 |
Vector<String>::const_iterator end = features.end(); |
|
322 |
for (Vector<String>::const_iterator it = features.begin(); it != end; ++it) { |
|
323 |
String s = *it; |
|
324 |
int pos = s.find('='); |
|
325 |
int colonPos = s.find(':'); |
|
326 |
if (pos >= 0 && colonPos >= 0) |
|
327 |
continue; // ignore any strings that have both = and : |
|
328 |
if (pos < 0) |
|
329 |
pos = colonPos; |
|
330 |
if (pos < 0) { |
|
331 |
// null string for value means key without value |
|
332 |
map.set(s.stripWhiteSpace().lower(), String()); |
|
333 |
} else { |
|
334 |
String key = s.left(pos).stripWhiteSpace().lower(); |
|
335 |
String val = s.substring(pos + 1).stripWhiteSpace().lower(); |
|
336 |
int spacePos = val.find(' '); |
|
337 |
if (spacePos != -1) |
|
338 |
val = val.left(spacePos); |
|
339 |
map.set(key, val); |
|
340 |
} |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
bool DOMWindow::allowPopUp(Frame* activeFrame) |
|
345 |
{ |
|
346 |
ASSERT(activeFrame); |
|
347 |
Settings* settings = activeFrame->settings(); |
|
348 |
return settings && settings->javaScriptCanOpenWindowsAutomatically(); |
|
349 |
} |
|
350 |
||
351 |
bool DOMWindow::canShowModalDialog(const Frame* frame) |
|
352 |
{ |
|
353 |
if (!frame) |
|
354 |
return false; |
|
355 |
Page* page = frame->page(); |
|
356 |
if (!page) |
|
357 |
return false; |
|
358 |
return page->chrome()->canRunModal(); |
|
359 |
} |
|
360 |
||
361 |
bool DOMWindow::canShowModalDialogNow(const Frame* frame) |
|
362 |
{ |
|
363 |
if (!frame) |
|
364 |
return false; |
|
365 |
Page* page = frame->page(); |
|
366 |
if (!page) |
|
367 |
return false; |
|
368 |
return page->chrome()->canRunModalNow(); |
|
369 |
} |
|
370 |
||
371 |
DOMWindow::DOMWindow(Frame* frame) |
|
372 |
: m_frame(frame) |
|
373 |
{ |
|
374 |
} |
|
375 |
||
376 |
DOMWindow::~DOMWindow() |
|
377 |
{ |
|
378 |
if (m_frame) |
|
379 |
m_frame->clearFormerDOMWindow(this); |
|
380 |
||
381 |
removeAllUnloadEventListeners(this); |
|
382 |
removeAllBeforeUnloadEventListeners(this); |
|
383 |
} |
|
384 |
||
385 |
ScriptExecutionContext* DOMWindow::scriptExecutionContext() const |
|
386 |
{ |
|
387 |
return document(); |
|
388 |
} |
|
389 |
||
390 |
void DOMWindow::disconnectFrame() |
|
391 |
{ |
|
392 |
m_frame = 0; |
|
393 |
clear(); |
|
394 |
} |
|
395 |
||
396 |
void DOMWindow::clear() |
|
397 |
{ |
|
398 |
if (m_screen) |
|
399 |
m_screen->disconnectFrame(); |
|
400 |
m_screen = 0; |
|
401 |
||
402 |
if (m_selection) |
|
403 |
m_selection->disconnectFrame(); |
|
404 |
m_selection = 0; |
|
405 |
||
406 |
if (m_history) |
|
407 |
m_history->disconnectFrame(); |
|
408 |
m_history = 0; |
|
409 |
||
410 |
if (m_locationbar) |
|
411 |
m_locationbar->disconnectFrame(); |
|
412 |
m_locationbar = 0; |
|
413 |
||
414 |
if (m_menubar) |
|
415 |
m_menubar->disconnectFrame(); |
|
416 |
m_menubar = 0; |
|
417 |
||
418 |
if (m_personalbar) |
|
419 |
m_personalbar->disconnectFrame(); |
|
420 |
m_personalbar = 0; |
|
421 |
||
422 |
if (m_scrollbars) |
|
423 |
m_scrollbars->disconnectFrame(); |
|
424 |
m_scrollbars = 0; |
|
425 |
||
426 |
if (m_statusbar) |
|
427 |
m_statusbar->disconnectFrame(); |
|
428 |
m_statusbar = 0; |
|
429 |
||
430 |
if (m_toolbar) |
|
431 |
m_toolbar->disconnectFrame(); |
|
432 |
m_toolbar = 0; |
|
433 |
||
434 |
if (m_console) |
|
435 |
m_console->disconnectFrame(); |
|
436 |
m_console = 0; |
|
437 |
||
438 |
if (m_navigator) |
|
439 |
m_navigator->disconnectFrame(); |
|
440 |
m_navigator = 0; |
|
441 |
||
442 |
if (m_location) |
|
443 |
m_location->disconnectFrame(); |
|
444 |
m_location = 0; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
445 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
446 |
if (m_media) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
447 |
m_media->disconnectFrame(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
448 |
m_media = 0; |
0 | 449 |
|
450 |
#if ENABLE(DOM_STORAGE) |
|
451 |
if (m_sessionStorage) |
|
452 |
m_sessionStorage->disconnectFrame(); |
|
453 |
m_sessionStorage = 0; |
|
454 |
||
455 |
if (m_localStorage) |
|
456 |
m_localStorage->disconnectFrame(); |
|
457 |
m_localStorage = 0; |
|
458 |
#endif |
|
459 |
||
460 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS) |
|
461 |
if (m_applicationCache) |
|
462 |
m_applicationCache->disconnectFrame(); |
|
463 |
m_applicationCache = 0; |
|
464 |
#endif |
|
465 |
||
466 |
#if ENABLE(NOTIFICATIONS) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
467 |
if (m_notifications) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
m_notifications->disconnectFrame(); |
0 | 469 |
m_notifications = 0; |
470 |
#endif |
|
471 |
} |
|
472 |
||
473 |
#if ENABLE(ORIENTATION_EVENTS) |
|
474 |
int DOMWindow::orientation() const |
|
475 |
{ |
|
476 |
if (!m_frame) |
|
477 |
return 0; |
|
478 |
||
479 |
return m_frame->orientation(); |
|
480 |
} |
|
481 |
#endif |
|
482 |
||
483 |
Screen* DOMWindow::screen() const |
|
484 |
{ |
|
485 |
if (!m_screen) |
|
486 |
m_screen = Screen::create(m_frame); |
|
487 |
return m_screen.get(); |
|
488 |
} |
|
489 |
||
490 |
History* DOMWindow::history() const |
|
491 |
{ |
|
492 |
if (!m_history) |
|
493 |
m_history = History::create(m_frame); |
|
494 |
return m_history.get(); |
|
495 |
} |
|
496 |
||
497 |
BarInfo* DOMWindow::locationbar() const |
|
498 |
{ |
|
499 |
if (!m_locationbar) |
|
500 |
m_locationbar = BarInfo::create(m_frame, BarInfo::Locationbar); |
|
501 |
return m_locationbar.get(); |
|
502 |
} |
|
503 |
||
504 |
BarInfo* DOMWindow::menubar() const |
|
505 |
{ |
|
506 |
if (!m_menubar) |
|
507 |
m_menubar = BarInfo::create(m_frame, BarInfo::Menubar); |
|
508 |
return m_menubar.get(); |
|
509 |
} |
|
510 |
||
511 |
BarInfo* DOMWindow::personalbar() const |
|
512 |
{ |
|
513 |
if (!m_personalbar) |
|
514 |
m_personalbar = BarInfo::create(m_frame, BarInfo::Personalbar); |
|
515 |
return m_personalbar.get(); |
|
516 |
} |
|
517 |
||
518 |
BarInfo* DOMWindow::scrollbars() const |
|
519 |
{ |
|
520 |
if (!m_scrollbars) |
|
521 |
m_scrollbars = BarInfo::create(m_frame, BarInfo::Scrollbars); |
|
522 |
return m_scrollbars.get(); |
|
523 |
} |
|
524 |
||
525 |
BarInfo* DOMWindow::statusbar() const |
|
526 |
{ |
|
527 |
if (!m_statusbar) |
|
528 |
m_statusbar = BarInfo::create(m_frame, BarInfo::Statusbar); |
|
529 |
return m_statusbar.get(); |
|
530 |
} |
|
531 |
||
532 |
BarInfo* DOMWindow::toolbar() const |
|
533 |
{ |
|
534 |
if (!m_toolbar) |
|
535 |
m_toolbar = BarInfo::create(m_frame, BarInfo::Toolbar); |
|
536 |
return m_toolbar.get(); |
|
537 |
} |
|
538 |
||
539 |
Console* DOMWindow::console() const |
|
540 |
{ |
|
541 |
if (!m_console) |
|
542 |
m_console = Console::create(m_frame); |
|
543 |
return m_console.get(); |
|
544 |
} |
|
545 |
||
546 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS) |
|
547 |
DOMApplicationCache* DOMWindow::applicationCache() const |
|
548 |
{ |
|
549 |
if (!m_applicationCache) |
|
550 |
m_applicationCache = DOMApplicationCache::create(m_frame); |
|
551 |
return m_applicationCache.get(); |
|
552 |
} |
|
553 |
#endif |
|
554 |
||
555 |
Navigator* DOMWindow::navigator() const |
|
556 |
{ |
|
557 |
if (!m_navigator) |
|
558 |
m_navigator = Navigator::create(m_frame); |
|
559 |
return m_navigator.get(); |
|
560 |
} |
|
561 |
||
562 |
Location* DOMWindow::location() const |
|
563 |
{ |
|
564 |
if (!m_location) |
|
565 |
m_location = Location::create(m_frame); |
|
566 |
return m_location.get(); |
|
567 |
} |
|
568 |
||
569 |
#if ENABLE(DOM_STORAGE) |
|
570 |
Storage* DOMWindow::sessionStorage() const |
|
571 |
{ |
|
572 |
if (m_sessionStorage) |
|
573 |
return m_sessionStorage.get(); |
|
574 |
||
575 |
Document* document = this->document(); |
|
576 |
if (!document) |
|
577 |
return 0; |
|
578 |
||
579 |
Page* page = document->page(); |
|
580 |
if (!page) |
|
581 |
return 0; |
|
582 |
||
583 |
RefPtr<StorageArea> storageArea = page->sessionStorage()->storageArea(document->securityOrigin()); |
|
584 |
#if ENABLE(INSPECTOR) |
|
585 |
page->inspectorController()->didUseDOMStorage(storageArea.get(), false, m_frame); |
|
586 |
#endif |
|
587 |
||
588 |
m_sessionStorage = Storage::create(m_frame, storageArea.release()); |
|
589 |
return m_sessionStorage.get(); |
|
590 |
} |
|
591 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
592 |
Storage* DOMWindow::localStorage(ExceptionCode& ec) const |
0 | 593 |
{ |
594 |
if (m_localStorage) |
|
595 |
return m_localStorage.get(); |
|
596 |
||
597 |
Document* document = this->document(); |
|
598 |
if (!document) |
|
599 |
return 0; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
600 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
601 |
if (!document->securityOrigin()->canAccessLocalStorage()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
602 |
ec = SECURITY_ERR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
603 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
604 |
} |
0 | 605 |
|
606 |
Page* page = document->page(); |
|
607 |
if (!page) |
|
608 |
return 0; |
|
609 |
||
610 |
if (!page->settings()->localStorageEnabled()) |
|
611 |
return 0; |
|
612 |
||
613 |
RefPtr<StorageArea> storageArea = page->group().localStorage()->storageArea(document->securityOrigin()); |
|
614 |
#if ENABLE(INSPECTOR) |
|
615 |
page->inspectorController()->didUseDOMStorage(storageArea.get(), true, m_frame); |
|
616 |
#endif |
|
617 |
||
618 |
m_localStorage = Storage::create(m_frame, storageArea.release()); |
|
619 |
return m_localStorage.get(); |
|
620 |
} |
|
621 |
#endif |
|
622 |
||
623 |
#if ENABLE(NOTIFICATIONS) |
|
624 |
NotificationCenter* DOMWindow::webkitNotifications() const |
|
625 |
{ |
|
626 |
if (m_notifications) |
|
627 |
return m_notifications.get(); |
|
628 |
||
629 |
Document* document = this->document(); |
|
630 |
if (!document) |
|
631 |
return 0; |
|
632 |
||
633 |
Page* page = document->page(); |
|
634 |
if (!page) |
|
635 |
return 0; |
|
636 |
||
637 |
NotificationPresenter* provider = page->chrome()->notificationPresenter(); |
|
638 |
if (provider) |
|
639 |
m_notifications = NotificationCenter::create(document, provider); |
|
640 |
||
641 |
return m_notifications.get(); |
|
642 |
} |
|
643 |
#endif |
|
644 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
645 |
#if ENABLE(INDEXED_DATABASE) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
646 |
IndexedDatabaseRequest* DOMWindow::indexedDB() const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
647 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
649 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
650 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
651 |
|
0 | 652 |
void DOMWindow::postMessage(PassRefPtr<SerializedScriptValue> message, MessagePort* port, const String& targetOrigin, DOMWindow* source, ExceptionCode& ec) |
653 |
{ |
|
654 |
MessagePortArray ports; |
|
655 |
if (port) |
|
656 |
ports.append(port); |
|
657 |
postMessage(message, &ports, targetOrigin, source, ec); |
|
658 |
} |
|
659 |
||
660 |
void DOMWindow::postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, const String& targetOrigin, DOMWindow* source, ExceptionCode& ec) |
|
661 |
{ |
|
662 |
if (!m_frame) |
|
663 |
return; |
|
664 |
||
665 |
// Compute the target origin. We need to do this synchronously in order |
|
666 |
// to generate the SYNTAX_ERR exception correctly. |
|
667 |
RefPtr<SecurityOrigin> target; |
|
668 |
if (targetOrigin != "*") { |
|
669 |
target = SecurityOrigin::createFromString(targetOrigin); |
|
670 |
if (target->isEmpty()) { |
|
671 |
ec = SYNTAX_ERR; |
|
672 |
return; |
|
673 |
} |
|
674 |
} |
|
675 |
||
676 |
OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(ports, ec); |
|
677 |
if (ec) |
|
678 |
return; |
|
679 |
||
680 |
// Capture the source of the message. We need to do this synchronously |
|
681 |
// in order to capture the source of the message correctly. |
|
682 |
Document* sourceDocument = source->document(); |
|
683 |
if (!sourceDocument) |
|
684 |
return; |
|
685 |
String sourceOrigin = sourceDocument->securityOrigin()->toString(); |
|
686 |
||
687 |
// Schedule the message. |
|
688 |
PostMessageTimer* timer = new PostMessageTimer(this, message, sourceOrigin, source, channels.release(), target.get()); |
|
689 |
timer->startOneShot(0); |
|
690 |
} |
|
691 |
||
692 |
void DOMWindow::postMessageTimerFired(PostMessageTimer* t) |
|
693 |
{ |
|
694 |
OwnPtr<PostMessageTimer> timer(t); |
|
695 |
||
696 |
if (!document()) |
|
697 |
return; |
|
698 |
||
699 |
if (timer->targetOrigin()) { |
|
700 |
// Check target origin now since the target document may have changed since the simer was scheduled. |
|
701 |
if (!timer->targetOrigin()->isSameSchemeHostPort(document()->securityOrigin())) { |
|
702 |
String message = String::format("Unable to post message to %s. Recipient has origin %s.\n", |
|
703 |
timer->targetOrigin()->toString().utf8().data(), document()->securityOrigin()->toString().utf8().data()); |
|
704 |
console()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, 0, String()); |
|
705 |
return; |
|
706 |
} |
|
707 |
} |
|
708 |
||
709 |
dispatchEvent(timer->event(document())); |
|
710 |
} |
|
711 |
||
712 |
DOMSelection* DOMWindow::getSelection() |
|
713 |
{ |
|
714 |
if (!m_selection) |
|
715 |
m_selection = DOMSelection::create(m_frame); |
|
716 |
return m_selection.get(); |
|
717 |
} |
|
718 |
||
719 |
Element* DOMWindow::frameElement() const |
|
720 |
{ |
|
721 |
if (!m_frame) |
|
722 |
return 0; |
|
723 |
||
724 |
return m_frame->ownerElement(); |
|
725 |
} |
|
726 |
||
727 |
void DOMWindow::focus() |
|
728 |
{ |
|
729 |
if (!m_frame) |
|
730 |
return; |
|
731 |
||
732 |
m_frame->focusWindow(); |
|
733 |
} |
|
734 |
||
735 |
void DOMWindow::blur() |
|
736 |
{ |
|
737 |
if (!m_frame) |
|
738 |
return; |
|
739 |
||
740 |
m_frame->unfocusWindow(); |
|
741 |
} |
|
742 |
||
743 |
void DOMWindow::close() |
|
744 |
{ |
|
745 |
if (!m_frame) |
|
746 |
return; |
|
747 |
||
748 |
Page* page = m_frame->page(); |
|
749 |
if (!page) |
|
750 |
return; |
|
751 |
||
752 |
if (m_frame != page->mainFrame()) |
|
753 |
return; |
|
754 |
||
755 |
Settings* settings = m_frame->settings(); |
|
756 |
bool allowScriptsToCloseWindows = settings && settings->allowScriptsToCloseWindows(); |
|
757 |
||
758 |
if (page->openedByDOM() || page->getHistoryLength() <= 1 || allowScriptsToCloseWindows) |
|
759 |
m_frame->scheduleClose(); |
|
760 |
} |
|
761 |
||
762 |
void DOMWindow::print() |
|
763 |
{ |
|
764 |
if (!m_frame) |
|
765 |
return; |
|
766 |
||
767 |
Page* page = m_frame->page(); |
|
768 |
if (!page) |
|
769 |
return; |
|
770 |
||
771 |
page->chrome()->print(m_frame); |
|
772 |
} |
|
773 |
||
774 |
void DOMWindow::stop() |
|
775 |
{ |
|
776 |
if (!m_frame) |
|
777 |
return; |
|
778 |
||
779 |
// We must check whether the load is complete asynchronously, because we might still be parsing |
|
780 |
// the document until the callstack unwinds. |
|
781 |
m_frame->loader()->stopForUserCancel(true); |
|
782 |
} |
|
783 |
||
784 |
void DOMWindow::alert(const String& message) |
|
785 |
{ |
|
786 |
if (!m_frame) |
|
787 |
return; |
|
788 |
||
789 |
m_frame->document()->updateStyleIfNeeded(); |
|
790 |
||
791 |
Page* page = m_frame->page(); |
|
792 |
if (!page) |
|
793 |
return; |
|
794 |
||
795 |
page->chrome()->runJavaScriptAlert(m_frame, message); |
|
796 |
} |
|
797 |
||
798 |
bool DOMWindow::confirm(const String& message) |
|
799 |
{ |
|
800 |
if (!m_frame) |
|
801 |
return false; |
|
802 |
||
803 |
m_frame->document()->updateStyleIfNeeded(); |
|
804 |
||
805 |
Page* page = m_frame->page(); |
|
806 |
if (!page) |
|
807 |
return false; |
|
808 |
||
809 |
return page->chrome()->runJavaScriptConfirm(m_frame, message); |
|
810 |
} |
|
811 |
||
812 |
String DOMWindow::prompt(const String& message, const String& defaultValue) |
|
813 |
{ |
|
814 |
if (!m_frame) |
|
815 |
return String(); |
|
816 |
||
817 |
m_frame->document()->updateStyleIfNeeded(); |
|
818 |
||
819 |
Page* page = m_frame->page(); |
|
820 |
if (!page) |
|
821 |
return String(); |
|
822 |
||
823 |
String returnValue; |
|
824 |
if (page->chrome()->runJavaScriptPrompt(m_frame, message, defaultValue, returnValue)) |
|
825 |
return returnValue; |
|
826 |
||
827 |
return String(); |
|
828 |
} |
|
829 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
830 |
static bool isSafeToConvertCharList(const String& string) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
831 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
832 |
for (unsigned i = 0; i < string.length(); i++) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
833 |
if (string[i] > 0xFF) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
834 |
return false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
835 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
836 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
837 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
838 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
839 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
840 |
String DOMWindow::btoa(const String& stringToEncode, ExceptionCode& ec) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
841 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
842 |
if (stringToEncode.isNull()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
843 |
return String(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
844 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
845 |
if (!isSafeToConvertCharList(stringToEncode)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
846 |
ec = INVALID_CHARACTER_ERR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
847 |
return String(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
848 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
849 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
850 |
Vector<char> in; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
851 |
in.append(stringToEncode.characters(), stringToEncode.length()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
852 |
Vector<char> out; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
853 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
854 |
base64Encode(in, out); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
855 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
856 |
return String(out.data(), out.size()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
857 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
858 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
859 |
String DOMWindow::atob(const String& encodedString, ExceptionCode& ec) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
860 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
861 |
if (encodedString.isNull()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
862 |
return String(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
863 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
864 |
if (!isSafeToConvertCharList(encodedString)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
865 |
ec = INVALID_CHARACTER_ERR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
866 |
return String(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
867 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
868 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
869 |
Vector<char> in; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
870 |
in.append(encodedString.characters(), encodedString.length()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
871 |
Vector<char> out; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
872 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
873 |
if (!base64Decode(in, out)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
874 |
ec = INVALID_CHARACTER_ERR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
875 |
return String(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
876 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
877 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
878 |
return String(out.data(), out.size()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
879 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
880 |
|
0 | 881 |
bool DOMWindow::find(const String& string, bool caseSensitive, bool backwards, bool wrap, bool /*wholeWord*/, bool /*searchInFrames*/, bool /*showDialog*/) const |
882 |
{ |
|
883 |
if (!m_frame) |
|
884 |
return false; |
|
885 |
||
886 |
// FIXME (13016): Support wholeWord, searchInFrames and showDialog |
|
887 |
return m_frame->findString(string, !backwards, caseSensitive, wrap, false); |
|
888 |
} |
|
889 |
||
890 |
bool DOMWindow::offscreenBuffering() const |
|
891 |
{ |
|
892 |
return true; |
|
893 |
} |
|
894 |
||
895 |
int DOMWindow::outerHeight() const |
|
896 |
{ |
|
897 |
if (!m_frame) |
|
898 |
return 0; |
|
899 |
||
900 |
Page* page = m_frame->page(); |
|
901 |
if (!page) |
|
902 |
return 0; |
|
903 |
||
904 |
return static_cast<int>(page->chrome()->windowRect().height()); |
|
905 |
} |
|
906 |
||
907 |
int DOMWindow::outerWidth() const |
|
908 |
{ |
|
909 |
if (!m_frame) |
|
910 |
return 0; |
|
911 |
||
912 |
Page* page = m_frame->page(); |
|
913 |
if (!page) |
|
914 |
return 0; |
|
915 |
||
916 |
return static_cast<int>(page->chrome()->windowRect().width()); |
|
917 |
} |
|
918 |
||
919 |
int DOMWindow::innerHeight() const |
|
920 |
{ |
|
921 |
if (!m_frame) |
|
922 |
return 0; |
|
923 |
||
924 |
FrameView* view = m_frame->view(); |
|
925 |
if (!view) |
|
926 |
return 0; |
|
927 |
||
928 |
return static_cast<int>(view->height() / m_frame->pageZoomFactor()); |
|
929 |
} |
|
930 |
||
931 |
int DOMWindow::innerWidth() const |
|
932 |
{ |
|
933 |
if (!m_frame) |
|
934 |
return 0; |
|
935 |
||
936 |
FrameView* view = m_frame->view(); |
|
937 |
if (!view) |
|
938 |
return 0; |
|
939 |
||
940 |
return static_cast<int>(view->width() / m_frame->pageZoomFactor()); |
|
941 |
} |
|
942 |
||
943 |
int DOMWindow::screenX() const |
|
944 |
{ |
|
945 |
if (!m_frame) |
|
946 |
return 0; |
|
947 |
||
948 |
Page* page = m_frame->page(); |
|
949 |
if (!page) |
|
950 |
return 0; |
|
951 |
||
952 |
return static_cast<int>(page->chrome()->windowRect().x()); |
|
953 |
} |
|
954 |
||
955 |
int DOMWindow::screenY() const |
|
956 |
{ |
|
957 |
if (!m_frame) |
|
958 |
return 0; |
|
959 |
||
960 |
Page* page = m_frame->page(); |
|
961 |
if (!page) |
|
962 |
return 0; |
|
963 |
||
964 |
return static_cast<int>(page->chrome()->windowRect().y()); |
|
965 |
} |
|
966 |
||
967 |
int DOMWindow::scrollX() const |
|
968 |
{ |
|
969 |
if (!m_frame) |
|
970 |
return 0; |
|
971 |
||
972 |
FrameView* view = m_frame->view(); |
|
973 |
if (!view) |
|
974 |
return 0; |
|
975 |
||
976 |
m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
|
977 |
||
978 |
return static_cast<int>(view->scrollX() / m_frame->pageZoomFactor()); |
|
979 |
} |
|
980 |
||
981 |
int DOMWindow::scrollY() const |
|
982 |
{ |
|
983 |
if (!m_frame) |
|
984 |
return 0; |
|
985 |
||
986 |
FrameView* view = m_frame->view(); |
|
987 |
if (!view) |
|
988 |
return 0; |
|
989 |
||
990 |
m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
|
991 |
||
992 |
return static_cast<int>(view->scrollY() / m_frame->pageZoomFactor()); |
|
993 |
} |
|
994 |
||
995 |
bool DOMWindow::closed() const |
|
996 |
{ |
|
997 |
return !m_frame; |
|
998 |
} |
|
999 |
||
1000 |
unsigned DOMWindow::length() const |
|
1001 |
{ |
|
1002 |
if (!m_frame) |
|
1003 |
return 0; |
|
1004 |
||
1005 |
return m_frame->tree()->childCount(); |
|
1006 |
} |
|
1007 |
||
1008 |
String DOMWindow::name() const |
|
1009 |
{ |
|
1010 |
if (!m_frame) |
|
1011 |
return String(); |
|
1012 |
||
1013 |
return m_frame->tree()->name(); |
|
1014 |
} |
|
1015 |
||
1016 |
void DOMWindow::setName(const String& string) |
|
1017 |
{ |
|
1018 |
if (!m_frame) |
|
1019 |
return; |
|
1020 |
||
1021 |
m_frame->tree()->setName(string); |
|
1022 |
} |
|
1023 |
||
1024 |
String DOMWindow::status() const |
|
1025 |
{ |
|
1026 |
if (!m_frame) |
|
1027 |
return String(); |
|
1028 |
||
1029 |
return m_frame->jsStatusBarText(); |
|
1030 |
} |
|
1031 |
||
1032 |
void DOMWindow::setStatus(const String& string) |
|
1033 |
{ |
|
1034 |
if (!m_frame) |
|
1035 |
return; |
|
1036 |
||
1037 |
m_frame->setJSStatusBarText(string); |
|
1038 |
} |
|
1039 |
||
1040 |
String DOMWindow::defaultStatus() const |
|
1041 |
{ |
|
1042 |
if (!m_frame) |
|
1043 |
return String(); |
|
1044 |
||
1045 |
return m_frame->jsDefaultStatusBarText(); |
|
1046 |
} |
|
1047 |
||
1048 |
void DOMWindow::setDefaultStatus(const String& string) |
|
1049 |
{ |
|
1050 |
if (!m_frame) |
|
1051 |
return; |
|
1052 |
||
1053 |
m_frame->setJSDefaultStatusBarText(string); |
|
1054 |
} |
|
1055 |
||
1056 |
DOMWindow* DOMWindow::self() const |
|
1057 |
{ |
|
1058 |
if (!m_frame) |
|
1059 |
return 0; |
|
1060 |
||
1061 |
return m_frame->domWindow(); |
|
1062 |
} |
|
1063 |
||
1064 |
DOMWindow* DOMWindow::opener() const |
|
1065 |
{ |
|
1066 |
if (!m_frame) |
|
1067 |
return 0; |
|
1068 |
||
1069 |
Frame* opener = m_frame->loader()->opener(); |
|
1070 |
if (!opener) |
|
1071 |
return 0; |
|
1072 |
||
1073 |
return opener->domWindow(); |
|
1074 |
} |
|
1075 |
||
1076 |
DOMWindow* DOMWindow::parent() const |
|
1077 |
{ |
|
1078 |
if (!m_frame) |
|
1079 |
return 0; |
|
1080 |
||
1081 |
Frame* parent = m_frame->tree()->parent(true); |
|
1082 |
if (parent) |
|
1083 |
return parent->domWindow(); |
|
1084 |
||
1085 |
return m_frame->domWindow(); |
|
1086 |
} |
|
1087 |
||
1088 |
DOMWindow* DOMWindow::top() const |
|
1089 |
{ |
|
1090 |
if (!m_frame) |
|
1091 |
return 0; |
|
1092 |
||
1093 |
Page* page = m_frame->page(); |
|
1094 |
if (!page) |
|
1095 |
return 0; |
|
1096 |
||
1097 |
return m_frame->tree()->top(true)->domWindow(); |
|
1098 |
} |
|
1099 |
||
1100 |
Document* DOMWindow::document() const |
|
1101 |
{ |
|
1102 |
// FIXME: This function shouldn't need a frame to work. |
|
1103 |
if (!m_frame) |
|
1104 |
return 0; |
|
1105 |
||
1106 |
// The m_frame pointer is not zeroed out when the window is put into b/f cache, so it can hold an unrelated document/window pair. |
|
1107 |
// FIXME: We should always zero out the frame pointer on navigation to avoid accidentally accessing the new frame content. |
|
1108 |
if (m_frame->domWindow() != this) |
|
1109 |
return 0; |
|
1110 |
||
1111 |
ASSERT(m_frame->document()); |
|
1112 |
return m_frame->document(); |
|
1113 |
} |
|
1114 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1115 |
PassRefPtr<StyleMedia> DOMWindow::styleMedia() const |
0 | 1116 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1117 |
if (!m_media) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1118 |
m_media = StyleMedia::create(m_frame); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1119 |
return m_media.get(); |
0 | 1120 |
} |
1121 |
||
1122 |
PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* elt, const String&) const |
|
1123 |
{ |
|
1124 |
if (!elt) |
|
1125 |
return 0; |
|
1126 |
||
1127 |
// FIXME: This needs take pseudo elements into account. |
|
1128 |
return computedStyle(elt); |
|
1129 |
} |
|
1130 |
||
1131 |
PassRefPtr<CSSRuleList> DOMWindow::getMatchedCSSRules(Element* elt, const String& pseudoElt, bool authorOnly) const |
|
1132 |
{ |
|
1133 |
if (!m_frame) |
|
1134 |
return 0; |
|
1135 |
||
1136 |
Document* doc = m_frame->document(); |
|
1137 |
||
1138 |
if (!pseudoElt.isEmpty()) |
|
1139 |
return doc->styleSelector()->pseudoStyleRulesForElement(elt, pseudoElt, authorOnly); |
|
1140 |
return doc->styleSelector()->styleRulesForElement(elt, authorOnly); |
|
1141 |
} |
|
1142 |
||
1143 |
PassRefPtr<WebKitPoint> DOMWindow::webkitConvertPointFromNodeToPage(Node* node, const WebKitPoint* p) const |
|
1144 |
{ |
|
1145 |
if (!node || !p) |
|
1146 |
return 0; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1147 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1148 |
m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1149 |
|
0 | 1150 |
FloatPoint pagePoint(p->x(), p->y()); |
1151 |
pagePoint = node->convertToPage(pagePoint); |
|
1152 |
return WebKitPoint::create(pagePoint.x(), pagePoint.y()); |
|
1153 |
} |
|
1154 |
||
1155 |
PassRefPtr<WebKitPoint> DOMWindow::webkitConvertPointFromPageToNode(Node* node, const WebKitPoint* p) const |
|
1156 |
{ |
|
1157 |
if (!node || !p) |
|
1158 |
return 0; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1159 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1160 |
m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1161 |
|
0 | 1162 |
FloatPoint nodePoint(p->x(), p->y()); |
1163 |
nodePoint = node->convertFromPage(nodePoint); |
|
1164 |
return WebKitPoint::create(nodePoint.x(), nodePoint.y()); |
|
1165 |
} |
|
1166 |
||
1167 |
double DOMWindow::devicePixelRatio() const |
|
1168 |
{ |
|
1169 |
if (!m_frame) |
|
1170 |
return 0.0; |
|
1171 |
||
1172 |
Page* page = m_frame->page(); |
|
1173 |
if (!page) |
|
1174 |
return 0.0; |
|
1175 |
||
1176 |
return page->chrome()->scaleFactor(); |
|
1177 |
} |
|
1178 |
||
1179 |
#if ENABLE(DATABASE) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1180 |
PassRefPtr<Database> DOMWindow::openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec) |
0 | 1181 |
{ |
1182 |
if (!m_frame) |
|
1183 |
return 0; |
|
1184 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1185 |
if (!Database::isAvailable()) |
0 | 1186 |
return 0; |
1187 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1188 |
Document* document = m_frame->document(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1189 |
if (!document->securityOrigin()->canAccessDatabase()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1190 |
ec = SECURITY_ERR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1191 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1192 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1193 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1194 |
return Database::openDatabase(document, name, version, displayName, estimatedSize, creationCallback, ec); |
0 | 1195 |
} |
1196 |
#endif |
|
1197 |
||
1198 |
void DOMWindow::scrollBy(int x, int y) const |
|
1199 |
{ |
|
1200 |
if (!m_frame) |
|
1201 |
return; |
|
1202 |
||
1203 |
m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
|
1204 |
||
1205 |
FrameView* view = m_frame->view(); |
|
1206 |
if (!view) |
|
1207 |
return; |
|
1208 |
||
1209 |
view->scrollBy(IntSize(x, y)); |
|
1210 |
} |
|
1211 |
||
1212 |
void DOMWindow::scrollTo(int x, int y) const |
|
1213 |
{ |
|
1214 |
if (!m_frame) |
|
1215 |
return; |
|
1216 |
||
1217 |
m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
|
1218 |
||
1219 |
FrameView* view = m_frame->view(); |
|
1220 |
if (!view) |
|
1221 |
return; |
|
1222 |
||
1223 |
int zoomedX = static_cast<int>(x * m_frame->pageZoomFactor()); |
|
1224 |
int zoomedY = static_cast<int>(y * m_frame->pageZoomFactor()); |
|
1225 |
view->setScrollPosition(IntPoint(zoomedX, zoomedY)); |
|
1226 |
} |
|
1227 |
||
1228 |
void DOMWindow::moveBy(float x, float y) const |
|
1229 |
{ |
|
1230 |
if (!m_frame) |
|
1231 |
return; |
|
1232 |
||
1233 |
Page* page = m_frame->page(); |
|
1234 |
if (!page) |
|
1235 |
return; |
|
1236 |
||
1237 |
if (m_frame != page->mainFrame()) |
|
1238 |
return; |
|
1239 |
||
1240 |
FloatRect fr = page->chrome()->windowRect(); |
|
1241 |
FloatRect update = fr; |
|
1242 |
update.move(x, y); |
|
1243 |
// Security check (the spec talks about UniversalBrowserWrite to disable this check...) |
|
1244 |
adjustWindowRect(screenAvailableRect(page->mainFrame()->view()), fr, update); |
|
1245 |
page->chrome()->setWindowRect(fr); |
|
1246 |
} |
|
1247 |
||
1248 |
void DOMWindow::moveTo(float x, float y) const |
|
1249 |
{ |
|
1250 |
if (!m_frame) |
|
1251 |
return; |
|
1252 |
||
1253 |
Page* page = m_frame->page(); |
|
1254 |
if (!page) |
|
1255 |
return; |
|
1256 |
||
1257 |
if (m_frame != page->mainFrame()) |
|
1258 |
return; |
|
1259 |
||
1260 |
FloatRect fr = page->chrome()->windowRect(); |
|
1261 |
FloatRect sr = screenAvailableRect(page->mainFrame()->view()); |
|
1262 |
fr.setLocation(sr.location()); |
|
1263 |
FloatRect update = fr; |
|
1264 |
update.move(x, y); |
|
1265 |
// Security check (the spec talks about UniversalBrowserWrite to disable this check...) |
|
1266 |
adjustWindowRect(sr, fr, update); |
|
1267 |
page->chrome()->setWindowRect(fr); |
|
1268 |
} |
|
1269 |
||
1270 |
void DOMWindow::resizeBy(float x, float y) const |
|
1271 |
{ |
|
1272 |
if (!m_frame) |
|
1273 |
return; |
|
1274 |
||
1275 |
Page* page = m_frame->page(); |
|
1276 |
if (!page) |
|
1277 |
return; |
|
1278 |
||
1279 |
if (m_frame != page->mainFrame()) |
|
1280 |
return; |
|
1281 |
||
1282 |
FloatRect fr = page->chrome()->windowRect(); |
|
1283 |
FloatSize dest = fr.size() + FloatSize(x, y); |
|
1284 |
FloatRect update(fr.location(), dest); |
|
1285 |
adjustWindowRect(screenAvailableRect(page->mainFrame()->view()), fr, update); |
|
1286 |
page->chrome()->setWindowRect(fr); |
|
1287 |
} |
|
1288 |
||
1289 |
void DOMWindow::resizeTo(float width, float height) const |
|
1290 |
{ |
|
1291 |
if (!m_frame) |
|
1292 |
return; |
|
1293 |
||
1294 |
Page* page = m_frame->page(); |
|
1295 |
if (!page) |
|
1296 |
return; |
|
1297 |
||
1298 |
if (m_frame != page->mainFrame()) |
|
1299 |
return; |
|
1300 |
||
1301 |
FloatRect fr = page->chrome()->windowRect(); |
|
1302 |
FloatSize dest = FloatSize(width, height); |
|
1303 |
FloatRect update(fr.location(), dest); |
|
1304 |
adjustWindowRect(screenAvailableRect(page->mainFrame()->view()), fr, update); |
|
1305 |
page->chrome()->setWindowRect(fr); |
|
1306 |
} |
|
1307 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1308 |
int DOMWindow::setTimeout(PassOwnPtr<ScheduledAction> action, int timeout, ExceptionCode& ec) |
0 | 1309 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1310 |
ScriptExecutionContext* context = scriptExecutionContext(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1311 |
if (!context) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1312 |
ec = INVALID_ACCESS_ERR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1313 |
return -1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1314 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1315 |
return DOMTimer::install(context, action, timeout, true); |
0 | 1316 |
} |
1317 |
||
1318 |
void DOMWindow::clearTimeout(int timeoutId) |
|
1319 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1320 |
ScriptExecutionContext* context = scriptExecutionContext(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1321 |
if (!context) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1322 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1323 |
DOMTimer::removeById(context, timeoutId); |
0 | 1324 |
} |
1325 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1326 |
int DOMWindow::setInterval(PassOwnPtr<ScheduledAction> action, int timeout, ExceptionCode& ec) |
0 | 1327 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1328 |
ScriptExecutionContext* context = scriptExecutionContext(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1329 |
if (!context) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1330 |
ec = INVALID_ACCESS_ERR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1331 |
return -1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1332 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1333 |
return DOMTimer::install(context, action, timeout, false); |
0 | 1334 |
} |
1335 |
||
1336 |
void DOMWindow::clearInterval(int timeoutId) |
|
1337 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1338 |
ScriptExecutionContext* context = scriptExecutionContext(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1339 |
if (!context) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1340 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1341 |
DOMTimer::removeById(context, timeoutId); |
0 | 1342 |
} |
1343 |
||
1344 |
bool DOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture) |
|
1345 |
{ |
|
1346 |
if (!EventTarget::addEventListener(eventType, listener, useCapture)) |
|
1347 |
return false; |
|
1348 |
||
1349 |
if (Document* document = this->document()) |
|
1350 |
document->addListenerTypeIfNeeded(eventType); |
|
1351 |
||
1352 |
if (eventType == eventNames().unloadEvent) |
|
1353 |
addUnloadEventListener(this); |
|
1354 |
else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this)) |
|
1355 |
addBeforeUnloadEventListener(this); |
|
1356 |
||
1357 |
return true; |
|
1358 |
} |
|
1359 |
||
1360 |
bool DOMWindow::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture) |
|
1361 |
{ |
|
1362 |
if (!EventTarget::removeEventListener(eventType, listener, useCapture)) |
|
1363 |
return false; |
|
1364 |
||
1365 |
if (eventType == eventNames().unloadEvent) |
|
1366 |
removeUnloadEventListener(this); |
|
1367 |
else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this)) |
|
1368 |
removeBeforeUnloadEventListener(this); |
|
1369 |
||
1370 |
return true; |
|
1371 |
} |
|
1372 |
||
1373 |
void DOMWindow::dispatchLoadEvent() |
|
1374 |
{ |
|
1375 |
dispatchEvent(Event::create(eventNames().loadEvent, false, false), document()); |
|
1376 |
||
1377 |
// For load events, send a separate load event to the enclosing frame only. |
|
1378 |
// This is a DOM extension and is independent of bubbling/capturing rules of |
|
1379 |
// the DOM. |
|
1380 |
Element* ownerElement = document()->ownerElement(); |
|
1381 |
if (ownerElement) { |
|
1382 |
RefPtr<Event> ownerEvent = Event::create(eventNames().loadEvent, false, false); |
|
1383 |
ownerEvent->setTarget(ownerElement); |
|
1384 |
ownerElement->dispatchGenericEvent(ownerEvent.release()); |
|
1385 |
} |
|
1386 |
||
1387 |
#if ENABLE(INSPECTOR) |
|
1388 |
if (!frame() || !frame()->page()) |
|
1389 |
return; |
|
1390 |
||
1391 |
if (InspectorController* controller = frame()->page()->inspectorController()) |
|
1392 |
controller->mainResourceFiredLoadEvent(frame()->loader()->documentLoader(), url()); |
|
1393 |
#endif |
|
1394 |
} |
|
1395 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1396 |
#if ENABLE(INSPECTOR) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1397 |
InspectorTimelineAgent* DOMWindow::inspectorTimelineAgent() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1398 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1399 |
if (frame() && frame()->page()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1400 |
return frame()->page()->inspectorTimelineAgent(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1401 |
return 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1402 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1403 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1404 |
|
0 | 1405 |
bool DOMWindow::dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget) |
1406 |
{ |
|
1407 |
RefPtr<EventTarget> protect = this; |
|
1408 |
RefPtr<Event> event = prpEvent; |
|
1409 |
||
1410 |
event->setTarget(prpTarget ? prpTarget : this); |
|
1411 |
event->setCurrentTarget(this); |
|
1412 |
event->setEventPhase(Event::AT_TARGET); |
|
1413 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1414 |
#if ENABLE(INSPECTOR) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1415 |
InspectorTimelineAgent* timelineAgent = inspectorTimelineAgent(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1416 |
bool timelineAgentIsActive = timelineAgent && hasEventListeners(event->type()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1417 |
if (timelineAgentIsActive) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1418 |
timelineAgent->willDispatchEvent(*event); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1419 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1420 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1421 |
bool result = fireEventListeners(event.get()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1422 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1423 |
#if ENABLE(INSPECTOR) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1424 |
if (timelineAgentIsActive) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1425 |
timelineAgent = inspectorTimelineAgent(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1426 |
if (timelineAgent) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1427 |
timelineAgent->didDispatchEvent(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1428 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1429 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1430 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1431 |
return result; |
0 | 1432 |
} |
1433 |
||
1434 |
void DOMWindow::removeAllEventListeners() |
|
1435 |
{ |
|
1436 |
EventTarget::removeAllEventListeners(); |
|
1437 |
||
1438 |
removeAllUnloadEventListeners(this); |
|
1439 |
removeAllBeforeUnloadEventListeners(this); |
|
1440 |
} |
|
1441 |
||
1442 |
void DOMWindow::captureEvents() |
|
1443 |
{ |
|
1444 |
// Not implemented. |
|
1445 |
} |
|
1446 |
||
1447 |
void DOMWindow::releaseEvents() |
|
1448 |
{ |
|
1449 |
// Not implemented. |
|
1450 |
} |
|
1451 |
||
1452 |
EventTargetData* DOMWindow::eventTargetData() |
|
1453 |
{ |
|
1454 |
return &m_eventTargetData; |
|
1455 |
} |
|
1456 |
||
1457 |
EventTargetData* DOMWindow::ensureEventTargetData() |
|
1458 |
{ |
|
1459 |
return &m_eventTargetData; |
|
1460 |
} |
|
1461 |
||
1462 |
} // namespace WebCore |