| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights | 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 #include "platform/ContentType.h" | 75 #include "platform/ContentType.h" |
| 76 #include "platform/Histogram.h" | 76 #include "platform/Histogram.h" |
| 77 #include "platform/LayoutTestSupport.h" | 77 #include "platform/LayoutTestSupport.h" |
| 78 #include "platform/MIMETypeFromURL.h" | 78 #include "platform/MIMETypeFromURL.h" |
| 79 #include "platform/RuntimeEnabledFeatures.h" | 79 #include "platform/RuntimeEnabledFeatures.h" |
| 80 #include "platform/UserGestureIndicator.h" | 80 #include "platform/UserGestureIndicator.h" |
| 81 #include "platform/audio/AudioBus.h" | 81 #include "platform/audio/AudioBus.h" |
| 82 #include "platform/audio/AudioSourceProviderClient.h" | 82 #include "platform/audio/AudioSourceProviderClient.h" |
| 83 #include "platform/graphics/GraphicsLayer.h" | 83 #include "platform/graphics/GraphicsLayer.h" |
| 84 #include "platform/mediastream/MediaStreamDescriptor.h" | 84 #include "platform/mediastream/MediaStreamDescriptor.h" |
| 85 #include "platform/scheduler/CancellableTaskFactory.h" | |
| 86 #include "platform/weborigin/SecurityOrigin.h" | 85 #include "platform/weborigin/SecurityOrigin.h" |
| 87 #include "public/platform/Platform.h" | 86 #include "public/platform/Platform.h" |
| 88 #include "public/platform/WebAudioSourceProvider.h" | 87 #include "public/platform/WebAudioSourceProvider.h" |
| 89 #include "public/platform/WebContentDecryptionModule.h" | 88 #include "public/platform/WebContentDecryptionModule.h" |
| 90 #include "public/platform/WebInbandTextTrack.h" | 89 #include "public/platform/WebInbandTextTrack.h" |
| 91 #include "public/platform/WebMediaPlayerSource.h" | 90 #include "public/platform/WebMediaPlayerSource.h" |
| 92 #include "public/platform/WebMediaStream.h" | 91 #include "public/platform/WebMediaStream.h" |
| 93 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h
" | 92 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h
" |
| 94 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" | 93 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" |
| 95 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" | 94 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 m_ignorePreloadNone(false), | 444 m_ignorePreloadNone(false), |
| 446 m_textTracksVisible(false), | 445 m_textTracksVisible(false), |
| 447 m_shouldPerformAutomaticTrackSelection(true), | 446 m_shouldPerformAutomaticTrackSelection(true), |
| 448 m_tracksAreReady(true), | 447 m_tracksAreReady(true), |
| 449 m_processingPreferenceChange(false), | 448 m_processingPreferenceChange(false), |
| 450 m_playingRemotely(false), | 449 m_playingRemotely(false), |
| 451 m_inOverlayFullscreenVideo(false), | 450 m_inOverlayFullscreenVideo(false), |
| 452 m_audioTracks(this, AudioTrackList::create(*this)), | 451 m_audioTracks(this, AudioTrackList::create(*this)), |
| 453 m_videoTracks(this, VideoTrackList::create(*this)), | 452 m_videoTracks(this, VideoTrackList::create(*this)), |
| 454 m_textTracks(this, nullptr), | 453 m_textTracks(this, nullptr), |
| 455 m_playPromiseResolveTask(CancellableTaskFactory::create( | |
| 456 this, | |
| 457 &HTMLMediaElement::resolveScheduledPlayPromises)), | |
| 458 m_playPromiseRejectTask(CancellableTaskFactory::create( | |
| 459 this, | |
| 460 &HTMLMediaElement::rejectScheduledPlayPromises)), | |
| 461 m_audioSourceNode(nullptr), | 454 m_audioSourceNode(nullptr), |
| 462 m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)), | 455 m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)), |
| 463 m_autoplayHelper( | 456 m_autoplayHelper( |
| 464 AutoplayExperimentHelper::create(m_autoplayHelperClient.get())), | 457 AutoplayExperimentHelper::create(m_autoplayHelperClient.get())), |
| 465 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)), | 458 m_autoplayUmaHelper(AutoplayUmaHelper::create(this)), |
| 466 m_remotePlaybackClient(nullptr), | 459 m_remotePlaybackClient(nullptr), |
| 467 m_autoplayVisibilityObserver(nullptr) { | 460 m_autoplayVisibilityObserver(nullptr) { |
| 468 ThreadState::current()->registerPreFinalizer(this); | 461 ThreadState::current()->registerPreFinalizer(this); |
| 469 | 462 |
| 470 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; | 463 BLINK_MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 // play promises or project pending play prmoises algorithms, immediately | 778 // play promises or project pending play prmoises algorithms, immediately |
| 786 // resolve or reject those promises in the order the corresponding tasks | 779 // resolve or reject those promises in the order the corresponding tasks |
| 787 // were queued. | 780 // were queued. |
| 788 // | 781 // |
| 789 // TODO(mlamouri): the promises are first resolved then rejected but the | 782 // TODO(mlamouri): the promises are first resolved then rejected but the |
| 790 // order between resolved/rejected promises isn't respected. This could be | 783 // order between resolved/rejected promises isn't respected. This could be |
| 791 // improved when the same task is used for both cases. | 784 // improved when the same task is used for both cases. |
| 792 // | 785 // |
| 793 // TODO(mlamouri): don't run the callback synchronously if we are not allowed | 786 // TODO(mlamouri): don't run the callback synchronously if we are not allowed |
| 794 // to run scripts. It can happen in some edge cases. https://crbug.com/660382 | 787 // to run scripts. It can happen in some edge cases. https://crbug.com/660382 |
| 795 if (m_playPromiseResolveTask->isPending() && | 788 if (m_playPromiseResolveTaskHandle.isActive() && |
| 796 !ScriptForbiddenScope::isScriptForbidden()) { | 789 !ScriptForbiddenScope::isScriptForbidden()) { |
| 797 m_playPromiseResolveTask->cancel(); | 790 m_playPromiseResolveTaskHandle.cancel(); |
| 798 resolveScheduledPlayPromises(); | 791 resolveScheduledPlayPromises(); |
| 799 } | 792 } |
| 800 if (m_playPromiseRejectTask->isPending() && | 793 if (m_playPromiseRejectTaskHandle.isActive() && |
| 801 !ScriptForbiddenScope::isScriptForbidden()) { | 794 !ScriptForbiddenScope::isScriptForbidden()) { |
| 802 m_playPromiseRejectTask->cancel(); | 795 m_playPromiseRejectTaskHandle.cancel(); |
| 803 rejectScheduledPlayPromises(); | 796 rejectScheduledPlayPromises(); |
| 804 } | 797 } |
| 805 | 798 |
| 806 // 4 - Remove each task in pending tasks from its task queue. | 799 // 4 - Remove each task in pending tasks from its task queue. |
| 807 cancelPendingEventsAndCallbacks(); | 800 cancelPendingEventsAndCallbacks(); |
| 808 | 801 |
| 809 // 5 - If the media element's networkState is set to NETWORK_LOADING or | 802 // 5 - If the media element's networkState is set to NETWORK_LOADING or |
| 810 // NETWORK_IDLE, queue a task to fire a simple event named abort at the media | 803 // NETWORK_IDLE, queue a task to fire a simple event named abort at the media |
| 811 // element. | 804 // element. |
| 812 if (m_networkState == kNetworkLoading || m_networkState == kNetworkIdle) | 805 if (m_networkState == kNetworkLoading || m_networkState == kNetworkIdle) |
| (...skipping 3149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3962 } | 3955 } |
| 3963 | 3956 |
| 3964 void HTMLMediaElement::scheduleResolvePlayPromises() { | 3957 void HTMLMediaElement::scheduleResolvePlayPromises() { |
| 3965 // TODO(mlamouri): per spec, we should create a new task but we can't create | 3958 // TODO(mlamouri): per spec, we should create a new task but we can't create |
| 3966 // a new cancellable task without cancelling the previous one. There are two | 3959 // a new cancellable task without cancelling the previous one. There are two |
| 3967 // approaches then: cancel the previous task and create a new one with the | 3960 // approaches then: cancel the previous task and create a new one with the |
| 3968 // appended promise list or append the new promise to the current list. The | 3961 // appended promise list or append the new promise to the current list. The |
| 3969 // latter approach is preferred because it might be the less observable | 3962 // latter approach is preferred because it might be the less observable |
| 3970 // change. | 3963 // change. |
| 3971 DCHECK(m_playPromiseResolveList.isEmpty() || | 3964 DCHECK(m_playPromiseResolveList.isEmpty() || |
| 3972 m_playPromiseResolveTask->isPending()); | 3965 m_playPromiseResolveTaskHandle.isActive()); |
| 3973 if (m_playPromiseResolvers.isEmpty()) | 3966 if (m_playPromiseResolvers.isEmpty()) |
| 3974 return; | 3967 return; |
| 3975 | 3968 |
| 3976 m_playPromiseResolveList.appendVector(m_playPromiseResolvers); | 3969 m_playPromiseResolveList.appendVector(m_playPromiseResolvers); |
| 3977 m_playPromiseResolvers.clear(); | 3970 m_playPromiseResolvers.clear(); |
| 3978 | 3971 |
| 3979 if (m_playPromiseResolveTask->isPending()) | 3972 if (m_playPromiseResolveTaskHandle.isActive()) |
| 3980 return; | 3973 return; |
| 3981 | 3974 |
| 3982 TaskRunnerHelper::get(TaskType::MediaElementEvent, &document()) | 3975 m_playPromiseResolveTaskHandle = |
| 3983 ->postTask(BLINK_FROM_HERE, m_playPromiseResolveTask->cancelAndCreate()); | 3976 TaskRunnerHelper::get(TaskType::MediaElementEvent, &document()) |
| 3977 ->postCancellableTask( |
| 3978 BLINK_FROM_HERE, |
| 3979 WTF::bind(&HTMLMediaElement::resolveScheduledPlayPromises, |
| 3980 wrapWeakPersistent(this))); |
| 3984 } | 3981 } |
| 3985 | 3982 |
| 3986 void HTMLMediaElement::scheduleRejectPlayPromises(ExceptionCode code) { | 3983 void HTMLMediaElement::scheduleRejectPlayPromises(ExceptionCode code) { |
| 3987 // TODO(mlamouri): per spec, we should create a new task but we can't create | 3984 // TODO(mlamouri): per spec, we should create a new task but we can't create |
| 3988 // a new cancellable task without cancelling the previous one. There are two | 3985 // a new cancellable task without cancelling the previous one. There are two |
| 3989 // approaches then: cancel the previous task and create a new one with the | 3986 // approaches then: cancel the previous task and create a new one with the |
| 3990 // appended promise list or append the new promise to the current list. The | 3987 // appended promise list or append the new promise to the current list. The |
| 3991 // latter approach is preferred because it might be the less observable | 3988 // latter approach is preferred because it might be the less observable |
| 3992 // change. | 3989 // change. |
| 3993 DCHECK(m_playPromiseRejectList.isEmpty() || | 3990 DCHECK(m_playPromiseRejectList.isEmpty() || |
| 3994 m_playPromiseRejectTask->isPending()); | 3991 m_playPromiseRejectTaskHandle.isActive()); |
| 3995 if (m_playPromiseResolvers.isEmpty()) | 3992 if (m_playPromiseResolvers.isEmpty()) |
| 3996 return; | 3993 return; |
| 3997 | 3994 |
| 3998 m_playPromiseRejectList.appendVector(m_playPromiseResolvers); | 3995 m_playPromiseRejectList.appendVector(m_playPromiseResolvers); |
| 3999 m_playPromiseResolvers.clear(); | 3996 m_playPromiseResolvers.clear(); |
| 4000 | 3997 |
| 4001 if (m_playPromiseRejectTask->isPending()) | 3998 if (m_playPromiseRejectTaskHandle.isActive()) |
| 4002 return; | 3999 return; |
| 4003 | 4000 |
| 4004 // TODO(mlamouri): because cancellable tasks can't take parameters, the | 4001 // TODO(nhiroki): Bind this error code to a cancellable task instead of a |
| 4005 // error code needs to be saved. | 4002 // member field. |
| 4006 m_playPromiseErrorCode = code; | 4003 m_playPromiseErrorCode = code; |
| 4007 TaskRunnerHelper::get(TaskType::MediaElementEvent, &document()) | 4004 m_playPromiseRejectTaskHandle = |
| 4008 ->postTask(BLINK_FROM_HERE, m_playPromiseRejectTask->cancelAndCreate()); | 4005 TaskRunnerHelper::get(TaskType::MediaElementEvent, &document()) |
| 4006 ->postCancellableTask( |
| 4007 BLINK_FROM_HERE, |
| 4008 WTF::bind(&HTMLMediaElement::rejectScheduledPlayPromises, |
| 4009 wrapWeakPersistent(this))); |
| 4009 } | 4010 } |
| 4010 | 4011 |
| 4011 void HTMLMediaElement::scheduleNotifyPlaying() { | 4012 void HTMLMediaElement::scheduleNotifyPlaying() { |
| 4012 scheduleEvent(EventTypeNames::playing); | 4013 scheduleEvent(EventTypeNames::playing); |
| 4013 scheduleResolvePlayPromises(); | 4014 scheduleResolvePlayPromises(); |
| 4014 } | 4015 } |
| 4015 | 4016 |
| 4016 void HTMLMediaElement::resolveScheduledPlayPromises() { | 4017 void HTMLMediaElement::resolveScheduledPlayPromises() { |
| 4017 for (auto& resolver : m_playPromiseResolveList) | 4018 for (auto& resolver : m_playPromiseResolveList) |
| 4018 resolver->resolve(); | 4019 resolver->resolve(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4187 | 4188 |
| 4188 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() | 4189 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() |
| 4189 const { | 4190 const { |
| 4190 IntRect result; | 4191 IntRect result; |
| 4191 if (LayoutObject* object = m_element->layoutObject()) | 4192 if (LayoutObject* object = m_element->layoutObject()) |
| 4192 result = object->absoluteBoundingBoxRect(); | 4193 result = object->absoluteBoundingBoxRect(); |
| 4193 return result; | 4194 return result; |
| 4194 } | 4195 } |
| 4195 | 4196 |
| 4196 } // namespace blink | 4197 } // namespace blink |
| OLD | NEW |