Commit Graph

178 Commits

Author SHA1 Message Date
Theodore Abshire 34337ca28d feat(UI): Added polyfill for screen.orientation.
There are some platforms (e.g. iPad) which can be rotated,
but do not support the screen.orientation API. This is relevant
because iPad now supports requestFullscreen, which it did not
before.

Found while investigating #2653

Change-Id: Iacc93433aa1fb50a25d968203dc9fd4f7f16b4ae
2020-06-17 12:31:24 -07:00
Joey Parrish f539147d48 fix: Correct license headers in compiled output
This fixes all the license headers in the main library, which corrects
the appearance of the main license in the compiled output.

It seems that the `!` in the header forces the compiler to keep it in
the output.  I believe older compiler releases did this purely based
on `@license`.

Issue #2638

Change-Id: I7f0e918caad10c9af689c9d07672b7fe9be7b2f3
2020-06-09 16:05:09 -07:00
Joey Parrish 453ab69a11 Add missing goog.require calls in polyfills
Change-Id: Ieb3724fb8e6b29a1b85e73cb249c1bd5a166f732
2020-05-21 11:46:10 -07:00
Sandra Lokshina 26d2e98959 Add a util for handling media readyState related logic.
Fixes #2555.

Change-Id: I735064952bc425bfb18d6c5681921ae1691eb348
2020-05-19 22:43:13 +00:00
michellezhuo 8ad0f48939 export shaka.polyfill
@exportInterface is used by the extern generator, but ignored by the
compiler. @export should be used for shaka.polyfill.

Closes #2549 .

Change-Id: I400db152ec8ca222a45a598ab58ddfbe44552443
2020-05-12 17:27:33 -07:00
Álvaro Velad Galván 6f9b36f755 Allow OPUS on Tizen 5 or higher. (#2564) 2020-05-11 15:07:04 -07:00
Joey Parrish 80f53221fd Correct minimum supported Safari version in README
Also add a note to the MSE polyfill about restrictions being applied
in Player as well.  We used to restrict Safari versions only in the
polyfill, and I had forgotten about the other version check.

Closes #2548

Change-Id: I4d2f319939c3a079e7f0ec7134876d91fc425bf4
2020-05-05 14:47:08 -07:00
Joey Parrish 5f62f4e779 Clean up use of "self" in arrow function
There is no need to use "self" to capture "this" with arrow functions.

Change-Id: I8d4c2251292d7e27952770b2d45f34fbdfceceb6
2020-05-05 09:13:43 -07:00
Joey Parrish 11f3347a48 Fix static method aliases
We used to alias static utility methods by assigning the method itself
to a local variable.  This is not allowed by the new Closure Compiler
release that we are adopting, and for good reason.

The old compiler did not understand the use of "this" in static
methods, but the new one does.  And it turns out that when we start
using "this" in static methods (see #2532), aliasing the method itself
can break everything.

When you refer to "this" in a static method, it refers to the class.
This is really useful in utility classes that have private static
methods they use to perform common tasks.  However, just as it ruins
the value of "this" to alias an instance method, the same is true of
an ES6 class's static method.

The fix is to always alias the class instead of the method.  The new
compiler will simply not let us get away with the old way any more, so
regressions after this are unlikely.

Issue #2528 (compiler upgrade)
Issue #2532 (static "this")

Change-Id: Id800d466e639c7cbcf4aa6fbb05114c772a2229f
2020-04-30 19:28:53 +00:00
Joey Parrish 34cde38108 Fix type info and initData types in EME polyfills
The latest Closure Compiler initially complained about "initData" not
being a known property of "Event".  Correcting the type to
MediaEncryptedEvent exposed a potential bug, which is that we were
assigning Uint8Array in some cases instead of the correct ArrayBuffer.
This fixes both the type of the event and converts the Uint8Arrays to
ArrayBuffers.

This also works around a complaint about "code" on "Error".  We use
"Error" objects as look-alikes for DOMException because there is no
exposed constructor for DOMExceptions.  To satisfy the compiler, we
use square brackets now to set the "code" field on these DOMException
look-alikes.

Finally, this removes the "method" field on certain Errors in the
WebKit EME polyfill.  These must have been leftover from some
debugging, and are not used at all.

Issue #2528

Change-Id: I32c4617b14a30c412d5bc532ec17a46fdc1fea1a
2020-04-28 22:30:19 +00:00
Joey Parrish 15e48e91f3 Fix over-indentation of classes
These classes were over-idented, making formatting more challenging.
I wanted to fix this before making compiler-upgrade-related changes in
these files.

Issue #2528

Change-Id: Ic44448760161a3e724d8c92f41f07c1a0babfa72
2020-04-28 22:30:19 +00:00
Joey Parrish e3486303e3 Use brackets in VTTCue polyfill
These polyfills don't have the exact same type as the thing they are
polyfilling.  Instead of being constructors for VTTCue (which doesn't
exist if we are using the polyfill), they are functions that return
TextTrackCue (the base class of VTTCue and the closest thing we have
on some platforms).

Because the types don't match, the latest Closure Compiler complains.
To get around this, we use square brackets.

Issue #2528

Change-Id: Ie1e3f13dc51f2145f7d3c9d510b64d9a8d7b1f64
2020-04-28 21:40:33 +00:00
Joey Parrish df0a5f7290 Fix Safari-prefixed fullscreen APIs
We had made some mistakes in these prefixed names.  The corrections
were made after consulting both MDN and Apple's docs.

This was caught by a compiler upgrade.

Issue #2528

Change-Id: I80994569b04a14b26b3e2fbb2673992ca7e68f50
2020-04-28 20:58:16 +00:00
Jacob Trimble 7ae6fc7d93 Fix FairPlay encrypted event handling.
The 'webkitkeyneeded' and 'encrypted' events send similar data, but
they were incompatible with each other and our transform handling.
This makes our polyfill produce the same format as the browser for
cases where the browser may only fire the old event.  This also makes
our utilities work with the new format.

The 'webkitkeyneeded' event was a length-prefixed UTF-16 string while
the 'encrypted' event was just a UTF-8 string.

This also makes a breaking change in the transform callback to pass the
init data type.  This shouldn't break anyone that only uses the first
argument; the second argument was mainly added so we could have the
default transform work without knowing anything.

This change could also break people who use custom transform functions.
The init data format is changing, which could break people who read
it directly.  If they follow the tutorial and use our utilities, it
shouldn't break.  This also updates the tutorial to match the new format
and be more clear about the format.

Fixes #2214

Change-Id: I006382028e828e31e20e085114fd7fd85c0e1eaa
2020-04-07 16:59:27 +00:00
Jacob Trimble 3fa7472086 Add non-nullable modifier to return types.
This is a copy of the internal CL: cr/299901617.

Change-Id: I49abbde9563f08819ec99dbc9deb99b66dd8053b
2020-03-11 15:46:06 -07:00
Joey Parrish 917e788271 Fix exception thrown for Chrome & Firefox on iOS
Because we have some polyfills and blacklists that are specific to
Safari and iOS, we need to detect specific versions of Safari and iOS.
The existing detection of Safari/iOS versions was in multiple places,
and did not account for non-Safari browsers on iOS.  This refactor
allows us to correctly detect iOS Chrome, and fixes a fatal exception
thrown in the MediaSource polyfill for all non-Safari browsers on iOS.

Change-Id: Ic88dc1a4c82087054cd4791dbf295b7ea2aeab09
2020-02-04 18:57:51 +00:00
Joey Parrish 37a5e4abd2 Fix PiP polyfill for iOS
This solution involves polyfilling the disablePictureInPicture
attribute on the video element. If the polyfill is installed, it will
show document.pictureInPictureEnabled==true, but
video.disablePictureInPicture will be a getter that does a runtime
check on that specific element using webkitSupportsPresentationMode.

disablePictureInPicture (JS property & HTML attribute) is part of the
PiP spec, so this should be sufficient to disable PiP correctly on iOS
in your application, whether or not you are using our UI.

Closes #2199

Change-Id: Iac9fc7e6cf6d4b0f7576f55af7507348ab2dc02c
2020-01-27 21:04:47 -08:00
Joey Parrish 51c3717305 Update fullscreen externs
This updates the fullscreen externs to:
 - Add a newer definition for requestFullscreen which includes options
   for the method
 - Remove prefixed methods which are now built into the compiler and
   are no longer necessary
 - Drop document.webkitSupportsFullscreen method, which does not seem
   to exist as defined, even on iOS (confusion with similar property
   on video element: https://apple.co/39TLC5I)

This enables PR #2325 to resolve issue #2324

Change-Id: Ie7bea7e7d4fd59d6d801431e2ba996649e185dc1
2020-01-06 19:42:18 +00:00
Jacob Trimble 011749e95f Standardize argument comments.
This changes the eslint rule to enforce a strict pattern for the
argument comments.  The comment must appear before the argument and
must be /* foo= */.  This still ignores line comments.

Change-Id: I3afb01c65e1088eda13facb3aeeaa7595a2f5aee
2020-01-06 19:40:52 +00:00
Joey Parrish 8a3708de76 Update encryption scheme polyfill
The new release includes support for encryption scheme queries in
MediaCapabilities.

Change-Id: I041773ed4e8e957123bfd3b666749999a72a7da3
2019-12-20 22:50:38 +00:00
Joey Parrish 0ad9aa3fd9 Fix EME polyfill issues
This fixes several inter-related issues:
 1. Catch errors in polyfill installation so that test setup isn't
    interrupted half-way through
 2. Use the compiled polyfill in tests, fixing polyfill installation
    error during tests on IE
 3. Require at least version 1.0.2 of the polyfill, since 1.0.0 had
    bugs in the module export and 1.0.1 had an infinite recursion bug

Change-Id: I38c973152409d9b3168e70e82f20579566663208
2019-12-02 12:28:28 -08:00
Joey Parrish aff3ad78cd Fix shaka.polyfill missing in externs
The generated externs did not include shaka.polyfill because we used
the wrong annotation on the class.  This fixes it.

Raised in PR #1273

Change-Id: I348064a117a7e1878b439ad8bd1ce49df56bfd39
2019-11-22 10:47:39 -08:00
Joey Parrish 64896d70b0 Use shorter license header
This reflects changes in Google's policy on JavaScript license
headers, which should be smaller to avoid increasing the size of the
binary unnecessarily.

This also updates the company name from "Google, Inc" to "Google LLC".

Change-Id: I3f8b9ed3700b6351f43173d50c94d35c333e82b4
2019-11-22 18:18:36 +00:00
Joey Parrish b9b4118938 Add a polyfill for EME encryption scheme queries
Note that the encryptionScheme field isn't being used by Shaka Player
yet, but that this will enable us to experiment with it ahead of the
full launch of the feature in browsers.

See also:
 - https://wicg.github.io/encrypted-media-encryption-scheme/
 - https://github.com/WICG/encrypted-media-encryption-scheme/issues/13
 - https://github.com/w3c/encrypted-media/pull/457

Change-Id: I9e8c2b6ce4ce3f4fe634fa4164669c69959e7fde
2019-11-22 18:18:36 +00:00
Germán Krauss b4bfa1550d Disable indexedDB support if an error is thrown (#2236) 2019-11-14 11:16:03 -08:00
Joey Parrish 65370b4b99 Update MediaSource polyfills for Safari 13
Safari 13 is out, and needs polyfills just like Safari 12 did
(although one fewer).  This assumes that Safari 13+ all need the same
polyfills (to avoid surprise failures when Safari 14 comes out).

This also raises the minimum version from Safari 9 to Safari 11, since
usage stats for Safari 9 and 10 are vanishingly small.  Dropping
support for Safari 9 and 10 allows us to delete a complicated polyfill
used for those versions.

Change-Id: I8f833d915215fc19a89e3aea292b67c5d677c779
2019-10-08 15:36:38 -07:00
Álvaro Velad Galván 46ddaa0b8b Move PatchedMediaKeysMs.normaliseInitData_ to shaka.util.Pssh.normaliseInitData (#2161)
Related to ongoing work for #1531
2019-09-26 10:44:08 -07:00
Jacob Trimble 50938a02a4 Remove throws directives.
These are intermittently used and cannot be verified.  Most of our
methods can throw a shaka.util.Error, so having it doesn't really add
anything.  Plus, if we change a function to throw, we'd need to update
all their callers to ensure they have an accurate description of what
they throw; otherwise we can't trust the directive.

Change-Id: I520bd0fc4c33443e967bf5b103ca5aa9e3274884
2019-08-28 17:00:04 +00:00
Jacob Trimble 26aecdd36e Use Uint8ArrayUtils.concat in polyfill.
Change-Id: Ie6170e662ba8964fd2d683f2d06f54b38326e91c
2019-08-22 21:11:16 +00:00
Jacob Trimble 454ff49006 Add a type to lazily generate a value.
Change-Id: Ibcd5bc76953f1c0c153dd5845d1b095dac0bb358
2019-08-21 22:02:06 +00:00
Jacob Trimble 887f2e614d Make Uint8ArrayUtils accept BufferSource.
Change-Id: Ia22b4535f4a6cbc156022299d732b27602c677d3
2019-08-21 20:41:45 +00:00
Jacob Trimble 18b59c5294 Disallow using new Uint8Array with BufferSource.
Using "new Uint8Array" with a TypedArray creates a copy of the buffer;
this is unnecessarily expensive for large buffers.  This adds a rule
to disallow using it in favor of a new utility that correctly creates
a new "view" on the same buffer.

Note it is fine to pass an ArrayBuffer to "new Uint8Array" and it won't
copy; but there there are many cases where the type is BufferSource,
so it could be a TypedArray.  Unfortunately, there are many other cases
where we explicitly pass an ArrayBuffer; but the compiler rules don't
allow us to whitelist this case (since ArrayBuffer is part of
BufferSource).

Change-Id: I58696a85a9cbcc188c0b16919c9eeb63e56edca1
2019-08-21 20:40:59 +00:00
Jacob Trimble a2bcf7278d Move some utilities to BufferUtils.
Change-Id: Ifb3c4348cc912640b99ff53f7cac59a63480c68e
2019-08-20 22:07:35 +00:00
Jacob Trimble 596c80a949 Refactor handling of ArrayBuffer.
This changes the network API to use BufferSource instead of ArrayBuffer,
which allows plugins to return a "view" on a buffer instead of the
whole buffer.  This also adds some utilities for changing between
views and buffers.

Lastly this forbids the use of the "buffer" property of TypedArrays
since it doesn't work with partial "views".  This audits and fixes the
usages of the "buffer" property to ensure correct usage.

It should be noted that both MSE and EME accept a BufferSource as input,
so we don't need to convert a "view" into an ArrayBuffer before passing
to it.

Change-Id: Iaa417773f8ce5304424e43c7372ce10ebf540d2a
2019-08-20 20:17:33 +00:00
Jacob Trimble c5b9d6804f Allow custom content ID in FairPlay.
Now there is a generic callback to transform the init data before
passing it to the browser.  This can be used by apps to use a custom
content ID in FairPlay content.  This also adds some utilities to help
in writing these functions and moves the default behavior to DrmEngine.

Closes #1951

Change-Id: I78ce660c126b53a69d5f55b16775ffcdbbe4d748
2019-08-07 18:38:40 +00:00
Jacob Trimble b12075093e Add sessionId field to network request.
This allows a request/response filter to determine which EME session
made the request.  This also changes the session ID of FairPlay sessions
so they are available too.

Issue #1951

Change-Id: I1a07abae6faf4a87fad7b5d4290a00b25e83da8e
2019-08-05 16:52:11 +00:00
Joey Parrish 625938e2f9 Revert offline PSSH support for manifest that are missing inline init data
This reverts commit 6e5a0797de, #2042.

The PR as it landed broke some test cases and functionality for storing persistent licenses, and it doesn't seem to work even for its intended use case.
2019-08-02 16:56:24 -07:00
Ante Wall 6e5a0797de feature: Offline PSSH support for manifest that are missing inline init data (#2042)
* fix: Reference issue with SegmentReference createUris

* test: Added Segment GetUris Test for timeline

* feat: Get PSSH from segements if not initdata exists

* feat: Get PSSH from segements if not initdata exists

* fix: JSDoc comments and moved drmEngine update to storage

* fix: Remove comments

* fix: Remove unused import

* fix: Lint erros and dedup initData code

* fix: remove no init data test and add check for use persistent license
2019-07-26 11:01:05 -07:00
Joey Parrish 0e20f69e8d Fix Chromecast MSE polyfill
The Chromecast MediaSource polyfill was broken in "Avoid integer for
loops", Change-Id: I3ba3cb6a439264e823022b2a64e7cdbd265494c7.

This particular loop used to start at index 1, and the previous change
made it start at 0.  Because of a test infrastructure failure that
prevented testing on Chromecast, we missed this mistake.

This bug did not affect any release versions.

This fixes the bug by using shift() to remove the first item before
the loop, instead of [0] to access it in-place.

Change-Id: I3aa53436e23a1b389375df2b06b3bbbab18ecf0b
2019-07-17 20:26:05 +00:00
Joey Parrish 85ba5e49bb Ignore case in MIME type checks
Closes #1991

Change-Id: Ib76f7539ff5173fca1ddb409e33240e7e9d3fd11
2019-07-09 20:24:50 +00:00
Jacob Trimble 5c35108cb8 Avoid integer for loops.
Issue #1518

Change-Id: I3ba3cb6a439264e823022b2a64e7cdbd265494c7
2019-07-09 17:11:49 +00:00
Jacob Trimble 3da809019b Enable additional ES6 linter rules.
Change-Id: I6861541b27153ba034364a5972a9b086de581cef
2019-06-11 18:35:09 +00:00
Joey Parrish 6cb12ad174 Fix stack overflow in tests on IE
In our tests, we can load the library many times.  Each time, the
polyfills get installed, so each polyfill must be able to handle being
installed twice, and avoid any bad behavior.

The InputEvent polyfill, which is used on IE only to get correct UI
behavior on input elements, was only able to handle being installed
twice if each call was on the same copy of the library.  In our tests,
this is not the case.  If we load the library 20 times, we get the
polyfill installed 20 times.

Since it was comparing addEventListener with the polyfilled version,
this check would fail when the library was reloaded.  Each "shaka"
namespace was distinct.  So on 20 hypothetical library loads, each
polyfill would delegate to its predecessor, creating a stack some 40
functions deep.  This would trigger a stack overflow when testing on
IE.

Instead, we can store the original addEventListener in some global
place, such as on HTMLInputElement.prototype.originalAddEventListener.
If that exists, the polyfill (or some version of it) was installed, so
we don't install another.

Found in Jasmine upgrade process (issue #1949)

Change-Id: I714631c9b3ac5c59cf82a5cf7501cb544d1cb5cb
2019-06-05 09:08:37 -07:00
Joey Parrish 0239d04915 Fix IE11 EME polyfill
Two patches in the IE EME polyfill became undefined during the ES6
conversion.  These mistakes were caught by a newer compiler.

setMediaKeys was declared on a different class (MediaKeySystemAccess).
And both setMediaKeys and requestMediaKeySystemAccess needed to be
declared static in order to be referenced from a static install
method.

Issue #1852

Change-Id: Ibbeb57bb3f25e84826ab094681717fdaf1b5a8b7
2019-06-03 18:40:50 +00:00
Theodore Abshire 4816359982 Convert patchedmediakeys polyfills to ES6
Issue #1157

Change-Id: I034cb3b6b947f24f828e221612f46366ec6d660d
2019-05-30 16:57:27 +00:00
Theodore Abshire f584c9aab6 Convert remaining polyfills to ES6.
Issue #1157

Change-Id: Ie330cd870ccf14dc3f56987b2787970b46b1ac89
2019-05-29 23:39:08 +00:00
Jacob Trimble d5780d401b Fix line length issues for indent fix.
Change-Id: I87d75fd88000f8f9bff7b9f1bf5667ba28f6dd60
2019-05-13 22:31:20 +00:00
Jacob Trimble f130dffcef Enable eslint indentation rule.
This is a fully automated change.  The linter will fail because the
extra indentation caused line-length errors.  These won't be fixed
automatically.  They are fixed in a follow-up to make this one fully
automated.

Change-Id: I4d8cf9c998985add2bcd24a81c8d65495668c4f3
2019-05-13 22:31:09 +00:00
Jacob Trimble 0dd64074b9 Only allow one statement per line.
With the new style rule, we cannot have two statements on the same line.
So we can no longer have an "if" on a single line and we cannot have
an arrow function with a body on the same line as when it is used.
This is mostly a manual change.

Change-Id: I2285202dd5ecbad764308bc725e6d317ff2ee7f0
2019-05-13 22:11:50 +00:00
Jacob Trimble 381274fbbd Enforce a consistent dot location.
Change-Id: Ic3b86c4c113023206bc37a117e96f672f351121b
2019-05-09 21:09:30 +00:00