mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Firefox,Safari: fill vAPI.app in a different way
Pass the extension data (name and version) as the fragment of the URL for the background script, so vAPI.app can be filled without using XHR to read the manifest files.
This commit is contained in:
parent
20bd1287cf
commit
e61514b9b1
47
platform/firefox/bootstrap.js
vendored
47
platform/firefox/bootstrap.js
vendored
@ -19,43 +19,37 @@
|
||||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
/* global Services, APP_STARTUP, APP_SHUTDOWN */
|
||||
/* global APP_SHUTDOWN */
|
||||
/* exported startup, shutdown, install, uninstall */
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var bgProcess;
|
||||
|
||||
Components.utils['import']('resource://gre/modules/Services.jsm');
|
||||
let bgProcess;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
function startup(data, reason) {
|
||||
bgProcess = function(ev) {
|
||||
if (ev) {
|
||||
this.removeEventListener(ev.type, bgProcess);
|
||||
}
|
||||
function startup(data) {
|
||||
let {AddonManager} = Components.utils['import'](
|
||||
'resource://gre/modules/AddonManager.jsm',
|
||||
null
|
||||
);
|
||||
|
||||
bgProcess = Services.appShell.hiddenDOMWindow.document;
|
||||
bgProcess = bgProcess.documentElement.appendChild(
|
||||
bgProcess.createElementNS('http://www.w3.org/1999/xhtml', 'iframe')
|
||||
AddonManager.getAddonByID(data.id, addon => {
|
||||
let hDoc = Components.classes['@mozilla.org/appshell/appShellService;1']
|
||||
.getService(Components.interfaces.nsIAppShellService)
|
||||
.hiddenDOMWindow.document;
|
||||
|
||||
bgProcess = hDoc.documentElement.appendChild(
|
||||
hDoc.createElementNS('http://www.w3.org/1999/xhtml', 'iframe')
|
||||
);
|
||||
bgProcess.setAttribute('src', 'chrome://ublock/content/background.html');
|
||||
};
|
||||
|
||||
if (reason === APP_STARTUP) {
|
||||
Services.ww.registerNotification({
|
||||
observe: function(win) {
|
||||
Services.ww.unregisterNotification(this);
|
||||
win.addEventListener('DOMContentLoaded', bgProcess);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
bgProcess();
|
||||
}
|
||||
let bgURI = 'chrome://ublock/content/background.html';
|
||||
|
||||
// send addon data synchronously to the background script
|
||||
bgProcess.src = bgURI + '#' + [addon.name, addon.version];
|
||||
});
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
@ -70,7 +64,8 @@ function shutdown(data, reason) {
|
||||
|
||||
function install() {
|
||||
// https://bugzil.la/719376
|
||||
Services.strings.flushBundles();
|
||||
Components.classes['@mozilla.org/intl/stringbundle;1']
|
||||
.getService(Components.interfaces.nsIStringBundleService).flushBundles();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -43,9 +43,10 @@ vAPI.firefox = true;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.app = location.hash.slice(1).split(',');
|
||||
vAPI.app = {
|
||||
name: 'µBlock',
|
||||
version: '0.8.2.0'
|
||||
name: vAPI.app[0],
|
||||
version: vAPI.app[1]
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>Database Quota</key>
|
||||
<real>52428800</real>
|
||||
<key>Global Page</key>
|
||||
<string>background.html</string>
|
||||
<string>background.html#{appInfo}</string>
|
||||
<key>Popovers</key>
|
||||
<array>
|
||||
<dict>
|
||||
|
@ -32,20 +32,14 @@
|
||||
/******************************************************************************/
|
||||
|
||||
self.vAPI = self.vAPI || {};
|
||||
|
||||
vAPI.safari = true;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var xhr = new XMLHttpRequest;
|
||||
xhr.overrideMimeType('application/x-javascript;charset=utf-8');
|
||||
xhr.open('GET', 'Info.plist', false);
|
||||
xhr.send();
|
||||
xhr = xhr.responseText;
|
||||
|
||||
vAPI.app = location.hash.slice(1).split(',');
|
||||
vAPI.app = {
|
||||
name: xhr.match(/DisplayName<\S+[^>]+>([^<]+)/)[1],
|
||||
version: xhr.match(/ShortVersionString<\S+[^>]+>([^<]+)/)[1]
|
||||
name: decodeURIComponent(vAPI.app[0]),
|
||||
version: vAPI.app[1]
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -5,6 +5,7 @@ import json
|
||||
import sys
|
||||
import codecs
|
||||
from time import time
|
||||
from urllib import parse
|
||||
from shutil import rmtree
|
||||
from collections import OrderedDict
|
||||
|
||||
@ -58,6 +59,14 @@ with codecs.open(chromium_manifest, encoding='utf8') as m:
|
||||
manifest['buildNumber'] = int(time())
|
||||
manifest['description'] = description
|
||||
|
||||
# pass "#name,version" as the fragment in the URL of the background script
|
||||
manifest['appInfo'] = ','.join([
|
||||
parse.quote(manifest['name']),
|
||||
manifest['version']
|
||||
])
|
||||
|
||||
info_plist = pj(build_dir, 'Info.plist')
|
||||
|
||||
with codecs.open(pj(build_dir, 'Info.plist'), 'r+', encoding='utf8') as f:
|
||||
info_plist = f.read()
|
||||
f.seek(0)
|
||||
|
Loading…
Reference in New Issue
Block a user