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

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

Issue 1148133005: Window.postMessage() to self can cause document leaks (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase to master Created 5 years, 6 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
« no previous file with comments | « Source/core/frame/LocalDOMWindow.h ('k') | no next file » | 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 , m_stackTrace(stackTrace) 119 , m_stackTrace(stackTrace)
120 , m_userGestureToken(userGestureToken) 120 , m_userGestureToken(userGestureToken)
121 { 121 {
122 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarti ng(executionContext(), "postMessage"); 122 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarti ng(executionContext(), "postMessage");
123 } 123 }
124 124
125 PassRefPtrWillBeRawPtr<MessageEvent> event() const { return m_event.get(); } 125 PassRefPtrWillBeRawPtr<MessageEvent> event() const { return m_event.get(); }
126 SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); } 126 SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); }
127 ScriptCallStack* stackTrace() const { return m_stackTrace.get(); } 127 ScriptCallStack* stackTrace() const { return m_stackTrace.get(); }
128 UserGestureToken* userGestureToken() const { return m_userGestureToken.get() ; } 128 UserGestureToken* userGestureToken() const { return m_userGestureToken.get() ; }
129 virtual void stop() override
130 {
131 SuspendableTimer::stop();
132 // Will destroy this object
133 m_window->removePostMessageTimer(this);
134 }
129 135
130 DEFINE_INLINE_VIRTUAL_TRACE() 136 DEFINE_INLINE_VIRTUAL_TRACE()
131 { 137 {
132 visitor->trace(m_event); 138 visitor->trace(m_event);
133 visitor->trace(m_window); 139 visitor->trace(m_window);
134 visitor->trace(m_stackTrace); 140 visitor->trace(m_stackTrace);
135 SuspendableTimer::trace(visitor); 141 SuspendableTimer::trace(visitor);
136 } 142 }
137 143
138 private: 144 private:
139 virtual void fired() override 145 virtual void fired() override
140 { 146 {
141 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceA syncOperationCompletedCallbackStarting(executionContext(), m_asyncOperationId); 147 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceA syncOperationCompletedCallbackStarting(executionContext(), m_asyncOperationId);
142 m_window->postMessageTimerFired(this); 148 m_window->postMessageTimerFired(this);
143 // This object is deleted now. 149 // Will destroy this object
150 m_window->removePostMessageTimer(this);
144 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); 151 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
145 } 152 }
146 153
147 RefPtrWillBeMember<MessageEvent> m_event; 154 RefPtrWillBeMember<MessageEvent> m_event;
148 RawPtrWillBeMember<LocalDOMWindow> m_window; 155 RawPtrWillBeMember<LocalDOMWindow> m_window;
149 RefPtr<SecurityOrigin> m_targetOrigin; 156 RefPtr<SecurityOrigin> m_targetOrigin;
150 RefPtrWillBeMember<ScriptCallStack> m_stackTrace; 157 RefPtrWillBeMember<ScriptCallStack> m_stackTrace;
151 RefPtr<UserGestureToken> m_userGestureToken; 158 RefPtr<UserGestureToken> m_userGestureToken;
152 int m_asyncOperationId; 159 int m_asyncOperationId;
153 }; 160 };
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 // Schedule the message. 660 // Schedule the message.
654 OwnPtrWillBeRawPtr<PostMessageTimer> timer = adoptPtrWillBeNoop(new PostMess ageTimer(*this, event, source, target, stackTrace, UserGestureIndicator::current Token())); 661 OwnPtrWillBeRawPtr<PostMessageTimer> timer = adoptPtrWillBeNoop(new PostMess ageTimer(*this, event, source, target, stackTrace, UserGestureIndicator::current Token()));
655 timer->startOneShot(0, FROM_HERE); 662 timer->startOneShot(0, FROM_HERE);
656 timer->suspendIfNeeded(); 663 timer->suspendIfNeeded();
657 m_postMessageTimers.add(timer.release()); 664 m_postMessageTimers.add(timer.release());
658 } 665 }
659 666
660 void LocalDOMWindow::postMessageTimerFired(PostMessageTimer* timer) 667 void LocalDOMWindow::postMessageTimerFired(PostMessageTimer* timer)
661 { 668 {
662 if (!isCurrentlyDisplayedInFrame()) { 669 if (!isCurrentlyDisplayedInFrame()) {
663 m_postMessageTimers.remove(timer);
664 return; 670 return;
665 } 671 }
666 672
667 RefPtrWillBeRawPtr<MessageEvent> event = timer->event(); 673 RefPtrWillBeRawPtr<MessageEvent> event = timer->event();
668 674
669 UserGestureIndicator gestureIndicator(timer->userGestureToken()); 675 UserGestureIndicator gestureIndicator(timer->userGestureToken());
670 676
671 event->entangleMessagePorts(document()); 677 event->entangleMessagePorts(document());
672 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta ckTrace()); 678 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta ckTrace());
679 }
680
681 void LocalDOMWindow::removePostMessageTimer(PostMessageTimer* timer)
682 {
673 m_postMessageTimers.remove(timer); 683 m_postMessageTimers.remove(timer);
674 } 684 }
675 685
676 void LocalDOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intende dTargetOrigin, PassRefPtrWillBeRawPtr<Event> event, PassRefPtrWillBeRawPtr<Scrip tCallStack> stackTrace) 686 void LocalDOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intende dTargetOrigin, PassRefPtrWillBeRawPtr<Event> event, PassRefPtrWillBeRawPtr<Scrip tCallStack> stackTrace)
677 { 687 {
678 if (intendedTargetOrigin) { 688 if (intendedTargetOrigin) {
679 // Check target origin now since the target document may have changed si nce the timer was scheduled. 689 // Check target origin now since the target document may have changed si nce the timer was scheduled.
680 if (!intendedTargetOrigin->isSameSchemeHostPort(document()->securityOrig in())) { 690 if (!intendedTargetOrigin->isSameSchemeHostPort(document()->securityOrig in())) {
681 String message = ExceptionMessages::failedToExecute("postMessage", " DOMWindow", "The target origin provided ('" + intendedTargetOrigin->toString() + "') does not match the recipient window's origin ('" + document()->securityOrig in()->toString() + "')."); 691 String message = ExceptionMessages::failedToExecute("postMessage", " DOMWindow", "The target origin provided ('" + intendedTargetOrigin->toString() + "') does not match the recipient window's origin ('" + document()->securityOrig in()->toString() + "').");
682 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(SecurityMessageSource, ErrorMessageLevel, message); 692 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(SecurityMessageSource, ErrorMessageLevel, message);
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 DOMWindow::trace(visitor); 1533 DOMWindow::trace(visitor);
1524 DOMWindowLifecycleNotifier::trace(visitor); 1534 DOMWindowLifecycleNotifier::trace(visitor);
1525 } 1535 }
1526 1536
1527 LocalFrame* LocalDOMWindow::frame() const 1537 LocalFrame* LocalDOMWindow::frame() const
1528 { 1538 {
1529 return m_frameObserver->frame(); 1539 return m_frameObserver->frame();
1530 } 1540 }
1531 1541
1532 } // namespace blink 1542 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/LocalDOMWindow.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698