зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1772107 - Use plain object for lazy getter in uriloader/exthandler/. r=smaug
Depends on D147893 Differential Revision: https://phabricator.services.mozilla.com/D147894
This commit is contained in:
Родитель
b458dbc7a5
Коммит
95dea67f22
|
@ -4,8 +4,10 @@
|
||||||
|
|
||||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||||
|
|
||||||
|
const lazy = {};
|
||||||
|
|
||||||
ChromeUtils.defineModuleGetter(
|
ChromeUtils.defineModuleGetter(
|
||||||
this,
|
lazy,
|
||||||
"PrivateBrowsingUtils",
|
"PrivateBrowsingUtils",
|
||||||
"resource://gre/modules/PrivateBrowsingUtils.jsm"
|
"resource://gre/modules/PrivateBrowsingUtils.jsm"
|
||||||
);
|
);
|
||||||
|
@ -112,7 +114,7 @@ nsWebHandlerApp.prototype = {
|
||||||
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||||
|
|
||||||
// If this is an extension handler, check private browsing access.
|
// If this is an extension handler, check private browsing access.
|
||||||
if (!privateAllowed && PrivateBrowsingUtils.isWindowPrivate(win)) {
|
if (!privateAllowed && lazy.PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||||
throw Components.Exception(
|
throw Components.Exception(
|
||||||
"Extension not allowed in private windows.",
|
"Extension not allowed in private windows.",
|
||||||
Cr.NS_ERROR_FILE_NOT_FOUND
|
Cr.NS_ERROR_FILE_NOT_FOUND
|
||||||
|
|
|
@ -17,20 +17,22 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||||
);
|
);
|
||||||
const { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
|
const { Assert } = ChromeUtils.import("resource://testing-common/Assert.jsm");
|
||||||
|
|
||||||
|
const lazy = {};
|
||||||
|
|
||||||
XPCOMUtils.defineLazyServiceGetter(
|
XPCOMUtils.defineLazyServiceGetter(
|
||||||
this,
|
lazy,
|
||||||
"gExternalProtocolService",
|
"gExternalProtocolService",
|
||||||
"@mozilla.org/uriloader/external-protocol-service;1",
|
"@mozilla.org/uriloader/external-protocol-service;1",
|
||||||
"nsIExternalProtocolService"
|
"nsIExternalProtocolService"
|
||||||
);
|
);
|
||||||
XPCOMUtils.defineLazyServiceGetter(
|
XPCOMUtils.defineLazyServiceGetter(
|
||||||
this,
|
lazy,
|
||||||
"gMIMEService",
|
"gMIMEService",
|
||||||
"@mozilla.org/mime;1",
|
"@mozilla.org/mime;1",
|
||||||
"nsIMIMEService"
|
"nsIMIMEService"
|
||||||
);
|
);
|
||||||
XPCOMUtils.defineLazyServiceGetter(
|
XPCOMUtils.defineLazyServiceGetter(
|
||||||
this,
|
lazy,
|
||||||
"gHandlerService",
|
"gHandlerService",
|
||||||
"@mozilla.org/uriloader/handler-service;1",
|
"@mozilla.org/uriloader/handler-service;1",
|
||||||
"nsIHandlerService"
|
"nsIHandlerService"
|
||||||
|
@ -47,7 +49,10 @@ var HandlerServiceTestUtils = {
|
||||||
* alphabetically regardless of category.
|
* alphabetically regardless of category.
|
||||||
*/
|
*/
|
||||||
getAllHandlerInfoTypes() {
|
getAllHandlerInfoTypes() {
|
||||||
return Array.from(gHandlerService.enumerate(), info => info.type).sort();
|
return Array.from(
|
||||||
|
lazy.gHandlerService.enumerate(),
|
||||||
|
info => info.type
|
||||||
|
).sort();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +91,7 @@ var HandlerServiceTestUtils = {
|
||||||
// access to getMIMEInfoFromOS. This means that we have to reset the data
|
// access to getMIMEInfoFromOS. This means that we have to reset the data
|
||||||
// that may have been imported from the default nsIHandlerService instance
|
// that may have been imported from the default nsIHandlerService instance
|
||||||
// and is not overwritten by fillHandlerInfo later.
|
// and is not overwritten by fillHandlerInfo later.
|
||||||
let handlerInfo = gMIMEService.getFromTypeAndExtension(type, null);
|
let handlerInfo = lazy.gMIMEService.getFromTypeAndExtension(type, null);
|
||||||
if (AppConstants.platform == "android") {
|
if (AppConstants.platform == "android") {
|
||||||
// On Android, the first handler application is always the internal one.
|
// On Android, the first handler application is always the internal one.
|
||||||
while (handlerInfo.possibleApplicationHandlers.length > 1) {
|
while (handlerInfo.possibleApplicationHandlers.length > 1) {
|
||||||
|
@ -97,8 +102,8 @@ var HandlerServiceTestUtils = {
|
||||||
}
|
}
|
||||||
handlerInfo.setFileExtensions("");
|
handlerInfo.setFileExtensions("");
|
||||||
// Populate the object from the handler service instance under testing.
|
// Populate the object from the handler service instance under testing.
|
||||||
if (gHandlerService.exists(handlerInfo)) {
|
if (lazy.gHandlerService.exists(handlerInfo)) {
|
||||||
gHandlerService.fillHandlerInfo(handlerInfo, "");
|
lazy.gHandlerService.fillHandlerInfo(handlerInfo, "");
|
||||||
}
|
}
|
||||||
return handlerInfo;
|
return handlerInfo;
|
||||||
}
|
}
|
||||||
|
@ -107,14 +112,14 @@ var HandlerServiceTestUtils = {
|
||||||
// testing, like the nsIExternalProtocolService::GetProtocolHandlerInfo
|
// testing, like the nsIExternalProtocolService::GetProtocolHandlerInfo
|
||||||
// method does on the default nsIHandlerService instance.
|
// method does on the default nsIHandlerService instance.
|
||||||
let osDefaultHandlerFound = {};
|
let osDefaultHandlerFound = {};
|
||||||
let handlerInfo = gExternalProtocolService.getProtocolHandlerInfoFromOS(
|
let handlerInfo = lazy.gExternalProtocolService.getProtocolHandlerInfoFromOS(
|
||||||
type,
|
type,
|
||||||
osDefaultHandlerFound
|
osDefaultHandlerFound
|
||||||
);
|
);
|
||||||
if (gHandlerService.exists(handlerInfo)) {
|
if (lazy.gHandlerService.exists(handlerInfo)) {
|
||||||
gHandlerService.fillHandlerInfo(handlerInfo, "");
|
lazy.gHandlerService.fillHandlerInfo(handlerInfo, "");
|
||||||
} else {
|
} else {
|
||||||
gExternalProtocolService.setProtocolHandlerDefaults(
|
lazy.gExternalProtocolService.setProtocolHandlerDefaults(
|
||||||
handlerInfo,
|
handlerInfo,
|
||||||
osDefaultHandlerFound.value
|
osDefaultHandlerFound.value
|
||||||
);
|
);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче