Bug 1324548 - Apply clang-format. r?padenot,baku draft
authorLéo Paquet
Thu, 02 Nov 2017 17:43:22 +0100
changeset 692157 a94297de3c0f4d4a3fe4c6573994d42b50fde7ef
parent 692071 2505e4a7270da68f9548e5d774e94ffdefb808ec
child 692158 737fd7ea08139261f917919f1a98eb28f0687278
push id87419
push userbmo:leo.paquet@etu.univ-lyon1.fr
push dateThu, 02 Nov 2017 17:01:47 +0000
reviewerspadenot, baku
bugs1324548
milestone58.0a1
Bug 1324548 - Apply clang-format. r?padenot,baku MozReview-Commit-ID: 6P56O4ZQ7sm
dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp
dom/media/webaudio/MediaStreamTrackAudioSourceNode.h
--- a/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp
+++ b/dom/media/webaudio/MediaStreamTrackAudioSourceNode.cpp
@@ -1,56 +1,60 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MediaStreamTrackAudioSourceNode.h"
-#include "mozilla/dom/MediaStreamTrackAudioSourceNodeBinding.h"
 #include "AudioNodeEngine.h"
 #include "AudioNodeExternalInputStream.h"
 #include "AudioStreamTrack.h"
+#include "mozilla/CORSMode.h"
+#include "mozilla/dom/MediaStreamTrackAudioSourceNodeBinding.h"
+#include "nsContentUtils.h"
 #include "nsIDocument.h"
-#include "mozilla/CORSMode.h"
-#include "nsContentUtils.h"
 #include "nsIScriptError.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(MediaStreamTrackAudioSourceNode)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MediaStreamTrackAudioSourceNode)
   tmp->Destroy();
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mInputTrack)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(AudioNode)
 
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MediaStreamTrackAudioSourceNode, AudioNode)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(
+  MediaStreamTrackAudioSourceNode,
+  AudioNode)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInputTrack)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaStreamTrackAudioSourceNode)
 NS_INTERFACE_MAP_END_INHERITING(AudioNode)
 
 NS_IMPL_ADDREF_INHERITED(MediaStreamTrackAudioSourceNode, AudioNode)
 NS_IMPL_RELEASE_INHERITED(MediaStreamTrackAudioSourceNode, AudioNode)
 
-MediaStreamTrackAudioSourceNode::MediaStreamTrackAudioSourceNode(AudioContext* aContext)
+MediaStreamTrackAudioSourceNode::MediaStreamTrackAudioSourceNode(
+  AudioContext* aContext)
   : AudioNode(aContext,
               2,
               ChannelCountMode::Max,
               ChannelInterpretation::Speakers)
 {
 }
 
 /* static */ already_AddRefed<MediaStreamTrackAudioSourceNode>
-MediaStreamTrackAudioSourceNode::Create(AudioContext& aAudioContext,
-                                   const MediaStreamTrackAudioSourceOptions& aOptions,
-                                   ErrorResult& aRv)
+MediaStreamTrackAudioSourceNode::Create(
+  AudioContext& aAudioContext,
+  const MediaStreamTrackAudioSourceOptions& aOptions,
+  ErrorResult& aRv)
 {
   if (aAudioContext.IsOffline()) {
     aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     return nullptr;
   }
 
   if (aAudioContext.CheckClosed(aRv)) {
     return nullptr;
@@ -63,23 +67,29 @@ MediaStreamTrackAudioSourceNode::Create(
   if (aRv.Failed()) {
     return nullptr;
   }
 
   return node.forget();
 }
 
 void
-MediaStreamTrackAudioSourceNode::Init(MediaStreamTrack* aMediaStreamTrack, ErrorResult& aRv)
+MediaStreamTrackAudioSourceNode::Init(MediaStreamTrack* aMediaStreamTrack,
+                                      ErrorResult& aRv)
 {
   if (!aMediaStreamTrack) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
+  if (!aMediaStreamTrack->AsAudioStreamTrack()) {
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return;
+  }
+
   MediaStreamGraph* graph = Context()->Graph();
 
   AudioNodeEngine* engine = new MediaStreamTrackAudioSourceNodeEngine(this);
   mStream = AudioNodeExternalInputStream::Create(graph, engine);
 
   AttachToTrack(aMediaStreamTrack);
 }
 
@@ -90,17 +100,18 @@ MediaStreamTrackAudioSourceNode::Destroy
 }
 
 MediaStreamTrackAudioSourceNode::~MediaStreamTrackAudioSourceNode()
 {
   Destroy();
 }
 
 void
-MediaStreamTrackAudioSourceNode::AttachToTrack(const RefPtr<MediaStreamTrack>& aTrack)
+MediaStreamTrackAudioSourceNode::AttachToTrack(
+  const RefPtr<MediaStreamTrack>& aTrack)
 {
   MOZ_ASSERT(!mInputTrack);
   MOZ_ASSERT(aTrack->AsAudioStreamTrack());
 
   if (!mStream) {
     return;
   }
 
@@ -163,89 +174,92 @@ void
 MediaStreamTrackAudioSourceNode::NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack)
 {
   if (aTrack != mInputTrack) {
     return;
   }
 
   DetachFromTrack();
 }
-
 /**
  * Changes the principal. Note that this will be called on the main thread, but
  * changes will be enacted on the MediaStreamGraph thread. If the principal
  * change results in the document principal losing access to the stream, then
  * there needs to be other measures in place to ensure that any media that is
  * governed by the new stream principal is not available to the MediaStreamGraph
  * before this change completes. Otherwise, a site could get access to
  * media that they are not authorized to receive.
  *
  * One solution is to block the altered content, call this method, then dispatch
  * another change request to the MediaStreamGraph thread that allows the content
  * under the new principal to flow. This might be unnecessary if the principal
  * change is changing to be the document principal.
  */
 void
-MediaStreamTrackAudioSourceNode::PrincipalChanged(MediaStreamTrack* aMediaStreamTrack)
+MediaStreamTrackAudioSourceNode::PrincipalChanged(
+  MediaStreamTrack* aMediaStreamTrack)
 {
   MOZ_ASSERT(aMediaStreamTrack == mInputTrack);
 
   bool subsumes = false;
   nsIDocument* doc = nullptr;
   if (nsPIDOMWindowInner* parent = Context()->GetParentObject()) {
     doc = parent->GetExtantDoc();
     if (doc) {
       nsIPrincipal* docPrincipal = doc->NodePrincipal();
       nsIPrincipal* trackPrincipal = aMediaStreamTrack->GetPrincipal();
-      if (!trackPrincipal || NS_FAILED(docPrincipal->Subsumes(trackPrincipal, &subsumes))) {
+      if (!trackPrincipal ||
+          NS_FAILED(docPrincipal->Subsumes(trackPrincipal, &subsumes))) {
         subsumes = false;
       }
     }
   }
   auto stream = static_cast<AudioNodeExternalInputStream*>(mStream.get());
   bool enabled = subsumes || aMediaStreamTrack->GetCORSMode() != CORS_NONE;
-  stream->SetInt32Parameter(MediaStreamTrackAudioSourceNodeEngine::ENABLE, enabled);
+  stream->SetInt32Parameter(MediaStreamTrackAudioSourceNodeEngine::ENABLE,
+                            enabled);
 
   if (!enabled && doc) {
     nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
                                     NS_LITERAL_CSTRING("Web Audio"),
                                     doc,
                                     nsContentUtils::eDOM_PROPERTIES,
                                     CrossOriginErrorString());
   }
 }
 
 size_t
-MediaStreamTrackAudioSourceNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
+MediaStreamTrackAudioSourceNode::SizeOfExcludingThis(
+  MallocSizeOf aMallocSizeOf) const
 {
-  // Future:
-  // - mInputStream
   size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
   if (mInputPort) {
     amount += mInputPort->SizeOfIncludingThis(aMallocSizeOf);
   }
   return amount;
 }
 
 size_t
-MediaStreamTrackAudioSourceNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+MediaStreamTrackAudioSourceNode::SizeOfIncludingThis(
+  MallocSizeOf aMallocSizeOf) const
 {
   return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
 }
 
 void
 MediaStreamTrackAudioSourceNode::DestroyMediaStream()
 {
   if (mInputPort) {
     mInputPort->Destroy();
     mInputPort = nullptr;
   }
   AudioNode::DestroyMediaStream();
 }
 
 JSObject*
-MediaStreamTrackAudioSourceNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+MediaStreamTrackAudioSourceNode::WrapObject(JSContext* aCx,
+                                            JS::Handle<JSObject*> aGivenProto)
 {
   return MediaStreamTrackAudioSourceNodeBinding::Wrap(aCx, this, aGivenProto);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/webaudio/MediaStreamTrackAudioSourceNode.h
+++ b/dom/media/webaudio/MediaStreamTrackAudioSourceNode.h
@@ -3,71 +3,78 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MediaStreamTrackAudioSourceNode_h_
 #define MediaStreamTrackAudioSourceNode_h_
 
 #include "AudioNode.h"
+#include "AudioNodeEngine.h"
 #include "DOMMediaStream.h"
-#include "AudioNodeEngine.h"
 
 namespace mozilla {
 
 namespace dom {
 
 class AudioContext;
 struct MediaStreamTrackAudioSourceOptions;
 
 class MediaStreamTrackAudioSourceNodeEngine final : public AudioNodeEngine
 {
 public:
   explicit MediaStreamTrackAudioSourceNodeEngine(AudioNode* aNode)
-    : AudioNodeEngine(aNode), mEnabled(false) {}
+    : AudioNodeEngine(aNode)
+    , mEnabled(false)
+  {}
 
   bool IsEnabled() const { return mEnabled; }
-  enum Parameters {
+  enum Parameters
+  {
     ENABLE
   };
   void SetInt32Parameter(uint32_t aIndex, int32_t aValue) override
   {
     switch (aIndex) {
-    case ENABLE:
-      mEnabled = !!aValue;
-      break;
-    default:
-      NS_ERROR("MediaStreamTrackAudioSourceNodeEngine bad parameter index");
+      case ENABLE:
+        mEnabled = !!aValue;
+        break;
+      default:
+        NS_ERROR("MediaStreamTrackAudioSourceNodeEngine bad parameter index");
     }
   }
 
 private:
   bool mEnabled;
 };
 
-class MediaStreamTrackAudioSourceNode : public AudioNode,
-                                   public DOMMediaStream::TrackListener,
-                                   public PrincipalChangeObserver<MediaStreamTrack>
+class MediaStreamTrackAudioSourceNode
+  : public AudioNode
+  , public DOMMediaStream::TrackListener
+  , public PrincipalChangeObserver<MediaStreamTrack>
 {
 public:
   static already_AddRefed<MediaStreamTrackAudioSourceNode>
-  Create(AudioContext& aContext, const MediaStreamTrackAudioSourceOptions& aOptions,
-         ErrorResult& aRv);
+  Create(AudioContext& aContext,
+         const MediaStreamTrackAudioSourceOptions& aOptions, ErrorResult& aRv);
 
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamTrackAudioSourceNode, AudioNode)
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamTrackAudioSourceNode,
+                                           AudioNode)
 
   static already_AddRefed<MediaStreamTrackAudioSourceNode>
   Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
-              const MediaStreamTrackAudioSourceOptions& aOptions, ErrorResult& aRv)
+              const MediaStreamTrackAudioSourceOptions& aOptions,
+              ErrorResult& aRv)
   {
     return Create(aAudioContext, aOptions, aRv);
   }
 
-  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+  JSObject*
+  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void DestroyMediaStream() override;
 
   uint16_t NumberOfInputs() const override { return 0; }
 
   const char* NodeType() const override
   {
     return "MediaStreamTrackAudioSourceNode";
@@ -84,21 +91,19 @@ public:
   // Attaches to aTrack so that its audio content will be used as input.
   void AttachToTrack(const RefPtr<MediaStreamTrack>& aTrack);
 
   // Detaches from the currently attached track if there is one.
   void DetachFromTrack();
 
   // Attaches to the first available audio track in aMediaStream.
   void AttachToFirstTrack(const RefPtr<DOMMediaStream>& aMediaStream);
-
   // From DOMMediaStream::TrackListener.
   void NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack) override;
   void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack) override;
-
   // From PrincipalChangeObserver<MediaStreamTrack>.
   void PrincipalChanged(MediaStreamTrack* aMediaStreamTrack) override;
 
 protected:
   explicit MediaStreamTrackAudioSourceNode(AudioContext* aContext);
   void Init(MediaStreamTrack* aMediaStreamTrack, ErrorResult& aRv);
   void Destroy();
   virtual ~MediaStreamTrackAudioSourceNode();