Bug 1463398 - Removal of deprecated newChannel() API on nsIIOService r?ckerschb
MozReview-Commit-ID: 5AwSnQhFtT2
--- a/devtools/client/jsonview/test/browser_jsonview_save_json.js
+++ b/devtools/client/jsonview/test/browser_jsonview_save_json.js
@@ -47,17 +47,21 @@ function awaitFileSave(name, ext) {
resolve(destFile);
};
};
});
}
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()));
} else {
reject();
}
});
});
--- a/netwerk/base/NetUtil.jsm
+++ b/netwerk/base/NetUtil.jsm
@@ -229,58 +229,22 @@ var NetUtil = {
* These will be used as values for the nsILoadInfo object on the
* created channel. For details, see nsILoadInfo in nsILoadInfo.idl
* loadUsingSystemPrincipal:
* Set this to true to use the system principal as
* loadingPrincipal. This must be omitted if loadingPrincipal or
* 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,
Components.stack.caller
);
}
let { uri,
--- a/netwerk/base/nsIIOService.idl
+++ b/netwerk/base/nsIIOService.idl
@@ -132,38 +132,16 @@ interface nsIIOService : nsISupports
in nsIURI aBaseURI,
in nsIDOMNode aLoadingNode,
in nsIPrincipal aLoadingPrincipal,
in nsIPrincipal aTriggeringPrincipal,
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
* necessarily correlate with whether there is actually a network
* available -- that's hard to detect without causing the dialer to
* come up).
*
* Changing this fires observer notifications ... see below.
*/
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -1,15 +1,14 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 cindent et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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"
#include "nsIDOMNode.h"
#include "nsIProtocolHandler.h"
#include "nsIFileProtocolHandler.h"
#include "nscore.h"
#include "nsIURI.h"
@@ -26,17 +25,16 @@
#include "nsNetCID.h"
#include "nsCRT.h"
#include "nsSecCheckWrapChannel.h"
#include "nsSimpleNestedURI.h"
#include "nsTArray.h"
#include "nsIConsoleService.h"
#include "nsIUploadChannel2.h"
#include "nsXULAppAPI.h"
-#include "nsIScriptError.h"
#include "nsIScriptSecurityManager.h"
#include "nsIProtocolProxyCallback.h"
#include "nsICancelable.h"
#include "nsINetworkLinkService.h"
#include "nsPISocketTransportService.h"
#include "nsAsyncRedirectVerifyHelper.h"
#include "nsURLHelper.h"
#include "nsIProtocolProxyService2.h"
@@ -755,51 +753,16 @@ nsIOService::NewChannelFromURIWithClient
aTriggeringPrincipal,
aLoadingClientInfo,
aController,
aSecurityFlags,
aContentPolicyType,
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,
nsIChannel** result)
{
return NewChannelFromURIWithProxyFlagsInternal(aURI,
nullptr, // aProxyURI
0, // aProxyFlags
@@ -1011,54 +974,16 @@ nsIOService::NewChannel2(const nsACStrin
aLoadingNode,
aLoadingPrincipal,
aTriggeringPrincipal,
aSecurityFlags,
aContentPolicyType,
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()
{
InitializeNetworkLinkService();
if (!mNetworkLinkService) {
// We cannot decide, assume the link is up
return true;
--- a/netwerk/locales/en-US/necko.properties
+++ b/netwerk/locales/en-US/necko.properties
@@ -38,15 +38,11 @@ DirFileLabel=File:
PhishingAuth=You are about to visit “%1$S”. This site may be attempting to trick you into thinking you are visiting a different site. Use extreme caution.
PhishingAuthAccept=I understand and will be very careful
SuperfluousAuth=You are about to log in to the site “%1$S” with the username “%2$S”, but the website does not require authentication. This may be an attempt to trick you.\n\nIs “%1$S” the site you want to visit?
AutomaticAuth=You are about to log in to the site “%1$S” with the username “%2$S”.
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
--- a/netwerk/test/unit/test_NetUtil.js
+++ b/netwerk/test/unit/test_NetUtil.js
@@ -631,76 +631,16 @@ function test_newChannel_with_wrong_opti
loadingPrincipal: systemPrincipal,
loadUsingSystemPrincipal: true,
});
}, /does not accept 'loadUsingSystemPrincipal'/);
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";
let istream = Cc["@mozilla.org/io/string-input-stream;1"].
createInstance(Ci.nsISupportsCString);
istream.data = TEST_DATA;
Assert.equal(NetUtil.readInputStreamToString(istream, TEST_DATA.length),
@@ -847,18 +787,16 @@ function test_readInputStreamToString_in
test_asyncFetch_with_nsIFile,
test_asyncFetch_with_nsIInputString,
test_asyncFetch_does_not_block,
test_newChannel_no_specifier,
test_newChannel_with_string,
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,
test_readInputStreamToString_blocking_stream,
test_readInputStreamToString_too_many_bytes,
test_readInputStreamToString_with_charset,
test_readInputStreamToString_invalid_sequence,
].forEach(f => add_test(f));