this extends compatibility to FF-24-34

imported code from uBlock, including legacy toolbar support in 34485a04658ae7d8357dabe5e42b18e3e066a4b9,
which is itself directly based on work from @AlexVallat:
- 620a7d78d1
- d9b23d4f10
- 5ac4ec21e9
pull/2/head
gorhill 9 years ago
parent c8765697e1
commit 1f4ba9dda9

@ -0,0 +1,46 @@
#umatrix-legacy-button {
list-style-image: url('../img/browsericons/icon19-19.png');
}
#umatrix-legacy-button.off {
list-style-image: url('../img/browsericons/icon19-off.png');
}
toolbar[iconsize="small"] #umatrix-legacy-button {
list-style-image: url('../img/browsericons/icon19-19.png');
}
toolbar[iconsize="small"] #umatrix-legacy-button.off {
list-style-image: url('../img/browsericons/icon19-off.png');
}
#umatrix-legacy-button[badge]::before {
background: #000;
color: #fff;
content: attr(badge);
font: bold 10px sans-serif;
margin-top: -2px;
padding: 0 2px;
position: fixed;
}
/* This hack required because if the before content changes it de-pops the
popup (without firing any events). So just hide it instead. Note, can't
actually *hide* it, or the same thing happens.
**/
#umatrix-legacy-button[badge=""]::before {
padding: 0;
}
/* Override off state when in palette */
toolbarpaletteitem #umatrix-legacy-button.off {
list-style-image: url('../img/browsericons/icon19-12.png');
}
/* Override badge when in palette */
toolbarpaletteitem #umatrix-legacy-button[badge]::before {
content: none;
}
/* Prevent pale moon from showing the arrow underneath the button */
/* https://github.com/chrisaljoudi/uBlock/issues/1449#issuecomment-112112761 */
#umatrix-legacy-button .toolbarbutton-menu-dropmarker {
display: none;
-moz-box-orient: horizontal;
}

@ -38,13 +38,27 @@ const hostName = Services.io.newURI(Components.stack.filename, null, null).host;
/******************************************************************************/ /******************************************************************************/
const getMessageManager = function(win) { const getMessageManager = function(win) {
return win let iface = win
.QueryInterface(Ci.nsIInterfaceRequestor) .QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell) .getInterface(Ci.nsIDocShell)
.sameTypeRootTreeItem .sameTypeRootTreeItem
.QueryInterface(Ci.nsIDocShell) .QueryInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsIInterfaceRequestor) .QueryInterface(Ci.nsIInterfaceRequestor);
.getInterface(Ci.nsIContentFrameMessageManager);
try {
return iface.getInterface(Ci.nsIContentFrameMessageManager);
} catch (ex) {
// This can throw. It appears `shouldLoad` can be called *after* a
// tab has been closed. For example, a case where this happens all
// the time (FF38):
// - Open twitter.com (assuming you have an account and are logged in)
// - Close twitter.com
// There will be an exception raised when `shouldLoad` is called
// to process a XMLHttpRequest with URL `https://twitter.com/i/jot`
// fired from `https://twitter.com/`, *after* the tab is closed.
// In such case, `win` is `about:blank`.
}
return null;
}; };
/******************************************************************************/ /******************************************************************************/
@ -56,6 +70,7 @@ const contentObserver = {
ACCEPT: Ci.nsIContentPolicy.ACCEPT, ACCEPT: Ci.nsIContentPolicy.ACCEPT,
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT, MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
contentBaseURI: 'chrome://' + hostName + '/content/js/', contentBaseURI: 'chrome://' + hostName + '/content/js/',
cpMessageName: hostName + ':shouldLoad',
uniqueSandboxId: 1, uniqueSandboxId: 1,
get componentRegistrar() { get componentRegistrar() {
@ -113,6 +128,51 @@ const contentObserver = {
// https://bugzil.la/612921 // https://bugzil.la/612921
shouldLoad: function(type, location, origin, context) { shouldLoad: function(type, location, origin, context) {
if ( Services === undefined ) {
return this.ACCEPT;
}
if ( !context ) {
return this.ACCEPT;
}
if ( !location.schemeIs('http') && !location.schemeIs('https') ) {
return this.ACCEPT;
}
var contextWindow;
if ( type === this.MAIN_FRAME ) {
contextWindow = context.contentWindow || context;
} else if ( type === this.SUB_FRAME ) {
contextWindow = context.contentWindow;
} else {
contextWindow = (context.ownerDocument || context).defaultView;
}
// The context for the toolbar popup is an iframe element here,
// so check context.top instead of context
if ( !contextWindow.top || !contextWindow.location ) {
return this.ACCEPT;
}
let messageManager = getMessageManager(contextWindow);
if ( messageManager === null ) {
return this.ACCEPT;
}
let details = {
rawType: type,
url: location.asciiSpec
};
if ( typeof messageManager.sendRpcMessage === 'function' ) {
// https://bugzil.la/1092216
messageManager.sendRpcMessage(this.cpMessageName, details);
} else {
// Compatibility for older versions
messageManager.sendSyncMessage(this.cpMessageName, details);
}
return this.ACCEPT; return this.ACCEPT;
}, },

@ -19,7 +19,7 @@
<targetApplication> <targetApplication>
<r:Description> <r:Description>
<id>{{ec8030f7-c20a-464f-9b0e-13a3a9e97384}}</id> <id>{{ec8030f7-c20a-464f-9b0e-13a3a9e97384}}</id>
<minVersion>35.0</minVersion> <minVersion>24.0</minVersion>
<maxVersion>42.0</maxVersion> <maxVersion>42.0</maxVersion>
</r:Description> </r:Description>
</targetApplication> </targetApplication>

File diff suppressed because it is too large Load Diff

@ -128,12 +128,17 @@ vAPI.closePopup = function() {
// experience. // experience.
vAPI.localStorage = { vAPI.localStorage = {
PB: Services.prefs.getBranch('extensions.' + location.host + '.'), pbName: '',
pb: null,
str: Components.classes['@mozilla.org/supports-string;1'] str: Components.classes['@mozilla.org/supports-string;1']
.createInstance(Components.interfaces.nsISupportsString), .createInstance(Components.interfaces.nsISupportsString),
init: function(pbName) {
this.pbName = pbName;
this.pb = Services.prefs.getBranch(pbName);
},
getItem: function(key) { getItem: function(key) {
try { try {
return this.PB.getComplexValue( return this.pb.getComplexValue(
key, key,
Components.interfaces.nsISupportsString Components.interfaces.nsISupportsString
).data; ).data;
@ -143,20 +148,35 @@ vAPI.localStorage = {
}, },
setItem: function(key, value) { setItem: function(key, value) {
this.str.data = value; this.str.data = value;
this.PB.setComplexValue( this.pb.setComplexValue(
key, key,
Components.interfaces.nsISupportsString, Components.interfaces.nsISupportsString,
this.str this.str
); );
}, },
getBool: function(key) {
try {
return this.pb.getBoolPref(key);
} catch (ex) {
return null;
}
},
setBool: function(key, value) {
this.pb.setBoolPref(key, value);
},
setDefaultBool: function(key, defaultValue) {
Services.prefs.getDefaultBranch(this.pbName).setBoolPref(key, defaultValue);
},
removeItem: function(key) { removeItem: function(key) {
this.PB.clearUserPref(key); this.pb.clearUserPref(key);
}, },
clear: function() { clear: function() {
this.PB.deleteBranch(''); this.pb.deleteBranch('');
} }
}; };
vAPI.localStorage.init('extensions.' + location.host + '.');
/******************************************************************************/ /******************************************************************************/
})(); })();

@ -15,6 +15,7 @@ cp ./platform/firefox/vapi-*.js $DES/js/
cp ./platform/firefox/bootstrap.js $DES/ cp ./platform/firefox/bootstrap.js $DES/
cp ./platform/firefox/frame*.js $DES/ cp ./platform/firefox/frame*.js $DES/
cp -R ./platform/chromium/img $DES/ cp -R ./platform/chromium/img $DES/
cp ./platform/firefox/css/* $DES/css/
cp ./platform/firefox/chrome.manifest $DES/ cp ./platform/firefox/chrome.manifest $DES/
cp ./platform/firefox/install.rdf $DES/ cp ./platform/firefox/install.rdf $DES/
cp ./platform/firefox/*.xul $DES/ cp ./platform/firefox/*.xul $DES/

Loading…
Cancel
Save