Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 m_closedContextSampleRate(-1), | 101 m_closedContextSampleRate(-1), |
| 102 m_periodicWaveSine(nullptr), | 102 m_periodicWaveSine(nullptr), |
| 103 m_periodicWaveSquare(nullptr), | 103 m_periodicWaveSquare(nullptr), |
| 104 m_periodicWaveSawtooth(nullptr), | 104 m_periodicWaveSawtooth(nullptr), |
| 105 m_periodicWaveTriangle(nullptr) { | 105 m_periodicWaveTriangle(nullptr) { |
| 106 // If mediaPlaybackRequiresUserGesture is enabled, cross origin iframes will | 106 // If mediaPlaybackRequiresUserGesture is enabled, cross origin iframes will |
| 107 // require user gesture for the AudioContext to produce sound. | 107 // require user gesture for the AudioContext to produce sound. |
| 108 if (document->settings() && | 108 if (document->settings() && |
| 109 document->settings()->mediaPlaybackRequiresUserGesture() && | 109 document->settings()->mediaPlaybackRequiresUserGesture() && |
| 110 document->frame() && document->frame()->isCrossOriginSubframe()) { | 110 document->frame() && document->frame()->isCrossOriginSubframe()) { |
| 111 m_autoplayStatus = AutoplayStatus::AutoplayStatusFailed; | |
| 111 m_userGestureRequired = true; | 112 m_userGestureRequired = true; |
| 112 } | 113 } |
| 113 | 114 |
| 114 m_destinationNode = DefaultAudioDestinationNode::create(this); | 115 m_destinationNode = DefaultAudioDestinationNode::create(this); |
| 115 | 116 |
| 116 initialize(); | 117 initialize(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 // Constructor for offline (non-realtime) rendering. | 120 // Constructor for offline (non-realtime) rendering. |
| 120 BaseAudioContext::BaseAudioContext(Document* document, | 121 BaseAudioContext::BaseAudioContext(Document* document, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 138 | 139 |
| 139 BaseAudioContext::~BaseAudioContext() { | 140 BaseAudioContext::~BaseAudioContext() { |
| 140 deferredTaskHandler().contextWillBeDestroyed(); | 141 deferredTaskHandler().contextWillBeDestroyed(); |
| 141 // AudioNodes keep a reference to their context, so there should be no way to | 142 // AudioNodes keep a reference to their context, so there should be no way to |
| 142 // be in the destructor if there are still AudioNodes around. | 143 // be in the destructor if there are still AudioNodes around. |
| 143 DCHECK(!isDestinationInitialized()); | 144 DCHECK(!isDestinationInitialized()); |
| 144 DCHECK(!m_activeSourceNodes.size()); | 145 DCHECK(!m_activeSourceNodes.size()); |
| 145 DCHECK(!m_finishedSourceHandlers.size()); | 146 DCHECK(!m_finishedSourceHandlers.size()); |
| 146 DCHECK(!m_isResolvingResumePromises); | 147 DCHECK(!m_isResolvingResumePromises); |
| 147 DCHECK(!m_resumeResolvers.size()); | 148 DCHECK(!m_resumeResolvers.size()); |
| 149 | |
| 150 recordAutoplayStatus(); | |
|
haraken
2016/10/17 00:57:33
This is safe but in general it's not encouraged to
mlamouri (slow - plz ping)
2016/10/17 11:34:45
I can call this in "uninitialize" which I did firs
| |
| 148 } | 151 } |
| 149 | 152 |
| 150 void BaseAudioContext::initialize() { | 153 void BaseAudioContext::initialize() { |
| 151 if (isDestinationInitialized()) | 154 if (isDestinationInitialized()) |
| 152 return; | 155 return; |
| 153 | 156 |
| 154 FFTFrame::initialize(); | 157 FFTFrame::initialize(); |
| 155 | 158 |
| 156 if (m_destinationNode) { | 159 if (m_destinationNode) { |
| 157 m_destinationNode->handler().initialize(); | 160 m_destinationNode->handler().initialize(); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 // Initialize the table if necessary | 558 // Initialize the table if necessary |
| 556 if (!m_periodicWaveTriangle) | 559 if (!m_periodicWaveTriangle) |
| 557 m_periodicWaveTriangle = PeriodicWave::createTriangle(sampleRate()); | 560 m_periodicWaveTriangle = PeriodicWave::createTriangle(sampleRate()); |
| 558 return m_periodicWaveTriangle; | 561 return m_periodicWaveTriangle; |
| 559 default: | 562 default: |
| 560 NOTREACHED(); | 563 NOTREACHED(); |
| 561 return nullptr; | 564 return nullptr; |
| 562 } | 565 } |
| 563 } | 566 } |
| 564 | 567 |
| 568 void BaseAudioContext::maybeRecordStartAttempt() { | |
| 569 if (!m_userGestureRequired || !UserGestureIndicator::processingUserGesture()) | |
| 570 return; | |
| 571 | |
| 572 DCHECK(!m_autoplayStatus.has_value() || | |
| 573 m_autoplayStatus != AutoplayStatus::AutoplayStatusSucceeded); | |
| 574 m_autoplayStatus = AutoplayStatus::AutoplayStatusFailedWithStart; | |
| 575 } | |
| 576 | |
| 565 String BaseAudioContext::state() const { | 577 String BaseAudioContext::state() const { |
| 566 // These strings had better match the strings for AudioContextState in | 578 // These strings had better match the strings for AudioContextState in |
| 567 // AudioContext.idl. | 579 // AudioContext.idl. |
| 568 switch (m_contextState) { | 580 switch (m_contextState) { |
| 569 case Suspended: | 581 case Suspended: |
| 570 return "suspended"; | 582 return "suspended"; |
| 571 case Running: | 583 case Running: |
| 572 return "running"; | 584 return "running"; |
| 573 case Closed: | 585 case Closed: |
| 574 return "closed"; | 586 return "closed"; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 777 for (auto& resolver : m_decodeAudioResolvers) | 789 for (auto& resolver : m_decodeAudioResolvers) |
| 778 resolver->reject( | 790 resolver->reject( |
| 779 DOMException::create(InvalidStateError, "Audio context is going away")); | 791 DOMException::create(InvalidStateError, "Audio context is going away")); |
| 780 m_decodeAudioResolvers.clear(); | 792 m_decodeAudioResolvers.clear(); |
| 781 } | 793 } |
| 782 | 794 |
| 783 void BaseAudioContext::maybeUnlockUserGesture() { | 795 void BaseAudioContext::maybeUnlockUserGesture() { |
| 784 if (!m_userGestureRequired || !UserGestureIndicator::processingUserGesture()) | 796 if (!m_userGestureRequired || !UserGestureIndicator::processingUserGesture()) |
| 785 return; | 797 return; |
| 786 | 798 |
| 799 DCHECK(!m_autoplayStatus.has_value() || | |
| 800 m_autoplayStatus != AutoplayStatus::AutoplayStatusSucceeded); | |
| 801 | |
| 787 UserGestureIndicator::utilizeUserGesture(); | 802 UserGestureIndicator::utilizeUserGesture(); |
| 788 m_userGestureRequired = false; | 803 m_userGestureRequired = false; |
| 804 m_autoplayStatus = AutoplayStatus::AutoplayStatusSucceeded; | |
| 789 } | 805 } |
| 790 | 806 |
| 791 bool BaseAudioContext::isAllowedToStart() const { | 807 bool BaseAudioContext::isAllowedToStart() const { |
| 792 if (!m_userGestureRequired) | 808 if (!m_userGestureRequired) |
| 793 return true; | 809 return true; |
| 794 | 810 |
| 795 toDocument(getExecutionContext()) | 811 toDocument(getExecutionContext()) |
| 796 ->addConsoleMessage(ConsoleMessage::create( | 812 ->addConsoleMessage(ConsoleMessage::create( |
| 797 JSMessageSource, WarningMessageLevel, | 813 JSMessageSource, WarningMessageLevel, |
| 798 "An AudioContext in a cross origin iframe must be created or resumed " | 814 "An AudioContext in a cross origin iframe must be created or resumed " |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 809 for (auto& resolver : m_resumeResolvers) { | 825 for (auto& resolver : m_resumeResolvers) { |
| 810 resolver->reject( | 826 resolver->reject( |
| 811 DOMException::create(InvalidStateError, "Audio context is going away")); | 827 DOMException::create(InvalidStateError, "Audio context is going away")); |
| 812 } | 828 } |
| 813 m_resumeResolvers.clear(); | 829 m_resumeResolvers.clear(); |
| 814 m_isResolvingResumePromises = false; | 830 m_isResolvingResumePromises = false; |
| 815 | 831 |
| 816 rejectPendingDecodeAudioDataResolvers(); | 832 rejectPendingDecodeAudioDataResolvers(); |
| 817 } | 833 } |
| 818 | 834 |
| 835 void BaseAudioContext::recordAutoplayStatus() { | |
| 836 if (!m_autoplayStatus.has_value()) | |
| 837 return; | |
| 838 | |
| 839 DEFINE_STATIC_LOCAL( | |
| 840 EnumerationHistogram, autoplayHistogram, | |
| 841 ("WebAudio.Autoplay.CrossOrigin", AutoplayStatus::AutoplayStatusCount)); | |
| 842 autoplayHistogram.count(m_autoplayStatus.value()); | |
| 843 | |
| 844 m_autoplayStatus.reset(); | |
| 845 } | |
| 846 | |
| 819 const AtomicString& BaseAudioContext::interfaceName() const { | 847 const AtomicString& BaseAudioContext::interfaceName() const { |
| 820 return EventTargetNames::AudioContext; | 848 return EventTargetNames::AudioContext; |
| 821 } | 849 } |
| 822 | 850 |
| 823 ExecutionContext* BaseAudioContext::getExecutionContext() const { | 851 ExecutionContext* BaseAudioContext::getExecutionContext() const { |
| 824 return ActiveDOMObject::getExecutionContext(); | 852 return ActiveDOMObject::getExecutionContext(); |
| 825 } | 853 } |
| 826 | 854 |
| 827 void BaseAudioContext::startRendering() { | 855 void BaseAudioContext::startRendering() { |
| 828 // This is called for both online and offline contexts. | 856 // This is called for both online and offline contexts. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 852 } | 880 } |
| 853 | 881 |
| 854 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const { | 882 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const { |
| 855 if (getExecutionContext()) | 883 if (getExecutionContext()) |
| 856 return getExecutionContext()->getSecurityOrigin(); | 884 return getExecutionContext()->getSecurityOrigin(); |
| 857 | 885 |
| 858 return nullptr; | 886 return nullptr; |
| 859 } | 887 } |
| 860 | 888 |
| 861 } // namespace blink | 889 } // namespace blink |
| OLD | NEW |