Browse Source

this extends compatibility to FF-24-34

imported code from uBlock, including legacy toolbar support in 34485a0465,
which is itself directly based on work from @AlexVallat:
- 620a7d78d1
- d9b23d4f10
- 5ac4ec21e9
pull/2/head
gorhill 10 years ago
parent
commit
1f4ba9dda9
  1. 46
      platform/firefox/css/legacy-toolbar-button.css
  2. 66
      platform/firefox/frameModule.js
  3. 2
      platform/firefox/install.rdf
  4. 918
      platform/firefox/vapi-background.js
  5. 32
      platform/firefox/vapi-common.js
  6. 1
      tools/make-firefox.sh

46
platform/firefox/css/legacy-toolbar-button.css

@ -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;
}

66
platform/firefox/frameModule.js

@ -38,13 +38,27 @@ const hostName = Services.io.newURI(Components.stack.filename, null, null).host;
/******************************************************************************/
const getMessageManager = function(win) {
return win
let iface = win
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell)
.sameTypeRootTreeItem
.QueryInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIContentFrameMessageManager);
.QueryInterface(Ci.nsIInterfaceRequestor);
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,
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
contentBaseURI: 'chrome://' + hostName + '/content/js/',
cpMessageName: hostName + ':shouldLoad',
uniqueSandboxId: 1,
get componentRegistrar() {
@ -113,6 +128,51 @@ const contentObserver = {
// https://bugzil.la/612921
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;
},

2
platform/firefox/install.rdf

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

918
platform/firefox/vapi-background.js
File diff suppressed because it is too large
View File

32
platform/firefox/vapi-common.js

@ -128,12 +128,17 @@ vAPI.closePopup = function() {
// experience.
vAPI.localStorage = {
PB: Services.prefs.getBranch('extensions.' + location.host + '.'),
pbName: '',
pb: null,
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) {
try {
return this.PB.getComplexValue(
return this.pb.getComplexValue(
key,
Components.interfaces.nsISupportsString
).data;
@ -143,20 +148,35 @@ vAPI.localStorage = {
},
setItem: function(key, value) {
this.str.data = value;
this.PB.setComplexValue(
this.pb.setComplexValue(
key,
Components.interfaces.nsISupportsString,
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) {
this.PB.clearUserPref(key);
this.pb.clearUserPref(key);
},
clear: function() {
this.PB.deleteBranch('');
this.pb.deleteBranch('');
}
};
vAPI.localStorage.init('extensions.' + location.host + '.');
/******************************************************************************/
})();

1
tools/make-firefox.sh

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

Loading…
Cancel
Save