michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "necko-config.h" michael@0: #include "nsHttp.h" michael@0: #include "mozilla/net/NeckoParent.h" michael@0: #include "mozilla/net/HttpChannelParent.h" michael@0: #include "mozilla/net/CookieServiceParent.h" michael@0: #include "mozilla/net/WyciwygChannelParent.h" michael@0: #include "mozilla/net/FTPChannelParent.h" michael@0: #include "mozilla/net/WebSocketChannelParent.h" michael@0: #ifdef NECKO_PROTOCOL_rtsp michael@0: #include "mozilla/net/RtspControllerParent.h" michael@0: #include "mozilla/net/RtspChannelParent.h" michael@0: #endif michael@0: #include "mozilla/net/DNSRequestParent.h" michael@0: #include "mozilla/net/RemoteOpenFileParent.h" michael@0: #include "mozilla/net/ChannelDiverterParent.h" michael@0: #include "mozilla/dom/ContentParent.h" michael@0: #include "mozilla/dom/TabParent.h" michael@0: #include "mozilla/dom/network/TCPSocketParent.h" michael@0: #include "mozilla/dom/network/TCPServerSocketParent.h" michael@0: #include "mozilla/dom/network/UDPSocketParent.h" michael@0: #include "mozilla/ipc/URIUtils.h" michael@0: #include "mozilla/LoadContext.h" michael@0: #include "mozilla/AppProcessChecker.h" michael@0: #include "nsPrintfCString.h" michael@0: #include "nsHTMLDNSPrefetch.h" michael@0: #include "nsIAppsService.h" michael@0: #include "nsIUDPSocketFilter.h" michael@0: #include "nsEscape.h" michael@0: #include "RemoteOpenFileParent.h" michael@0: #include "SerializedLoadContext.h" michael@0: michael@0: using mozilla::dom::ContentParent; michael@0: using mozilla::dom::TabParent; michael@0: using mozilla::net::PTCPSocketParent; michael@0: using mozilla::dom::TCPSocketParent; michael@0: using mozilla::net::PTCPServerSocketParent; michael@0: using mozilla::dom::TCPServerSocketParent; michael@0: using mozilla::net::PUDPSocketParent; michael@0: using mozilla::dom::UDPSocketParent; michael@0: using IPC::SerializedLoadContext; michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: // C++ file contents michael@0: NeckoParent::NeckoParent() michael@0: { michael@0: // Init HTTP protocol handler now since we need atomTable up and running very michael@0: // early (IPDL argument handling for PHttpChannel constructor needs it) so michael@0: // normal init (during 1st Http channel request) isn't early enough. michael@0: nsCOMPtr proto = michael@0: do_GetService("@mozilla.org/network/protocol;1?name=http"); michael@0: michael@0: if (UsingNeckoIPCSecurity()) { michael@0: // cache values for core/packaged apps basepaths michael@0: nsAutoString corePath, webPath; michael@0: nsCOMPtr appsService = do_GetService(APPS_SERVICE_CONTRACTID); michael@0: if (appsService) { michael@0: appsService->GetCoreAppsBasePath(corePath); michael@0: appsService->GetWebAppsBasePath(webPath); michael@0: } michael@0: // corePath may be empty: we don't use it for all build types michael@0: MOZ_ASSERT(!webPath.IsEmpty()); michael@0: michael@0: LossyCopyUTF16toASCII(corePath, mCoreAppsBasePath); michael@0: LossyCopyUTF16toASCII(webPath, mWebAppsBasePath); michael@0: } michael@0: } michael@0: michael@0: NeckoParent::~NeckoParent() michael@0: { michael@0: } michael@0: michael@0: static PBOverrideStatus michael@0: PBOverrideStatusFromLoadContext(const SerializedLoadContext& aSerialized) michael@0: { michael@0: if (!aSerialized.IsNotNull() && aSerialized.IsPrivateBitValid()) { michael@0: return aSerialized.mUsePrivateBrowsing ? michael@0: kPBOverride_Private : michael@0: kPBOverride_NotPrivate; michael@0: } michael@0: return kPBOverride_Unset; michael@0: } michael@0: michael@0: const char* michael@0: NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized, michael@0: PContentParent* aContent, michael@0: uint32_t* aAppId, michael@0: bool* aInBrowserElement) michael@0: { michael@0: *aAppId = NECKO_UNKNOWN_APP_ID; michael@0: *aInBrowserElement = false; michael@0: michael@0: if (UsingNeckoIPCSecurity()) { michael@0: if (!aSerialized.IsNotNull()) { michael@0: return "SerializedLoadContext from child is null"; michael@0: } michael@0: } michael@0: michael@0: const InfallibleTArray& browsers = aContent->ManagedPBrowserParent(); michael@0: for (uint32_t i = 0; i < browsers.Length(); i++) { michael@0: nsRefPtr tabParent = static_cast(browsers[i]); michael@0: uint32_t appId = tabParent->OwnOrContainingAppId(); michael@0: bool inBrowserElement = aSerialized.IsNotNull() ? aSerialized.mIsInBrowserElement michael@0: : tabParent->IsBrowserElement(); michael@0: michael@0: if (appId == NECKO_UNKNOWN_APP_ID) { michael@0: continue; michael@0: } michael@0: // We may get appID=NO_APP if child frame is neither a browser nor an app michael@0: if (appId == NECKO_NO_APP_ID) { michael@0: if (tabParent->HasOwnApp()) { michael@0: continue; michael@0: } michael@0: if (UsingNeckoIPCSecurity() && tabParent->IsBrowserElement()) { michael@0: //