mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 23:38:38 +09:00
[PALEMOON] Use message manager to detect full-screen HTML5 video in S4E module
This commit is contained in:
parent
606356d1f9
commit
87117726dc
4 changed files with 69 additions and 20 deletions
|
|
@ -35,7 +35,7 @@ S4EStatusService.prototype =
|
|||
_defaultStatus: { val: "", type: "" },
|
||||
|
||||
_isFullScreen: false,
|
||||
_isFullScreenVideo: false,
|
||||
_isVideo: false,
|
||||
|
||||
_statusText: { val: "", type: "" },
|
||||
_noUpdate: false,
|
||||
|
|
@ -222,18 +222,10 @@ S4EStatusService.prototype =
|
|||
}
|
||||
},
|
||||
|
||||
updateFullScreen: function()
|
||||
setFullScreenState: function(isFullScreen, isVideo)
|
||||
{
|
||||
this._isFullScreen = this._window.fullScreen;
|
||||
this._isFullScreenVideo = false;
|
||||
if(this._isFullScreen)
|
||||
{
|
||||
let fsEl = this._window.content.document.mozFullScreenElement;
|
||||
if(fsEl && (fsEl.nodeName == "VIDEO" || fsEl.getElementsByTagName("VIDEO").length > 0))
|
||||
{
|
||||
this._isFullScreenVideo = true;
|
||||
}
|
||||
}
|
||||
this._isFullScreen = isFullScreen;
|
||||
this._isVideo = isFullScreen && isVideo;
|
||||
|
||||
this.clearStatusField();
|
||||
this.updateStatusField(true);
|
||||
|
|
@ -305,7 +297,7 @@ S4EStatusService.prototype =
|
|||
|
||||
let label = null;
|
||||
|
||||
if(this._isFullScreen && this._service.advancedStatusDetectFullScreen)
|
||||
if(this._isFullScreen)
|
||||
{
|
||||
switch(location)
|
||||
{
|
||||
|
|
@ -330,7 +322,7 @@ S4EStatusService.prototype =
|
|||
break;
|
||||
case 3: // Popup
|
||||
default:
|
||||
if(this._isFullScreenVideo && this._service.advancedStatusDetectVideo)
|
||||
if(this._isVideo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ function Status4Evar(window, gBrowser, toolbox)
|
|||
this.statusService = new S4EStatusService(this._window, s4e_service, this.getters);
|
||||
this.progressMeter = new S4EProgressService(gBrowser, s4e_service, this.getters, this.statusService);
|
||||
this.downloadStatus = new S4EDownloadService(this._window, gBrowser, s4e_service, this.getters);
|
||||
this.sizeModeService = new SizeModeService(this._window, this);
|
||||
this.sizeModeService = new SizeModeService(this._window, gBrowser, this);
|
||||
|
||||
this._window.addEventListener("unload", this, false);
|
||||
}
|
||||
|
|
@ -232,20 +232,31 @@ S4EWindowGetters.prototype =
|
|||
}
|
||||
};
|
||||
|
||||
function SizeModeService(window, s4e)
|
||||
function SizeModeService(window, gBrowser, s4e)
|
||||
{
|
||||
this._window = window;
|
||||
this._gBrowser = gBrowser;
|
||||
this._s4e = s4e;
|
||||
this._mm = this._window.messageManager;
|
||||
|
||||
this.lastFullScreen = this._window.fullScreen;
|
||||
this.lastwindowState = this._window.windowState;
|
||||
|
||||
if(s4e_service.advancedStatusDetectFullScreen)
|
||||
{
|
||||
this._mm.addMessageListener("status4evar@caligonstudios.com:video-detect-answer", this)
|
||||
this._mm.loadFrameScript("resource:///modules/statusbar/content-thunk.js", true);
|
||||
}
|
||||
|
||||
this._window.addEventListener("sizemodechange", this, false);
|
||||
}
|
||||
|
||||
SizeModeService.prototype =
|
||||
{
|
||||
_window: null,
|
||||
_gBrowser: null,
|
||||
_s4e: null,
|
||||
_mm: null,
|
||||
|
||||
lastFullScreen: null,
|
||||
lastwindowState: null,
|
||||
|
|
@ -254,7 +265,13 @@ SizeModeService.prototype =
|
|||
{
|
||||
this._window.removeEventListener("sizemodechange", this, false);
|
||||
|
||||
["_window", "_s4e"].forEach(function(prop)
|
||||
if(s4e_service.advancedStatusDetectFullScreen)
|
||||
{
|
||||
this._mm.removeDelayedFrameScript("resource:///modules/statusbar/content-thunk.js");
|
||||
this._mm.removeMessageListener("status4evar@caligonstudios.com:video-detect-answer", this);
|
||||
}
|
||||
|
||||
["_window", "_gBrowser", "_s4e", "_mm"].forEach(function(prop)
|
||||
{
|
||||
delete this[prop];
|
||||
}, this);
|
||||
|
|
@ -262,10 +279,18 @@ SizeModeService.prototype =
|
|||
|
||||
handleEvent: function(e)
|
||||
{
|
||||
if(this._window.fullScreen != this.lastFullScreen)
|
||||
if(this._window.fullScreen != this.lastFullScreen && s4e_service.advancedStatusDetectFullScreen)
|
||||
{
|
||||
this.lastFullScreen = this._window.fullScreen;
|
||||
this._s4e.statusService.updateFullScreen();
|
||||
|
||||
if(this.lastFullScreen && s4e_service.advancedStatusDetectVideo)
|
||||
{
|
||||
this._gBrowser.selectedBrowser.messageManager.sendAsyncMessage("status4evar@caligonstudios.com:video-detect");
|
||||
}
|
||||
else
|
||||
{
|
||||
this._s4e.statusService.setFullScreenState(this.lastFullScreen, false);
|
||||
}
|
||||
}
|
||||
|
||||
if(this._window.windowState != this.lastwindowState)
|
||||
|
|
@ -275,5 +300,13 @@ SizeModeService.prototype =
|
|||
}
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([ CI.nsIDOMEventListener ])
|
||||
receiveMessage: function(message)
|
||||
{
|
||||
if(message.name == "status4evar@caligonstudios.com:video-detect-answer")
|
||||
{
|
||||
this._s4e.statusService.setFullScreenState(this.lastFullScreen, message.data.isVideo);
|
||||
}
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([ CI.nsIDOMEventListener, CI.nsIMessageListener ])
|
||||
};
|
||||
|
|
|
|||
23
application/palemoon/components/statusbar/content-thunk.js
Normal file
23
application/palemoon/components/statusbar/content-thunk.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* 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/. */
|
||||
|
||||
function handleVideoDetect(message)
|
||||
{
|
||||
let isVideo = false;
|
||||
|
||||
let fsEl = content.document.mozFullScreenElement;
|
||||
if(fsEl)
|
||||
{
|
||||
isVideo = (
|
||||
fsEl.nodeName == "VIDEO"
|
||||
|| (fsEl.nodeName == "IFRAME" && fsEl.contentDocument && fsEl.contentDocument.getElementsByTagName("VIDEO").length > 0)
|
||||
|| fsEl.getElementsByTagName("VIDEO").length > 0
|
||||
);
|
||||
}
|
||||
|
||||
sendAsyncMessage("status4evar@caligonstudios.com:video-detect-answer", {isVideo: isVideo});
|
||||
}
|
||||
|
||||
addMessageListener("status4evar@caligonstudios.com:video-detect", handleVideoDetect);
|
||||
|
||||
|
|
@ -16,6 +16,7 @@ EXTRA_COMPONENTS += [
|
|||
]
|
||||
|
||||
EXTRA_JS_MODULES.statusbar = [
|
||||
'content-thunk.js',
|
||||
'Downloads.jsm',
|
||||
'Progress.jsm',
|
||||
'Status.jsm',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue