зеркало из https://github.com/mozilla/gecko-dev.git
Bug 398579 - "Allow using chrome:// URLs in Components.utils.import()" [p=ajvincent@gmail.com (Alex Vincent) r=sayrer sr=bsmedberg a1.9=damons]
This commit is contained in:
Родитель
d8d80a602f
Коммит
ca9a0becff
|
@ -1396,6 +1396,7 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
|
|||
JSObject * *_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
*_retval = nsnull;
|
||||
|
||||
if (!mInitialized) {
|
||||
rv = ReallyInit();
|
||||
|
@ -1405,19 +1406,12 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
|
|||
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCAutoString scheme;
|
||||
rv = ioService->ExtractScheme(aLocation, scheme);
|
||||
if (NS_FAILED(rv) ||
|
||||
!scheme.EqualsLiteral("resource")) {
|
||||
*_retval = nsnull;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// Get the resource:// URI.
|
||||
// Get the URI.
|
||||
nsCOMPtr<nsIURI> resURI;
|
||||
rv = ioService->NewURI(aLocation, nsnull, nsnull, getter_AddRefs(resURI));
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(resURI, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// If we don't have a file URL, then the location passed in is invalid.
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_INVALID_ARG);
|
||||
|
||||
// Get the file belonging to it.
|
||||
nsCOMPtr<nsIFile> file;
|
||||
|
|
|
@ -67,6 +67,20 @@ function run_test() {
|
|||
|
||||
do_check_true(scope2.XPCOMUtils == scope.XPCOMUtils);
|
||||
|
||||
// try on a new object using a file URL
|
||||
var res = Components.classes["@mozilla.org/network/protocol;1?name=resource"]
|
||||
.getService(Components.interfaces.nsIResProtocolHandler);
|
||||
var resURI = res.newURI("resource://gre/modules/XPCOMUtils.jsm", null, null);
|
||||
dump("resURI: " + resURI + "\n");
|
||||
var filePath = res.resolveURI(resURI);
|
||||
do_check_eq(filePath.indexOf("file://"), 0);
|
||||
var scope3 = {};
|
||||
Components.utils.import(filePath, scope3);
|
||||
do_check_eq(typeof(scope3.XPCOMUtils), "object");
|
||||
do_check_eq(typeof(scope3.XPCOMUtils.generateModule), "function");
|
||||
|
||||
do_check_true(scope3.XPCOMUtils == scope.XPCOMUtils);
|
||||
|
||||
// make sure we throw when the second arg is bogus
|
||||
var didThrow = false;
|
||||
try {
|
||||
|
|
Загрузка…
Ссылка в новой задаче