Skip to content

UserScriptLoader.uc.js 0.1.8.1 bug fix? #10

@lastdream2013

Description

@lastdream2013

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);

};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions