Add patch to play videos in background
This commit is contained in:
parent
6807e7b388
commit
5b2034ff45
1 changed files with 70 additions and 0 deletions
70
patches/BRM039_play-videos-in-background.patch
Normal file
70
patches/BRM039_play-videos-in-background.patch
Normal file
|
@ -0,0 +1,70 @@
|
|||
Author: csagan5 <32685696+csagan5@users.noreply.github.com>
|
||||
Date: Sun Feb 18 22:15:25 2018 +0100
|
||||
|
||||
Play videos in background
|
||||
Break Page Visibility API and Fullscreen API for youtube.com and vimeo.com
|
||||
Original Javascript code by timdream
|
||||
|
||||
diff --git a/third_party/WebKit/Source/core/dom/BUILD.gn b/third_party/WebKit/Source/core/dom/BUILD.gn
|
||||
--- a/third_party/WebKit/Source/core/dom/BUILD.gn
|
||||
+++ b/third_party/WebKit/Source/core/dom/BUILD.gn
|
||||
@@ -302,6 +302,7 @@ blink_core_sources("dom") {
|
||||
"events/WindowEventContext.cpp",
|
||||
"events/WindowEventContext.h",
|
||||
"extensions/dont-track-me.h",
|
||||
+ "extensions/video-bg-play.h",
|
||||
"ng/flat_tree_traversal_ng.cc",
|
||||
"ng/flat_tree_traversal_ng.h",
|
||||
"trustedtypes/TrustedHTML.cpp",
|
||||
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp
|
||||
--- a/third_party/WebKit/Source/core/dom/Document.cpp
|
||||
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
|
||||
@@ -222,6 +222,7 @@
|
||||
#include "core/xml_names.h"
|
||||
#include "core/xmlns_names.h"
|
||||
#include "extensions/dont-track-me.h"
|
||||
+#include "extensions/video-bg-play.h"
|
||||
#include "platform/CrossThreadFunctional.h"
|
||||
#include "platform/DateComponents.h"
|
||||
#include "platform/EventDispatchForbiddenScope.h"
|
||||
@@ -5887,17 +5888,25 @@ void Document::FinishedParsing() {
|
||||
|
||||
// determine whether this is a Google search results page
|
||||
const SecurityOrigin *origin = GetSecurityOrigin();
|
||||
- if (origin) {
|
||||
+ auto* bodyElement = body();
|
||||
+ if (origin && bodyElement) {
|
||||
WTF::String domain = origin->Domain();
|
||||
size_t pos = domain.Find(".google.");
|
||||
- auto* bodyElement = body();
|
||||
- if (bodyElement && (pos != WTF::kNotFound) && (domain.length() - pos - 8 < 4)) {
|
||||
+ if ((pos != WTF::kNotFound) && (domain.length() - pos - 8 < 4)) {
|
||||
LOG(INFO) << "injecting dont-track-me Javascript payload";
|
||||
HTMLScriptElement* e = HTMLScriptElement::Create(*this, CreateElementFlags());
|
||||
e->setText(DONT_TRACK_ME_JS);
|
||||
bodyElement->AppendChild(e);
|
||||
}
|
||||
- }
|
||||
+
|
||||
+ // check for eligibility of the video bg fix
|
||||
+ if ((WTF::kNotFound != domain.Find("youtube.com")) || (WTF::kNotFound != domain.Find("vimeo.com"))) {
|
||||
+ LOG(INFO) << "injecting video-bg-play Javascript payload";
|
||||
+ HTMLScriptElement* e = HTMLScriptElement::Create(*this, CreateElementFlags());
|
||||
+ e->setText(VIDEO_BG_PLAY_JS);
|
||||
+ bodyElement->AppendChild(e);
|
||||
+ }
|
||||
+ } // has origin and body element
|
||||
}
|
||||
|
||||
void Document::ElementDataCacheClearTimerFired(TimerBase*) {
|
||||
diff --git a/third_party/WebKit/Source/core/dom/extensions/video-bg-play.h b/third_party/WebKit/Source/core/dom/extensions/video-bg-play.h
|
||||
new file mode 100644
|
||||
--- /dev/null
|
||||
+++ b/third_party/WebKit/Source/core/dom/extensions/video-bg-play.h
|
||||
@@ -0,0 +1,6 @@
|
||||
+#ifndef video_bg_play_h
|
||||
+#define video_bg_play_h
|
||||
+
|
||||
+#define VIDEO_BG_PLAY_JS "'use strict';\n\n/* video background play fix - original version by timdream */\ndocument.videoBGFix = {};\n\n// Page Visibility API\nObject.defineProperties(document.videoBGFix,\n { 'hidden': {value: false}, 'visibilityState': {value: 'visible'} });\n\nwindow.addEventListener(\n 'visibilitychange', evt => evt.stopImmediatePropagation(), true);\nwindow.addEventListener(\n 'blur', evt => evt.stopImmediatePropagation(), true);\n\n// Fullscreen API\nwindow.addEventListener('fullscreenchange', evt => {\n Object.defineProperties(document.videoBGFix,\n { 'fullscreenEnabled': {value: true},\n 'fullscreen': {value: true},\n 'fullscreenElement': {value: document.fullscreenElement.videoBGFix}});\n window.addEventListener(\n 'fullscreenchange', evt => evt.stopImmediatePropagation(), true);\n}, { capture: true, once: true });\n"
|
||||
+
|
||||
+#endif // video_bg_play_h
|
Loading…
Add table
Reference in a new issue