2009-08-18 12:05:15 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
|
|
|
|
2012-05-21 04:12:37 -07: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/. */
|
2009-08-18 12:05:15 -07:00
|
|
|
|
2013-11-11 14:52:33 -08:00
|
|
|
#include "necko-config.h"
|
Bug 530952: Electrolysis HTTP Channel implementation. author=jduell, r=bsmedberg, sr=bz
- Supports only primitive xpcshell HTTP requests which don't set/get HTTP
headers, don't do redirects, observers, load groups, or anything else other
than basic things like looking at the reply body, Content-type, Content-length, etc.
- Tested with network/test/unit_ipc/test_simple_wrap.js (patch @ bug 521922)
- Only used if "NECKO_E10S_HTTP" set in environment.
- Force http.h to get #included before any IPDL files, to centralize #define
handling of LOG and to make sure FORCE_PR_LOGGING is set if needed (bug
545995)
2009-09-22 11:55:33 -07:00
|
|
|
#include "nsHttp.h"
|
2009-08-18 12:05:15 -07:00
|
|
|
#include "mozilla/net/NeckoParent.h"
|
|
|
|
#include "mozilla/net/HttpChannelParent.h"
|
2010-03-25 16:02:28 -07:00
|
|
|
#include "mozilla/net/CookieServiceParent.h"
|
2010-10-11 04:35:10 -07:00
|
|
|
#include "mozilla/net/WyciwygChannelParent.h"
|
2010-08-10 11:47:00 -07:00
|
|
|
#include "mozilla/net/FTPChannelParent.h"
|
2011-05-04 06:36:23 -07:00
|
|
|
#include "mozilla/net/WebSocketChannelParent.h"
|
2015-03-27 13:12:37 -07:00
|
|
|
#include "mozilla/net/DataChannelParent.h"
|
2013-11-11 14:52:33 -08:00
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
2013-09-23 03:12:11 -07:00
|
|
|
#include "mozilla/net/RtspControllerParent.h"
|
2014-04-03 04:08:34 -07:00
|
|
|
#include "mozilla/net/RtspChannelParent.h"
|
2013-09-23 03:12:11 -07:00
|
|
|
#endif
|
2013-12-11 11:03:51 -08:00
|
|
|
#include "mozilla/net/DNSRequestParent.h"
|
2012-12-22 05:56:21 -08:00
|
|
|
#include "mozilla/net/RemoteOpenFileParent.h"
|
2014-03-10 15:04:28 -07:00
|
|
|
#include "mozilla/net/ChannelDiverterParent.h"
|
2013-08-20 23:49:41 -07:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2014-12-09 08:34:00 -08:00
|
|
|
#include "mozilla/dom/TabContext.h"
|
2011-05-04 06:36:23 -07:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2012-09-24 11:53:49 -07:00
|
|
|
#include "mozilla/dom/network/TCPSocketParent.h"
|
2013-07-29 10:36:43 -07:00
|
|
|
#include "mozilla/dom/network/TCPServerSocketParent.h"
|
2013-05-10 05:00:28 -07:00
|
|
|
#include "mozilla/dom/network/UDPSocketParent.h"
|
2012-12-22 05:56:21 -08:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2012-12-29 01:02:16 -08:00
|
|
|
#include "mozilla/LoadContext.h"
|
2013-02-26 10:57:39 -08:00
|
|
|
#include "mozilla/AppProcessChecker.h"
|
2012-12-29 01:02:16 -08:00
|
|
|
#include "nsPrintfCString.h"
|
2010-07-26 11:49:09 -07:00
|
|
|
#include "nsHTMLDNSPrefetch.h"
|
2012-12-22 05:56:21 -08:00
|
|
|
#include "nsIAppsService.h"
|
|
|
|
#include "nsEscape.h"
|
2013-02-07 05:06:58 -08:00
|
|
|
#include "RemoteOpenFileParent.h"
|
2013-10-18 13:57:55 -07:00
|
|
|
#include "SerializedLoadContext.h"
|
2014-06-10 22:44:36 -07:00
|
|
|
#include "nsAuthInformationHolder.h"
|
|
|
|
#include "nsIAuthPromptCallback.h"
|
2014-08-28 17:20:27 -07:00
|
|
|
#include "nsPrincipal.h"
|
2014-08-22 20:05:56 -07:00
|
|
|
#include "nsIOService.h"
|
|
|
|
#include "mozilla/net/OfflineObserver.h"
|
2015-02-20 14:01:36 -08:00
|
|
|
#include "nsISpeculativeConnect.h"
|
2010-07-26 11:49:09 -07:00
|
|
|
|
2013-08-20 23:49:41 -07:00
|
|
|
using mozilla::dom::ContentParent;
|
2014-12-09 08:34:00 -08:00
|
|
|
using mozilla::dom::TabContext;
|
2011-05-04 06:36:23 -07:00
|
|
|
using mozilla::dom::TabParent;
|
2012-09-24 11:53:49 -07:00
|
|
|
using mozilla::net::PTCPSocketParent;
|
|
|
|
using mozilla::dom::TCPSocketParent;
|
2013-07-29 10:36:43 -07:00
|
|
|
using mozilla::net::PTCPServerSocketParent;
|
|
|
|
using mozilla::dom::TCPServerSocketParent;
|
2013-05-10 05:00:28 -07:00
|
|
|
using mozilla::net::PUDPSocketParent;
|
|
|
|
using mozilla::dom::UDPSocketParent;
|
2012-12-29 01:02:16 -08:00
|
|
|
using IPC::SerializedLoadContext;
|
2011-05-04 06:36:23 -07:00
|
|
|
|
2009-08-18 12:05:15 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
// C++ file contents
|
|
|
|
NeckoParent::NeckoParent()
|
|
|
|
{
|
2013-06-22 09:09:19 -07:00
|
|
|
// 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<nsIProtocolHandler> proto =
|
|
|
|
do_GetService("@mozilla.org/network/protocol;1?name=http");
|
|
|
|
|
2013-01-24 11:22:00 -08:00
|
|
|
if (UsingNeckoIPCSecurity()) {
|
2012-12-22 05:56:21 -08:00
|
|
|
// cache values for core/packaged apps basepaths
|
|
|
|
nsAutoString corePath, webPath;
|
|
|
|
nsCOMPtr<nsIAppsService> 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);
|
|
|
|
}
|
2014-08-22 20:05:56 -07:00
|
|
|
|
|
|
|
mObserver = new OfflineObserver(this);
|
2009-08-18 12:05:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NeckoParent::~NeckoParent()
|
|
|
|
{
|
2014-08-22 20:05:56 -07:00
|
|
|
if (mObserver) {
|
|
|
|
mObserver->RemoveObserver();
|
|
|
|
}
|
2009-08-18 12:05:15 -07:00
|
|
|
}
|
|
|
|
|
2012-12-29 01:02:16 -08:00
|
|
|
static PBOverrideStatus
|
|
|
|
PBOverrideStatusFromLoadContext(const SerializedLoadContext& aSerialized)
|
|
|
|
{
|
|
|
|
if (!aSerialized.IsNotNull() && aSerialized.IsPrivateBitValid()) {
|
|
|
|
return aSerialized.mUsePrivateBrowsing ?
|
|
|
|
kPBOverride_Private :
|
|
|
|
kPBOverride_NotPrivate;
|
|
|
|
}
|
|
|
|
return kPBOverride_Unset;
|
|
|
|
}
|
|
|
|
|
2013-08-20 23:49:41 -07:00
|
|
|
const char*
|
|
|
|
NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
|
|
|
|
PContentParent* aContent,
|
|
|
|
uint32_t* aAppId,
|
|
|
|
bool* aInBrowserElement)
|
|
|
|
{
|
|
|
|
*aAppId = NECKO_UNKNOWN_APP_ID;
|
|
|
|
*aInBrowserElement = false;
|
|
|
|
|
2014-06-27 08:12:03 -07:00
|
|
|
if (UsingNeckoIPCSecurity()) {
|
|
|
|
if (!aSerialized.IsNotNull()) {
|
|
|
|
return "SerializedLoadContext from child is null";
|
2013-08-20 23:49:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-09 08:34:00 -08:00
|
|
|
nsTArray<TabContext> contextArray =
|
|
|
|
static_cast<ContentParent*>(aContent)->GetManagedTabContext();
|
|
|
|
for (uint32_t i = 0; i < contextArray.Length(); i++) {
|
|
|
|
TabContext tabContext = contextArray[i];
|
|
|
|
uint32_t appId = tabContext.OwnOrContainingAppId();
|
2014-06-27 08:12:03 -07:00
|
|
|
bool inBrowserElement = aSerialized.IsNotNull() ? aSerialized.mIsInBrowserElement
|
2014-12-09 08:34:00 -08:00
|
|
|
: tabContext.IsBrowserElement();
|
2012-12-29 01:02:16 -08:00
|
|
|
|
2013-08-20 23:49:44 -07:00
|
|
|
if (appId == NECKO_UNKNOWN_APP_ID) {
|
|
|
|
continue;
|
2012-12-29 01:02:16 -08:00
|
|
|
}
|
|
|
|
// We may get appID=NO_APP if child frame is neither a browser nor an app
|
2013-08-20 23:49:44 -07:00
|
|
|
if (appId == NECKO_NO_APP_ID) {
|
2014-12-09 08:34:00 -08:00
|
|
|
if (tabContext.HasOwnApp()) {
|
2013-08-20 23:49:44 -07:00
|
|
|
continue;
|
2012-12-29 01:02:16 -08:00
|
|
|
}
|
2014-12-09 08:34:00 -08:00
|
|
|
if (UsingNeckoIPCSecurity() && tabContext.IsBrowserElement()) {
|
2012-12-29 01:02:16 -08:00
|
|
|
// <iframe mozbrowser> which doesn't have an <iframe mozapp> above it.
|
|
|
|
// This is not supported now, and we'll need to do a code audit to make
|
|
|
|
// sure we can handle it (i.e don't short-circuit using separate
|
|
|
|
// namespace if just appID==0)
|
2013-08-20 23:49:44 -07:00
|
|
|
continue;
|
2012-12-29 01:02:16 -08:00
|
|
|
}
|
|
|
|
}
|
2014-06-27 08:12:03 -07:00
|
|
|
*aAppId = appId;
|
|
|
|
*aInBrowserElement = inBrowserElement;
|
|
|
|
return nullptr;
|
2013-08-20 23:49:44 -07:00
|
|
|
}
|
|
|
|
|
2014-12-09 08:34:00 -08:00
|
|
|
if (contextArray.Length() != 0) {
|
2013-08-20 23:49:44 -07:00
|
|
|
return "App does not have permission";
|
|
|
|
}
|
|
|
|
|
2014-06-27 08:12:03 -07:00
|
|
|
if (!UsingNeckoIPCSecurity()) {
|
|
|
|
// We are running xpcshell tests
|
|
|
|
if (aSerialized.IsNotNull()) {
|
|
|
|
*aAppId = aSerialized.mAppId;
|
|
|
|
*aInBrowserElement = aSerialized.mIsInBrowserElement;
|
|
|
|
} else {
|
|
|
|
*aAppId = NECKO_NO_APP_ID;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-08-20 23:49:44 -07:00
|
|
|
return "ContentParent does not have any PBrowsers";
|
2012-12-29 01:02:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2014-06-10 22:44:36 -07:00
|
|
|
NeckoParent::CreateChannelLoadContext(const PBrowserOrId& aBrowser,
|
2013-08-20 23:49:44 -07:00
|
|
|
PContentParent* aContent,
|
2012-12-29 01:02:16 -08:00
|
|
|
const SerializedLoadContext& aSerialized,
|
|
|
|
nsCOMPtr<nsILoadContext> &aResult)
|
|
|
|
{
|
|
|
|
uint32_t appId = NECKO_UNKNOWN_APP_ID;
|
|
|
|
bool inBrowser = false;
|
2014-06-27 08:12:03 -07:00
|
|
|
const char* error = GetValidatedAppInfo(aSerialized, aContent, &appId, &inBrowser);
|
2012-12-29 01:02:16 -08:00
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-01-24 11:22:00 -08:00
|
|
|
// if !UsingNeckoIPCSecurity(), we may not have a LoadContext to set. This is
|
2012-12-29 01:02:16 -08:00
|
|
|
// the common case for most xpcshell tests.
|
|
|
|
if (aSerialized.IsNotNull()) {
|
2014-06-10 22:44:36 -07:00
|
|
|
switch (aBrowser.type()) {
|
|
|
|
case PBrowserOrId::TPBrowserParent:
|
|
|
|
{
|
|
|
|
nsRefPtr<TabParent> tabParent =
|
2015-02-05 13:47:32 -08:00
|
|
|
TabParent::GetFrom(aBrowser.get_PBrowserParent());
|
2014-06-10 22:44:36 -07:00
|
|
|
dom::Element* topFrameElement = nullptr;
|
|
|
|
if (tabParent) {
|
|
|
|
topFrameElement = tabParent->GetOwnerElement();
|
|
|
|
}
|
|
|
|
aResult = new LoadContext(aSerialized, topFrameElement,
|
|
|
|
appId, inBrowser);
|
|
|
|
break;
|
|
|
|
}
|
2014-10-23 17:29:00 -07:00
|
|
|
case PBrowserOrId::TTabId:
|
2014-06-10 22:44:36 -07:00
|
|
|
{
|
2014-10-23 17:29:00 -07:00
|
|
|
aResult = new LoadContext(aSerialized, aBrowser.get_TabId(),
|
2014-06-10 22:44:36 -07:00
|
|
|
appId, inBrowser);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2012-12-29 01:02:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-02 11:44:13 -07:00
|
|
|
void
|
|
|
|
NeckoParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
// Implement me! Bug 1005184
|
|
|
|
}
|
|
|
|
|
2012-10-09 16:46:24 -07:00
|
|
|
PHttpChannelParent*
|
2014-06-10 22:44:36 -07:00
|
|
|
NeckoParent::AllocPHttpChannelParent(const PBrowserOrId& aBrowser,
|
2013-07-08 08:48:39 -07:00
|
|
|
const SerializedLoadContext& aSerialized,
|
|
|
|
const HttpChannelCreationArgs& aOpenArgs)
|
2009-08-18 12:05:15 -07:00
|
|
|
{
|
2012-12-29 01:02:16 -08:00
|
|
|
nsCOMPtr<nsILoadContext> loadContext;
|
2013-08-20 23:49:44 -07:00
|
|
|
const char *error = CreateChannelLoadContext(aBrowser, Manager(),
|
|
|
|
aSerialized, loadContext);
|
2012-12-29 01:02:16 -08:00
|
|
|
if (error) {
|
2013-07-08 08:48:39 -07:00
|
|
|
printf_stderr("NeckoParent::AllocPHttpChannelParent: "
|
2013-01-02 20:15:19 -08:00
|
|
|
"FATAL error: %s: KILLING CHILD PROCESS\n",
|
|
|
|
error);
|
2012-12-29 01:02:16 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
PBOverrideStatus overrideStatus = PBOverrideStatusFromLoadContext(aSerialized);
|
|
|
|
HttpChannelParent *p = new HttpChannelParent(aBrowser, loadContext, overrideStatus);
|
Bug 530952: Electrolysis HTTP Channel implementation. author=jduell, r=bsmedberg, sr=bz
- Supports only primitive xpcshell HTTP requests which don't set/get HTTP
headers, don't do redirects, observers, load groups, or anything else other
than basic things like looking at the reply body, Content-type, Content-length, etc.
- Tested with network/test/unit_ipc/test_simple_wrap.js (patch @ bug 521922)
- Only used if "NECKO_E10S_HTTP" set in environment.
- Force http.h to get #included before any IPDL files, to centralize #define
handling of LOG and to make sure FORCE_PR_LOGGING is set if needed (bug
545995)
2009-09-22 11:55:33 -07:00
|
|
|
p->AddRef();
|
|
|
|
return p;
|
2009-08-18 12:05:15 -07:00
|
|
|
}
|
|
|
|
|
2012-10-09 16:46:24 -07:00
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::DeallocPHttpChannelParent(PHttpChannelParent* channel)
|
2009-08-18 12:05:15 -07:00
|
|
|
{
|
Bug 530952: Electrolysis HTTP Channel implementation. author=jduell, r=bsmedberg, sr=bz
- Supports only primitive xpcshell HTTP requests which don't set/get HTTP
headers, don't do redirects, observers, load groups, or anything else other
than basic things like looking at the reply body, Content-type, Content-length, etc.
- Tested with network/test/unit_ipc/test_simple_wrap.js (patch @ bug 521922)
- Only used if "NECKO_E10S_HTTP" set in environment.
- Force http.h to get #included before any IPDL files, to centralize #define
handling of LOG and to make sure FORCE_PR_LOGGING is set if needed (bug
545995)
2009-09-22 11:55:33 -07:00
|
|
|
HttpChannelParent *p = static_cast<HttpChannelParent *>(channel);
|
|
|
|
p->Release();
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-08-18 12:05:15 -07:00
|
|
|
}
|
|
|
|
|
2013-06-22 09:09:19 -07:00
|
|
|
bool
|
|
|
|
NeckoParent::RecvPHttpChannelConstructor(
|
|
|
|
PHttpChannelParent* aActor,
|
2014-06-10 22:44:36 -07:00
|
|
|
const PBrowserOrId& aBrowser,
|
2013-06-22 09:09:19 -07:00
|
|
|
const SerializedLoadContext& aSerialized,
|
|
|
|
const HttpChannelCreationArgs& aOpenArgs)
|
|
|
|
{
|
|
|
|
HttpChannelParent* p = static_cast<HttpChannelParent*>(aActor);
|
|
|
|
return p->Init(aOpenArgs);
|
|
|
|
}
|
|
|
|
|
2010-08-10 11:47:00 -07:00
|
|
|
PFTPChannelParent*
|
2014-06-10 22:44:36 -07:00
|
|
|
NeckoParent::AllocPFTPChannelParent(const PBrowserOrId& aBrowser,
|
2013-07-08 08:48:39 -07:00
|
|
|
const SerializedLoadContext& aSerialized,
|
|
|
|
const FTPChannelCreationArgs& aOpenArgs)
|
2010-08-10 11:47:00 -07:00
|
|
|
{
|
2012-12-29 01:02:16 -08:00
|
|
|
nsCOMPtr<nsILoadContext> loadContext;
|
2013-08-20 23:49:44 -07:00
|
|
|
const char *error = CreateChannelLoadContext(aBrowser, Manager(),
|
|
|
|
aSerialized, loadContext);
|
2012-12-29 01:02:16 -08:00
|
|
|
if (error) {
|
2013-07-08 08:48:39 -07:00
|
|
|
printf_stderr("NeckoParent::AllocPFTPChannelParent: "
|
2013-01-02 20:15:19 -08:00
|
|
|
"FATAL error: %s: KILLING CHILD PROCESS\n",
|
|
|
|
error);
|
2012-12-29 01:02:16 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
PBOverrideStatus overrideStatus = PBOverrideStatusFromLoadContext(aSerialized);
|
|
|
|
FTPChannelParent *p = new FTPChannelParent(loadContext, overrideStatus);
|
2010-08-10 11:47:00 -07:00
|
|
|
p->AddRef();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::DeallocPFTPChannelParent(PFTPChannelParent* channel)
|
2010-08-10 11:47:00 -07:00
|
|
|
{
|
|
|
|
FTPChannelParent *p = static_cast<FTPChannelParent *>(channel);
|
|
|
|
p->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-22 09:09:19 -07:00
|
|
|
bool
|
|
|
|
NeckoParent::RecvPFTPChannelConstructor(
|
|
|
|
PFTPChannelParent* aActor,
|
2014-06-10 22:44:36 -07:00
|
|
|
const PBrowserOrId& aBrowser,
|
2013-06-22 09:09:19 -07:00
|
|
|
const SerializedLoadContext& aSerialized,
|
|
|
|
const FTPChannelCreationArgs& aOpenArgs)
|
|
|
|
{
|
|
|
|
FTPChannelParent* p = static_cast<FTPChannelParent*>(aActor);
|
|
|
|
return p->Init(aOpenArgs);
|
|
|
|
}
|
|
|
|
|
2013-07-08 08:48:39 -07:00
|
|
|
PCookieServiceParent*
|
|
|
|
NeckoParent::AllocPCookieServiceParent()
|
2010-03-25 16:02:28 -07:00
|
|
|
{
|
|
|
|
return new CookieServiceParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::DeallocPCookieServiceParent(PCookieServiceParent* cs)
|
2010-03-25 16:02:28 -07:00
|
|
|
{
|
|
|
|
delete cs;
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-18 12:05:15 -07:00
|
|
|
|
2010-10-11 04:35:10 -07:00
|
|
|
PWyciwygChannelParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::AllocPWyciwygChannelParent()
|
2010-10-11 04:35:10 -07:00
|
|
|
{
|
|
|
|
WyciwygChannelParent *p = new WyciwygChannelParent();
|
|
|
|
p->AddRef();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::DeallocPWyciwygChannelParent(PWyciwygChannelParent* channel)
|
2010-10-11 04:35:10 -07:00
|
|
|
{
|
|
|
|
WyciwygChannelParent *p = static_cast<WyciwygChannelParent *>(channel);
|
|
|
|
p->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-04 06:36:23 -07:00
|
|
|
PWebSocketParent*
|
2014-06-10 22:44:36 -07:00
|
|
|
NeckoParent::AllocPWebSocketParent(const PBrowserOrId& browser,
|
2013-07-08 08:48:39 -07:00
|
|
|
const SerializedLoadContext& serialized)
|
2011-05-04 06:36:23 -07:00
|
|
|
{
|
2012-12-29 01:02:16 -08:00
|
|
|
nsCOMPtr<nsILoadContext> loadContext;
|
2013-08-20 23:49:44 -07:00
|
|
|
const char *error = CreateChannelLoadContext(browser, Manager(),
|
|
|
|
serialized, loadContext);
|
2012-12-29 01:02:16 -08:00
|
|
|
if (error) {
|
2013-07-08 08:48:39 -07:00
|
|
|
printf_stderr("NeckoParent::AllocPWebSocketParent: "
|
2013-01-02 20:15:19 -08:00
|
|
|
"FATAL error: %s: KILLING CHILD PROCESS\n",
|
|
|
|
error);
|
2012-12-29 01:02:16 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-02-05 13:47:32 -08:00
|
|
|
nsRefPtr<TabParent> tabParent = TabParent::GetFrom(browser.get_PBrowserParent());
|
2012-12-29 01:02:16 -08:00
|
|
|
PBOverrideStatus overrideStatus = PBOverrideStatusFromLoadContext(serialized);
|
|
|
|
WebSocketChannelParent* p = new WebSocketChannelParent(tabParent, loadContext,
|
|
|
|
overrideStatus);
|
2011-05-04 06:36:23 -07:00
|
|
|
p->AddRef();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::DeallocPWebSocketParent(PWebSocketParent* actor)
|
2011-05-04 06:36:23 -07:00
|
|
|
{
|
|
|
|
WebSocketChannelParent* p = static_cast<WebSocketChannelParent*>(actor);
|
|
|
|
p->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-27 13:12:37 -07:00
|
|
|
PDataChannelParent*
|
|
|
|
NeckoParent::AllocPDataChannelParent(const uint32_t &channelId)
|
|
|
|
{
|
|
|
|
nsRefPtr<DataChannelParent> p = new DataChannelParent();
|
|
|
|
return p.forget().take();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::DeallocPDataChannelParent(PDataChannelParent* actor)
|
|
|
|
{
|
|
|
|
nsRefPtr<DataChannelParent> p = dont_AddRef(static_cast<DataChannelParent*>(actor));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::RecvPDataChannelConstructor(PDataChannelParent* actor,
|
|
|
|
const uint32_t& channelId)
|
|
|
|
{
|
|
|
|
DataChannelParent* p = static_cast<DataChannelParent*>(actor);
|
|
|
|
p->Init(channelId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-23 03:12:11 -07:00
|
|
|
PRtspControllerParent*
|
|
|
|
NeckoParent::AllocPRtspControllerParent()
|
|
|
|
{
|
2013-11-11 14:52:33 -08:00
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
2013-09-23 03:12:11 -07:00
|
|
|
RtspControllerParent* p = new RtspControllerParent();
|
|
|
|
p->AddRef();
|
|
|
|
return p;
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::DeallocPRtspControllerParent(PRtspControllerParent* actor)
|
|
|
|
{
|
2013-11-11 14:52:33 -08:00
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
2013-09-23 03:12:11 -07:00
|
|
|
RtspControllerParent* p = static_cast<RtspControllerParent*>(actor);
|
|
|
|
p->Release();
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-03 04:08:34 -07:00
|
|
|
PRtspChannelParent*
|
|
|
|
NeckoParent::AllocPRtspChannelParent(const RtspChannelConnectArgs& aArgs)
|
|
|
|
{
|
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
|
|
|
nsCOMPtr<nsIURI> uri = DeserializeURI(aArgs.uri());
|
|
|
|
RtspChannelParent *p = new RtspChannelParent(uri);
|
|
|
|
p->AddRef();
|
|
|
|
return p;
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::RecvPRtspChannelConstructor(
|
|
|
|
PRtspChannelParent* aActor,
|
|
|
|
const RtspChannelConnectArgs& aConnectArgs)
|
|
|
|
{
|
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
|
|
|
RtspChannelParent* p = static_cast<RtspChannelParent*>(aActor);
|
|
|
|
return p->Init(aConnectArgs);
|
|
|
|
#else
|
2014-06-06 12:31:30 -07:00
|
|
|
return false;
|
2014-04-03 04:08:34 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::DeallocPRtspChannelParent(PRtspChannelParent* actor)
|
|
|
|
{
|
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
|
|
|
RtspChannelParent* p = static_cast<RtspChannelParent*>(actor);
|
|
|
|
p->Release();
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-24 11:53:49 -07:00
|
|
|
PTCPSocketParent*
|
2013-12-18 19:21:12 -08:00
|
|
|
NeckoParent::AllocPTCPSocketParent(const nsString& /* host */,
|
|
|
|
const uint16_t& /* port */)
|
2012-09-24 11:53:49 -07:00
|
|
|
{
|
2013-12-18 19:21:12 -08:00
|
|
|
// We actually don't need host/port to construct a TCPSocketParent since
|
|
|
|
// TCPSocketParent will maintain an internal nsIDOMTCPSocket instance which
|
|
|
|
// can be delegated to get the host/port.
|
2012-09-24 11:53:49 -07:00
|
|
|
TCPSocketParent* p = new TCPSocketParent();
|
2013-07-29 10:36:43 -07:00
|
|
|
p->AddIPDLReference();
|
2012-09-24 11:53:49 -07:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-29 10:36:43 -07:00
|
|
|
NeckoParent::DeallocPTCPSocketParent(PTCPSocketParent* actor)
|
2012-09-24 11:53:49 -07:00
|
|
|
{
|
2013-07-29 10:36:43 -07:00
|
|
|
TCPSocketParent* p = static_cast<TCPSocketParent*>(actor);
|
|
|
|
p->ReleaseIPDLReference();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PTCPServerSocketParent*
|
|
|
|
NeckoParent::AllocPTCPServerSocketParent(const uint16_t& aLocalPort,
|
|
|
|
const uint16_t& aBacklog,
|
|
|
|
const nsString& aBinaryType)
|
|
|
|
{
|
|
|
|
TCPServerSocketParent* p = new TCPServerSocketParent();
|
|
|
|
p->AddIPDLReference();
|
|
|
|
return p;
|
2012-09-24 11:53:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-29 10:36:43 -07:00
|
|
|
NeckoParent::RecvPTCPServerSocketConstructor(PTCPServerSocketParent* aActor,
|
|
|
|
const uint16_t& aLocalPort,
|
|
|
|
const uint16_t& aBacklog,
|
|
|
|
const nsString& aBinaryType)
|
2012-09-24 11:53:49 -07:00
|
|
|
{
|
2013-07-29 10:36:43 -07:00
|
|
|
return static_cast<TCPServerSocketParent*>(aActor)->
|
|
|
|
Init(this, aLocalPort, aBacklog, aBinaryType);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::DeallocPTCPServerSocketParent(PTCPServerSocketParent* actor)
|
|
|
|
{
|
|
|
|
TCPServerSocketParent* p = static_cast<TCPServerSocketParent*>(actor);
|
|
|
|
p->ReleaseIPDLReference();
|
2012-09-24 11:53:49 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-10 05:00:28 -07:00
|
|
|
PUDPSocketParent*
|
2015-03-09 13:35:06 -07:00
|
|
|
NeckoParent::AllocPUDPSocketParent(const nsCString& /* unused */)
|
2014-05-06 03:32:25 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<UDPSocketParent> p = new UDPSocketParent();
|
2013-05-10 05:00:28 -07:00
|
|
|
|
2014-05-06 03:32:25 -07:00
|
|
|
return p.forget().take();
|
2013-05-10 05:00:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::RecvPUDPSocketConstructor(PUDPSocketParent* aActor,
|
2013-11-29 08:13:44 -08:00
|
|
|
const nsCString& aFilter)
|
2013-05-10 05:00:28 -07:00
|
|
|
{
|
2015-03-09 13:35:06 -07:00
|
|
|
return static_cast<UDPSocketParent*>(aActor)->Init(aFilter);
|
2013-05-10 05:00:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::DeallocPUDPSocketParent(PUDPSocketParent* actor)
|
|
|
|
{
|
|
|
|
UDPSocketParent* p = static_cast<UDPSocketParent*>(actor);
|
|
|
|
p->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-11 11:03:51 -08:00
|
|
|
PDNSRequestParent*
|
|
|
|
NeckoParent::AllocPDNSRequestParent(const nsCString& aHost,
|
2015-02-18 21:14:00 -08:00
|
|
|
const uint32_t& aFlags,
|
|
|
|
const nsCString& aNetworkInterface)
|
2013-12-11 11:03:51 -08:00
|
|
|
{
|
|
|
|
DNSRequestParent *p = new DNSRequestParent();
|
|
|
|
p->AddRef();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::RecvPDNSRequestConstructor(PDNSRequestParent* aActor,
|
|
|
|
const nsCString& aHost,
|
2015-02-18 21:14:00 -08:00
|
|
|
const uint32_t& aFlags,
|
|
|
|
const nsCString& aNetworkInterface)
|
2013-12-11 11:03:51 -08:00
|
|
|
{
|
2015-02-18 21:14:00 -08:00
|
|
|
static_cast<DNSRequestParent*>(aActor)->DoAsyncResolve(aHost, aFlags,
|
|
|
|
aNetworkInterface);
|
2013-12-11 11:03:51 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::DeallocPDNSRequestParent(PDNSRequestParent* aParent)
|
|
|
|
{
|
|
|
|
DNSRequestParent *p = static_cast<DNSRequestParent*>(aParent);
|
|
|
|
p->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-22 05:56:21 -08:00
|
|
|
PRemoteOpenFileParent*
|
2014-05-30 12:50:51 -07:00
|
|
|
NeckoParent::AllocPRemoteOpenFileParent(const SerializedLoadContext& aSerialized,
|
|
|
|
const URIParams& aURI,
|
2013-09-18 16:55:56 -07:00
|
|
|
const OptionalURIParams& aAppURI)
|
2012-12-22 05:56:21 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
|
|
|
|
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(uri);
|
|
|
|
if (!fileURL) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// security checks
|
2013-01-24 11:22:00 -08:00
|
|
|
if (UsingNeckoIPCSecurity()) {
|
2012-12-22 05:56:21 -08:00
|
|
|
nsCOMPtr<nsIAppsService> appsService =
|
|
|
|
do_GetService(APPS_SERVICE_CONTRACTID);
|
|
|
|
if (!appsService) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-27 08:12:03 -07:00
|
|
|
bool haveValidBrowser = false;
|
2012-12-22 05:56:21 -08:00
|
|
|
bool hasManage = false;
|
2013-08-20 23:49:43 -07:00
|
|
|
nsCOMPtr<mozIApplication> mozApp;
|
2014-12-09 08:34:00 -08:00
|
|
|
nsTArray<TabContext> contextArray =
|
|
|
|
static_cast<ContentParent*>(Manager())->GetManagedTabContext();
|
|
|
|
for (uint32_t i = 0; i < contextArray.Length(); i++) {
|
|
|
|
TabContext tabContext = contextArray[i];
|
|
|
|
uint32_t appId = tabContext.OwnOrContainingAppId();
|
2014-06-27 08:12:03 -07:00
|
|
|
// Note: this enforces that SerializedLoadContext.appID is one of the apps
|
|
|
|
// in the child process, but there's currently no way to verify the
|
|
|
|
// request is not from a different app in that process.
|
|
|
|
if (appId == aSerialized.mAppId) {
|
|
|
|
nsresult rv = appsService->GetAppByLocalId(appId, getter_AddRefs(mozApp));
|
|
|
|
if (NS_FAILED(rv) || !mozApp) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = mozApp->HasPermission("webapps-manage", &hasManage);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
haveValidBrowser = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-06-26 17:06:55 -07:00
|
|
|
}
|
2014-06-27 08:12:03 -07:00
|
|
|
|
|
|
|
if (!haveValidBrowser) {
|
2012-12-22 05:56:21 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString requestedPath;
|
|
|
|
fileURL->GetPath(requestedPath);
|
|
|
|
NS_UnescapeURL(requestedPath);
|
|
|
|
|
2013-09-24 14:21:12 -07:00
|
|
|
// Check if we load the whitelisted app uri for the neterror page.
|
|
|
|
bool netErrorWhiteList = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> appUri = DeserializeURI(aAppURI);
|
|
|
|
if (appUri) {
|
|
|
|
nsAdoptingString netErrorURI;
|
|
|
|
netErrorURI = Preferences::GetString("b2g.neterror.url");
|
|
|
|
if (netErrorURI) {
|
|
|
|
nsAutoCString spec;
|
|
|
|
appUri->GetSpec(spec);
|
|
|
|
netErrorWhiteList = spec.Equals(NS_ConvertUTF16toUTF8(netErrorURI).get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-28 17:20:27 -07:00
|
|
|
// Check if we load a resource from the shared theme url space.
|
|
|
|
// If we try to load the theme but have no permission, refuse to load.
|
|
|
|
bool themeWhitelist = false;
|
|
|
|
if (Preferences::GetBool("dom.mozApps.themable") && appUri) {
|
|
|
|
nsAutoCString origin;
|
|
|
|
nsPrincipal::GetOriginForURI(appUri, getter_Copies(origin));
|
|
|
|
nsAutoCString themeOrigin;
|
|
|
|
themeOrigin = Preferences::GetCString("b2g.theme.origin");
|
|
|
|
themeWhitelist = origin.Equals(themeOrigin);
|
|
|
|
if (themeWhitelist) {
|
|
|
|
bool hasThemePerm = false;
|
|
|
|
mozApp->HasPermission("themeable", &hasThemePerm);
|
|
|
|
if (!hasThemePerm) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasManage || netErrorWhiteList || themeWhitelist) {
|
2012-12-22 05:56:21 -08:00
|
|
|
// webapps-manage permission means allow reading any application.zip file
|
|
|
|
// in either the regular webapps directory, or the core apps directory (if
|
|
|
|
// we're using one).
|
|
|
|
NS_NAMED_LITERAL_CSTRING(appzip, "/application.zip");
|
|
|
|
nsAutoCString pathEnd;
|
|
|
|
requestedPath.Right(pathEnd, appzip.Length());
|
|
|
|
if (!pathEnd.Equals(appzip)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsAutoCString pathStart;
|
|
|
|
requestedPath.Left(pathStart, mWebAppsBasePath.Length());
|
|
|
|
if (!pathStart.Equals(mWebAppsBasePath)) {
|
|
|
|
if (mCoreAppsBasePath.IsEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
requestedPath.Left(pathStart, mCoreAppsBasePath.Length());
|
|
|
|
if (!pathStart.Equals(mCoreAppsBasePath)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Finally: make sure there are no "../" in URI.
|
|
|
|
// Note: not checking for symlinks (would cause I/O for each path
|
|
|
|
// component). So it's up to us to avoid creating symlinks that could
|
|
|
|
// provide attack vectors.
|
|
|
|
if (PL_strnstr(requestedPath.BeginReading(), "/../",
|
|
|
|
requestedPath.Length())) {
|
2013-01-02 20:15:19 -08:00
|
|
|
printf_stderr("NeckoParent::AllocPRemoteOpenFile: "
|
2013-01-08 09:52:29 -08:00
|
|
|
"FATAL error: requested file URI '%s' contains '/../' "
|
|
|
|
"KILLING CHILD PROCESS\n", requestedPath.get());
|
2012-12-22 05:56:21 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// regular packaged apps can only access their own application.zip file
|
|
|
|
nsAutoString basePath;
|
2013-08-20 23:49:43 -07:00
|
|
|
nsresult rv = mozApp->GetBasePath(basePath);
|
2012-12-22 05:56:21 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsAutoString uuid;
|
|
|
|
rv = mozApp->GetId(uuid);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsPrintfCString mustMatch("%s/%s/application.zip",
|
|
|
|
NS_LossyConvertUTF16toASCII(basePath).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(uuid).get());
|
|
|
|
if (!requestedPath.Equals(mustMatch)) {
|
2013-01-02 20:15:19 -08:00
|
|
|
printf_stderr("NeckoParent::AllocPRemoteOpenFile: "
|
2013-01-08 09:52:29 -08:00
|
|
|
"FATAL error: app without webapps-manage permission is "
|
|
|
|
"requesting file '%s' but is only allowed to open its "
|
2013-09-18 16:55:56 -07:00
|
|
|
"own application.zip at %s: KILLING CHILD PROCESS\n",
|
|
|
|
requestedPath.get(), mustMatch.get());
|
2012-12-22 05:56:21 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoteOpenFileParent* parent = new RemoteOpenFileParent(fileURL);
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2013-02-07 05:06:58 -08:00
|
|
|
bool
|
2014-05-30 12:50:51 -07:00
|
|
|
NeckoParent::RecvPRemoteOpenFileConstructor(
|
|
|
|
PRemoteOpenFileParent* aActor,
|
|
|
|
const SerializedLoadContext& aSerialized,
|
|
|
|
const URIParams& aFileURI,
|
|
|
|
const OptionalURIParams& aAppURI)
|
2013-02-07 05:06:58 -08:00
|
|
|
{
|
|
|
|
return static_cast<RemoteOpenFileParent*>(aActor)->OpenSendCloseDelete();
|
|
|
|
}
|
|
|
|
|
2012-12-22 05:56:21 -08:00
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::DeallocPRemoteOpenFileParent(PRemoteOpenFileParent* actor)
|
2012-12-22 05:56:21 -08:00
|
|
|
{
|
|
|
|
delete actor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-20 14:01:36 -08:00
|
|
|
bool
|
|
|
|
NeckoParent::RecvSpeculativeConnect(const URIParams &aURI)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISpeculativeConnect> speculator(gIOService);
|
|
|
|
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
|
|
|
|
if (uri && speculator) {
|
|
|
|
speculator->SpeculativeConnect(uri, nullptr);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-26 11:49:09 -07:00
|
|
|
bool
|
|
|
|
NeckoParent::RecvHTMLDNSPrefetch(const nsString& hostname,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint16_t& flags)
|
2010-07-26 11:49:09 -07:00
|
|
|
{
|
2012-01-20 15:14:46 -08:00
|
|
|
nsHTMLDNSPrefetch::Prefetch(hostname, flags);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::RecvCancelHTMLDNSPrefetch(const nsString& hostname,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint16_t& flags,
|
2012-01-20 15:14:46 -08:00
|
|
|
const nsresult& reason)
|
|
|
|
{
|
|
|
|
nsHTMLDNSPrefetch::CancelPrefetch(hostname, flags, reason);
|
2010-07-26 11:49:09 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-10 15:04:28 -07:00
|
|
|
PChannelDiverterParent*
|
|
|
|
NeckoParent::AllocPChannelDiverterParent(const ChannelDiverterArgs& channel)
|
|
|
|
{
|
|
|
|
return new ChannelDiverterParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::RecvPChannelDiverterConstructor(PChannelDiverterParent* actor,
|
|
|
|
const ChannelDiverterArgs& channel)
|
|
|
|
{
|
|
|
|
auto parent = static_cast<ChannelDiverterParent*>(actor);
|
|
|
|
parent->Init(channel);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::DeallocPChannelDiverterParent(PChannelDiverterParent* parent)
|
|
|
|
{
|
|
|
|
delete static_cast<ChannelDiverterParent*>(parent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:37 -07:00
|
|
|
void
|
|
|
|
NeckoParent::CloneManagees(ProtocolBase* aSource,
|
|
|
|
mozilla::ipc::ProtocolCloneContext* aCtx)
|
|
|
|
{
|
|
|
|
aCtx->SetNeckoParent(this); // For cloning protocols managed by this.
|
|
|
|
PNeckoParent::CloneManagees(aSource, aCtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IProtocol*
|
|
|
|
NeckoParent::CloneProtocol(Channel* aChannel,
|
|
|
|
mozilla::ipc::ProtocolCloneContext* aCtx)
|
|
|
|
{
|
|
|
|
ContentParent* contentParent = aCtx->GetContentParent();
|
|
|
|
nsAutoPtr<PNeckoParent> actor(contentParent->AllocPNeckoParent());
|
|
|
|
if (!actor || !contentParent->RecvPNeckoConstructor(actor)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return actor.forget();
|
|
|
|
}
|
|
|
|
|
2014-06-10 22:44:36 -07:00
|
|
|
namespace {
|
|
|
|
std::map<uint64_t, nsCOMPtr<nsIAuthPromptCallback> >&
|
|
|
|
CallbackMap()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
static std::map<uint64_t, nsCOMPtr<nsIAuthPromptCallback> > sCallbackMap;
|
|
|
|
return sCallbackMap;
|
|
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(NeckoParent::NestedFrameAuthPrompt, nsIAuthPrompt2)
|
|
|
|
|
|
|
|
NeckoParent::NestedFrameAuthPrompt::NestedFrameAuthPrompt(PNeckoParent* aParent,
|
2014-10-23 17:29:00 -07:00
|
|
|
TabId aNestedFrameId)
|
2014-06-10 22:44:36 -07:00
|
|
|
: mNeckoParent(aParent)
|
|
|
|
, mNestedFrameId(aNestedFrameId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NeckoParent::NestedFrameAuthPrompt::AsyncPromptAuth(
|
|
|
|
nsIChannel* aChannel, nsIAuthPromptCallback* callback,
|
|
|
|
nsISupports*, uint32_t,
|
|
|
|
nsIAuthInformation* aInfo, nsICancelable**)
|
|
|
|
{
|
|
|
|
static uint64_t callbackId = 0;
|
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsAutoCString spec;
|
|
|
|
if (uri) {
|
|
|
|
rv = uri->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
nsString realm;
|
|
|
|
rv = aInfo->GetRealm(realm);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
callbackId++;
|
|
|
|
if (mNeckoParent->SendAsyncAuthPromptForNestedFrame(mNestedFrameId,
|
|
|
|
spec,
|
|
|
|
realm,
|
|
|
|
callbackId)) {
|
|
|
|
CallbackMap()[callbackId] = callback;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::RecvOnAuthAvailable(const uint64_t& aCallbackId,
|
|
|
|
const nsString& aUser,
|
|
|
|
const nsString& aPassword,
|
|
|
|
const nsString& aDomain)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAuthPromptCallback> callback = CallbackMap()[aCallbackId];
|
|
|
|
if (!callback) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
CallbackMap().erase(aCallbackId);
|
|
|
|
|
|
|
|
nsRefPtr<nsAuthInformationHolder> holder =
|
|
|
|
new nsAuthInformationHolder(0, EmptyString(), EmptyCString());
|
|
|
|
holder->SetUsername(aUser);
|
|
|
|
holder->SetPassword(aPassword);
|
|
|
|
holder->SetDomain(aDomain);
|
|
|
|
|
|
|
|
callback->OnAuthAvailable(nullptr, holder);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NeckoParent::RecvOnAuthCancelled(const uint64_t& aCallbackId,
|
|
|
|
const bool& aUserCancel)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAuthPromptCallback> callback = CallbackMap()[aCallbackId];
|
|
|
|
if (!callback) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
CallbackMap().erase(aCallbackId);
|
|
|
|
callback->OnAuthCancelled(nullptr, aUserCancel);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-22 20:05:56 -07:00
|
|
|
nsresult
|
|
|
|
NeckoParent::OfflineNotification(nsISupports *aSubject)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAppOfflineInfo> info(do_QueryInterface(aSubject));
|
|
|
|
if (!info) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t targetAppId = NECKO_UNKNOWN_APP_ID;
|
|
|
|
info->GetAppId(&targetAppId);
|
|
|
|
|
2014-12-09 08:34:00 -08:00
|
|
|
nsTArray<TabContext> contextArray =
|
|
|
|
static_cast<ContentParent*>(Manager())->GetManagedTabContext();
|
|
|
|
for (uint32_t i = 0; i < contextArray.Length(); ++i) {
|
|
|
|
TabContext tabContext = contextArray[i];
|
|
|
|
uint32_t appId = tabContext.OwnOrContainingAppId();
|
2014-08-22 20:05:56 -07:00
|
|
|
|
|
|
|
if (appId == targetAppId) {
|
|
|
|
if (gIOService) {
|
|
|
|
bool offline = false;
|
|
|
|
nsresult rv = gIOService->IsAppOffline(appId, &offline);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
printf_stderr("Unexpected - NeckoParent: "
|
|
|
|
"appId not found by isAppOffline(): %u\n", appId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!SendAppOfflineStatus(appId, offline)) {
|
|
|
|
printf_stderr("NeckoParent: "
|
|
|
|
"SendAppOfflineStatus failed for appId: %u\n", appId);
|
|
|
|
}
|
|
|
|
// Once we found the targetAppId, we don't need to continue
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-18 12:05:15 -07:00
|
|
|
}} // mozilla::net
|