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

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

Issue 1186093003: Reland: Window.postMessage() to self can cause document leaks (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 class PostMessageTimer final : public NoBaseWillBeGarbageCollectedFinalized<Post MessageTimer>, public SuspendableTimer { 111 class PostMessageTimer final : public NoBaseWillBeGarbageCollectedFinalized<Post MessageTimer>, public SuspendableTimer {
112 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(PostMessageTimer); 112 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(PostMessageTimer);
113 public: 113 public:
114 PostMessageTimer(LocalDOMWindow& window, PassRefPtrWillBeRawPtr<MessageEvent > event, PassRefPtrWillBeRawPtr<LocalDOMWindow> source, SecurityOrigin* targetOr igin, PassRefPtrWillBeRawPtr<ScriptCallStack> stackTrace, UserGestureToken* user GestureToken) 114 PostMessageTimer(LocalDOMWindow& window, PassRefPtrWillBeRawPtr<MessageEvent > event, PassRefPtrWillBeRawPtr<LocalDOMWindow> source, SecurityOrigin* targetOr igin, PassRefPtrWillBeRawPtr<ScriptCallStack> stackTrace, UserGestureToken* user GestureToken)
115 : SuspendableTimer(window.document()) 115 : SuspendableTimer(window.document())
116 , m_event(event) 116 , m_event(event)
117 , m_window(&window) 117 , m_window(&window)
118 , m_targetOrigin(targetOrigin) 118 , m_targetOrigin(targetOrigin)
119 , m_stackTrace(stackTrace) 119 , m_stackTrace(stackTrace)
120 , m_userGestureToken(userGestureToken) 120 , m_userGestureToken(userGestureToken)
121 , m_preventDestruction(false)
121 { 122 {
122 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarti ng(executionContext(), "postMessage"); 123 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarti ng(executionContext(), "postMessage");
123 } 124 }
124 125
125 PassRefPtrWillBeRawPtr<MessageEvent> event() const { return m_event.get(); } 126 PassRefPtrWillBeRawPtr<MessageEvent> event() const { return m_event.get(); }
126 SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); } 127 SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); }
127 ScriptCallStack* stackTrace() const { return m_stackTrace.get(); } 128 ScriptCallStack* stackTrace() const { return m_stackTrace.get(); }
128 UserGestureToken* userGestureToken() const { return m_userGestureToken.get() ; } 129 UserGestureToken* userGestureToken() const { return m_userGestureToken.get() ; }
130 virtual void stop() override
131 {
132 SuspendableTimer::stop();
133
134 if (!m_preventDestruction) {
135 // Will destroy this object
136 m_window->removePostMessageTimer(this);
137 }
138 }
129 139
130 DEFINE_INLINE_VIRTUAL_TRACE() 140 DEFINE_INLINE_VIRTUAL_TRACE()
131 { 141 {
132 visitor->trace(m_event); 142 visitor->trace(m_event);
133 visitor->trace(m_window); 143 visitor->trace(m_window);
134 visitor->trace(m_stackTrace); 144 visitor->trace(m_stackTrace);
135 SuspendableTimer::trace(visitor); 145 SuspendableTimer::trace(visitor);
136 } 146 }
137 147
138 private: 148 private:
139 virtual void fired() override 149 virtual void fired() override
140 { 150 {
141 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceA syncOperationCompletedCallbackStarting(executionContext(), m_asyncOperationId); 151 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceA syncOperationCompletedCallbackStarting(executionContext(), m_asyncOperationId);
152 // Prevent calls to stop triggered from the event handler to
153 // kill this object.
154 m_preventDestruction = true;
142 m_window->postMessageTimerFired(this); 155 m_window->postMessageTimerFired(this);
143 // This object is deleted now. 156 // Will destroy this object
157 m_window->removePostMessageTimer(this);
144 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); 158 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie);
145 } 159 }
146 160
147 RefPtrWillBeMember<MessageEvent> m_event; 161 RefPtrWillBeMember<MessageEvent> m_event;
148 RawPtrWillBeMember<LocalDOMWindow> m_window; 162 RawPtrWillBeMember<LocalDOMWindow> m_window;
149 RefPtr<SecurityOrigin> m_targetOrigin; 163 RefPtr<SecurityOrigin> m_targetOrigin;
150 RefPtrWillBeMember<ScriptCallStack> m_stackTrace; 164 RefPtrWillBeMember<ScriptCallStack> m_stackTrace;
151 RefPtr<UserGestureToken> m_userGestureToken; 165 RefPtr<UserGestureToken> m_userGestureToken;
152 int m_asyncOperationId; 166 int m_asyncOperationId;
167 bool m_preventDestruction;
153 }; 168 };
154 169
155 static void updateSuddenTerminationStatus(LocalDOMWindow* domWindow, bool addedL istener, FrameLoaderClient::SuddenTerminationDisablerType disablerType) 170 static void updateSuddenTerminationStatus(LocalDOMWindow* domWindow, bool addedL istener, FrameLoaderClient::SuddenTerminationDisablerType disablerType)
156 { 171 {
157 Platform::current()->suddenTerminationChanged(!addedListener); 172 Platform::current()->suddenTerminationChanged(!addedListener);
158 if (domWindow->frame() && domWindow->frame()->loader().client()) 173 if (domWindow->frame() && domWindow->frame()->loader().client())
159 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged( addedListener, disablerType); 174 domWindow->frame()->loader().client()->suddenTerminationDisablerChanged( addedListener, disablerType);
160 } 175 }
161 176
162 typedef HashCountedSet<LocalDOMWindow*> DOMWindowSet; 177 typedef HashCountedSet<LocalDOMWindow*> DOMWindowSet;
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 // Schedule the message. 668 // Schedule the message.
654 OwnPtrWillBeRawPtr<PostMessageTimer> timer = adoptPtrWillBeNoop(new PostMess ageTimer(*this, event, source, target, stackTrace, UserGestureIndicator::current Token())); 669 OwnPtrWillBeRawPtr<PostMessageTimer> timer = adoptPtrWillBeNoop(new PostMess ageTimer(*this, event, source, target, stackTrace, UserGestureIndicator::current Token()));
655 timer->startOneShot(0, FROM_HERE); 670 timer->startOneShot(0, FROM_HERE);
656 timer->suspendIfNeeded(); 671 timer->suspendIfNeeded();
657 m_postMessageTimers.add(timer.release()); 672 m_postMessageTimers.add(timer.release());
658 } 673 }
659 674
660 void LocalDOMWindow::postMessageTimerFired(PostMessageTimer* timer) 675 void LocalDOMWindow::postMessageTimerFired(PostMessageTimer* timer)
661 { 676 {
662 if (!isCurrentlyDisplayedInFrame()) { 677 if (!isCurrentlyDisplayedInFrame()) {
663 m_postMessageTimers.remove(timer);
664 return; 678 return;
665 } 679 }
666 680
667 RefPtrWillBeRawPtr<MessageEvent> event = timer->event(); 681 RefPtrWillBeRawPtr<MessageEvent> event = timer->event();
668 682
669 UserGestureIndicator gestureIndicator(timer->userGestureToken()); 683 UserGestureIndicator gestureIndicator(timer->userGestureToken());
670 684
671 event->entangleMessagePorts(document()); 685 event->entangleMessagePorts(document());
672 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta ckTrace()); 686 dispatchMessageEventWithOriginCheck(timer->targetOrigin(), event, timer->sta ckTrace());
687 }
688
689 void LocalDOMWindow::removePostMessageTimer(PostMessageTimer* timer)
690 {
673 m_postMessageTimers.remove(timer); 691 m_postMessageTimers.remove(timer);
674 } 692 }
675 693
676 void LocalDOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intende dTargetOrigin, PassRefPtrWillBeRawPtr<Event> event, PassRefPtrWillBeRawPtr<Scrip tCallStack> stackTrace) 694 void LocalDOMWindow::dispatchMessageEventWithOriginCheck(SecurityOrigin* intende dTargetOrigin, PassRefPtrWillBeRawPtr<Event> event, PassRefPtrWillBeRawPtr<Scrip tCallStack> stackTrace)
677 { 695 {
678 if (intendedTargetOrigin) { 696 if (intendedTargetOrigin) {
679 // Check target origin now since the target document may have changed si nce the timer was scheduled. 697 // Check target origin now since the target document may have changed si nce the timer was scheduled.
680 if (!intendedTargetOrigin->isSameSchemeHostPort(document()->securityOrig in())) { 698 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() + "')."); 699 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); 700 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(SecurityMessageSource, ErrorMessageLevel, message);
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 DOMWindow::trace(visitor); 1521 DOMWindow::trace(visitor);
1504 DOMWindowLifecycleNotifier::trace(visitor); 1522 DOMWindowLifecycleNotifier::trace(visitor);
1505 } 1523 }
1506 1524
1507 LocalFrame* LocalDOMWindow::frame() const 1525 LocalFrame* LocalDOMWindow::frame() const
1508 { 1526 {
1509 return m_frameObserver->frame(); 1527 return m_frameObserver->frame();
1510 } 1528 }
1511 1529
1512 } // namespace blink 1530 } // 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