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

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: Remove PostMessageTimers when stopped 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->postMessageTimerStopped(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 // This object is deleted now.
sof 2015/06/08 11:31:45 How about we call m_window->postMessageTimerStoppe
landell 2015/06/08 11:48:17 Sure, I think it shall be renamed to removePostMes
144 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); 150 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
145 } 151 }
146 152
147 RefPtrWillBeMember<MessageEvent> m_event; 153 RefPtrWillBeMember<MessageEvent> m_event;
148 RawPtrWillBeMember<LocalDOMWindow> m_window; 154 RawPtrWillBeMember<LocalDOMWindow> m_window;
149 RefPtr<SecurityOrigin> m_targetOrigin; 155 RefPtr<SecurityOrigin> m_targetOrigin;
150 RefPtrWillBeMember<ScriptCallStack> m_stackTrace; 156 RefPtrWillBeMember<ScriptCallStack> m_stackTrace;
151 RefPtr<UserGestureToken> m_userGestureToken; 157 RefPtr<UserGestureToken> m_userGestureToken;
152 int m_asyncOperationId; 158 int m_asyncOperationId;
153 }; 159 };
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 662
657 RefPtrWillBeRawPtr<MessageEvent> event = timer->event(); 663 RefPtrWillBeRawPtr<MessageEvent> event = timer->event();
658 664
659 UserGestureIndicator gestureIndicator(timer->userGestureToken()); 665 UserGestureIndicator gestureIndicator(timer->userGestureToken());
660 666
661 event->entangleMessagePorts(document()); 667 event->entangleMessagePorts(document());
662 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta ckTrace()); 668 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta ckTrace());
663 m_postMessageTimers.remove(timer); 669 m_postMessageTimers.remove(timer);
664 } 670 }
665 671
672 void LocalDOMWindow::postMessageTimerStopped(PostMessageTimer* timer)
673 {
674 m_postMessageTimers.remove(timer);
675 }
676
666 void LocalDOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intende dTargetOrigin, PassRefPtrWillBeRawPtr<Event> event, PassRefPtrWillBeRawPtr<Scrip tCallStack> stackTrace) 677 void LocalDOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intende dTargetOrigin, PassRefPtrWillBeRawPtr<Event> event, PassRefPtrWillBeRawPtr<Scrip tCallStack> stackTrace)
667 { 678 {
668 if (intendedTargetOrigin) { 679 if (intendedTargetOrigin) {
669 // Check target origin now since the target document may have changed si nce the timer was scheduled. 680 // Check target origin now since the target document may have changed si nce the timer was scheduled.
670 if (!intendedTargetOrigin->isSameSchemeHostPort(document()->securityOrig in())) { 681 if (!intendedTargetOrigin->isSameSchemeHostPort(document()->securityOrig in())) {
671 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 String message = ExceptionMessages::failedToExecute("postMessage", " DOMWindow", "The target origin provided ('" + intendedTargetOrigin->toString() + "') does not match the recipient window's origin ('" + document()->securityOrig in()->toString() + "').");
672 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(SecurityMessageSource, ErrorMessageLevel, message); 683 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(SecurityMessageSource, ErrorMessageLevel, message);
673 consoleMessage->setCallStack(stackTrace); 684 consoleMessage->setCallStack(stackTrace);
674 frameConsole()->addMessage(consoleMessage.release()); 685 frameConsole()->addMessage(consoleMessage.release());
675 return; 686 return;
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 DOMWindow::trace(visitor); 1524 DOMWindow::trace(visitor);
1514 DOMWindowLifecycleNotifier::trace(visitor); 1525 DOMWindowLifecycleNotifier::trace(visitor);
1515 } 1526 }
1516 1527
1517 LocalFrame* LocalDOMWindow::frame() const 1528 LocalFrame* LocalDOMWindow::frame() const
1518 { 1529 {
1519 return m_frameObserver->frame(); 1530 return m_frameObserver->frame();
1520 } 1531 }
1521 1532
1522 } // namespace blink 1533 } // 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