Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Side by Side Diff: Source/core/frame/DOMWindow.cpp

Issue 176763009: Have DOMWindow deal with references instead of pointers when possible (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/frame/DOMWindow.h ('k') | Source/core/html/HTMLFormElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 #include "wtf/text/WTFString.h" 105 #include "wtf/text/WTFString.h"
106 #include <algorithm> 106 #include <algorithm>
107 107
108 using std::min; 108 using std::min;
109 using std::max; 109 using std::max;
110 110
111 namespace WebCore { 111 namespace WebCore {
112 112
113 class PostMessageTimer FINAL : public SuspendableTimer { 113 class PostMessageTimer FINAL : public SuspendableTimer {
114 public: 114 public:
115 PostMessageTimer(DOMWindow* window, PassRefPtr<SerializedScriptValue> messag e, const String& sourceOrigin, PassRefPtr<DOMWindow> source, PassOwnPtr<MessageP ortChannelArray> channels, SecurityOrigin* targetOrigin, PassRefPtr<ScriptCallSt ack> stackTrace) 115 PostMessageTimer(DOMWindow& window, PassRefPtr<SerializedScriptValue> messag e, const String& sourceOrigin, PassRefPtr<DOMWindow> source, PassOwnPtr<MessageP ortChannelArray> channels, SecurityOrigin* targetOrigin, PassRefPtr<ScriptCallSt ack> stackTrace)
116 : SuspendableTimer(window->document()) 116 : SuspendableTimer(window.document())
117 , m_window(window) 117 , m_window(window)
118 , m_message(message) 118 , m_message(message)
119 , m_origin(sourceOrigin) 119 , m_origin(sourceOrigin)
120 , m_source(source) 120 , m_source(source)
121 , m_channels(channels) 121 , m_channels(channels)
122 , m_targetOrigin(targetOrigin) 122 , m_targetOrigin(targetOrigin)
123 , m_stackTrace(stackTrace) 123 , m_stackTrace(stackTrace)
124 { 124 {
125 } 125 }
126 126
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 { 245 {
246 return windowsWithUnloadEventListeners().count(const_cast<DOMWindow*>(this)) ; 246 return windowsWithUnloadEventListeners().count(const_cast<DOMWindow*>(this)) ;
247 } 247 }
248 248
249 // This function: 249 // This function:
250 // 1) Validates the pending changes are not changing any value to NaN; in that c ase keep original value. 250 // 1) Validates the pending changes are not changing any value to NaN; in that c ase keep original value.
251 // 2) Constrains the window rect to the minimum window size and no bigger than t he float rect's dimensions. 251 // 2) Constrains the window rect to the minimum window size and no bigger than t he float rect's dimensions.
252 // 3) Constrains the window rect to within the top and left boundaries of the av ailable screen rect. 252 // 3) Constrains the window rect to within the top and left boundaries of the av ailable screen rect.
253 // 4) Constrains the window rect to within the bottom and right boundaries of th e available screen rect. 253 // 4) Constrains the window rect to within the bottom and right boundaries of th e available screen rect.
254 // 5) Translate the window rect coordinates to be within the coordinate space of the screen. 254 // 5) Translate the window rect coordinates to be within the coordinate space of the screen.
255 FloatRect DOMWindow::adjustWindowRect(LocalFrame* frame, const FloatRect& pendin gChanges) 255 FloatRect DOMWindow::adjustWindowRect(LocalFrame& frame, const FloatRect& pendin gChanges)
256 { 256 {
257 ASSERT(frame); 257 FrameHost* host = frame.host();
258 FrameHost* host = frame->host();
259 ASSERT(host); 258 ASSERT(host);
260 259
261 FloatRect screen = screenAvailableRect(frame->view()); 260 FloatRect screen = screenAvailableRect(frame.view());
262 FloatRect window = host->chrome().windowRect(); 261 FloatRect window = host->chrome().windowRect();
263 262
264 // Make sure we're in a valid state before adjusting dimensions. 263 // Make sure we're in a valid state before adjusting dimensions.
265 ASSERT(std::isfinite(screen.x())); 264 ASSERT(std::isfinite(screen.x()));
266 ASSERT(std::isfinite(screen.y())); 265 ASSERT(std::isfinite(screen.y()));
267 ASSERT(std::isfinite(screen.width())); 266 ASSERT(std::isfinite(screen.width()));
268 ASSERT(std::isfinite(screen.height())); 267 ASSERT(std::isfinite(screen.height()));
269 ASSERT(std::isfinite(window.x())); 268 ASSERT(std::isfinite(window.x()));
270 ASSERT(std::isfinite(window.y())); 269 ASSERT(std::isfinite(window.y()));
271 ASSERT(std::isfinite(window.width())); 270 ASSERT(std::isfinite(window.width()));
(...skipping 16 matching lines...) Expand all
288 if (window.height()) 287 if (window.height())
289 window.setHeight(min(max(minimumSize.height(), window.height()), screen. height())); 288 window.setHeight(min(max(minimumSize.height(), window.height()), screen. height()));
290 289
291 // Constrain the window position within the valid screen area. 290 // Constrain the window position within the valid screen area.
292 window.setX(max(screen.x(), min(window.x(), screen.maxX() - window.width())) ); 291 window.setX(max(screen.x(), min(window.x(), screen.maxX() - window.width())) );
293 window.setY(max(screen.y(), min(window.y(), screen.maxY() - window.height()) )); 292 window.setY(max(screen.y(), min(window.y(), screen.maxY() - window.height()) ));
294 293
295 return window; 294 return window;
296 } 295 }
297 296
298 bool DOMWindow::allowPopUp(LocalFrame* firstFrame) 297 bool DOMWindow::allowPopUp(LocalFrame& firstFrame)
299 { 298 {
300 ASSERT(firstFrame);
301
302 if (UserGestureIndicator::processingUserGesture()) 299 if (UserGestureIndicator::processingUserGesture())
303 return true; 300 return true;
304 301
305 Settings* settings = firstFrame->settings(); 302 Settings* settings = firstFrame.settings();
306 return settings && settings->javaScriptCanOpenWindowsAutomatically(); 303 return settings && settings->javaScriptCanOpenWindowsAutomatically();
307 } 304 }
308 305
309 bool DOMWindow::allowPopUp() 306 bool DOMWindow::allowPopUp()
310 { 307 {
311 return m_frame && allowPopUp(m_frame); 308 return m_frame && allowPopUp(*m_frame);
312 } 309 }
313 310
314 DOMWindow::DOMWindow(LocalFrame* frame) 311 DOMWindow::DOMWindow(LocalFrame& frame)
315 : FrameDestructionObserver(frame) 312 : FrameDestructionObserver(&frame)
316 , m_shouldPrintWhenFinishedLoading(false) 313 , m_shouldPrintWhenFinishedLoading(false)
317 { 314 {
318 ASSERT(frame);
319 ScriptWrappable::init(this); 315 ScriptWrappable::init(this);
320 } 316 }
321 317
322 void DOMWindow::clearDocument() 318 void DOMWindow::clearDocument()
323 { 319 {
324 if (!m_document) 320 if (!m_document)
325 return; 321 return;
326 322
327 if (m_document->isActive()) { 323 if (m_document->isActive()) {
328 // FIXME: We don't call willRemove here. Why is that OK? 324 // FIXME: We don't call willRemove here. Why is that OK?
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 { 440 {
445 enqueueWindowEvent(HashChangeEvent::create(oldURL, newURL)); 441 enqueueWindowEvent(HashChangeEvent::create(oldURL, newURL));
446 } 442 }
447 443
448 void DOMWindow::enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObje ct) 444 void DOMWindow::enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObje ct)
449 { 445 {
450 if (!ContextFeatures::pushStateEnabled(document())) 446 if (!ContextFeatures::pushStateEnabled(document()))
451 return; 447 return;
452 448
453 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=36202 Popstate event needs to fire asynchronously 449 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=36202 Popstate event needs to fire asynchronously
454 dispatchEvent(PopStateEvent::create(stateObject, history())); 450 dispatchEvent(PopStateEvent::create(stateObject, &history()));
455 } 451 }
456 452
457 void DOMWindow::statePopped(PassRefPtr<SerializedScriptValue> stateObject) 453 void DOMWindow::statePopped(PassRefPtr<SerializedScriptValue> stateObject)
458 { 454 {
459 if (!frame()) 455 if (!frame())
460 return; 456 return;
461 457
462 // Per step 11 of section 6.5.9 (history traversal) of the HTML5 spec, we 458 // Per step 11 of section 6.5.9 (history traversal) of the HTML5 spec, we
463 // defer firing of popstate until we're in the complete state. 459 // defer firing of popstate until we're in the complete state.
464 if (document()->isLoadCompleted()) 460 if (document()->isLoadCompleted())
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 int DOMWindow::orientation() const 592 int DOMWindow::orientation() const
597 { 593 {
598 ASSERT(RuntimeEnabledFeatures::orientationEventEnabled()); 594 ASSERT(RuntimeEnabledFeatures::orientationEventEnabled());
599 595
600 if (!m_frame) 596 if (!m_frame)
601 return 0; 597 return 0;
602 598
603 return m_frame->orientation(); 599 return m_frame->orientation();
604 } 600 }
605 601
606 Screen* DOMWindow::screen() const 602 Screen& DOMWindow::screen() const
607 { 603 {
608 if (!m_screen) 604 if (!m_screen)
609 m_screen = Screen::create(m_frame); 605 m_screen = Screen::create(m_frame);
610 return m_screen.get(); 606 return *m_screen;
611 } 607 }
612 608
613 History* DOMWindow::history() const 609 History& DOMWindow::history() const
614 { 610 {
615 if (!m_history) 611 if (!m_history)
616 m_history = History::create(m_frame); 612 m_history = History::create(m_frame);
617 return m_history.get(); 613 return *m_history;
618 } 614 }
619 615
620 BarProp* DOMWindow::locationbar() const 616 BarProp& DOMWindow::locationbar() const
621 { 617 {
622 UseCounter::count(document(), UseCounter::BarPropLocationbar); 618 UseCounter::count(document(), UseCounter::BarPropLocationbar);
623 if (!m_locationbar) 619 if (!m_locationbar)
624 m_locationbar = BarProp::create(m_frame, BarProp::Locationbar); 620 m_locationbar = BarProp::create(m_frame, BarProp::Locationbar);
625 return m_locationbar.get(); 621 return *m_locationbar;
626 } 622 }
627 623
628 BarProp* DOMWindow::menubar() const 624 BarProp& DOMWindow::menubar() const
629 { 625 {
630 UseCounter::count(document(), UseCounter::BarPropMenubar); 626 UseCounter::count(document(), UseCounter::BarPropMenubar);
631 if (!m_menubar) 627 if (!m_menubar)
632 m_menubar = BarProp::create(m_frame, BarProp::Menubar); 628 m_menubar = BarProp::create(m_frame, BarProp::Menubar);
633 return m_menubar.get(); 629 return *m_menubar;
634 } 630 }
635 631
636 BarProp* DOMWindow::personalbar() const 632 BarProp& DOMWindow::personalbar() const
637 { 633 {
638 UseCounter::count(document(), UseCounter::BarPropPersonalbar); 634 UseCounter::count(document(), UseCounter::BarPropPersonalbar);
639 if (!m_personalbar) 635 if (!m_personalbar)
640 m_personalbar = BarProp::create(m_frame, BarProp::Personalbar); 636 m_personalbar = BarProp::create(m_frame, BarProp::Personalbar);
641 return m_personalbar.get(); 637 return *m_personalbar;
642 } 638 }
643 639
644 BarProp* DOMWindow::scrollbars() const 640 BarProp& DOMWindow::scrollbars() const
645 { 641 {
646 UseCounter::count(document(), UseCounter::BarPropScrollbars); 642 UseCounter::count(document(), UseCounter::BarPropScrollbars);
647 if (!m_scrollbars) 643 if (!m_scrollbars)
648 m_scrollbars = BarProp::create(m_frame, BarProp::Scrollbars); 644 m_scrollbars = BarProp::create(m_frame, BarProp::Scrollbars);
649 return m_scrollbars.get(); 645 return *m_scrollbars;
650 } 646 }
651 647
652 BarProp* DOMWindow::statusbar() const 648 BarProp& DOMWindow::statusbar() const
653 { 649 {
654 UseCounter::count(document(), UseCounter::BarPropStatusbar); 650 UseCounter::count(document(), UseCounter::BarPropStatusbar);
655 if (!m_statusbar) 651 if (!m_statusbar)
656 m_statusbar = BarProp::create(m_frame, BarProp::Statusbar); 652 m_statusbar = BarProp::create(m_frame, BarProp::Statusbar);
657 return m_statusbar.get(); 653 return *m_statusbar;
658 } 654 }
659 655
660 BarProp* DOMWindow::toolbar() const 656 BarProp& DOMWindow::toolbar() const
661 { 657 {
662 UseCounter::count(document(), UseCounter::BarPropToolbar); 658 UseCounter::count(document(), UseCounter::BarPropToolbar);
663 if (!m_toolbar) 659 if (!m_toolbar)
664 m_toolbar = BarProp::create(m_frame, BarProp::Toolbar); 660 m_toolbar = BarProp::create(m_frame, BarProp::Toolbar);
665 return m_toolbar.get(); 661 return *m_toolbar;
666 } 662 }
667 663
668 Console* DOMWindow::console() const 664 Console& DOMWindow::console() const
669 { 665 {
670 if (!m_console) 666 if (!m_console)
671 m_console = Console::create(m_frame); 667 m_console = Console::create(m_frame);
672 return m_console.get(); 668 return *m_console;
673 } 669 }
674 670
675 PageConsole* DOMWindow::pageConsole() const 671 PageConsole* DOMWindow::pageConsole() const
676 { 672 {
677 if (!isCurrentlyDisplayedInFrame()) 673 if (!isCurrentlyDisplayedInFrame())
678 return 0; 674 return 0;
679 return m_frame->host() ? &m_frame->host()->console() : 0; 675 return m_frame->host() ? &m_frame->host()->console() : 0;
680 } 676 }
681 677
682 ApplicationCache* DOMWindow::applicationCache() const 678 ApplicationCache* DOMWindow::applicationCache() const
683 { 679 {
684 if (!isCurrentlyDisplayedInFrame()) 680 if (!isCurrentlyDisplayedInFrame())
685 return 0; 681 return 0;
686 if (!m_applicationCache) 682 if (!m_applicationCache)
687 m_applicationCache = ApplicationCache::create(m_frame); 683 m_applicationCache = ApplicationCache::create(m_frame);
688 return m_applicationCache.get(); 684 return m_applicationCache.get();
689 } 685 }
690 686
691 Navigator* DOMWindow::navigator() const 687 Navigator& DOMWindow::navigator() const
692 { 688 {
693 if (!m_navigator) 689 if (!m_navigator)
694 m_navigator = Navigator::create(m_frame); 690 m_navigator = Navigator::create(m_frame);
695 return m_navigator.get(); 691 return *m_navigator;
696 } 692 }
697 693
698 Performance* DOMWindow::performance() const 694 Performance& DOMWindow::performance() const
699 { 695 {
700 if (!m_performance) 696 if (!m_performance)
701 m_performance = Performance::create(m_frame); 697 m_performance = Performance::create(m_frame);
702 return m_performance.get(); 698 return *m_performance;
703 } 699 }
704 700
705 Location* DOMWindow::location() const 701 Location& DOMWindow::location() const
706 { 702 {
707 if (!m_location) 703 if (!m_location)
708 m_location = Location::create(m_frame); 704 m_location = Location::create(m_frame);
709 return m_location.get(); 705 return *m_location;
710 } 706 }
711 707
712 Storage* DOMWindow::sessionStorage(ExceptionState& exceptionState) const 708 Storage* DOMWindow::sessionStorage(ExceptionState& exceptionState) const
713 { 709 {
714 if (!isCurrentlyDisplayedInFrame()) 710 if (!isCurrentlyDisplayedInFrame())
715 return 0; 711 return 0;
716 712
717 Document* document = this->document(); 713 Document* document = this->document();
718 if (!document) 714 if (!document)
719 return 0; 715 return 0;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 if (!sourceDocument) 823 if (!sourceDocument)
828 return; 824 return;
829 String sourceOrigin = sourceDocument->securityOrigin()->toString(); 825 String sourceOrigin = sourceDocument->securityOrigin()->toString();
830 826
831 // Capture stack trace only when inspector front-end is loaded as it may be time consuming. 827 // Capture stack trace only when inspector front-end is loaded as it may be time consuming.
832 RefPtr<ScriptCallStack> stackTrace; 828 RefPtr<ScriptCallStack> stackTrace;
833 if (InspectorInstrumentation::consoleAgentEnabled(sourceDocument)) 829 if (InspectorInstrumentation::consoleAgentEnabled(sourceDocument))
834 stackTrace = createScriptCallStack(ScriptCallStack::maxCallStackSizeToCa pture, true); 830 stackTrace = createScriptCallStack(ScriptCallStack::maxCallStackSizeToCa pture, true);
835 831
836 // Schedule the message. 832 // Schedule the message.
837 PostMessageTimer* timer = new PostMessageTimer(this, message, sourceOrigin, source, channels.release(), target.get(), stackTrace.release()); 833 PostMessageTimer* timer = new PostMessageTimer(*this, message, sourceOrigin, source, channels.release(), target.get(), stackTrace.release());
838 timer->startOneShot(0); 834 timer->startOneShot(0);
839 timer->suspendIfNeeded(); 835 timer->suspendIfNeeded();
840 } 836 }
841 837
842 void DOMWindow::postMessageTimerFired(PassOwnPtr<PostMessageTimer> t) 838 void DOMWindow::postMessageTimerFired(PassOwnPtr<PostMessageTimer> t)
843 { 839 {
844 OwnPtr<PostMessageTimer> timer(t); 840 OwnPtr<PostMessageTimer> timer(t);
845 841
846 if (!isCurrentlyDisplayedInFrame()) 842 if (!isCurrentlyDisplayedInFrame())
847 return; 843 return;
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 return 0; 1254 return 0;
1259 1255
1260 return m_frame->tree().top()->domWindow(); 1256 return m_frame->tree().top()->domWindow();
1261 } 1257 }
1262 1258
1263 Document* DOMWindow::document() const 1259 Document* DOMWindow::document() const
1264 { 1260 {
1265 return m_document.get(); 1261 return m_document.get();
1266 } 1262 }
1267 1263
1268 PassRefPtr<StyleMedia> DOMWindow::styleMedia() const 1264 StyleMedia& DOMWindow::styleMedia() const
1269 { 1265 {
1270 if (!m_media) 1266 if (!m_media)
1271 m_media = StyleMedia::create(m_frame); 1267 m_media = StyleMedia::create(m_frame);
1272 return m_media.get(); 1268 return *m_media;
1273 } 1269 }
1274 1270
1275 PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* elt, const String& pseudoElt) const 1271 PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* elt, const String& pseudoElt) const
1276 { 1272 {
1277 if (!elt) 1273 if (!elt)
1278 return nullptr; 1274 return nullptr;
1279 1275
1280 return CSSComputedStyleDeclaration::create(elt, false, pseudoElt); 1276 return CSSComputedStyleDeclaration::create(elt, false, pseudoElt);
1281 } 1277 }
1282 1278
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 if (!m_frame || !m_frame->isMainFrame()) 1393 if (!m_frame || !m_frame->isMainFrame())
1398 return; 1394 return;
1399 1395
1400 FrameHost* host = m_frame->host(); 1396 FrameHost* host = m_frame->host();
1401 if (!host) 1397 if (!host)
1402 return; 1398 return;
1403 1399
1404 FloatRect windowRect = host->chrome().windowRect(); 1400 FloatRect windowRect = host->chrome().windowRect();
1405 windowRect.move(x, y); 1401 windowRect.move(x, y);
1406 // Security check (the spec talks about UniversalBrowserWrite to disable thi s check...) 1402 // Security check (the spec talks about UniversalBrowserWrite to disable thi s check...)
1407 host->chrome().setWindowRect(adjustWindowRect(m_frame, windowRect)); 1403 host->chrome().setWindowRect(adjustWindowRect(*m_frame, windowRect));
1408 } 1404 }
1409 1405
1410 void DOMWindow::moveTo(float x, float y) const 1406 void DOMWindow::moveTo(float x, float y) const
1411 { 1407 {
1412 if (!m_frame || !m_frame->isMainFrame()) 1408 if (!m_frame || !m_frame->isMainFrame())
1413 return; 1409 return;
1414 1410
1415 FrameHost* host = m_frame->host(); 1411 FrameHost* host = m_frame->host();
1416 if (!host) 1412 if (!host)
1417 return; 1413 return;
1418 1414
1419 FloatRect windowRect = host->chrome().windowRect(); 1415 FloatRect windowRect = host->chrome().windowRect();
1420 windowRect.setLocation(FloatPoint(x, y)); 1416 windowRect.setLocation(FloatPoint(x, y));
1421 // Security check (the spec talks about UniversalBrowserWrite to disable thi s check...) 1417 // Security check (the spec talks about UniversalBrowserWrite to disable thi s check...)
1422 host->chrome().setWindowRect(adjustWindowRect(m_frame, windowRect)); 1418 host->chrome().setWindowRect(adjustWindowRect(*m_frame, windowRect));
1423 } 1419 }
1424 1420
1425 void DOMWindow::resizeBy(float x, float y) const 1421 void DOMWindow::resizeBy(float x, float y) const
1426 { 1422 {
1427 if (!m_frame || !m_frame->isMainFrame()) 1423 if (!m_frame || !m_frame->isMainFrame())
1428 return; 1424 return;
1429 1425
1430 FrameHost* host = m_frame->host(); 1426 FrameHost* host = m_frame->host();
1431 if (!host) 1427 if (!host)
1432 return; 1428 return;
1433 1429
1434 FloatRect fr = host->chrome().windowRect(); 1430 FloatRect fr = host->chrome().windowRect();
1435 FloatSize dest = fr.size() + FloatSize(x, y); 1431 FloatSize dest = fr.size() + FloatSize(x, y);
1436 FloatRect update(fr.location(), dest); 1432 FloatRect update(fr.location(), dest);
1437 host->chrome().setWindowRect(adjustWindowRect(m_frame, update)); 1433 host->chrome().setWindowRect(adjustWindowRect(*m_frame, update));
1438 } 1434 }
1439 1435
1440 void DOMWindow::resizeTo(float width, float height) const 1436 void DOMWindow::resizeTo(float width, float height) const
1441 { 1437 {
1442 if (!m_frame || !m_frame->isMainFrame()) 1438 if (!m_frame || !m_frame->isMainFrame())
1443 return; 1439 return;
1444 1440
1445 FrameHost* host = m_frame->host(); 1441 FrameHost* host = m_frame->host();
1446 if (!host) 1442 if (!host)
1447 return; 1443 return;
1448 1444
1449 FloatRect fr = host->chrome().windowRect(); 1445 FloatRect fr = host->chrome().windowRect();
1450 FloatSize dest = FloatSize(width, height); 1446 FloatSize dest = FloatSize(width, height);
1451 FloatRect update(fr.location(), dest); 1447 FloatRect update(fr.location(), dest);
1452 host->chrome().setWindowRect(adjustWindowRect(m_frame, update)); 1448 host->chrome().setWindowRect(adjustWindowRect(*m_frame, update));
1453 } 1449 }
1454 1450
1455 int DOMWindow::requestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback> c allback) 1451 int DOMWindow::requestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback> c allback)
1456 { 1452 {
1457 callback->m_useLegacyTimeBase = false; 1453 callback->m_useLegacyTimeBase = false;
1458 if (Document* d = document()) 1454 if (Document* d = document())
1459 return d->requestAnimationFrame(callback); 1455 return d->requestAnimationFrame(callback);
1460 return 0; 1456 return 0;
1461 } 1457 }
1462 1458
1463 int DOMWindow::webkitRequestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallb ack> callback) 1459 int DOMWindow::webkitRequestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallb ack> callback)
1464 { 1460 {
1465 callback->m_useLegacyTimeBase = true; 1461 callback->m_useLegacyTimeBase = true;
1466 if (Document* d = document()) 1462 if (Document* d = document())
1467 return d->requestAnimationFrame(callback); 1463 return d->requestAnimationFrame(callback);
1468 return 0; 1464 return 0;
1469 } 1465 }
1470 1466
1471 void DOMWindow::cancelAnimationFrame(int id) 1467 void DOMWindow::cancelAnimationFrame(int id)
1472 { 1468 {
1473 if (Document* d = document()) 1469 if (Document* d = document())
1474 d->cancelAnimationFrame(id); 1470 d->cancelAnimationFrame(id);
1475 } 1471 }
1476 1472
1477 DOMWindowCSS* DOMWindow::css() 1473 DOMWindowCSS& DOMWindow::css() const
1478 { 1474 {
1479 if (!m_css) 1475 if (!m_css)
1480 m_css = DOMWindowCSS::create(); 1476 m_css = DOMWindowCSS::create();
1481 return m_css.get(); 1477 return *m_css;
1482 } 1478 }
1483 1479
1484 static void didAddStorageEventListener(DOMWindow* window) 1480 static void didAddStorageEventListener(DOMWindow* window)
1485 { 1481 {
1486 // Creating these WebCore::Storage objects informs the system that we'd like to receive 1482 // Creating these WebCore::Storage objects informs the system that we'd like to receive
1487 // notifications about storage events that might be triggered in other proce sses. Rather 1483 // notifications about storage events that might be triggered in other proce sses. Rather
1488 // than subscribe to these notifications explicitly, we subscribe to them im plicitly to 1484 // than subscribe to these notifications explicitly, we subscribe to them im plicitly to
1489 // simplify the work done by the system. 1485 // simplify the work done by the system.
1490 window->localStorage(IGNORE_EXCEPTION); 1486 window->localStorage(IGNORE_EXCEPTION);
1491 window->sessionStorage(IGNORE_EXCEPTION); 1487 window->sessionStorage(IGNORE_EXCEPTION);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 return; 1620 return;
1625 1621
1626 LocalFrame* firstFrame = enteredWindow->frame(); 1622 LocalFrame* firstFrame = enteredWindow->frame();
1627 if (!firstFrame) 1623 if (!firstFrame)
1628 return; 1624 return;
1629 1625
1630 KURL completedURL = firstFrame->document()->completeURL(urlString); 1626 KURL completedURL = firstFrame->document()->completeURL(urlString);
1631 if (completedURL.isNull()) 1627 if (completedURL.isNull())
1632 return; 1628 return;
1633 1629
1634 if (isInsecureScriptAccess(callingWindow, completedURL)) 1630 if (isInsecureScriptAccess(*callingWindow, completedURL))
1635 return; 1631 return;
1636 1632
1637 // We want a new history item if we are processing a user gesture. 1633 // We want a new history item if we are processing a user gesture.
1638 m_frame->navigationScheduler().scheduleLocationChange(activeDocument, 1634 m_frame->navigationScheduler().scheduleLocationChange(activeDocument,
1639 // FIXME: What if activeDocument()->frame() is 0? 1635 // FIXME: What if activeDocument()->frame() is 0?
1640 completedURL, Referrer(activeDocument->outgoingReferrer(), activeDocumen t->referrerPolicy()), 1636 completedURL, Referrer(activeDocument->outgoingReferrer(), activeDocumen t->referrerPolicy()),
1641 locking != LockHistoryBasedOnGestureState); 1637 locking != LockHistoryBasedOnGestureState);
1642 } 1638 }
1643 1639
1644 void DOMWindow::printErrorMessage(const String& message) 1640 void DOMWindow::printErrorMessage(const String& message)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", the frame being accessed set it to \"" + ta rgetOrigin->domain() + "\". Both must set \"document.domain\" to the same value to allow access."; 1706 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", the frame being accessed set it to \"" + ta rgetOrigin->domain() + "\". Both must set \"document.domain\" to the same value to allow access.";
1711 if (activeOrigin->domainWasSetInDOM()) 1707 if (activeOrigin->domainWasSetInDOM())
1712 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", but the frame being accessed did not. Both must set \"document.domain\" to the same value to allow access."; 1708 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", but the frame being accessed did not. Both must set \"document.domain\" to the same value to allow access.";
1713 if (targetOrigin->domainWasSetInDOM()) 1709 if (targetOrigin->domainWasSetInDOM())
1714 return message + "The frame being accessed set \"document.domain\" to \" " + targetOrigin->domain() + "\", but the frame requesting access did not. Both must set \"document.domain\" to the same value to allow access."; 1710 return message + "The frame being accessed set \"document.domain\" to \" " + targetOrigin->domain() + "\", but the frame requesting access did not. Both must set \"document.domain\" to the same value to allow access.";
1715 1711
1716 // Default. 1712 // Default.
1717 return message + "Protocols, domains, and ports must match."; 1713 return message + "Protocols, domains, and ports must match.";
1718 } 1714 }
1719 1715
1720 bool DOMWindow::isInsecureScriptAccess(DOMWindow* callingWindow, const String& u rlString) 1716 bool DOMWindow::isInsecureScriptAccess(DOMWindow& callingWindow, const String& u rlString)
1721 { 1717 {
1722 if (!protocolIsJavaScript(urlString)) 1718 if (!protocolIsJavaScript(urlString))
1723 return false; 1719 return false;
1724 1720
1725 // If this DOMWindow isn't currently active in the LocalFrame, then there's no 1721 // If this DOMWindow isn't currently active in the LocalFrame, then there's no
1726 // way we should allow the access. 1722 // way we should allow the access.
1727 // FIXME: Remove this check if we're able to disconnect DOMWindow from 1723 // FIXME: Remove this check if we're able to disconnect DOMWindow from
1728 // LocalFrame on navigation: https://bugs.webkit.org/show_bug.cgi?id=62054 1724 // LocalFrame on navigation: https://bugs.webkit.org/show_bug.cgi?id=62054
1729 if (isCurrentlyDisplayedInFrame()) { 1725 if (isCurrentlyDisplayedInFrame()) {
1730 // FIXME: Is there some way to eliminate the need for a separate "callin gWindow == this" check? 1726 // FIXME: Is there some way to eliminate the need for a separate "callin gWindow == this" check?
1731 if (callingWindow == this) 1727 if (&callingWindow == this)
1732 return false; 1728 return false;
1733 1729
1734 // FIXME: The name canAccess seems to be a roundabout way to ask "can ex ecute script". 1730 // FIXME: The name canAccess seems to be a roundabout way to ask "can ex ecute script".
1735 // Can we name the SecurityOrigin function better to make this more clea r? 1731 // Can we name the SecurityOrigin function better to make this more clea r?
1736 if (callingWindow->document()->securityOrigin()->canAccess(document()->s ecurityOrigin())) 1732 if (callingWindow.document()->securityOrigin()->canAccess(document()->se curityOrigin()))
1737 return false; 1733 return false;
1738 } 1734 }
1739 1735
1740 printErrorMessage(crossDomainAccessErrorMessage(callingWindow)); 1736 printErrorMessage(crossDomainAccessErrorMessage(&callingWindow));
1741 return true; 1737 return true;
1742 } 1738 }
1743 1739
1744 PassRefPtr<DOMWindow> DOMWindow::open(const String& urlString, const AtomicStrin g& frameName, const String& windowFeaturesString, 1740 PassRefPtr<DOMWindow> DOMWindow::open(const String& urlString, const AtomicStrin g& frameName, const String& windowFeaturesString,
1745 DOMWindow* callingWindow, DOMWindow* enteredWindow) 1741 DOMWindow* callingWindow, DOMWindow* enteredWindow)
1746 { 1742 {
1747 if (!isCurrentlyDisplayedInFrame()) 1743 if (!isCurrentlyDisplayedInFrame())
1748 return nullptr; 1744 return nullptr;
1749 Document* activeDocument = callingWindow->document(); 1745 Document* activeDocument = callingWindow->document();
1750 if (!activeDocument) 1746 if (!activeDocument)
(...skipping 19 matching lines...) Expand all
1770 targetFrame = parent; 1766 targetFrame = parent;
1771 else 1767 else
1772 targetFrame = m_frame; 1768 targetFrame = m_frame;
1773 } 1769 }
1774 if (targetFrame) { 1770 if (targetFrame) {
1775 if (!activeDocument->canNavigate(targetFrame)) 1771 if (!activeDocument->canNavigate(targetFrame))
1776 return nullptr; 1772 return nullptr;
1777 1773
1778 KURL completedURL = firstFrame->document()->completeURL(urlString); 1774 KURL completedURL = firstFrame->document()->completeURL(urlString);
1779 1775
1780 if (targetFrame->domWindow()->isInsecureScriptAccess(callingWindow, comp letedURL)) 1776 if (targetFrame->domWindow()->isInsecureScriptAccess(*callingWindow, com pletedURL))
1781 return targetFrame->domWindow(); 1777 return targetFrame->domWindow();
1782 1778
1783 if (urlString.isEmpty()) 1779 if (urlString.isEmpty())
1784 return targetFrame->domWindow(); 1780 return targetFrame->domWindow();
1785 1781
1786 // For whatever reason, Firefox uses the first window rather than the ac tive window to 1782 // For whatever reason, Firefox uses the first window rather than the ac tive window to
1787 // determine the outgoing referrer. We replicate that behavior here. 1783 // determine the outgoing referrer. We replicate that behavior here.
1788 targetFrame->navigationScheduler().scheduleLocationChange( 1784 targetFrame->navigationScheduler().scheduleLocationChange(
1789 activeDocument, 1785 activeDocument,
1790 completedURL, 1786 completedURL,
1791 Referrer(firstFrame->document()->outgoingReferrer(), firstFrame->doc ument()->referrerPolicy()), 1787 Referrer(firstFrame->document()->outgoingReferrer(), firstFrame->doc ument()->referrerPolicy()),
1792 false); 1788 false);
1793 return targetFrame->domWindow(); 1789 return targetFrame->domWindow();
1794 } 1790 }
1795 1791
1796 WindowFeatures windowFeatures(windowFeaturesString); 1792 WindowFeatures windowFeatures(windowFeaturesString);
1797 LocalFrame* result = createWindow(urlString, frameName, windowFeatures, call ingWindow, firstFrame, m_frame); 1793 LocalFrame* result = createWindow(urlString, frameName, windowFeatures, *cal lingWindow, *firstFrame, *m_frame);
1798 return result ? result->domWindow() : 0; 1794 return result ? result->domWindow() : 0;
1799 } 1795 }
1800 1796
1801 DOMWindow* DOMWindow::anonymousIndexedGetter(uint32_t index) 1797 DOMWindow* DOMWindow::anonymousIndexedGetter(uint32_t index)
1802 { 1798 {
1803 LocalFrame* frame = this->frame(); 1799 LocalFrame* frame = this->frame();
1804 if (!frame) 1800 if (!frame)
1805 return 0; 1801 return 0;
1806 1802
1807 LocalFrame* child = frame->tree().scopedChild(index); 1803 LocalFrame* child = frame->tree().scopedChild(index);
1808 if (child) 1804 if (child)
1809 return child->domWindow(); 1805 return child->domWindow();
1810 1806
1811 return 0; 1807 return 0;
1812 } 1808 }
1813 1809
1814 DOMWindowLifecycleNotifier& DOMWindow::lifecycleNotifier() 1810 DOMWindowLifecycleNotifier& DOMWindow::lifecycleNotifier()
1815 { 1811 {
1816 return static_cast<DOMWindowLifecycleNotifier&>(LifecycleContext<DOMWindow>: :lifecycleNotifier()); 1812 return static_cast<DOMWindowLifecycleNotifier&>(LifecycleContext<DOMWindow>: :lifecycleNotifier());
1817 } 1813 }
1818 1814
1819 PassOwnPtr<LifecycleNotifier<DOMWindow> > DOMWindow::createLifecycleNotifier() 1815 PassOwnPtr<LifecycleNotifier<DOMWindow> > DOMWindow::createLifecycleNotifier()
1820 { 1816 {
1821 return DOMWindowLifecycleNotifier::create(this); 1817 return DOMWindowLifecycleNotifier::create(this);
1822 } 1818 }
1823 1819
1824 1820
1825 } // namespace WebCore 1821 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/frame/DOMWindow.h ('k') | Source/core/html/HTMLFormElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698