Bug 1463398 - Removal of deprecated newChannel() API on nsIIOService r=ckerschb

MozReview-Commit-ID: 5AwSnQhFtT2

--HG--
extra : rebase_source : e9e8a3109f045f5583389042b2c6dc187cf0b6a8
This commit is contained in:
Jonathan Kingston 2018-05-22 13:09:41 +01:00
Родитель 989d6b51f0
Коммит 5054bfcd70
6 изменённых файлов: 8 добавлений и 203 удалений

Просмотреть файл

@ -52,7 +52,11 @@ function awaitFileSave(name, ext) {
function getFileContents(file) {
return new Promise((resolve, reject) => {
NetUtil.asyncFetch(file, function(inputStream, status) {
let channel = NetUtil.newChannel({
uri: NetUtil.newURI(file),
loadUsingSystemPrincipal: true,
});
NetUtil.asyncFetch(channel, function(inputStream, status) {
if (Components.isSuccessCode(status)) {
info("Fetched downloaded contents.");
resolve(NetUtil.readInputStreamToString(inputStream, inputStream.available()));

Просмотреть файл

@ -234,48 +234,12 @@ var NetUtil = {
* loadingNode are present.
* This should be used with care as it skips security checks.
* }
* @param aOriginCharset [deprecated]
* The character set for the URI. Only used if aWhatToLoad is a
* string, which is a deprecated API. Must be undefined otherwise.
* Use NetUtil.newURI if you need to use this option.
* @param aBaseURI [deprecated]
* The base URI for the spec. Only used if aWhatToLoad is a string,
* which is a deprecated API. Must be undefined otherwise. Use
* NetUtil.newURI if you need to use this option.
* @return an nsIChannel object.
*/
newChannel: function NetUtil_newChannel(aWhatToLoad, aOriginCharset, aBaseURI)
newChannel: function NetUtil_newChannel(aWhatToLoad)
{
// Check for the deprecated API first.
if (typeof aWhatToLoad == "string" ||
(aWhatToLoad instanceof Ci.nsIFile) ||
(aWhatToLoad instanceof Ci.nsIURI)) {
let uri = (aWhatToLoad instanceof Ci.nsIURI)
? aWhatToLoad
: this.newURI(aWhatToLoad, aOriginCharset, aBaseURI);
// log deprecation warning for developers.
Services.console.logStringMessage(
"Warning: NetUtil.newChannel(uri) deprecated, please provide argument 'aWhatToLoad'");
// Provide default loadinfo arguments and call the new API.
let systemPrincipal =
Services.scriptSecurityManager.getSystemPrincipal();
return this.ioService.newChannelFromURI2(
uri,
null, // loadingNode
systemPrincipal, // loadingPrincipal
null, // triggeringPrincipal
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
Ci.nsIContentPolicy.TYPE_OTHER);
}
// We are using the updated API, that requires only the options object.
if (typeof aWhatToLoad != "object" ||
aOriginCharset !== undefined ||
aBaseURI !== undefined) {
// Make sure the API is called using only the options object.
if (typeof aWhatToLoad != "object" || arguments.length != 1) {
throw new Components.Exception(
"newChannel requires a single object argument",
Cr.NS_ERROR_INVALID_ARG,

Просмотреть файл

@ -136,28 +136,6 @@ interface nsIIOService : nsISupports
in unsigned long aSecurityFlags,
in unsigned long aContentPolicyType);
/**
* ***** DEPRECATED *****
* Please use NewChannelFromURI2()
*
* Creates a channel for a given URI.
*
* @param aURI nsIURI from which to make a channel
* @return reference to the new nsIChannel object
*/
nsIChannel newChannelFromURI(in nsIURI aURI);
/**
* ***** DEPRECATED *****
* Please use newChannel2().
*
* Equivalent to newChannelFromURI(newURI(...))
*/
nsIChannel newChannel(in AUTF8String aSpec,
in string aOriginCharset,
in nsIURI aBaseURI);
/**
* Returns true if networking is in "offline" mode. When in offline mode,
* attempts to access the network will fail (although this does not

Просмотреть файл

@ -4,7 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ArrayUtils.h"
#include "mozilla/DebugOnly.h"
#include "nsIOService.h"
@ -31,7 +30,6 @@
#include "nsIConsoleService.h"
#include "nsIUploadChannel2.h"
#include "nsXULAppAPI.h"
#include "nsIScriptError.h"
#include "nsIScriptSecurityManager.h"
#include "nsIProtocolProxyCallback.h"
#include "nsICancelable.h"
@ -760,41 +758,6 @@ nsIOService::NewChannelFromURIWithClientAndController(nsIURI* aURI,
aResult);
}
/* ***** DEPRECATED *****
* please use NewChannelFromURI2 providing the right arguments for:
* * aLoadingNode
* * aLoadingPrincipal
* * aTriggeringPrincipal
* * aSecurityFlags
* * aContentPolicyType
*
* See nsIIoService.idl for a detailed description of those arguments
*/
NS_IMETHODIMP
nsIOService::NewChannelFromURI(nsIURI *aURI, nsIChannel **result)
{
NS_ASSERTION(false, "Deprecated, use NewChannelFromURI2 providing loadInfo arguments!");
const char16_t* params[] = {
u"nsIOService::NewChannelFromURI()",
u"nsIOService::NewChannelFromURI2()"
};
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("Security by Default"),
nullptr, // aDocument
nsContentUtils::eNECKO_PROPERTIES,
"APIDeprecationWarning",
params, ArrayLength(params));
return NewChannelFromURI2(aURI,
nullptr, // aLoadingNode
nsContentUtils::GetSystemPrincipal(),
nullptr, // aTriggeringPrincipal
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER,
result);
}
NS_IMETHODIMP
nsIOService::NewChannelFromURIWithLoadInfo(nsIURI* aURI,
nsILoadInfo* aLoadInfo,
@ -1016,44 +979,6 @@ nsIOService::NewChannel2(const nsACString& aSpec,
result);
}
/* ***** DEPRECATED *****
* please use NewChannel2 providing the right arguments for:
* * aLoadingNode
* * aLoadingPrincipal
* * aTriggeringPrincipal
* * aSecurityFlags
* * aContentPolicyType
*
* See nsIIoService.idl for a detailed description of those arguments
*/
NS_IMETHODIMP
nsIOService::NewChannel(const nsACString &aSpec, const char *aCharset, nsIURI *aBaseURI, nsIChannel **result)
{
NS_ASSERTION(false, "Deprecated, use NewChannel2 providing loadInfo arguments!");
const char16_t* params[] = {
u"nsIOService::NewChannel()",
u"nsIOService::NewChannel2()"
};
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("Security by Default"),
nullptr, // aDocument
nsContentUtils::eNECKO_PROPERTIES,
"APIDeprecationWarning",
params, ArrayLength(params));
// Call NewChannel2 providing default arguments for the loadInfo.
return NewChannel2(aSpec,
aCharset,
aBaseURI,
nullptr, // aLoadingNode
nsContentUtils::GetSystemPrincipal(), // aLoadingPrincipal
nullptr, // aTriggeringPrincipal
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER,
result);
}
bool
nsIOService::IsLinkUp()
{

Просмотреть файл

@ -43,10 +43,6 @@ AutomaticAuth=You are about to log in to the site “%1$S” with the username
TrackingUriBlocked=The resource at “%1$S” was blocked because tracking protection is enabled.
UnsafeUriBlocked=The resource at “%1$S” was blocked by Safe Browsing.
# LOCALIZATION NOTE (APIDeprecationWarning):
# %1$S is the deprecated API; %2$S is the API function that should be used.
APIDeprecationWarning=Warning: %1$S deprecated, please use %2$S
# LOCALIZATION NOTE (nsICookieManagerAPIDeprecated): don't localize originAttributes.
# %1$S is the deprecated API; %2$S is the interface suffix that the given deprecated API belongs to.
nsICookieManagerAPIDeprecated=“%1$S” is changed. Update your code and pass the correct originAttributes. Read more on MDN: https://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsICookieManager%2$S

Просмотреть файл

@ -636,66 +636,6 @@ function test_newChannel_with_wrong_options()
run_next_test();
}
function test_deprecated_newChannel_API_with_string() {
const TEST_SPEC = "http://mozilla.org";
let uri = NetUtil.newURI(TEST_SPEC);
let oneArgChannel = NetUtil.newChannel(TEST_SPEC);
let threeArgChannel = NetUtil.newChannel(TEST_SPEC, null, null);
Assert.ok(uri.equals(oneArgChannel.URI));
Assert.ok(uri.equals(threeArgChannel.URI));
run_next_test();
}
function test_deprecated_newChannel_API_with_nsIFile()
{
const TEST_DATA = "this is a test string";
// First we need a file to read from.
let file = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
get("ProfD", Ci.nsIFile);
file.append("NetUtil-deprecated-newchannel-api-test-file.tmp");
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o666);
// Write the test data to the file.
let ostream = Cc["@mozilla.org/network/file-output-stream;1"].
createInstance(Ci.nsIFileOutputStream);
ostream.init(file, -1, -1, 0);
ostream.write(TEST_DATA, TEST_DATA.length);
// Sanity check to make sure the data was written.
Assert.equal(TEST_DATA, getFileContents(file));
// create a channel using the file
let channel = NetUtil.newChannel(file);
// Create a pipe that will create our output stream that we can use once
// we have gotten all the data.
let pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
pipe.init(true, true, 0, 0, null);
let listener = Cc["@mozilla.org/network/simple-stream-listener;1"].
createInstance(Ci.nsISimpleStreamListener);
listener.init(pipe.outputStream, {
onStartRequest: function(aRequest, aContext) {},
onStopRequest: function(aRequest, aContext, aStatusCode) {
pipe.outputStream.close();
Assert.ok(Components.isSuccessCode(aContext));
// Check that we got the right data.
Assert.equal(pipe.inputStream.available(), TEST_DATA.length);
let is = Cc["@mozilla.org/scriptableinputstream;1"].
createInstance(Ci.nsIScriptableInputStream);
is.init(pipe.inputStream);
let result = is.read(TEST_DATA.length);
Assert.equal(TEST_DATA, result);
run_next_test();
}
});
channel.asyncOpen2(listener);
}
function test_readInputStreamToString()
{
const TEST_DATA = "this is a test string\0 with an embedded null";
@ -852,8 +792,6 @@ function test_readInputStreamToString_invalid_sequence()
test_newChannel_with_nsIURI,
test_newChannel_with_options,
test_newChannel_with_wrong_options,
test_deprecated_newChannel_API_with_string,
test_deprecated_newChannel_API_with_nsIFile,
test_readInputStreamToString,
test_readInputStreamToString_no_input_stream,
test_readInputStreamToString_no_bytes_arg,