Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserScriptLoader.uc.js 0.1.8.1 bug fix? #10

Open
lastdream2013 opened this issue Mar 5, 2013 · 0 comments
Open

UserScriptLoader.uc.js 0.1.8.1 bug fix? #10

lastdream2013 opened this issue Mar 5, 2013 · 0 comments

Comments

@lastdream2013
Copy link

if user Script content include "@require" , UserScriptLoader.uc.js 0.1.8.1 get an error.

this function maybe can fix like this?

USL.getContents = function(aURL, aCallback){
try {
urlSecurityCheck(aURL, gBrowser.contentPrincipal, Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
} catch(ex) {
return;
}
var uri = Services.io.newURI(aURL, null, null);
if (uri.scheme != 'http' && uri.scheme != 'https')
return USL.error('getContents is "http" or "https" only');

let aFile = USL.REQUIRES_FOLDER.clone();
aFile.QueryInterface(Ci.nsILocalFile);
aFile.appendRelativePath(encodeURIComponent(aURL));

var wbp = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);
wbp.persistFlags &= ~Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_NO_CONVERSION;
if (aCallback) {
    wbp.progressListener = {
        onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
            if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP){
                let channel = aRequest.QueryInterface(Ci.nsIHttpChannel);
                let bytes = USL.loadBinary(aFile); 
                aCallback(bytes, channel.contentType);
                return;
            }
        },
        onLocationChange: function(aProgress, aRequest, aURI){},
        onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {},
        onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {},
        onSecurityChange: function(aWebProgress, aRequest, aState) {},
        onLinkIconAvailable: function(aIconURL) {},
    }
}
wbp.saveURI(uri, null, null, null, null, aFile, null);
USL.debug("getContents: " + aURL);

};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant