2014-04-16 07:06:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 "mozilla/dom/VideoTrack.h"
|
|
|
|
#include "mozilla/dom/VideoTrackList.h"
|
|
|
|
#include "mozilla/dom/VideoTrackListBinding.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
VideoTrackList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-04-16 07:06:45 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return VideoTrackListBinding::Wrap(aCx, this, aGivenProto);
|
2014-04-16 07:06:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoTrack*
|
|
|
|
VideoTrackList::operator[](uint32_t aIndex)
|
|
|
|
{
|
|
|
|
MediaTrack* track = MediaTrackList::operator[](aIndex);
|
|
|
|
return track->AsVideoTrack();
|
|
|
|
}
|
|
|
|
|
2016-05-10 11:28:24 +03:00
|
|
|
void
|
|
|
|
VideoTrackList::RemoveTrack(const RefPtr<MediaTrack>& aTrack)
|
|
|
|
{
|
|
|
|
// we need to find the video track before |MediaTrackList::RemoveTrack|. Or
|
|
|
|
// mSelectedIndex will not be valid. The check of mSelectedIndex == -1
|
|
|
|
// need to be done after RemoveTrack. Also the call of
|
|
|
|
// |MediaTrackList::RemoveTrack| is necessary even when mSelectedIndex = -1.
|
|
|
|
bool found;
|
2016-05-10 12:02:15 +03:00
|
|
|
VideoTrack* selectedVideoTrack = IndexedGetter(mSelectedIndex, found);
|
2016-05-10 11:28:24 +03:00
|
|
|
MediaTrackList::RemoveTrack(aTrack);
|
|
|
|
if (mSelectedIndex == -1) {
|
|
|
|
// There was no selected track and we don't select another track on removal.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(found, "When mSelectedIndex is set it should point to a track");
|
2016-05-10 12:02:15 +03:00
|
|
|
MOZ_ASSERT(selectedVideoTrack, "The mSelectedIndex should be set to video track only");
|
2016-05-10 11:28:24 +03:00
|
|
|
|
|
|
|
// Let the caller of RemoveTrack deal with choosing the new selected track if
|
|
|
|
// it removes the currently-selected track.
|
2016-05-10 12:02:15 +03:00
|
|
|
if (aTrack == selectedVideoTrack) {
|
2016-05-10 11:28:24 +03:00
|
|
|
mSelectedIndex = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The removed track was not the selected track and there is a
|
|
|
|
// currently-selected video track. We need to find the new location of the
|
|
|
|
// selected track.
|
|
|
|
for (size_t ix = 0; ix < mTracks.Length(); ix++) {
|
2016-05-10 12:02:15 +03:00
|
|
|
if (mTracks[ix] == selectedVideoTrack) {
|
2016-05-10 11:28:24 +03:00
|
|
|
mSelectedIndex = ix;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-16 07:06:45 +04:00
|
|
|
void
|
|
|
|
VideoTrackList::EmptyTracks()
|
|
|
|
{
|
|
|
|
mSelectedIndex = -1;
|
|
|
|
MediaTrackList::EmptyTracks();
|
|
|
|
}
|
|
|
|
|
2016-07-19 06:45:27 +03:00
|
|
|
VideoTrack* VideoTrackList::GetSelectedTrack()
|
|
|
|
{
|
|
|
|
if (mSelectedIndex < 0 || static_cast<size_t>(mSelectedIndex) >= mTracks.Length()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return operator[](mSelectedIndex);
|
|
|
|
}
|
|
|
|
|
2014-04-16 07:06:45 +04:00
|
|
|
VideoTrack*
|
|
|
|
VideoTrackList::IndexedGetter(uint32_t aIndex, bool& aFound)
|
|
|
|
{
|
|
|
|
MediaTrack* track = MediaTrackList::IndexedGetter(aIndex, aFound);
|
|
|
|
return track ? track->AsVideoTrack() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoTrack*
|
|
|
|
VideoTrackList::GetTrackById(const nsAString& aId)
|
|
|
|
{
|
|
|
|
MediaTrack* track = MediaTrackList::GetTrackById(aId);
|
|
|
|
return track ? track->AsVideoTrack() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|