/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set sw=2 ts=8 et tw=80 : */ /* 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 "necko-config.h" #include "nsHttp.h" #include "mozilla/net/NeckoParent.h" #include "mozilla/net/HttpChannelParent.h" #include "mozilla/net/CookieServiceParent.h" #include "mozilla/net/WyciwygChannelParent.h" #include "mozilla/net/FTPChannelParent.h" #include "mozilla/net/WebSocketChannelParent.h" #include "mozilla/net/WebSocketEventListenerParent.h" #include "mozilla/net/DataChannelParent.h" #ifdef NECKO_PROTOCOL_rtsp #include "mozilla/net/RtspControllerParent.h" #include "mozilla/net/RtspChannelParent.h" #endif #include "mozilla/net/DNSRequestParent.h" #include "mozilla/net/RemoteOpenFileParent.h" #include "mozilla/net/ChannelDiverterParent.h" #include "mozilla/dom/ContentParent.h" #include "mozilla/dom/TabContext.h" #include "mozilla/dom/TabParent.h" #include "mozilla/dom/network/TCPSocketParent.h" #include "mozilla/dom/network/TCPServerSocketParent.h" #include "mozilla/dom/network/UDPSocketParent.h" #include "mozilla/ipc/URIUtils.h" #include "mozilla/LoadContext.h" #include "mozilla/AppProcessChecker.h" #include "nsPrintfCString.h" #include "nsHTMLDNSPrefetch.h" #include "nsIAppsService.h" #include "nsEscape.h" #include "RemoteOpenFileParent.h" #include "SerializedLoadContext.h" #include "nsAuthInformationHolder.h" #include "nsIAuthPromptCallback.h" #include "nsPrincipal.h" #include "nsIOService.h" #include "nsINetworkPredictor.h" #include "mozilla/net/OfflineObserver.h" #include "nsISpeculativeConnect.h" using mozilla::DocShellOriginAttributes; using mozilla::NeckoOriginAttributes; using mozilla::dom::ContentParent; using mozilla::dom::TabContext; using mozilla::dom::TabParent; using mozilla::net::PTCPSocketParent; using mozilla::dom::TCPSocketParent; using mozilla::net::PTCPServerSocketParent; using mozilla::dom::TCPServerSocketParent; using mozilla::net::PUDPSocketParent; using mozilla::dom::UDPSocketParent; using IPC::SerializedLoadContext; namespace mozilla { namespace net { PNeckoParent *gNeckoParent = nullptr; // C++ file contents NeckoParent::NeckoParent() { // Init HTTP protocol handler now since we need atomTable up and running very // early (IPDL argument handling for PHttpChannel constructor needs it) so // normal init (during 1st Http channel request) isn't early enough. nsCOMPtr proto = do_GetService("@mozilla.org/network/protocol;1?name=http"); if (UsingNeckoIPCSecurity()) { // cache values for core/packaged apps basepaths nsAutoString corePath, webPath; nsCOMPtr appsService = do_GetService(APPS_SERVICE_CONTRACTID); if (appsService) { appsService->GetCoreAppsBasePath(corePath); appsService->GetWebAppsBasePath(webPath); } // corePath may be empty: we don't use it for all build types MOZ_ASSERT(!webPath.IsEmpty()); LossyCopyUTF16toASCII(corePath, mCoreAppsBasePath); LossyCopyUTF16toASCII(webPath, mWebAppsBasePath); } mObserver = new OfflineObserver(this); gNeckoParent = this; } NeckoParent::~NeckoParent() { if (mObserver) { mObserver->RemoveObserver(); } } static PBOverrideStatus PBOverrideStatusFromLoadContext(const SerializedLoadContext& aSerialized) { if (!aSerialized.IsNotNull() && aSerialized.IsPrivateBitValid()) { return aSerialized.mUsePrivateBrowsing ? kPBOverride_Private : kPBOverride_NotPrivate; } return kPBOverride_Unset; } const char* NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized, PContentParent* aContent, DocShellOriginAttributes& aAttrs) { if (UsingNeckoIPCSecurity()) { if (!aSerialized.IsNotNull()) { return "SerializedLoadContext from child is null"; } } nsTArray contextArray = static_cast(aContent)->GetManagedTabContext(); for (uint32_t i = 0; i < contextArray.Length(); i++) { TabContext tabContext = contextArray[i]; uint32_t appId = tabContext.OwnOrContainingAppId(); bool inBrowserElement = aSerialized.IsNotNull() ? aSerialized.mOriginAttributes.mInBrowser : tabContext.IsBrowserElement(); if (appId == NECKO_UNKNOWN_APP_ID) { continue; } // We may get appID=NO_APP if child frame is neither a browser nor an app if (appId == NECKO_NO_APP_ID) { if (tabContext.HasOwnApp()) { continue; } if (UsingNeckoIPCSecurity() && tabContext.IsBrowserElement()) { //