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

Side by Side Diff: third_party/WebKit/Source/core/animation/Animation.cpp

Issue 2785303002: Post task when rejecting Animation promises inside ScriptForbiddenScope (Closed)
Patch Set: Rebase Created 3 years, 8 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 | « third_party/WebKit/Source/core/animation/Animation.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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 "blink.animations,devtools.timeline,benchmark,rail", "Animation", 1031 "blink.animations,devtools.timeline,benchmark,rail", "Animation",
1032 animation_, "data", InspectorAnimationStateEvent::Data(*animation_)); 1032 animation_, "data", InspectorAnimationStateEvent::Data(*animation_));
1033 } 1033 }
1034 1034
1035 // Ordering is important, the ready promise should resolve/reject before 1035 // Ordering is important, the ready promise should resolve/reject before
1036 // the finished promise. 1036 // the finished promise.
1037 if (animation_->ready_promise_ && new_play_state != old_play_state) { 1037 if (animation_->ready_promise_ && new_play_state != old_play_state) {
1038 if (new_play_state == kIdle) { 1038 if (new_play_state == kIdle) {
1039 if (animation_->ready_promise_->GetState() == 1039 if (animation_->ready_promise_->GetState() ==
1040 AnimationPromise::kPending) { 1040 AnimationPromise::kPending) {
1041 animation_->ready_promise_->Reject(DOMException::Create(kAbortError)); 1041 animation_->RejectPromise(animation_->ready_promise_.Get());
1042 } 1042 }
1043 animation_->ready_promise_->Reset(); 1043 animation_->ready_promise_->Reset();
1044 animation_->ResolvePromiseMaybeAsync(animation_->ready_promise_.Get()); 1044 animation_->ResolvePromiseMaybeAsync(animation_->ready_promise_.Get());
1045 } else if (old_play_state == kPending) { 1045 } else if (old_play_state == kPending) {
1046 animation_->ResolvePromiseMaybeAsync(animation_->ready_promise_.Get()); 1046 animation_->ResolvePromiseMaybeAsync(animation_->ready_promise_.Get());
1047 } else if (new_play_state == kPending) { 1047 } else if (new_play_state == kPending) {
1048 DCHECK_NE(animation_->ready_promise_->GetState(), 1048 DCHECK_NE(animation_->ready_promise_->GetState(),
1049 AnimationPromise::kPending); 1049 AnimationPromise::kPending);
1050 animation_->ready_promise_->Reset(); 1050 animation_->ready_promise_->Reset();
1051 } 1051 }
1052 } 1052 }
1053 1053
1054 if (animation_->finished_promise_ && new_play_state != old_play_state) { 1054 if (animation_->finished_promise_ && new_play_state != old_play_state) {
1055 if (new_play_state == kIdle) { 1055 if (new_play_state == kIdle) {
1056 if (animation_->finished_promise_->GetState() == 1056 if (animation_->finished_promise_->GetState() ==
1057 AnimationPromise::kPending) { 1057 AnimationPromise::kPending) {
1058 animation_->finished_promise_->Reject( 1058 animation_->RejectPromise(animation_->finished_promise_);
1059 DOMException::Create(kAbortError));
1060 } 1059 }
1061 animation_->finished_promise_->Reset(); 1060 animation_->finished_promise_->Reset();
1062 } else if (new_play_state == kFinished) { 1061 } else if (new_play_state == kFinished) {
1063 animation_->ResolvePromiseMaybeAsync(animation_->finished_promise_.Get()); 1062 animation_->ResolvePromiseMaybeAsync(animation_->finished_promise_.Get());
1064 } else if (old_play_state == kFinished) { 1063 } else if (old_play_state == kFinished) {
1065 animation_->finished_promise_->Reset(); 1064 animation_->finished_promise_->Reset();
1066 } 1065 }
1067 } 1066 }
1068 1067
1069 if (old_play_state != new_play_state && 1068 if (old_play_state != new_play_state &&
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 if (ScriptForbiddenScope::IsScriptForbidden()) { 1142 if (ScriptForbiddenScope::IsScriptForbidden()) {
1144 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetExecutionContext()) 1143 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetExecutionContext())
1145 ->PostTask(BLINK_FROM_HERE, 1144 ->PostTask(BLINK_FROM_HERE,
1146 WTF::Bind(&AnimationPromise::Resolve<Animation*>, 1145 WTF::Bind(&AnimationPromise::Resolve<Animation*>,
1147 WrapPersistent(promise), WrapPersistent(this))); 1146 WrapPersistent(promise), WrapPersistent(this)));
1148 } else { 1147 } else {
1149 promise->Resolve(this); 1148 promise->Resolve(this);
1150 } 1149 }
1151 } 1150 }
1152 1151
1152 void Animation::RejectPromise(AnimationPromise* promise) {
1153 // Animation promises can be rejected inside a ScriptForbiddenScope. When
haraken 2017/04/27 00:17:13 Would you help me understand where the ScriptForbi
adithyas 2017/04/27 19:09:52 It's set in Document::updateStyleAndLayout: https:
1154 // rejecting the promise with a DOMException, ToV8 is called on the exception,
1155 // making it possible for the DOMException constructor to be called inside a
1156 // forbidden scope. Since the constructor for DOMException is not user-defined
1157 // (and cannot be overwritten), we can allow it to run in a forbidden scope.
haraken 2017/04/27 00:17:13 Your analysis looks correct but for safety I'd pre
adithyas 2017/04/27 19:09:52 I've updated the CL to do this (i.e. post a task i
1158 ScriptForbiddenScope::AllowUserAgentScript allow_script;
1159 promise->Reject(DOMException::Create(kAbortError));
1160 }
1161
1153 DEFINE_TRACE(Animation) { 1162 DEFINE_TRACE(Animation) {
1154 visitor->Trace(content_); 1163 visitor->Trace(content_);
1155 visitor->Trace(timeline_); 1164 visitor->Trace(timeline_);
1156 visitor->Trace(pending_finished_event_); 1165 visitor->Trace(pending_finished_event_);
1157 visitor->Trace(pending_cancelled_event_); 1166 visitor->Trace(pending_cancelled_event_);
1158 visitor->Trace(finished_promise_); 1167 visitor->Trace(finished_promise_);
1159 visitor->Trace(ready_promise_); 1168 visitor->Trace(ready_promise_);
1160 visitor->Trace(compositor_player_); 1169 visitor->Trace(compositor_player_);
1161 EventTargetWithInlineData::Trace(visitor); 1170 EventTargetWithInlineData::Trace(visitor);
1162 ContextLifecycleObserver::Trace(visitor); 1171 ContextLifecycleObserver::Trace(visitor);
(...skipping 19 matching lines...) Expand all
1182 DCHECK(!compositor_player_); 1191 DCHECK(!compositor_player_);
1183 } 1192 }
1184 1193
1185 void Animation::CompositorAnimationPlayerHolder::Detach() { 1194 void Animation::CompositorAnimationPlayerHolder::Detach() {
1186 DCHECK(compositor_player_); 1195 DCHECK(compositor_player_);
1187 compositor_player_->SetAnimationDelegate(nullptr); 1196 compositor_player_->SetAnimationDelegate(nullptr);
1188 animation_ = nullptr; 1197 animation_ = nullptr;
1189 compositor_player_.reset(); 1198 compositor_player_.reset();
1190 } 1199 }
1191 } // namespace blink 1200 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/animation/Animation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698