From 5b2034ff45f854b5b95848b7e4910fa4142c4c5f Mon Sep 17 00:00:00 2001 From: csagan5 <32685696+csagan5@users.noreply.github.com> Date: Sun, 18 Feb 2018 22:43:29 +0100 Subject: [PATCH] Add patch to play videos in background --- .../BRM039_play-videos-in-background.patch | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 patches/BRM039_play-videos-in-background.patch diff --git a/patches/BRM039_play-videos-in-background.patch b/patches/BRM039_play-videos-in-background.patch new file mode 100644 index 00000000..d6230cfa --- /dev/null +++ b/patches/BRM039_play-videos-in-background.patch @@ -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