2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 18:39:55 +03:00
|
|
|
/* vim:set ts=4 sw=2 cindent et: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
#include "nsIOService.h"
|
|
|
|
#include "nsIProtocolHandler.h"
|
2002-02-01 01:17:35 +03:00
|
|
|
#include "nsIFileProtocolHandler.h"
|
1999-06-08 01:33:30 +04:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsIURI.h"
|
1999-06-08 23:04:13 +04:00
|
|
|
#include "prprf.h"
|
2018-11-04 23:12:41 +03:00
|
|
|
#include "nsErrorService.h"
|
2001-01-17 22:51:28 +03:00
|
|
|
#include "netCore.h"
|
|
|
|
#include "nsIObserverService.h"
|
2001-10-09 02:27:14 +04:00
|
|
|
#include "nsIPrefService.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
2001-09-13 06:21:05 +04:00
|
|
|
#include "nsIProxiedProtocolHandler.h"
|
|
|
|
#include "nsIProxyInfo.h"
|
2001-09-08 16:47:05 +04:00
|
|
|
#include "nsEscape.h"
|
2015-09-10 20:07:00 +03:00
|
|
|
#include "nsNetUtil.h"
|
2001-11-16 05:09:13 +03:00
|
|
|
#include "nsNetCID.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsCRT.h"
|
2009-08-24 02:48:07 +04:00
|
|
|
#include "nsSimpleNestedURI.h"
|
2009-01-22 07:15:34 +03:00
|
|
|
#include "nsTArray.h"
|
2009-11-19 02:21:13 +03:00
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIUploadChannel2.h"
|
2010-05-11 16:44:12 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2014-08-23 07:05:56 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2012-09-15 00:27:46 +04:00
|
|
|
#include "nsIProtocolProxyCallback.h"
|
|
|
|
#include "nsICancelable.h"
|
2013-09-22 07:04:57 +04:00
|
|
|
#include "nsINetworkLinkService.h"
|
|
|
|
#include "nsPISocketTransportService.h"
|
|
|
|
#include "nsAsyncRedirectVerifyHelper.h"
|
|
|
|
#include "nsURLHelper.h"
|
|
|
|
#include "nsIProtocolProxyService2.h"
|
|
|
|
#include "MainThreadUtils.h"
|
2016-01-09 04:20:50 +03:00
|
|
|
#include "nsINode.h"
|
2014-09-19 14:34:00 +04:00
|
|
|
#include "nsIWidget.h"
|
2014-08-22 21:15:00 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2014-12-12 20:05:21 +03:00
|
|
|
#include "mozilla/LoadInfo.h"
|
2014-08-22 21:15:00 +04:00
|
|
|
#include "mozilla/net/NeckoCommon.h"
|
2015-09-10 20:07:00 +03:00
|
|
|
#include "mozilla/Services.h"
|
2015-02-06 16:27:33 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2014-10-14 01:35:51 +04:00
|
|
|
#include "mozilla/net/DNS.h"
|
2016-05-17 22:51:24 +03:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
|
|
|
#include "mozilla/net/NeckoChild.h"
|
2018-05-30 17:36:42 +03:00
|
|
|
#include "mozilla/net/NeckoParent.h"
|
2018-01-23 18:38:54 +03:00
|
|
|
#include "mozilla/dom/ClientInfo.h"
|
2016-10-24 07:18:25 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2018-01-23 18:38:54 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerDescriptor.h"
|
2016-11-17 19:35:24 +03:00
|
|
|
#include "mozilla/net/CaptivePortalService.h"
|
2018-10-29 14:22:40 +03:00
|
|
|
#include "mozilla/net/NetworkConnectivityService.h"
|
2019-01-11 21:57:23 +03:00
|
|
|
#include "mozilla/net/SocketProcessHost.h"
|
|
|
|
#include "mozilla/net/SocketProcessParent.h"
|
2017-07-27 14:10:21 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-06-06 01:25:24 +03:00
|
|
|
#include "ReferrerPolicy.h"
|
2015-12-07 02:33:14 +03:00
|
|
|
#include "nsContentSecurityManager.h"
|
2016-03-19 03:11:42 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-03-25 17:08:13 +03:00
|
|
|
#include "nsExceptionHandler.h"
|
2010-05-20 03:22:19 +04:00
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
2012-10-25 23:47:55 +04:00
|
|
|
|
2018-01-23 18:38:54 +03:00
|
|
|
using mozilla::Maybe;
|
|
|
|
using mozilla::dom::ClientInfo;
|
|
|
|
using mozilla::dom::ServiceWorkerDescriptor;
|
|
|
|
|
2009-01-13 08:52:00 +03:00
|
|
|
#define PORT_PREF_PREFIX "network.security.ports."
|
|
|
|
#define PORT_PREF(x) PORT_PREF_PREFIX x
|
|
|
|
#define MANAGE_OFFLINE_STATUS_PREF "network.manage-offline-status"
|
2015-03-26 14:19:47 +03:00
|
|
|
#define OFFLINE_MIRRORS_CONNECTIVITY "network.offline-mirrors-connectivity"
|
2001-10-09 02:27:14 +04:00
|
|
|
|
2012-01-10 07:43:52 +04:00
|
|
|
// Nb: these have been misnomers since bug 715770 removed the buffer cache.
|
|
|
|
// "network.segment.count" and "network.segment.size" would be better names,
|
|
|
|
// but the old names are still used to preserve backward compatibility.
|
2010-04-20 20:32:28 +04:00
|
|
|
#define NECKO_BUFFER_CACHE_COUNT_PREF "network.buffer.cache.count"
|
|
|
|
#define NECKO_BUFFER_CACHE_SIZE_PREF "network.buffer.cache.size"
|
2014-09-19 14:36:00 +04:00
|
|
|
#define NETWORK_NOTIFY_CHANGED_PREF "network.notify.changed"
|
2014-10-14 01:35:51 +04:00
|
|
|
#define NETWORK_CAPTIVE_PORTAL_PREF "network.captive-portal-service.enabled"
|
2019-01-11 21:57:23 +03:00
|
|
|
#define WEBRTC_PREF_PREFIX "media.peerconnection."
|
2010-04-20 20:32:28 +04:00
|
|
|
|
2007-03-12 08:56:45 +03:00
|
|
|
#define MAX_RECURSION_COUNT 50
|
|
|
|
|
2017-10-30 02:02:40 +03:00
|
|
|
nsIOService *gIOService;
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool gHasWarnedUploadChannel2;
|
2017-04-12 17:52:14 +03:00
|
|
|
static bool gCaptivePortalEnabled = false;
|
2016-05-19 05:02:57 +03:00
|
|
|
static LazyLogModule gIOServiceLog("nsIOService");
|
2015-11-18 17:25:39 +03:00
|
|
|
#undef LOG
|
2016-05-19 05:02:57 +03:00
|
|
|
#define LOG(args) MOZ_LOG(gIOServiceLog, LogLevel::Debug, args)
|
2015-11-18 17:25:39 +03:00
|
|
|
|
2014-09-25 07:14:00 +04:00
|
|
|
// A general port blacklist. Connections to these ports will not be allowed
|
|
|
|
// unless the protocol overrides.
|
2001-06-06 04:10:09 +04:00
|
|
|
//
|
2017-07-06 15:00:35 +03:00
|
|
|
// TODO: I am sure that there are more ports to be added.
|
2001-06-06 04:10:09 +04:00
|
|
|
// This cut is based on the classic mozilla codebase
|
|
|
|
|
2016-03-30 06:04:00 +03:00
|
|
|
int16_t gBadPortList[] = {
|
|
|
|
1, // tcpmux
|
|
|
|
7, // echo
|
|
|
|
9, // discard
|
|
|
|
11, // systat
|
|
|
|
13, // daytime
|
|
|
|
15, // netstat
|
|
|
|
17, // qotd
|
|
|
|
19, // chargen
|
|
|
|
20, // ftp-data
|
2018-06-05 08:49:02 +03:00
|
|
|
21, // ftp
|
2016-03-30 06:04:00 +03:00
|
|
|
22, // ssh
|
|
|
|
23, // telnet
|
|
|
|
25, // smtp
|
|
|
|
37, // time
|
|
|
|
42, // name
|
|
|
|
43, // nicname
|
|
|
|
53, // domain
|
|
|
|
77, // priv-rjs
|
|
|
|
79, // finger
|
|
|
|
87, // ttylink
|
|
|
|
95, // supdup
|
2001-06-06 04:10:09 +04:00
|
|
|
101, // hostriame
|
2016-03-30 06:04:00 +03:00
|
|
|
102, // iso-tsap
|
|
|
|
103, // gppitnp
|
|
|
|
104, // acr-nema
|
|
|
|
109, // pop2
|
|
|
|
110, // pop3
|
|
|
|
111, // sunrpc
|
|
|
|
113, // auth
|
|
|
|
115, // sftp
|
2001-06-06 04:10:09 +04:00
|
|
|
117, // uucp-path
|
2016-03-30 06:04:00 +03:00
|
|
|
119, // nntp
|
2018-06-05 08:49:02 +03:00
|
|
|
123, // ntp
|
2016-03-30 06:04:00 +03:00
|
|
|
135, // loc-srv / epmap
|
2001-06-06 04:10:09 +04:00
|
|
|
139, // netbios
|
2016-03-30 06:04:00 +03:00
|
|
|
143, // imap2
|
2018-06-05 08:49:02 +03:00
|
|
|
179, // bgp
|
2016-03-30 06:04:00 +03:00
|
|
|
389, // ldap
|
2018-06-05 08:49:02 +03:00
|
|
|
427, // afp (alternate)
|
2018-06-05 08:49:02 +03:00
|
|
|
465, // smtp (alternate)
|
2016-03-30 06:04:00 +03:00
|
|
|
512, // print / exec
|
|
|
|
513, // login
|
|
|
|
514, // shell
|
|
|
|
515, // printer
|
|
|
|
526, // tempo
|
|
|
|
530, // courier
|
2018-06-05 08:49:02 +03:00
|
|
|
531, // chat
|
2016-03-30 06:04:00 +03:00
|
|
|
532, // netnews
|
2017-07-06 15:00:35 +03:00
|
|
|
540, // uucp
|
2018-06-05 08:49:02 +03:00
|
|
|
548, // afp
|
2016-03-30 06:04:00 +03:00
|
|
|
556, // remotefs
|
2006-07-06 23:40:38 +04:00
|
|
|
563, // nntp+ssl
|
2018-06-05 08:49:02 +03:00
|
|
|
587, // smtp (outgoing)
|
|
|
|
601, // syslog-conn
|
2006-07-06 23:40:38 +04:00
|
|
|
636, // ldap+ssl
|
|
|
|
993, // imap+ssl
|
|
|
|
995, // pop3+ssl
|
2001-06-06 04:10:09 +04:00
|
|
|
2049, // nfs
|
2018-06-05 08:49:02 +03:00
|
|
|
3659, // apple-sasl
|
2001-06-06 04:10:09 +04:00
|
|
|
4045, // lockd
|
2016-03-30 06:04:00 +03:00
|
|
|
6000, // x11
|
2018-06-05 08:49:02 +03:00
|
|
|
6665, // irc (alternate)
|
|
|
|
6666, // irc (alternate)
|
|
|
|
6667, // irc (default)
|
|
|
|
6668, // irc (alternate)
|
|
|
|
6669, // irc (alternate)
|
2018-06-05 08:49:02 +03:00
|
|
|
6697, // irc+tls
|
2018-06-05 08:49:02 +03:00
|
|
|
0, // Sentinel value: This MUST be zero
|
2001-06-06 04:10:09 +04:00
|
|
|
};
|
1999-08-29 20:42:27 +04:00
|
|
|
|
2001-11-07 07:26:19 +03:00
|
|
|
static const char kProfileChangeNetTeardownTopic[] =
|
|
|
|
"profile-change-net-teardown";
|
|
|
|
static const char kProfileChangeNetRestoreTopic[] =
|
|
|
|
"profile-change-net-restore";
|
2011-10-18 13:46:59 +04:00
|
|
|
static const char kProfileDoChange[] = "profile-do-change";
|
2001-11-07 07:26:19 +03:00
|
|
|
|
2012-01-10 07:43:52 +04:00
|
|
|
// Necko buffer defaults
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nsIOService::gDefaultSegmentSize = 4096;
|
|
|
|
uint32_t nsIOService::gDefaultSegmentCount = 24;
|
2002-07-02 22:15:19 +04:00
|
|
|
|
2017-05-17 06:03:33 +03:00
|
|
|
bool nsIOService::sIsDataURIUniqueOpaqueOrigin = false;
|
2017-07-24 19:51:21 +03:00
|
|
|
bool nsIOService::sBlockToplevelDataUriNavigations = false;
|
2018-04-09 22:07:01 +03:00
|
|
|
bool nsIOService::sBlockFTPSubresources = false;
|
2015-02-06 16:27:33 +03:00
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsIOService::nsIOService()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mOffline(true),
|
|
|
|
mOfflineForProfileChange(false),
|
2015-05-02 00:14:39 +03:00
|
|
|
mManageLinkStatus(false),
|
|
|
|
mConnectivity(true),
|
2015-03-26 14:19:47 +03:00
|
|
|
mOfflineMirrorsConnectivity(true),
|
2011-10-17 18:59:28 +04:00
|
|
|
mSettingOffline(false),
|
|
|
|
mSetOfflineValue(false),
|
2019-01-12 04:00:26 +03:00
|
|
|
mSocketProcessLaunchComplete(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mShutdown(false),
|
2016-02-04 06:14:00 +03:00
|
|
|
mHttpHandlerAlreadyShutingDown(false),
|
2011-10-18 13:46:59 +04:00
|
|
|
mNetworkLinkServiceInitialized(false),
|
2006-02-22 17:07:21 +03:00
|
|
|
mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY),
|
2014-09-19 14:36:00 +04:00
|
|
|
mNetworkNotifyChanged(true),
|
2017-05-10 20:23:54 +03:00
|
|
|
mTotalRequests(0),
|
|
|
|
mCacheWon(0),
|
|
|
|
mNetWon(0),
|
2015-07-07 12:13:00 +03:00
|
|
|
mLastOfflineStateChange(PR_IntervalNow()),
|
|
|
|
mLastConnectivityChange(PR_IntervalNow()),
|
|
|
|
mLastNetworkLinkChange(PR_IntervalNow()),
|
2019-01-11 21:57:23 +03:00
|
|
|
mNetTearingDownStarted(0),
|
|
|
|
mSocketProcess(nullptr) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-07-05 23:25:03 +03:00
|
|
|
static const char *gCallbackPrefs[] = {
|
|
|
|
PORT_PREF_PREFIX,
|
|
|
|
MANAGE_OFFLINE_STATUS_PREF,
|
|
|
|
NECKO_BUFFER_CACHE_COUNT_PREF,
|
|
|
|
NECKO_BUFFER_CACHE_SIZE_PREF,
|
|
|
|
NETWORK_NOTIFY_CHANGED_PREF,
|
|
|
|
NETWORK_CAPTIVE_PORTAL_PREF,
|
|
|
|
nullptr,
|
|
|
|
};
|
|
|
|
|
2019-01-11 21:57:23 +03:00
|
|
|
static const char *gCallbackPrefsForSocketProcess[] = {
|
|
|
|
WEBRTC_PREF_PREFIX,
|
|
|
|
nullptr,
|
|
|
|
};
|
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
nsresult nsIOService::Init() {
|
2003-01-18 05:15:14 +03:00
|
|
|
// XXX hack until xpidl supports error info directly (bug 13423)
|
2018-11-04 23:12:41 +03:00
|
|
|
nsCOMPtr<nsIErrorService> errorService = nsErrorService::GetOrCreate();
|
|
|
|
MOZ_ALWAYS_TRUE(errorService);
|
|
|
|
errorService->RegisterErrorStringBundle(NS_ERROR_MODULE_NETWORK,
|
|
|
|
NECKO_MSGS_URL);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-14 01:35:51 +04:00
|
|
|
InitializeCaptivePortalService();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-06-06 04:10:09 +04:00
|
|
|
// setup our bad port list stuff
|
2003-01-18 05:15:14 +03:00
|
|
|
for (int i = 0; gBadPortList[i]; i++)
|
2009-02-23 04:05:28 +03:00
|
|
|
mRestrictedPortList.AppendElement(gBadPortList[i]);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-10-09 02:27:14 +04:00
|
|
|
// Further modifications to the port list come from prefs
|
2018-07-05 23:25:03 +03:00
|
|
|
Preferences::RegisterPrefixCallbacks(
|
|
|
|
PREF_CHANGE_METHOD(nsIOService::PrefsChanged), gCallbackPrefs, this);
|
|
|
|
PrefsChanged();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-11-07 07:26:19 +03:00
|
|
|
// Register for profile change notifications
|
2016-05-19 05:02:57 +03:00
|
|
|
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
|
2001-11-07 07:26:19 +03:00
|
|
|
if (observerService) {
|
2011-10-17 18:59:28 +04:00
|
|
|
observerService->AddObserver(this, kProfileChangeNetTeardownTopic, true);
|
|
|
|
observerService->AddObserver(this, kProfileChangeNetRestoreTopic, true);
|
2011-10-18 13:46:59 +04:00
|
|
|
observerService->AddObserver(this, kProfileDoChange, true);
|
2011-10-17 18:59:28 +04:00
|
|
|
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
|
|
|
|
observerService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
|
2014-09-19 14:34:00 +04:00
|
|
|
observerService->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, true);
|
2019-01-11 21:57:23 +03:00
|
|
|
observerService->AddObserver(this, NS_PREFSERVICE_READ_TOPIC_ID, true);
|
2003-01-18 05:15:14 +03:00
|
|
|
} else
|
|
|
|
NS_WARNING("failed to get observer service");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-17 06:03:33 +03:00
|
|
|
Preferences::AddBoolVarCache(&sIsDataURIUniqueOpaqueOrigin,
|
|
|
|
"security.data_uri.unique_opaque_origin", false);
|
2017-07-24 19:51:21 +03:00
|
|
|
Preferences::AddBoolVarCache(
|
|
|
|
&sBlockToplevelDataUriNavigations,
|
|
|
|
"security.data_uri.block_toplevel_data_uri_navigations", false);
|
2018-04-09 22:07:01 +03:00
|
|
|
Preferences::AddBoolVarCache(&sBlockFTPSubresources,
|
|
|
|
"security.block_ftp_subresources", true);
|
2015-03-26 14:19:47 +03:00
|
|
|
Preferences::AddBoolVarCache(&mOfflineMirrorsConnectivity,
|
|
|
|
OFFLINE_MIRRORS_CONNECTIVITY, true);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-02-22 17:07:21 +03:00
|
|
|
gIOService = this;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-18 13:46:59 +04:00
|
|
|
InitializeNetworkLinkService();
|
2017-07-27 14:10:21 +03:00
|
|
|
InitializeProtocolProxyService();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-03 16:23:18 +03:00
|
|
|
SetOffline(false);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-06-06 04:10:09 +04:00
|
|
|
return NS_OK;
|
2000-06-13 07:00:53 +04:00
|
|
|
}
|
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
nsIOService::~nsIOService() {
|
2017-10-30 02:02:40 +03:00
|
|
|
if (gIOService) {
|
|
|
|
MOZ_ASSERT(gIOService == this);
|
|
|
|
gIOService = nullptr;
|
|
|
|
}
|
2010-11-25 08:20:11 +03:00
|
|
|
}
|
|
|
|
|
2014-10-14 01:35:51 +04:00
|
|
|
nsresult nsIOService::InitializeCaptivePortalService() {
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
// We only initalize a captive portal service in the main process
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCaptivePortalService = do_GetService(NS_CAPTIVEPORTAL_CID);
|
|
|
|
if (mCaptivePortalService) {
|
|
|
|
return static_cast<CaptivePortalService *>(mCaptivePortalService.get())
|
|
|
|
->Initialize();
|
|
|
|
}
|
|
|
|
|
2018-12-03 02:29:27 +03:00
|
|
|
RefPtr<NetworkConnectivityService> ncs =
|
|
|
|
NetworkConnectivityService::GetSingleton();
|
|
|
|
ncs->Init();
|
|
|
|
|
2014-10-14 01:35:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-25 08:20:11 +03:00
|
|
|
nsresult nsIOService::InitializeSocketTransportService() {
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mSocketTransportService) {
|
|
|
|
mSocketTransportService =
|
|
|
|
do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("failed to get socket transport service");
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-11-25 08:20:11 +03:00
|
|
|
|
|
|
|
if (mSocketTransportService) {
|
|
|
|
rv = mSocketTransportService->Init();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "socket transport service init failed");
|
2012-09-18 03:45:10 +04:00
|
|
|
mSocketTransportService->SetOffline(false);
|
2010-11-25 08:20:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2011-10-18 13:46:59 +04:00
|
|
|
nsresult nsIOService::InitializeNetworkLinkService() {
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (mNetworkLinkServiceInitialized) return rv;
|
|
|
|
|
|
|
|
if (!NS_IsMainThread()) {
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_WARNING("Network link service should be created on main thread");
|
|
|
|
return NS_ERROR_FAILURE;
|
2011-10-18 13:46:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// go into managed mode if we can, and chrome process
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2011-10-18 13:46:59 +04:00
|
|
|
mNetworkLinkService =
|
|
|
|
do_GetService(NS_NETWORK_LINK_SERVICE_CONTRACTID, &rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNetworkLinkService) {
|
|
|
|
mNetworkLinkServiceInitialized = true;
|
|
|
|
}
|
|
|
|
|
2015-05-02 00:14:39 +03:00
|
|
|
// After initializing the networkLinkService, query the connectivity state
|
|
|
|
OnNetworkLinkEvent(NS_NETWORK_LINK_DATA_UNKNOWN);
|
|
|
|
|
2011-10-18 13:46:59 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-07-27 14:10:21 +03:00
|
|
|
nsresult nsIOService::InitializeProtocolProxyService() {
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
// for early-initialization
|
|
|
|
Unused << do_GetService(NS_PROTOCOLPROXYSERVICE_CONTRACTID, &rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-10-17 07:08:42 +03:00
|
|
|
already_AddRefed<nsIOService> nsIOService::GetInstance() {
|
2006-03-01 21:45:14 +03:00
|
|
|
if (!gIOService) {
|
2017-10-17 07:08:42 +03:00
|
|
|
RefPtr<nsIOService> ios = new nsIOService();
|
2017-10-30 02:02:40 +03:00
|
|
|
if (NS_SUCCEEDED(ios->Init())) {
|
|
|
|
MOZ_ASSERT(gIOService == ios.get());
|
|
|
|
return ios.forget();
|
2006-03-01 21:45:14 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-10-17 07:08:42 +03:00
|
|
|
return do_AddRef(gIOService);
|
2006-03-01 21:45:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-11 21:57:23 +03:00
|
|
|
class SocketProcessListenerProxy : public SocketProcessHost::Listener {
|
|
|
|
public:
|
|
|
|
SocketProcessListenerProxy() = default;
|
|
|
|
void OnProcessLaunchComplete(SocketProcessHost *aHost, bool aSucceeded) {
|
|
|
|
if (!gIOService) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gIOService->OnProcessLaunchComplete(aHost, aSucceeded);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnProcessUnexpectedShutdown(SocketProcessHost *aHost) {
|
|
|
|
if (!gIOService) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gIOService->OnProcessUnexpectedShutdown(aHost);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult nsIOService::LaunchSocketProcess() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSocketProcess) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Preferences::GetBool("network.process.enabled", true)) {
|
|
|
|
LOG(("nsIOService skipping LaunchSocketProcess because of the pref"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Preferences::RegisterPrefixCallbacks(
|
|
|
|
PREF_CHANGE_METHOD(nsIOService::NotifySocketProcessPrefsChanged),
|
|
|
|
gCallbackPrefsForSocketProcess, this);
|
|
|
|
|
|
|
|
// The subprocess is launched asynchronously, so we wait for a callback to
|
|
|
|
// acquire the IPDL actor.
|
|
|
|
mSocketProcess = new SocketProcessHost(new SocketProcessListenerProxy());
|
|
|
|
LOG(("nsIOService::LaunchSocketProcess"));
|
|
|
|
if (!mSocketProcess->Launch()) {
|
|
|
|
NS_WARNING("Failed to launch socket process!!");
|
|
|
|
DestroySocketProcess();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsIOService::DestroySocketProcess() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default || !mSocketProcess) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Preferences::UnregisterPrefixCallbacks(
|
|
|
|
PREF_CHANGE_METHOD(nsIOService::NotifySocketProcessPrefsChanged),
|
|
|
|
gCallbackPrefsForSocketProcess, this);
|
|
|
|
|
|
|
|
mSocketProcess->Shutdown();
|
|
|
|
mSocketProcess = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsIOService::SocketProcessReady() {
|
|
|
|
return mSocketProcess && mSocketProcess->IsConnected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsIOService::NotifySocketProcessPrefsChanged(const char *aName) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2019-01-12 04:00:26 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
2019-01-11 21:57:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-21 07:51:43 +03:00
|
|
|
dom::Pref pref(nsCString(aName), /* isLocked */ false, Nothing(), Nothing());
|
2019-01-11 21:57:23 +03:00
|
|
|
Preferences::GetPreference(&pref);
|
2019-01-12 04:00:26 +03:00
|
|
|
auto sendPrefUpdate = [pref]() {
|
|
|
|
Unused << gIOService->mSocketProcess->GetActor()->SendPreferenceUpdate(
|
|
|
|
pref);
|
|
|
|
};
|
|
|
|
CallOrWaitForSocketProcess(sendPrefUpdate);
|
2019-01-11 21:57:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsIOService::OnProcessLaunchComplete(SocketProcessHost *aHost,
|
|
|
|
bool aSucceeded) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
LOG(("nsIOService::OnProcessLaunchComplete aSucceeded=%d\n", aSucceeded));
|
2019-01-12 04:00:26 +03:00
|
|
|
|
|
|
|
mSocketProcessLaunchComplete = true;
|
|
|
|
|
|
|
|
if (mShutdown || !SocketProcessReady()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mPendingEvents.IsEmpty()) {
|
|
|
|
nsTArray<std::function<void()>> pendingEvents;
|
|
|
|
mPendingEvents.SwapElements(pendingEvents);
|
|
|
|
for (auto &func : pendingEvents) {
|
|
|
|
func();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsIOService::CallOrWaitForSocketProcess(
|
|
|
|
const std::function<void()> &aFunc) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (IsSocketProcessLaunchComplete() && SocketProcessReady()) {
|
|
|
|
aFunc();
|
|
|
|
} else {
|
|
|
|
mPendingEvents.AppendElement(aFunc); // infallible
|
2019-01-11 21:57:23 +03:00
|
|
|
}
|
2019-01-12 04:00:26 +03:00
|
|
|
}
|
|
|
|
|
2019-02-23 21:07:59 +03:00
|
|
|
int32_t nsIOService::SocketProcessPid() {
|
|
|
|
if (!mSocketProcess) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (SocketProcessParent *actor = mSocketProcess->GetActor()) {
|
|
|
|
return (int32_t)actor->OtherPid();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-12 04:00:26 +03:00
|
|
|
bool nsIOService::IsSocketProcessLaunchComplete() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mSocketProcessLaunchComplete;
|
2019-01-11 21:57:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsIOService::OnProcessUnexpectedShutdown(SocketProcessHost *aHost) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
LOG(("nsIOService::OnProcessUnexpectedShutdown\n"));
|
|
|
|
DestroySocketProcess();
|
|
|
|
}
|
|
|
|
|
2019-01-11 23:52:39 +03:00
|
|
|
RefPtr<MemoryReportingProcess> nsIOService::GetSocketProcessMemoryReporter() {
|
|
|
|
// Check the prefs here again, since we don't want to create
|
|
|
|
// SocketProcessMemoryReporter for some tests.
|
|
|
|
if (!Preferences::GetBool("network.process.enabled") ||
|
|
|
|
!SocketProcessReady()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new SocketProcessMemoryReporter();
|
|
|
|
}
|
|
|
|
|
2019-01-16 02:15:38 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::SocketProcessTelemetryPing() {
|
|
|
|
CallOrWaitForSocketProcess([]() {
|
|
|
|
Unused << gIOService->mSocketProcess->GetActor()
|
|
|
|
->SendSocketProcessTelemetryPing();
|
|
|
|
});
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsIOService, nsIIOService, nsINetUtil, nsISpeculativeConnect,
|
|
|
|
nsIObserver, nsIIOServiceInternal, nsISupportsWeakReference)
|
2008-02-21 23:39:20 +03:00
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-05-18 00:55:52 +03:00
|
|
|
nsresult nsIOService::RecheckCaptivePortal() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be called on the main thread");
|
2017-05-08 14:19:40 +03:00
|
|
|
if (!mCaptivePortalService) {
|
|
|
|
return NS_OK;
|
2016-05-18 00:55:52 +03:00
|
|
|
}
|
2017-05-08 14:19:40 +03:00
|
|
|
nsCOMPtr<nsIRunnable> task = NewRunnableMethod(
|
|
|
|
"nsIOService::RecheckCaptivePortal", mCaptivePortalService,
|
|
|
|
&nsICaptivePortalService::RecheckCaptivePortal);
|
|
|
|
return NS_DispatchToMainThread(task);
|
2016-05-18 00:55:52 +03:00
|
|
|
}
|
|
|
|
|
2014-10-14 01:35:51 +04:00
|
|
|
nsresult nsIOService::RecheckCaptivePortalIfLocalRedirect(nsIChannel *newChan) {
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!mCaptivePortalService) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = newChan->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString host;
|
|
|
|
rv = uri->GetHost(host);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRNetAddr prAddr;
|
|
|
|
if (PR_StringToNetAddr(host.BeginReading(), &prAddr) != PR_SUCCESS) {
|
|
|
|
// The redirect wasn't to an IP literal, so there's probably no need
|
|
|
|
// to trigger the captive portal detection right now. It can wait.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
NetAddr netAddr;
|
2014-10-14 01:35:51 +04:00
|
|
|
PRNetAddrToNetAddr(&prAddr, &netAddr);
|
|
|
|
if (IsIPAddrLocal(&netAddr)) {
|
|
|
|
// Redirects to local IP addresses are probably captive portals
|
2017-05-08 14:19:40 +03:00
|
|
|
RecheckCaptivePortal();
|
2014-10-14 01:35:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-05 06:15:55 +04:00
|
|
|
nsresult nsIOService::AsyncOnChannelRedirect(
|
|
|
|
nsIChannel *oldChan, nsIChannel *newChan, uint32_t flags,
|
|
|
|
nsAsyncRedirectVerifyHelper *helper) {
|
2014-10-14 01:35:51 +04:00
|
|
|
// If a redirect to a local network address occurs, then chances are we
|
|
|
|
// are in a captive portal, so we trigger a recheck.
|
|
|
|
RecheckCaptivePortalIfLocalRedirect(newChan);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-12-07 02:33:14 +03:00
|
|
|
// This is silly. I wish there was a simpler way to get at the global
|
|
|
|
// reference of the contentSecurityManager. But it lives in the XPCOM
|
|
|
|
// service registry.
|
2006-02-22 17:07:21 +03:00
|
|
|
nsCOMPtr<nsIChannelEventSink> sink =
|
2015-12-07 02:33:14 +03:00
|
|
|
do_GetService(NS_CONTENTSECURITYMANAGER_CONTRACTID);
|
2006-02-22 17:07:21 +03:00
|
|
|
if (sink) {
|
2010-08-05 06:15:55 +04:00
|
|
|
nsresult rv =
|
|
|
|
helper->DelegateOnChannelRedirect(sink, oldChan, newChan, flags);
|
2006-02-22 17:07:21 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, our category
|
2013-10-10 16:48:03 +04:00
|
|
|
nsCOMArray<nsIChannelEventSink> entries;
|
|
|
|
mChannelEventSinks.GetEntries(entries);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t len = entries.Count();
|
|
|
|
for (int32_t i = 0; i < len; ++i) {
|
2010-08-05 06:15:55 +04:00
|
|
|
nsresult rv =
|
|
|
|
helper->DelegateOnChannelRedirect(entries[i], oldChan, newChan, flags);
|
2006-02-22 17:07:21 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-22 10:16:50 +04:00
|
|
|
nsresult nsIOService::CacheProtocolHandler(const char *scheme,
|
|
|
|
nsIProtocolHandler *handler) {
|
2016-08-09 14:43:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2000-08-22 10:16:50 +04:00
|
|
|
for (unsigned int i = 0; i < NS_N(gScheme); i++) {
|
|
|
|
if (!nsCRT::strcasecmp(scheme, gScheme[i])) {
|
|
|
|
nsresult rv;
|
|
|
|
NS_ASSERTION(!mWeakHandler[i], "Protocol handler already cached");
|
|
|
|
// Make sure the handler supports weak references.
|
|
|
|
nsCOMPtr<nsISupportsWeakReference> factoryPtr =
|
|
|
|
do_QueryInterface(handler, &rv);
|
|
|
|
if (!factoryPtr) {
|
2005-11-25 11:16:51 +03:00
|
|
|
// Don't cache handlers that don't support weak reference as
|
2000-08-22 10:16:50 +04:00
|
|
|
// there is real danger of a circular reference.
|
2000-10-29 02:17:53 +04:00
|
|
|
#ifdef DEBUG_dp
|
|
|
|
printf(
|
|
|
|
"DEBUG: %s protcol handler doesn't support weak ref. Not cached.\n",
|
|
|
|
scheme);
|
|
|
|
#endif /* DEBUG_dp */
|
2000-08-22 10:16:50 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-07-25 23:06:59 +04:00
|
|
|
mWeakHandler[i] = do_GetWeakReference(handler);
|
2000-08-22 10:16:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2000-08-22 10:16:50 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsIOService::GetCachedProtocolHandler(const char *scheme,
|
|
|
|
nsIProtocolHandler **result,
|
|
|
|
uint32_t start, uint32_t end) {
|
2016-08-09 14:43:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = end - start - 1;
|
2000-08-22 10:16:50 +04:00
|
|
|
for (unsigned int i = 0; i < NS_N(gScheme); i++) {
|
2001-10-31 01:20:06 +03:00
|
|
|
if (!mWeakHandler[i]) continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-08-17 08:01:38 +04:00
|
|
|
// handle unterminated strings
|
|
|
|
// start is inclusive, end is exclusive, len = end - start - 1
|
2001-10-31 01:20:06 +03:00
|
|
|
if (end ? (!nsCRT::strncasecmp(scheme + start, gScheme[i], len) &&
|
|
|
|
gScheme[i][len] == '\0')
|
|
|
|
: (!nsCRT::strcasecmp(scheme, gScheme[i]))) {
|
2002-11-06 16:03:49 +03:00
|
|
|
return CallQueryReferent(mWeakHandler[i].get(), result);
|
2000-08-22 10:16:50 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2000-08-22 10:16:50 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2016-10-03 07:43:15 +03:00
|
|
|
static bool UsesExternalProtocolHandler(const char *aScheme) {
|
|
|
|
if (NS_LITERAL_CSTRING("file").Equals(aScheme) ||
|
|
|
|
NS_LITERAL_CSTRING("chrome").Equals(aScheme) ||
|
|
|
|
NS_LITERAL_CSTRING("resource").Equals(aScheme)) {
|
|
|
|
// Don't allow file:, chrome: or resource: URIs to be handled with
|
|
|
|
// nsExternalProtocolHandler, since internally we rely on being able to
|
|
|
|
// use and read from these URIs.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-19 18:13:00 +03:00
|
|
|
for (const auto &forcedExternalScheme : gForcedExternalSchemes) {
|
|
|
|
if (!nsCRT::strcasecmp(forcedExternalScheme, aScheme)) {
|
2018-04-17 17:48:13 +03:00
|
|
|
return true;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-04-17 17:48:13 +03:00
|
|
|
|
2016-10-03 07:43:15 +03:00
|
|
|
nsAutoCString pref("network.protocol-handler.external.");
|
|
|
|
pref += aScheme;
|
|
|
|
|
|
|
|
return Preferences::GetBool(pref.get(), false);
|
|
|
|
}
|
|
|
|
|
1999-06-08 01:33:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::GetProtocolHandler(const char *scheme,
|
|
|
|
nsIProtocolHandler **result) {
|
|
|
|
nsresult rv;
|
|
|
|
|
2000-05-04 01:47:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(scheme);
|
2017-07-06 15:00:35 +03:00
|
|
|
// XXX we may want to speed this up by introducing our own protocol
|
1999-06-08 01:33:30 +04:00
|
|
|
// scheme -> protocol handler mapping, avoiding the string manipulation
|
|
|
|
// and service manager stuff
|
|
|
|
|
2000-08-22 10:16:50 +04:00
|
|
|
rv = GetCachedProtocolHandler(scheme, result);
|
2004-08-25 01:50:15 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) return rv;
|
2000-08-22 10:16:50 +04:00
|
|
|
|
2018-04-17 17:38:36 +03:00
|
|
|
if (scheme[0] != '\0' && !UsesExternalProtocolHandler(scheme)) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contractID(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX);
|
2002-03-26 18:58:26 +03:00
|
|
|
contractID += scheme;
|
|
|
|
ToLowerCase(contractID);
|
|
|
|
|
|
|
|
rv = CallGetService(contractID.get(), result);
|
2004-08-25 01:50:15 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
CacheProtocolHandler(scheme, *result);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-04-05 08:06:25 +03:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2011-03-24 06:38:03 +03:00
|
|
|
// check to see whether GVFS can handle this URI scheme. if it can
|
|
|
|
// create a nsIURI for the "scheme:", then we assume it has support for
|
|
|
|
// the requested protocol. otherwise, we failover to using the default
|
|
|
|
// protocol handler.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-03-24 06:38:03 +03:00
|
|
|
rv =
|
|
|
|
CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "moz-gio", result);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec(scheme);
|
2011-03-24 06:38:03 +03:00
|
|
|
spec.Append(':');
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-03-05 21:43:02 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = (*result)->NewURI(spec, nullptr, nullptr, getter_AddRefs(uri));
|
2011-03-24 06:38:03 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-03-24 06:38:03 +03:00
|
|
|
NS_RELEASE(*result);
|
2007-11-09 09:13:26 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
#endif
|
|
|
|
}
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2004-08-25 01:50:15 +04:00
|
|
|
// Okay we don't have a protocol handler to handle this url type, so use
|
|
|
|
// the default protocol handler. This will cause urls to get dispatched
|
|
|
|
// out to the OS ('cause we can't do anything with them) when we try to
|
|
|
|
// read from a channel created by the default protocol handler.
|
2000-08-22 10:16:50 +04:00
|
|
|
|
2004-08-25 01:50:15 +04:00
|
|
|
rv = CallGetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "default", result);
|
|
|
|
if (NS_FAILED(rv)) return NS_ERROR_UNKNOWN_PROTOCOL;
|
|
|
|
|
|
|
|
return rv;
|
1999-06-08 01:33:30 +04:00
|
|
|
}
|
|
|
|
|
1999-11-12 09:13:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsIOService::ExtractScheme(const nsACString &inURI, nsACString &scheme) {
|
2016-02-05 16:45:08 +03:00
|
|
|
return net_ExtractURLScheme(inURI, scheme);
|
2001-06-22 02:02:47 +04:00
|
|
|
}
|
|
|
|
|
2017-03-31 23:39:45 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::HostnameIsLocalIPAddress(nsIURI *aURI, bool *aResult) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(innerURI);
|
|
|
|
|
|
|
|
nsAutoCString host;
|
|
|
|
nsresult rv = innerURI->GetAsciiHost(host);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = false;
|
|
|
|
|
|
|
|
PRNetAddr addr;
|
|
|
|
PRStatus result = PR_StringToNetAddr(host.get(), &addr);
|
|
|
|
if (result == PR_SUCCESS) {
|
|
|
|
NetAddr netAddr;
|
|
|
|
PRNetAddrToNetAddr(&addr, &netAddr);
|
|
|
|
if (IsIPAddrLocal(&netAddr)) {
|
|
|
|
*aResult = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIOService::GetProtocolFlags(const char *scheme, uint32_t *flags) {
|
2001-08-08 00:42:57 +04:00
|
|
|
nsCOMPtr<nsIProtocolHandler> handler;
|
|
|
|
nsresult rv = GetProtocolHandler(scheme, getter_AddRefs(handler));
|
2002-03-06 10:48:55 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-27 23:27:38 +03:00
|
|
|
// We can't call DoGetProtocolFlags here because we don't have a URI. This
|
|
|
|
// API is used by (and only used by) extensions, which is why it's still
|
|
|
|
// around. Calling this on a scheme with dynamic flags will throw.
|
2001-09-13 06:21:05 +04:00
|
|
|
rv = handler->GetProtocolFlags(flags);
|
2017-02-18 00:25:48 +03:00
|
|
|
#if !IS_ORIGIN_IS_FULL_SPEC_DEFINED
|
|
|
|
MOZ_RELEASE_ASSERT(!(*flags & nsIProtocolHandler::ORIGIN_IS_FULL_SPEC),
|
|
|
|
"ORIGIN_IS_FULL_SPEC is unsupported but used");
|
|
|
|
#endif
|
2001-08-08 00:42:57 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-03-12 08:56:45 +03:00
|
|
|
class AutoIncrement {
|
|
|
|
public:
|
2014-08-05 17:20:24 +04:00
|
|
|
explicit AutoIncrement(uint32_t *var) : mVar(var) { ++*var; }
|
2007-03-12 08:56:45 +03:00
|
|
|
~AutoIncrement() { --*mVar; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-12 08:56:45 +03:00
|
|
|
private:
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t *mVar;
|
2007-03-12 08:56:45 +03:00
|
|
|
};
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsresult nsIOService::NewURI(const nsACString &aSpec, const char *aCharset,
|
|
|
|
nsIURI *aBaseURI, nsIURI **result) {
|
2007-03-12 08:56:45 +03:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "wrong thread");
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t recursionCount = 0;
|
2007-03-12 08:56:45 +03:00
|
|
|
if (recursionCount >= MAX_RECURSION_COUNT) return NS_ERROR_MALFORMED_URI;
|
|
|
|
AutoIncrement inc(&recursionCount);
|
2001-08-17 08:01:38 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2007-03-12 08:56:45 +03:00
|
|
|
nsresult rv = ExtractScheme(aSpec, scheme);
|
2002-08-30 01:31:55 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-07-27 12:45:20 +04:00
|
|
|
// then aSpec is relative
|
|
|
|
if (!aBaseURI) return NS_ERROR_MALFORMED_URI;
|
2016-07-27 01:38:46 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (!aSpec.IsEmpty() && aSpec[0] == '#') {
|
2016-07-27 01:38:46 +03:00
|
|
|
// Looks like a reference instead of a fully-specified URI.
|
2002-03-06 10:48:55 +03:00
|
|
|
// --> initialize |uri| as a clone of |aBaseURI|, with ref appended.
|
|
|
|
return NS_GetURIWithNewRef(aBaseURI, aSpec, result);
|
2001-08-17 08:01:38 +04:00
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
rv = aBaseURI->GetScheme(scheme);
|
1999-07-10 15:26:43 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// now get the handler for this scheme
|
|
|
|
nsCOMPtr<nsIProtocolHandler> handler;
|
|
|
|
rv = GetProtocolHandler(scheme.get(), getter_AddRefs(handler));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
return handler->NewURI(aSpec, aCharset, aBaseURI, result);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2001-06-22 02:02:47 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
2002-02-01 01:17:35 +03:00
|
|
|
nsIOService::NewFileURI(nsIFile *file, nsIURI **result) {
|
2001-06-22 02:02:47 +04:00
|
|
|
nsresult rv;
|
2002-02-01 01:17:35 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(file);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProtocolHandler> handler;
|
|
|
|
|
|
|
|
rv = GetProtocolHandler("file", getter_AddRefs(handler));
|
2001-06-22 02:02:47 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-02-01 01:17:35 +03:00
|
|
|
nsCOMPtr<nsIFileProtocolHandler> fileHandler(do_QueryInterface(handler, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2002-02-01 01:17:35 +03:00
|
|
|
return fileHandler->NewFileURI(file, result);
|
2001-06-22 02:02:47 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 04:20:12 +04:00
|
|
|
NS_IMETHODIMP
|
2019-02-21 14:48:20 +03:00
|
|
|
nsIOService::NewChannelFromURI(nsIURI *aURI, nsINode *aLoadingNode,
|
|
|
|
nsIPrincipal *aLoadingPrincipal,
|
|
|
|
nsIPrincipal *aTriggeringPrincipal,
|
|
|
|
uint32_t aSecurityFlags,
|
|
|
|
uint32_t aContentPolicyType,
|
|
|
|
nsIChannel **result) {
|
|
|
|
return NewChannelFromURIWithProxyFlags(aURI,
|
|
|
|
nullptr, // aProxyURI
|
|
|
|
0, // aProxyFlags
|
|
|
|
aLoadingNode, aLoadingPrincipal,
|
|
|
|
aTriggeringPrincipal, aSecurityFlags,
|
|
|
|
aContentPolicyType, result);
|
2014-10-23 04:20:12 +04:00
|
|
|
}
|
2018-01-23 18:38:54 +03:00
|
|
|
nsresult nsIOService::NewChannelFromURIWithClientAndController(
|
|
|
|
nsIURI *aURI, nsINode *aLoadingNode, nsIPrincipal *aLoadingPrincipal,
|
|
|
|
nsIPrincipal *aTriggeringPrincipal,
|
|
|
|
const Maybe<ClientInfo> &aLoadingClientInfo,
|
|
|
|
const Maybe<ServiceWorkerDescriptor> &aController, uint32_t aSecurityFlags,
|
|
|
|
uint32_t aContentPolicyType, nsIChannel **aResult) {
|
|
|
|
return NewChannelFromURIWithProxyFlagsInternal(
|
|
|
|
aURI,
|
|
|
|
nullptr, // aProxyURI
|
|
|
|
0, // aProxyFlags
|
|
|
|
aLoadingNode, aLoadingPrincipal, aTriggeringPrincipal, aLoadingClientInfo,
|
|
|
|
aController, aSecurityFlags, aContentPolicyType, aResult);
|
|
|
|
}
|
2014-10-23 04:20:12 +04:00
|
|
|
|
2014-12-13 01:24:57 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::NewChannelFromURIWithLoadInfo(nsIURI *aURI, nsILoadInfo *aLoadInfo,
|
|
|
|
nsIChannel **result) {
|
|
|
|
return NewChannelFromURIWithProxyFlagsInternal(aURI,
|
|
|
|
nullptr, // aProxyURI
|
|
|
|
0, // aProxyFlags
|
|
|
|
aLoadInfo, result);
|
|
|
|
}
|
|
|
|
|
2018-01-23 18:38:54 +03:00
|
|
|
nsresult nsIOService::NewChannelFromURIWithProxyFlagsInternal(
|
|
|
|
nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags,
|
|
|
|
nsINode *aLoadingNode, nsIPrincipal *aLoadingPrincipal,
|
|
|
|
nsIPrincipal *aTriggeringPrincipal,
|
|
|
|
const Maybe<ClientInfo> &aLoadingClientInfo,
|
|
|
|
const Maybe<ServiceWorkerDescriptor> &aController, uint32_t aSecurityFlags,
|
|
|
|
uint32_t aContentPolicyType, nsIChannel **result) {
|
|
|
|
// Ideally all callers of NewChannelFromURIWithProxyFlagsInternal provide
|
|
|
|
// the necessary arguments to create a loadinfo.
|
|
|
|
//
|
|
|
|
// Note, historically this could be called with nullptr aLoadingNode,
|
|
|
|
// aLoadingPrincipal, and aTriggeringPrincipal from addons using
|
|
|
|
// newChannelFromURIWithProxyFlags(). This code tried to accomodate
|
|
|
|
// by not creating a LoadInfo in such cases. Now that both the legacy
|
|
|
|
// addons and that API are gone we could possibly require always creating a
|
|
|
|
// LoadInfo here. See bug 1432205.
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-23 18:38:54 +03:00
|
|
|
// TYPE_DOCUMENT loads don't require a loadingNode or principal, but other
|
|
|
|
// types do.
|
|
|
|
if (aLoadingNode || aLoadingPrincipal ||
|
|
|
|
aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) {
|
|
|
|
loadInfo = new LoadInfo(aLoadingPrincipal, aTriggeringPrincipal,
|
|
|
|
aLoadingNode, aSecurityFlags, aContentPolicyType,
|
|
|
|
aLoadingClientInfo, aController);
|
|
|
|
}
|
2019-04-03 15:51:51 +03:00
|
|
|
if (!loadInfo) {
|
|
|
|
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
|
|
|
// if coming from JS we like to know the JS stack, otherwise
|
|
|
|
// we just assert that we are able to create a valid loadinfo!
|
|
|
|
if (cx) {
|
|
|
|
JS::UniqueChars chars = xpc_PrintJSStack(cx,
|
|
|
|
/*showArgs=*/false,
|
|
|
|
/*showLocals=*/false,
|
|
|
|
/*showThisProps=*/false);
|
|
|
|
nsDependentCString stackTrace(chars.get());
|
|
|
|
CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::Bug_1541161,
|
|
|
|
stackTrace);
|
|
|
|
}
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(false,
|
|
|
|
"Please pass security info when creating a channel");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2018-01-23 18:38:54 +03:00
|
|
|
return NewChannelFromURIWithProxyFlagsInternal(aURI, aProxyURI, aProxyFlags,
|
|
|
|
loadInfo, result);
|
|
|
|
}
|
|
|
|
|
2014-12-13 01:24:57 +03:00
|
|
|
nsresult nsIOService::NewChannelFromURIWithProxyFlagsInternal(
|
|
|
|
nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags,
|
|
|
|
nsILoadInfo *aLoadInfo, nsIChannel **result) {
|
1999-06-08 22:28:10 +04:00
|
|
|
nsresult rv;
|
2000-05-04 01:47:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2001-09-13 06:21:05 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = aURI->GetScheme(scheme);
|
1999-07-10 15:26:43 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIProtocolHandler> handler;
|
2005-03-25 06:41:33 +03:00
|
|
|
rv = GetProtocolHandler(scheme.get(), getter_AddRefs(handler));
|
1999-07-10 15:26:43 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t protoFlags;
|
2015-07-27 23:27:38 +03:00
|
|
|
rv = handler->DoGetProtocolFlags(aURI, &protoFlags);
|
1999-07-10 15:26:43 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-29 20:41:41 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2012-09-15 00:27:46 +04:00
|
|
|
nsCOMPtr<nsIProxiedProtocolHandler> pph = do_QueryInterface(handler);
|
2014-12-12 20:05:21 +03:00
|
|
|
if (pph) {
|
2019-02-19 17:42:42 +03:00
|
|
|
rv = pph->NewProxiedChannel(aURI, nullptr, aProxyFlags, aProxyURI,
|
|
|
|
aLoadInfo, getter_AddRefs(channel));
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2019-02-19 21:20:37 +03:00
|
|
|
rv = handler->NewChannel(aURI, aLoadInfo, getter_AddRefs(channel));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-04-01 08:41:49 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2015-05-29 20:41:41 +03:00
|
|
|
|
|
|
|
// Make sure that all the individual protocolhandlers attach a loadInfo.
|
|
|
|
if (aLoadInfo) {
|
2015-01-12 07:21:37 +03:00
|
|
|
// make sure we have the same instance of loadInfo on the newly created
|
|
|
|
// channel
|
2019-02-20 15:27:25 +03:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
|
2015-01-12 07:21:37 +03:00
|
|
|
if (aLoadInfo != loadInfo) {
|
|
|
|
MOZ_ASSERT(false, "newly created channel must have a loadinfo attached");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2014-12-12 20:05:21 +03:00
|
|
|
|
|
|
|
// If we're sandboxed, make sure to clear any owner the channel
|
|
|
|
// might already have.
|
|
|
|
if (loadInfo->GetLoadingSandboxed()) {
|
2015-05-29 20:41:41 +03:00
|
|
|
channel->SetOwner(nullptr);
|
2014-12-12 20:05:21 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2009-11-19 02:21:13 +03:00
|
|
|
|
|
|
|
// Some extensions override the http protocol handler and provide their own
|
|
|
|
// implementation. The channels returned from that implementation doesn't
|
|
|
|
// seem to always implement the nsIUploadChannel2 interface, presumably
|
|
|
|
// because it's a new interface.
|
|
|
|
// Eventually we should remove this and simply require that http channels
|
|
|
|
// implement the new interface.
|
|
|
|
// See bug 529041
|
|
|
|
if (!gHasWarnedUploadChannel2 && scheme.EqualsLiteral("http")) {
|
2015-05-29 20:41:41 +03:00
|
|
|
nsCOMPtr<nsIUploadChannel2> uploadChannel2 = do_QueryInterface(channel);
|
2009-11-19 02:21:13 +03:00
|
|
|
if (!uploadChannel2) {
|
|
|
|
nsCOMPtr<nsIConsoleService> consoleService =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
if (consoleService) {
|
2017-03-14 05:26:27 +03:00
|
|
|
consoleService->LogStringMessage(
|
|
|
|
u"Http channel implementation "
|
|
|
|
"doesn't support nsIUploadChannel2. An extension has "
|
|
|
|
"supplied a non-functional http protocol handler. This will "
|
|
|
|
"break behavior and in future releases not work at all.");
|
2009-11-19 02:21:13 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
gHasWarnedUploadChannel2 = true;
|
2009-11-19 02:21:13 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2009-11-19 02:21:13 +03:00
|
|
|
|
2015-05-29 20:41:41 +03:00
|
|
|
channel.forget(result);
|
2009-11-19 02:21:13 +03:00
|
|
|
return NS_OK;
|
1999-06-08 01:33:30 +04:00
|
|
|
}
|
|
|
|
|
2014-12-13 01:24:57 +03:00
|
|
|
NS_IMETHODIMP
|
2019-02-21 14:48:20 +03:00
|
|
|
nsIOService::NewChannelFromURIWithProxyFlags(
|
2014-12-13 01:24:57 +03:00
|
|
|
nsIURI *aURI, nsIURI *aProxyURI, uint32_t aProxyFlags,
|
|
|
|
nsINode *aLoadingNode, nsIPrincipal *aLoadingPrincipal,
|
|
|
|
nsIPrincipal *aTriggeringPrincipal, uint32_t aSecurityFlags,
|
|
|
|
uint32_t aContentPolicyType, nsIChannel **result) {
|
|
|
|
return NewChannelFromURIWithProxyFlagsInternal(
|
2018-01-23 18:38:54 +03:00
|
|
|
aURI, aProxyURI, aProxyFlags, aLoadingNode, aLoadingPrincipal,
|
|
|
|
aTriggeringPrincipal, Maybe<ClientInfo>(),
|
|
|
|
Maybe<ServiceWorkerDescriptor>(), aSecurityFlags, aContentPolicyType,
|
2014-12-13 01:24:57 +03:00
|
|
|
result);
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:20:12 +04:00
|
|
|
NS_IMETHODIMP
|
2019-02-21 14:48:20 +03:00
|
|
|
nsIOService::NewChannel(const nsACString &aSpec, const char *aCharset,
|
|
|
|
nsIURI *aBaseURI, nsINode *aLoadingNode,
|
|
|
|
nsIPrincipal *aLoadingPrincipal,
|
|
|
|
nsIPrincipal *aTriggeringPrincipal,
|
|
|
|
uint32_t aSecurityFlags, uint32_t aContentPolicyType,
|
|
|
|
nsIChannel **result) {
|
1999-06-08 22:28:10 +04:00
|
|
|
nsresult rv;
|
1999-09-26 14:11:36 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = NewURI(aSpec, aCharset, aBaseURI, getter_AddRefs(uri));
|
1999-06-08 22:28:10 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-02-21 14:48:20 +03:00
|
|
|
return NewChannelFromURI(uri, aLoadingNode, aLoadingPrincipal,
|
|
|
|
aTriggeringPrincipal, aSecurityFlags,
|
|
|
|
aContentPolicyType, result);
|
2014-10-23 04:20:12 +04:00
|
|
|
}
|
|
|
|
|
2008-11-13 18:38:02 +03:00
|
|
|
bool nsIOService::IsLinkUp() {
|
2011-10-18 13:46:59 +04:00
|
|
|
InitializeNetworkLinkService();
|
|
|
|
|
2008-11-13 18:38:02 +03:00
|
|
|
if (!mNetworkLinkService) {
|
|
|
|
// We cannot decide, assume the link is up
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-11-13 18:38:02 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isLinkUp;
|
2008-11-13 18:38:02 +03:00
|
|
|
nsresult rv;
|
|
|
|
rv = mNetworkLinkService->GetIsLinkUp(&isLinkUp);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-11-13 18:38:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return isLinkUp;
|
|
|
|
}
|
|
|
|
|
2000-01-05 05:44:23 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsIOService::GetOffline(bool *offline) {
|
2015-03-26 14:19:47 +03:00
|
|
|
if (mOfflineMirrorsConnectivity) {
|
|
|
|
*offline = mOffline || !mConnectivity;
|
|
|
|
} else {
|
|
|
|
*offline = mOffline;
|
|
|
|
}
|
2000-01-05 05:44:23 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsIOService::SetOffline(bool offline) {
|
2015-11-18 17:25:39 +03:00
|
|
|
LOG(("nsIOService::SetOffline offline=%d\n", offline));
|
2009-03-18 17:52:31 +03:00
|
|
|
// When someone wants to go online (!offline) after we got XPCOM shutdown
|
|
|
|
// throw ERROR_NOT_AVAILABLE to prevent return to online state.
|
2012-11-30 01:07:37 +04:00
|
|
|
if ((mShutdown || mOfflineForProfileChange) && !offline)
|
2009-03-18 17:52:31 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-02-22 22:09:09 +03:00
|
|
|
// SetOffline() may re-enter while it's shutting down services.
|
|
|
|
// If that happens, save the most recent value and it will be
|
|
|
|
// processed when the first SetOffline() call is done bringing
|
|
|
|
// down the service.
|
|
|
|
mSetOfflineValue = offline;
|
|
|
|
if (mSettingOffline) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-05-11 16:44:12 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mSettingOffline = true;
|
2009-02-22 22:09:09 +03:00
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
|
2001-01-17 22:51:28 +03:00
|
|
|
|
2010-05-11 16:44:12 +04:00
|
|
|
NS_ASSERTION(observerService, "The observer service should not be null");
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2010-05-11 16:44:12 +04:00
|
|
|
if (observerService) {
|
2012-07-30 18:20:58 +04:00
|
|
|
(void)observerService->NotifyObservers(nullptr,
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC,
|
2016-07-21 08:03:25 +03:00
|
|
|
offline ? u"true" : u"false");
|
2010-05-11 16:44:12 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-05-11 16:44:12 +04:00
|
|
|
|
2012-09-18 03:45:10 +04:00
|
|
|
nsIIOService *subject = static_cast<nsIIOService *>(this);
|
2009-02-22 22:09:09 +03:00
|
|
|
while (mSetOfflineValue != mOffline) {
|
|
|
|
offline = mSetOfflineValue;
|
|
|
|
|
|
|
|
if (offline && !mOffline) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mOffline = true; // indicate we're trying to shutdown
|
2009-02-22 22:09:09 +03:00
|
|
|
|
2012-09-18 03:45:10 +04:00
|
|
|
// don't care if notifications fail
|
2009-02-22 22:09:09 +03:00
|
|
|
if (observerService)
|
2012-09-18 03:45:10 +04:00
|
|
|
observerService->NotifyObservers(subject,
|
2009-02-22 22:09:09 +03:00
|
|
|
NS_IOSERVICE_GOING_OFFLINE_TOPIC,
|
2017-03-14 05:26:27 +03:00
|
|
|
u"" NS_IOSERVICE_OFFLINE);
|
2009-02-22 22:09:09 +03:00
|
|
|
|
2012-09-18 03:45:10 +04:00
|
|
|
if (mSocketTransportService) mSocketTransportService->SetOffline(true);
|
2009-02-22 22:09:09 +03:00
|
|
|
|
2015-07-07 12:13:00 +03:00
|
|
|
mLastOfflineStateChange = PR_IntervalNow();
|
2009-02-22 22:09:09 +03:00
|
|
|
if (observerService)
|
2012-09-18 03:45:10 +04:00
|
|
|
observerService->NotifyObservers(subject,
|
2009-02-22 22:09:09 +03:00
|
|
|
NS_IOSERVICE_OFFLINE_STATUS_TOPIC,
|
2017-03-14 05:26:27 +03:00
|
|
|
u"" NS_IOSERVICE_OFFLINE);
|
2009-02-22 22:09:09 +03:00
|
|
|
} else if (!offline && mOffline) {
|
|
|
|
// go online
|
2010-11-25 08:20:11 +03:00
|
|
|
InitializeSocketTransportService();
|
2011-10-17 18:59:28 +04:00
|
|
|
mOffline = false; // indicate success only AFTER we've
|
2009-02-22 22:09:09 +03:00
|
|
|
// brought up the services
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-07 12:13:00 +03:00
|
|
|
mLastOfflineStateChange = PR_IntervalNow();
|
2009-02-22 22:09:09 +03:00
|
|
|
// don't care if notification fails
|
2015-05-02 00:14:39 +03:00
|
|
|
// Only send the ONLINE notification if there is connectivity
|
2015-07-07 12:13:00 +03:00
|
|
|
if (observerService && mConnectivity) {
|
2012-09-18 03:45:10 +04:00
|
|
|
observerService->NotifyObservers(subject,
|
2009-02-22 22:09:09 +03:00
|
|
|
NS_IOSERVICE_OFFLINE_STATUS_TOPIC,
|
2016-07-20 07:07:53 +03:00
|
|
|
(u"" NS_IOSERVICE_ONLINE));
|
2003-01-18 05:15:14 +03:00
|
|
|
}
|
2000-03-28 02:17:48 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2009-02-22 22:09:09 +03:00
|
|
|
|
2012-09-18 03:45:10 +04:00
|
|
|
// Don't notify here, as the above notifications (if used) suffice.
|
2012-11-30 01:07:37 +04:00
|
|
|
if ((mShutdown || mOfflineForProfileChange) && mOffline) {
|
2012-09-18 03:45:10 +04:00
|
|
|
if (mSocketTransportService) {
|
2016-09-19 20:29:59 +03:00
|
|
|
DebugOnly<nsresult> rv = mSocketTransportService->Shutdown(mShutdown);
|
2012-09-18 03:45:10 +04:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"socket transport service shutdown failed");
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-09-18 03:45:10 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mSettingOffline = false;
|
2009-02-22 22:09:09 +03:00
|
|
|
|
2000-01-05 05:44:23 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-02 00:14:39 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::GetConnectivity(bool *aConnectivity) {
|
|
|
|
*aConnectivity = mConnectivity;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::SetConnectivity(bool aConnectivity) {
|
2015-11-18 17:25:39 +03:00
|
|
|
LOG(("nsIOService::SetConnectivity aConnectivity=%d\n", aConnectivity));
|
2015-05-02 00:14:39 +03:00
|
|
|
// This should only be called from ContentChild to pass the connectivity
|
|
|
|
// value from the chrome process to the content process.
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2015-05-02 00:14:39 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
return SetConnectivityInternal(aConnectivity);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsIOService::SetConnectivityInternal(bool aConnectivity) {
|
2015-11-18 17:25:39 +03:00
|
|
|
LOG(("nsIOService::SetConnectivityInternal aConnectivity=%d\n",
|
|
|
|
aConnectivity));
|
2015-05-02 00:14:39 +03:00
|
|
|
if (mConnectivity == aConnectivity) {
|
|
|
|
// Nothing to do here.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mConnectivity = aConnectivity;
|
2015-07-07 12:13:00 +03:00
|
|
|
|
2017-01-09 18:07:03 +03:00
|
|
|
// This is used for PR_Connect PR_Close telemetry so it is important that
|
|
|
|
// we have statistic about network change event even if we are offline.
|
|
|
|
mLastConnectivityChange = PR_IntervalNow();
|
|
|
|
|
2015-05-02 00:14:39 +03:00
|
|
|
if (mCaptivePortalService) {
|
|
|
|
if (aConnectivity && gCaptivePortalEnabled) {
|
|
|
|
// This will also trigger a captive portal check for the new network
|
|
|
|
static_cast<CaptivePortalService *>(mCaptivePortalService.get())->Start();
|
|
|
|
} else {
|
|
|
|
static_cast<CaptivePortalService *>(mCaptivePortalService.get())->Stop();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-02 00:14:39 +03:00
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
|
2015-05-02 00:14:39 +03:00
|
|
|
if (!observerService) {
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-02 00:14:39 +03:00
|
|
|
// This notification sends the connectivity to the child processes
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
observerService->NotifyObservers(nullptr,
|
|
|
|
NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC,
|
|
|
|
aConnectivity ? u"true" : u"false");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOffline) {
|
|
|
|
// We don't need to send any notifications if we're offline
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-05-02 00:14:39 +03:00
|
|
|
if (aConnectivity) {
|
|
|
|
// If we were previously offline due to connectivity=false,
|
|
|
|
// send the ONLINE notification
|
|
|
|
observerService->NotifyObservers(static_cast<nsIIOService *>(this),
|
|
|
|
NS_IOSERVICE_OFFLINE_STATUS_TOPIC,
|
2016-07-20 07:07:53 +03:00
|
|
|
(u"" NS_IOSERVICE_ONLINE));
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2015-05-02 00:14:39 +03:00
|
|
|
// If we were previously online and lost connectivity
|
|
|
|
// send the OFFLINE notification
|
|
|
|
observerService->NotifyObservers(static_cast<nsIIOService *>(this),
|
|
|
|
NS_IOSERVICE_GOING_OFFLINE_TOPIC,
|
2017-03-14 05:26:27 +03:00
|
|
|
u"" NS_IOSERVICE_OFFLINE);
|
2015-05-02 00:14:39 +03:00
|
|
|
observerService->NotifyObservers(static_cast<nsIIOService *>(this),
|
|
|
|
NS_IOSERVICE_OFFLINE_STATUS_TOPIC,
|
2017-03-14 05:26:27 +03:00
|
|
|
u"" NS_IOSERVICE_OFFLINE);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-02 00:14:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-22 11:03:33 +04:00
|
|
|
|
2001-06-06 04:10:09 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIOService::AllowPort(int32_t inPort, const char *scheme, bool *_retval) {
|
|
|
|
int16_t port = inPort;
|
2001-06-06 04:10:09 +04:00
|
|
|
if (port == -1) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = true;
|
2001-06-06 04:10:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-01-05 00:42:42 +04:00
|
|
|
|
|
|
|
if (port == 0) {
|
|
|
|
*_retval = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-06-06 04:10:09 +04:00
|
|
|
// first check to see if the port is in our blacklist:
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t badPortListCnt = mRestrictedPortList.Length();
|
2001-06-06 04:10:09 +04:00
|
|
|
for (int i = 0; i < badPortListCnt; i++) {
|
2009-02-23 04:05:28 +03:00
|
|
|
if (port == mRestrictedPortList[i]) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2001-06-06 04:10:09 +04:00
|
|
|
|
|
|
|
// check to see if the protocol wants to override
|
|
|
|
if (!scheme) return NS_OK;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2001-06-06 04:10:09 +04:00
|
|
|
nsCOMPtr<nsIProtocolHandler> handler;
|
|
|
|
nsresult rv = GetProtocolHandler(scheme, getter_AddRefs(handler));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// let the protocol handler decide
|
|
|
|
return handler->AllowPort(port, scheme, _retval);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2001-06-06 04:10:09 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = true;
|
2001-06-06 04:10:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-27 11:57:14 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2001-10-09 02:27:14 +04:00
|
|
|
|
2018-07-05 23:25:03 +03:00
|
|
|
void nsIOService::PrefsChanged(const char *pref) {
|
2001-10-09 02:27:14 +04:00
|
|
|
// Look for extra ports to block
|
2003-06-25 05:13:30 +04:00
|
|
|
if (!pref || strcmp(pref, PORT_PREF("banned")) == 0)
|
2018-07-05 23:25:03 +03:00
|
|
|
ParsePortList(PORT_PREF("banned"), false);
|
2010-04-20 20:32:28 +04:00
|
|
|
|
|
|
|
// ...as well as previous blocks to remove.
|
|
|
|
if (!pref || strcmp(pref, PORT_PREF("banned.override")) == 0)
|
2018-07-05 23:25:03 +03:00
|
|
|
ParsePortList(PORT_PREF("banned.override"), true);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-04-20 20:32:28 +04:00
|
|
|
if (!pref || strcmp(pref, MANAGE_OFFLINE_STATUS_PREF) == 0) {
|
2012-08-22 19:56:38 +04:00
|
|
|
bool manage;
|
2018-07-05 23:25:03 +03:00
|
|
|
if (mNetworkLinkServiceInitialized &&
|
|
|
|
NS_SUCCEEDED(
|
|
|
|
Preferences::GetBool(MANAGE_OFFLINE_STATUS_PREF, &manage))) {
|
2010-04-20 20:32:28 +04:00
|
|
|
LOG(("nsIOService::PrefsChanged ManageOfflineStatus manage=%d\n",
|
|
|
|
manage));
|
2016-09-01 08:01:16 +03:00
|
|
|
SetManageOfflineStatus(manage);
|
2010-04-20 20:32:28 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-19 14:36:00 +04:00
|
|
|
|
2014-10-14 01:35:51 +04:00
|
|
|
if (!pref || strcmp(pref, NECKO_BUFFER_CACHE_COUNT_PREF) == 0) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count;
|
2014-10-14 01:35:51 +04:00
|
|
|
if (NS_SUCCEEDED(
|
2018-07-05 23:25:03 +03:00
|
|
|
Preferences::GetInt(NECKO_BUFFER_CACHE_COUNT_PREF, &count)))
|
2010-04-20 20:32:28 +04:00
|
|
|
/* check for bogus values and default if we find such a value */
|
|
|
|
if (count > 0) gDefaultSegmentCount = count;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2009-01-13 08:52:00 +03:00
|
|
|
if (!pref || strcmp(pref, NECKO_BUFFER_CACHE_SIZE_PREF) == 0) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t size;
|
2018-07-05 23:25:03 +03:00
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(NECKO_BUFFER_CACHE_SIZE_PREF, &size)))
|
2010-04-20 20:32:28 +04:00
|
|
|
/* check for bogus values and default if we find such a value
|
|
|
|
* the upper limit here is arbitrary. having a 1mb segment size
|
|
|
|
* is pretty crazy. if you remove this, consider adding some
|
|
|
|
* integer rollover test.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2010-04-20 20:32:28 +04:00
|
|
|
if (size > 0 && size < 1024 * 1024) gDefaultSegmentSize = size;
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(!(size & (size - 1)),
|
|
|
|
"network segment size is not a power of 2!");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-19 14:36:00 +04:00
|
|
|
if (!pref || strcmp(pref, NETWORK_NOTIFY_CHANGED_PREF) == 0) {
|
|
|
|
bool allow;
|
2018-07-05 23:25:03 +03:00
|
|
|
nsresult rv = Preferences::GetBool(NETWORK_NOTIFY_CHANGED_PREF, &allow);
|
2014-09-19 14:36:00 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mNetworkNotifyChanged = allow;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-14 01:35:51 +04:00
|
|
|
|
|
|
|
if (!pref || strcmp(pref, NETWORK_CAPTIVE_PORTAL_PREF) == 0) {
|
2018-07-05 23:25:03 +03:00
|
|
|
nsresult rv = Preferences::GetBool(NETWORK_CAPTIVE_PORTAL_PREF,
|
|
|
|
&gCaptivePortalEnabled);
|
2014-10-14 01:35:51 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && mCaptivePortalService) {
|
2018-07-02 16:26:48 +03:00
|
|
|
if (gCaptivePortalEnabled) {
|
2014-10-14 01:35:51 +04:00
|
|
|
static_cast<CaptivePortalService *>(mCaptivePortalService.get())
|
|
|
|
->Start();
|
|
|
|
} else {
|
|
|
|
static_cast<CaptivePortalService *>(mCaptivePortalService.get())
|
|
|
|
->Stop();
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2001-10-09 02:27:14 +04:00
|
|
|
}
|
|
|
|
|
2018-07-05 23:25:03 +03:00
|
|
|
void nsIOService::ParsePortList(const char *pref, bool remove) {
|
2017-10-27 02:30:33 +03:00
|
|
|
nsAutoCString portList;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-10-09 02:27:14 +04:00
|
|
|
// Get a pref string and chop it up into a list of ports.
|
2018-07-05 23:25:03 +03:00
|
|
|
Preferences::GetCString(pref, portList);
|
2017-08-16 06:58:55 +03:00
|
|
|
if (!portList.IsVoid()) {
|
2009-01-22 07:15:34 +03:00
|
|
|
nsTArray<nsCString> portListArray;
|
|
|
|
ParseString(portList, ',', portListArray);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t index;
|
2009-01-22 07:15:34 +03:00
|
|
|
for (index = 0; index < portListArray.Length(); index++) {
|
|
|
|
portListArray[index].StripWhitespace();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t portBegin, portEnd;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-01-22 07:15:34 +03:00
|
|
|
if (PR_sscanf(portListArray[index].get(), "%d-%d", &portBegin,
|
|
|
|
&portEnd) == 2) {
|
2002-06-14 00:51:03 +04:00
|
|
|
if ((portBegin < 65536) && (portEnd < 65536)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t curPort;
|
2002-06-14 00:51:03 +04:00
|
|
|
if (remove) {
|
|
|
|
for (curPort = portBegin; curPort <= portEnd; curPort++)
|
2009-02-23 04:05:28 +03:00
|
|
|
mRestrictedPortList.RemoveElement(curPort);
|
2002-06-14 00:51:03 +04:00
|
|
|
} else {
|
|
|
|
for (curPort = portBegin; curPort <= portEnd; curPort++)
|
2009-02-23 04:05:28 +03:00
|
|
|
mRestrictedPortList.AppendElement(curPort);
|
2002-06-14 00:51:03 +04:00
|
|
|
}
|
2001-10-09 02:27:14 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2012-07-27 17:59:29 +04:00
|
|
|
nsresult aErrorCode;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t port = portListArray[index].ToInteger(&aErrorCode);
|
2002-06-14 00:51:03 +04:00
|
|
|
if (NS_SUCCEEDED(aErrorCode) && port < 65536) {
|
|
|
|
if (remove)
|
2009-02-23 04:05:28 +03:00
|
|
|
mRestrictedPortList.RemoveElement(port);
|
2018-11-30 13:46:48 +03:00
|
|
|
else
|
2009-02-23 04:05:28 +03:00
|
|
|
mRestrictedPortList.AppendElement(port);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2001-10-09 02:27:14 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2001-10-09 02:27:14 +04:00
|
|
|
}
|
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
class nsWakeupNotifier : public Runnable {
|
2015-07-31 23:39:48 +03:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit nsWakeupNotifier(nsIIOServiceInternal *ioService)
|
|
|
|
: Runnable("net::nsWakeupNotifier"), mIOService(ioService) {}
|
2015-07-31 23:39:48 +03:00
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
NS_IMETHOD Run() override { return mIOService->NotifyWakeup(); }
|
2015-07-31 23:39:48 +03:00
|
|
|
|
|
|
|
private:
|
2018-04-30 19:46:04 +03:00
|
|
|
virtual ~nsWakeupNotifier() = default;
|
2015-07-31 23:39:48 +03:00
|
|
|
nsCOMPtr<nsIIOServiceInternal> mIOService;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::NotifyWakeup() {
|
2016-05-19 05:02:57 +03:00
|
|
|
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
|
2015-07-31 23:39:48 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(observerService, "The observer service should not be null");
|
|
|
|
|
|
|
|
if (observerService && mNetworkNotifyChanged) {
|
|
|
|
(void)observerService->NotifyObservers(nullptr, NS_NETWORK_LINK_TOPIC,
|
2016-07-20 07:07:53 +03:00
|
|
|
(u"" NS_NETWORK_LINK_DATA_CHANGED));
|
2015-07-31 23:39:48 +03:00
|
|
|
}
|
|
|
|
|
2016-05-18 00:55:52 +03:00
|
|
|
RecheckCaptivePortal();
|
2015-07-31 23:39:48 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-04 06:14:00 +03:00
|
|
|
void nsIOService::SetHttpHandlerAlreadyShutingDown() {
|
|
|
|
if (!mShutdown && !mOfflineForProfileChange) {
|
|
|
|
mNetTearingDownStarted = PR_IntervalNow();
|
|
|
|
mHttpHandlerAlreadyShutingDown = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-09 02:27:14 +04:00
|
|
|
// nsIObserver interface
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::Observe(nsISupports *subject, const char *topic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *data) {
|
2018-07-05 23:25:03 +03:00
|
|
|
if (!strcmp(topic, kProfileChangeNetTeardownTopic)) {
|
2016-02-04 06:14:00 +03:00
|
|
|
if (!mHttpHandlerAlreadyShutingDown) {
|
|
|
|
mNetTearingDownStarted = PR_IntervalNow();
|
|
|
|
}
|
|
|
|
mHttpHandlerAlreadyShutingDown = false;
|
2001-11-07 07:26:19 +03:00
|
|
|
if (!mOffline) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mOfflineForProfileChange = true;
|
2012-11-30 01:07:37 +04:00
|
|
|
SetOffline(true);
|
2001-11-07 07:26:19 +03:00
|
|
|
}
|
2014-09-19 14:34:00 +04:00
|
|
|
} else if (!strcmp(topic, kProfileChangeNetRestoreTopic)) {
|
2001-11-07 07:26:19 +03:00
|
|
|
if (mOfflineForProfileChange) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mOfflineForProfileChange = false;
|
2015-05-02 00:14:39 +03:00
|
|
|
SetOffline(false);
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
} else if (!strcmp(topic, kProfileDoChange)) {
|
2019-01-12 04:00:26 +03:00
|
|
|
if (!data) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (NS_LITERAL_STRING("startup").Equals(data)) {
|
2011-10-18 13:46:59 +04:00
|
|
|
// Lazy initialization of network link service (see bug 620472)
|
|
|
|
InitializeNetworkLinkService();
|
|
|
|
// Set up the initilization flag regardless the actuall result.
|
|
|
|
// If we fail here, we will fail always on.
|
|
|
|
mNetworkLinkServiceInitialized = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-15 04:29:35 +04:00
|
|
|
// And now reflect the preference setting
|
2018-07-05 23:25:03 +03:00
|
|
|
PrefsChanged(MANAGE_OFFLINE_STATUS_PREF);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-29 13:16:27 +03:00
|
|
|
// Bug 870460 - Read cookie database at an early-as-possible time
|
|
|
|
// off main thread. Hence, we have more chance to finish db query
|
|
|
|
// before something calls into the cookie service.
|
|
|
|
nsCOMPtr<nsISupports> cookieServ =
|
|
|
|
do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
2019-01-12 04:00:26 +03:00
|
|
|
} else if (NS_LITERAL_STRING("xpcshell-do-get-profile").Equals(data)) {
|
|
|
|
// xpcshell doesn't read user profile.
|
|
|
|
LaunchSocketProcess();
|
2011-10-18 13:46:59 +04:00
|
|
|
}
|
2014-09-19 14:34:00 +04:00
|
|
|
} else if (!strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
2009-03-18 17:52:31 +03:00
|
|
|
// Remember we passed XPCOM shutdown notification to prevent any
|
|
|
|
// changes of the offline status from now. We must not allow going
|
|
|
|
// online after this point.
|
2011-10-17 18:59:28 +04:00
|
|
|
mShutdown = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-02-04 06:14:00 +03:00
|
|
|
if (!mHttpHandlerAlreadyShutingDown && !mOfflineForProfileChange) {
|
2016-01-18 10:20:00 +03:00
|
|
|
mNetTearingDownStarted = PR_IntervalNow();
|
|
|
|
}
|
2016-02-04 06:14:00 +03:00
|
|
|
mHttpHandlerAlreadyShutingDown = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
SetOffline(true);
|
2014-10-14 01:35:51 +04:00
|
|
|
|
|
|
|
if (mCaptivePortalService) {
|
|
|
|
static_cast<CaptivePortalService *>(mCaptivePortalService.get())->Stop();
|
2015-07-13 16:50:58 +03:00
|
|
|
mCaptivePortalService = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-01-11 21:57:23 +03:00
|
|
|
DestroySocketProcess();
|
2014-09-25 07:14:00 +04:00
|
|
|
} else if (!strcmp(topic, NS_NETWORK_LINK_TOPIC)) {
|
2015-05-02 00:14:39 +03:00
|
|
|
OnNetworkLinkEvent(NS_ConvertUTF16toUTF8(data).get());
|
2014-09-19 14:34:00 +04:00
|
|
|
} else if (!strcmp(topic, NS_WIDGET_WAKE_OBSERVER_TOPIC)) {
|
|
|
|
// coming back alive from sleep
|
2015-07-31 23:39:48 +03:00
|
|
|
// this indirection brought to you by:
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1152048#c19
|
|
|
|
nsCOMPtr<nsIRunnable> wakeupNotifier = new nsWakeupNotifier(this);
|
|
|
|
NS_DispatchToMainThread(wakeupNotifier);
|
2019-01-11 21:57:23 +03:00
|
|
|
} else if (!strcmp(topic, NS_PREFSERVICE_READ_TOPIC_ID)) {
|
|
|
|
// Launch socket process after we load user's pref. This is to make sure
|
|
|
|
// that socket process can get the latest prefs.
|
|
|
|
LaunchSocketProcess();
|
2014-08-26 23:56:51 +04:00
|
|
|
}
|
2014-09-25 07:14:00 +04:00
|
|
|
|
2001-10-09 02:27:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-07-26 00:27:04 +04:00
|
|
|
|
2015-10-01 21:36:19 +03:00
|
|
|
// nsINetUtil interface
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::ParseRequestContentType(const nsACString &aTypeHeader,
|
|
|
|
nsACString &aCharset, bool *aHadCharset,
|
|
|
|
nsACString &aContentType) {
|
|
|
|
net_ParseRequestContentType(aTypeHeader, aContentType, aCharset, aHadCharset);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-26 00:27:04 +04:00
|
|
|
// nsINetUtil interface
|
|
|
|
NS_IMETHODIMP
|
2015-10-01 19:50:13 +03:00
|
|
|
nsIOService::ParseResponseContentType(const nsACString &aTypeHeader,
|
|
|
|
nsACString &aCharset, bool *aHadCharset,
|
|
|
|
nsACString &aContentType) {
|
2006-04-05 01:26:17 +04:00
|
|
|
net_ParseContentType(aTypeHeader, aContentType, aCharset, aHadCharset);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::ProtocolHasFlags(nsIURI *uri, uint32_t flags, bool *result) {
|
|
|
|
NS_ENSURE_ARG(uri);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2006-05-02 22:54:19 +04:00
|
|
|
nsresult rv = uri->GetScheme(scheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-27 23:27:38 +03:00
|
|
|
// Grab the protocol flags from the URI.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t protocolFlags;
|
2015-07-27 23:27:38 +03:00
|
|
|
nsCOMPtr<nsIProtocolHandler> handler;
|
|
|
|
rv = GetProtocolHandler(scheme.get(), getter_AddRefs(handler));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = handler->DoGetProtocolFlags(uri, &protocolFlags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-07-27 23:27:38 +03:00
|
|
|
*result = (protocolFlags & flags) == flags;
|
|
|
|
return NS_OK;
|
2006-05-02 22:54:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::URIChainHasFlags(nsIURI *uri, uint32_t flags, bool *result) {
|
|
|
|
nsresult rv = ProtocolHasFlags(uri, flags, result);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (*result) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dig deeper into the chain. Note that this is not a do/while loop to
|
|
|
|
// avoid the extra addref/release on |uri| in the common (non-nested) case.
|
|
|
|
nsCOMPtr<nsINestedURI> nestedURI = do_QueryInterface(uri);
|
|
|
|
while (nestedURI) {
|
|
|
|
nsCOMPtr<nsIURI> innerURI;
|
|
|
|
rv = nestedURI->GetInnerURI(getter_AddRefs(innerURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = ProtocolHasFlags(innerURI, flags, result);
|
|
|
|
|
|
|
|
if (*result) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nestedURI = do_QueryInterface(innerURI);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2006-05-02 22:54:19 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-04-05 01:26:17 +04:00
|
|
|
NS_IMETHODIMP
|
2014-09-25 07:14:00 +04:00
|
|
|
nsIOService::SetManageOfflineStatus(bool aManage) {
|
2015-11-18 17:25:39 +03:00
|
|
|
LOG(("nsIOService::SetManageOfflineStatus aManage=%d\n", aManage));
|
2015-05-02 00:14:39 +03:00
|
|
|
mManageLinkStatus = aManage;
|
2011-10-18 13:46:59 +04:00
|
|
|
|
2015-05-02 00:14:39 +03:00
|
|
|
// When detection is not activated, the default connectivity state is true.
|
|
|
|
if (!mManageLinkStatus) {
|
|
|
|
SetConnectivityInternal(true);
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-03-08 20:24:17 +04:00
|
|
|
InitializeNetworkLinkService();
|
2015-05-02 00:14:39 +03:00
|
|
|
// If the NetworkLinkService is already initialized, it does not call
|
|
|
|
// OnNetworkLinkEvent. This is needed, when mManageLinkStatus goes from
|
|
|
|
// false to true.
|
|
|
|
OnNetworkLinkEvent(NS_NETWORK_LINK_DATA_UNKNOWN);
|
|
|
|
return NS_OK;
|
2006-04-05 01:26:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-05-02 00:14:39 +03:00
|
|
|
nsIOService::GetManageOfflineStatus(bool *aManage) {
|
|
|
|
*aManage = mManageLinkStatus;
|
2006-04-05 01:26:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:14:00 +04:00
|
|
|
// input argument 'data' is already UTF8'ed
|
|
|
|
nsresult nsIOService::OnNetworkLinkEvent(const char *data) {
|
2019-01-11 23:54:06 +03:00
|
|
|
if (IsNeckoChild() || IsSocketProcessChild()) {
|
2018-05-30 17:36:42 +03:00
|
|
|
// There is nothing IO service could do on the child process
|
|
|
|
// with this at the moment. Feel free to add functionality
|
|
|
|
// here at will, though.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-03-18 17:52:31 +03:00
|
|
|
|
2018-05-30 17:36:42 +03:00
|
|
|
if (mShutdown) {
|
2009-03-18 17:52:31 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2018-05-30 17:36:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCString dataAsString(data);
|
|
|
|
for (auto *cp : mozilla::dom::ContentParent::AllProcesses(
|
|
|
|
mozilla::dom::ContentParent::eLive)) {
|
|
|
|
PNeckoParent *neckoParent = SingleManagedOrNull(cp->ManagedPNeckoParent());
|
|
|
|
if (!neckoParent) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Unused << neckoParent->SendNetworkChangeNotification(dataAsString);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-05-30 17:36:42 +03:00
|
|
|
|
|
|
|
LOG(("nsIOService::OnNetworkLinkEvent data:%s\n", data));
|
|
|
|
if (!mNetworkLinkService) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-09-25 07:14:00 +04:00
|
|
|
|
2015-05-02 00:14:39 +03:00
|
|
|
if (!mManageLinkStatus) {
|
2015-11-18 17:25:39 +03:00
|
|
|
LOG(("nsIOService::OnNetworkLinkEvent mManageLinkStatus=false\n"));
|
|
|
|
return NS_OK;
|
2015-02-20 18:10:33 +03:00
|
|
|
}
|
|
|
|
|
2015-05-02 00:14:39 +03:00
|
|
|
bool isUp = true;
|
2015-03-12 11:46:00 +03:00
|
|
|
if (!strcmp(data, NS_NETWORK_LINK_DATA_CHANGED)) {
|
2015-07-07 12:13:00 +03:00
|
|
|
mLastNetworkLinkChange = PR_IntervalNow();
|
2015-03-12 11:46:00 +03:00
|
|
|
// CHANGED means UP/DOWN didn't change
|
2017-01-30 15:16:05 +03:00
|
|
|
// but the status of the captive portal may have changed.
|
|
|
|
RecheckCaptivePortal();
|
2015-03-12 11:46:00 +03:00
|
|
|
return NS_OK;
|
2018-05-30 17:36:42 +03:00
|
|
|
}
|
|
|
|
if (!strcmp(data, NS_NETWORK_LINK_DATA_DOWN)) {
|
2014-09-25 07:14:00 +04:00
|
|
|
isUp = false;
|
|
|
|
} else if (!strcmp(data, NS_NETWORK_LINK_DATA_UP)) {
|
|
|
|
isUp = true;
|
2015-03-12 11:46:00 +03:00
|
|
|
} else if (!strcmp(data, NS_NETWORK_LINK_DATA_UNKNOWN)) {
|
2014-09-25 07:14:00 +04:00
|
|
|
nsresult rv = mNetworkLinkService->GetIsLinkUp(&isUp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Unhandled network event!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-02-16 20:25:40 +03:00
|
|
|
|
2015-05-02 00:14:39 +03:00
|
|
|
return SetConnectivityInternal(isUp);
|
2005-07-26 00:27:04 +04:00
|
|
|
}
|
2006-05-02 20:27:23 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::EscapeString(const nsACString &aString, uint32_t aEscapeType,
|
|
|
|
nsACString &aResult) {
|
2012-03-24 12:18:09 +04:00
|
|
|
NS_ENSURE_ARG_MAX(aEscapeType, 4);
|
2006-05-02 20:27:23 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString stringCopy(aString);
|
2006-05-02 20:27:23 +04:00
|
|
|
nsCString result;
|
|
|
|
|
|
|
|
if (!NS_Escape(stringCopy, result, (nsEscapeMask)aEscapeType))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
aResult.Assign(result);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-04-23 18:19:04 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::EscapeURL(const nsACString &aStr, uint32_t aFlags,
|
2012-08-22 19:56:38 +04:00
|
|
|
nsACString &aResult) {
|
2007-06-22 00:18:25 +04:00
|
|
|
aResult.Truncate();
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_EscapeURL(aStr.BeginReading(), aStr.Length(), aFlags | esc_AlwaysCopy,
|
2008-09-15 17:34:46 +04:00
|
|
|
aResult);
|
2007-06-22 00:18:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-04-23 18:19:04 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::UnescapeString(const nsACString &aStr, uint32_t aFlags,
|
2012-08-22 19:56:38 +04:00
|
|
|
nsACString &aResult) {
|
2007-06-22 00:18:25 +04:00
|
|
|
aResult.Truncate();
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_UnescapeURL(aStr.BeginReading(), aStr.Length(), aFlags | esc_AlwaysCopy,
|
2008-09-15 17:34:46 +04:00
|
|
|
aResult);
|
2007-04-23 18:19:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-06-22 00:18:25 +04:00
|
|
|
|
2007-12-04 00:34:44 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::ExtractCharsetFromContentType(const nsACString &aTypeHeader,
|
|
|
|
nsACString &aCharset,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t *aCharsetStart,
|
|
|
|
int32_t *aCharsetEnd,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aHadCharset) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString ignored;
|
2007-12-04 00:34:44 +03:00
|
|
|
net_ParseContentType(aTypeHeader, ignored, aCharset, aHadCharset,
|
|
|
|
aCharsetStart, aCharsetEnd);
|
2008-02-29 07:24:32 +03:00
|
|
|
if (*aHadCharset && *aCharsetStart == *aCharsetEnd) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aHadCharset = false;
|
2007-12-04 00:34:44 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-04-25 16:54:42 +04:00
|
|
|
|
2015-06-06 01:25:24 +03:00
|
|
|
// parse policyString to policy enum value (see ReferrerPolicy.h)
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::ParseAttributePolicyString(const nsAString &policyString,
|
2018-11-01 15:09:15 +03:00
|
|
|
uint32_t *outPolicyEnum) {
|
2015-06-06 01:25:24 +03:00
|
|
|
NS_ENSURE_ARG(outPolicyEnum);
|
2016-05-19 05:02:57 +03:00
|
|
|
*outPolicyEnum = (uint32_t)AttributeReferrerPolicyFromString(policyString);
|
2015-06-06 01:25:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-01 15:09:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::GetReferrerPolicyString(uint32_t aPolicy, nsACString &aResult) {
|
|
|
|
if (aPolicy >= ArrayLength(kReferrerPolicyString)) {
|
|
|
|
aResult.AssignLiteral("unknown");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult.AssignASCII(
|
|
|
|
ReferrerPolicyToString(static_cast<ReferrerPolicy>(aPolicy)));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-25 16:54:42 +04:00
|
|
|
// nsISpeculativeConnect
|
2015-03-21 19:28:04 +03:00
|
|
|
class IOServiceProxyCallback final : public nsIProtocolProxyCallback {
|
2018-04-30 19:46:04 +03:00
|
|
|
~IOServiceProxyCallback() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPROTOCOLPROXYCALLBACK
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
IOServiceProxyCallback(nsIInterfaceRequestor *aCallbacks,
|
|
|
|
nsIOService *aIOService)
|
|
|
|
: mCallbacks(aCallbacks), mIOService(aIOService) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsIInterfaceRequestor> mCallbacks;
|
|
|
|
RefPtr<nsIOService> mIOService;
|
2012-09-15 00:27:46 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(IOServiceProxyCallback, nsIProtocolProxyCallback)
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2012-04-25 16:54:42 +04:00
|
|
|
NS_IMETHODIMP
|
2015-01-21 23:13:00 +03:00
|
|
|
IOServiceProxyCallback::OnProxyAvailable(nsICancelable *request,
|
|
|
|
nsIChannel *channel, nsIProxyInfo *pi,
|
2012-09-15 00:27:46 +04:00
|
|
|
nsresult status) {
|
|
|
|
// Checking proxy status for speculative connect
|
|
|
|
nsAutoCString type;
|
|
|
|
if (NS_SUCCEEDED(status) && pi && NS_SUCCEEDED(pi->GetType(type)) &&
|
|
|
|
!type.EqualsLiteral("direct")) {
|
|
|
|
// proxies dont do speculative connect
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2015-01-21 23:13:00 +03:00
|
|
|
rv = uri->GetScheme(scheme);
|
2012-04-25 16:54:42 +04:00
|
|
|
if (NS_FAILED(rv)) return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProtocolHandler> handler;
|
2012-09-15 00:27:46 +04:00
|
|
|
rv = mIOService->GetProtocolHandler(scheme.get(), getter_AddRefs(handler));
|
2012-04-25 16:54:42 +04:00
|
|
|
if (NS_FAILED(rv)) return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISpeculativeConnect> speculativeHandler =
|
|
|
|
do_QueryInterface(handler);
|
2012-04-28 00:18:21 +04:00
|
|
|
if (!speculativeHandler) return NS_OK;
|
2012-04-25 16:54:42 +04:00
|
|
|
|
2019-02-20 15:27:25 +03:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = loadInfo->LoadingPrincipal();
|
2016-10-26 06:14:41 +03:00
|
|
|
|
2015-05-06 04:15:36 +03:00
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
channel->GetLoadFlags(&loadFlags);
|
|
|
|
if (loadFlags & nsIRequest::LOAD_ANONYMOUS) {
|
2019-02-24 22:26:56 +03:00
|
|
|
speculativeHandler->SpeculativeAnonymousConnect(uri, principal, mCallbacks);
|
2015-05-06 04:15:36 +03:00
|
|
|
} else {
|
2019-02-24 22:26:56 +03:00
|
|
|
speculativeHandler->SpeculativeConnect(uri, principal, mCallbacks);
|
2015-05-06 04:15:36 +03:00
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-06 04:15:36 +03:00
|
|
|
nsresult nsIOService::SpeculativeConnectInternal(
|
|
|
|
nsIURI *aURI, nsIPrincipal *aPrincipal, nsIInterfaceRequestor *aCallbacks,
|
|
|
|
bool aAnonymous) {
|
2016-05-17 22:51:24 +03:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
bool isHTTP, isHTTPS;
|
|
|
|
if (!(NS_SUCCEEDED(aURI->SchemeIs("http", &isHTTP)) && isHTTP) &&
|
|
|
|
!(NS_SUCCEEDED(aURI->SchemeIs("https", &isHTTPS)) && isHTTPS)) {
|
|
|
|
// We don't speculatively connect to non-HTTP[S] URIs.
|
2015-03-20 22:27:34 +03:00
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2016-05-17 22:51:24 +03:00
|
|
|
if (IsNeckoChild()) {
|
2016-10-24 07:18:25 +03:00
|
|
|
ipc::URIParams params;
|
2018-10-05 16:42:37 +03:00
|
|
|
SerializeURI(aURI, params);
|
|
|
|
gNeckoChild->SendSpeculativeConnect(params, IPC::Principal(aPrincipal),
|
2015-03-20 22:27:34 +03:00
|
|
|
aAnonymous);
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-01-21 23:13:00 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// Check for proxy information. If there is a proxy configured then a
|
|
|
|
// speculative connect should not be performed because the potential
|
|
|
|
// reward is slim with tcp peers closely located to the browser.
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIProtocolProxyService> pps =
|
|
|
|
do_GetService(NS_PROTOCOLPROXYSERVICE_CONTRACTID, &rv);
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-10-24 07:18:25 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> loadingPrincipal = aPrincipal;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-05 16:42:37 +03:00
|
|
|
MOZ_ASSERT(aPrincipal, "We expect passing a principal here.");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-03-25 17:08:13 +03:00
|
|
|
if (!aPrincipal) {
|
2019-04-02 19:36:09 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2019-03-25 17:08:13 +03:00
|
|
|
}
|
|
|
|
|
2015-03-20 22:27:34 +03:00
|
|
|
// dummy channel used to create a TCP connection.
|
|
|
|
// we perform security checks on the *real* channel, responsible
|
|
|
|
// for any network loads. this real channel just checks the TCP
|
|
|
|
// pool if there is an available connection created by the
|
|
|
|
// channel we create underneath - hence it's safe to use
|
|
|
|
// the systemPrincipal as the loadingPrincipal for this channel.
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2019-02-21 14:48:20 +03:00
|
|
|
rv = NewChannelFromURI(aURI,
|
|
|
|
nullptr, // aLoadingNode,
|
|
|
|
loadingPrincipal,
|
|
|
|
nullptr, // aTriggeringPrincipal,
|
|
|
|
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
|
|
|
nsIContentPolicy::TYPE_SPECULATIVE,
|
|
|
|
getter_AddRefs(channel));
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-06 04:15:36 +03:00
|
|
|
if (aAnonymous) {
|
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
channel->GetLoadFlags(&loadFlags);
|
|
|
|
loadFlags |= nsIRequest::LOAD_ANONYMOUS;
|
|
|
|
channel->SetLoadFlags(loadFlags);
|
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
nsCOMPtr<nsICancelable> cancelable;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IOServiceProxyCallback> callback =
|
2012-11-14 20:00:44 +04:00
|
|
|
new IOServiceProxyCallback(aCallbacks, this);
|
2015-03-14 00:32:18 +03:00
|
|
|
nsCOMPtr<nsIProtocolProxyService2> pps2 = do_QueryInterface(pps);
|
|
|
|
if (pps2) {
|
2017-07-05 01:48:00 +03:00
|
|
|
return pps2->AsyncResolve2(channel, 0, callback, nullptr,
|
|
|
|
getter_AddRefs(cancelable));
|
2015-03-14 00:32:18 +03:00
|
|
|
}
|
2017-07-05 01:48:00 +03:00
|
|
|
return pps->AsyncResolve(channel, 0, callback, nullptr,
|
|
|
|
getter_AddRefs(cancelable));
|
2012-04-25 16:54:42 +04:00
|
|
|
}
|
2014-08-23 07:05:56 +04:00
|
|
|
|
2016-10-24 07:18:25 +03:00
|
|
|
NS_IMETHODIMP
|
2019-02-24 22:26:56 +03:00
|
|
|
nsIOService::SpeculativeConnect(nsIURI *aURI, nsIPrincipal *aPrincipal,
|
|
|
|
nsIInterfaceRequestor *aCallbacks) {
|
2016-10-24 07:18:25 +03:00
|
|
|
return SpeculativeConnectInternal(aURI, aPrincipal, aCallbacks, false);
|
2015-05-06 04:15:36 +03:00
|
|
|
}
|
|
|
|
|
2016-10-24 07:18:25 +03:00
|
|
|
NS_IMETHODIMP
|
2019-02-24 22:26:56 +03:00
|
|
|
nsIOService::SpeculativeAnonymousConnect(nsIURI *aURI, nsIPrincipal *aPrincipal,
|
|
|
|
nsIInterfaceRequestor *aCallbacks) {
|
2016-10-24 07:18:25 +03:00
|
|
|
return SpeculativeConnectInternal(aURI, aPrincipal, aCallbacks, true);
|
2015-05-06 04:15:36 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/*static*/
|
|
|
|
bool nsIOService::IsDataURIUniqueOpaqueOrigin() {
|
2017-05-17 06:03:33 +03:00
|
|
|
return sIsDataURIUniqueOpaqueOrigin;
|
2017-01-26 20:40:32 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/*static*/
|
|
|
|
bool nsIOService::BlockToplevelDataUriNavigations() {
|
2017-07-24 19:51:21 +03:00
|
|
|
return sBlockToplevelDataUriNavigations;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:11:11 +03:00
|
|
|
/*static*/
|
|
|
|
bool nsIOService::BlockFTPSubresources() { return sBlockFTPSubresources; }
|
2018-04-09 22:07:01 +03:00
|
|
|
|
2018-01-08 13:23:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIOService::NotImplemented() { return NS_ERROR_NOT_IMPLEMENTED; }
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|