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
|
|
|
|
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"
|
2012-12-22 05:56:21 -08:00
|
|
|
#include "mozilla/net/RemoteOpenFileParent.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"
|
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"
|
2010-07-26 11:49:09 -07:00
|
|
|
|
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;
|
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);
|
|
|
|
}
|
2009-08-18 12:05:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NeckoParent::~NeckoParent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
|
|
|
|
PBrowserParent* aBrowser,
|
|
|
|
uint32_t* aAppId,
|
|
|
|
bool* aInBrowserElement)
|
|
|
|
{
|
2013-01-24 11:22:00 -08:00
|
|
|
if (UsingNeckoIPCSecurity()) {
|
2012-12-29 01:02:16 -08:00
|
|
|
if (!aBrowser) {
|
|
|
|
return "missing required PBrowser argument";
|
|
|
|
}
|
|
|
|
if (!aSerialized.IsNotNull()) {
|
|
|
|
return "SerializedLoadContext from child is null";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aAppId = NECKO_UNKNOWN_APP_ID;
|
|
|
|
*aInBrowserElement = false;
|
|
|
|
|
|
|
|
if (aBrowser) {
|
|
|
|
nsRefPtr<TabParent> tabParent = static_cast<TabParent*>(aBrowser);
|
|
|
|
|
|
|
|
*aAppId = tabParent->OwnOrContainingAppId();
|
2013-05-20 10:20:19 -07:00
|
|
|
*aInBrowserElement = aSerialized.IsNotNull() ? aSerialized.mIsInBrowserElement
|
|
|
|
: tabParent->IsBrowserElement();
|
2012-12-29 01:02:16 -08:00
|
|
|
|
|
|
|
if (*aAppId == NECKO_UNKNOWN_APP_ID) {
|
|
|
|
return "TabParent reports appId=NECKO_UNKNOWN_APP_ID!";
|
|
|
|
}
|
|
|
|
// We may get appID=NO_APP if child frame is neither a browser nor an app
|
|
|
|
if (*aAppId == NECKO_NO_APP_ID) {
|
|
|
|
if (tabParent->HasOwnApp()) {
|
|
|
|
return "TabParent reports NECKO_NO_APP_ID but also is an app";
|
|
|
|
}
|
2013-01-24 11:22:00 -08:00
|
|
|
if (UsingNeckoIPCSecurity() && tabParent->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)
|
|
|
|
return "TabParent reports appId=NECKO_NO_APP_ID but is a mozbrowser";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Only trust appId/inBrowser from child-side loadcontext if we're in
|
|
|
|
// testing mode: allows xpcshell tests to masquerade as apps
|
2013-01-24 11:22:00 -08:00
|
|
|
MOZ_ASSERT(!UsingNeckoIPCSecurity());
|
|
|
|
if (UsingNeckoIPCSecurity()) {
|
2012-12-29 01:02:16 -08:00
|
|
|
return "internal error";
|
|
|
|
}
|
|
|
|
if (aSerialized.IsNotNull()) {
|
|
|
|
*aAppId = aSerialized.mAppId;
|
|
|
|
*aInBrowserElement = aSerialized.mIsInBrowserElement;
|
|
|
|
} else {
|
|
|
|
*aAppId = NECKO_NO_APP_ID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
NeckoParent::CreateChannelLoadContext(PBrowserParent* aBrowser,
|
|
|
|
const SerializedLoadContext& aSerialized,
|
|
|
|
nsCOMPtr<nsILoadContext> &aResult)
|
|
|
|
{
|
|
|
|
uint32_t appId = NECKO_UNKNOWN_APP_ID;
|
|
|
|
bool inBrowser = false;
|
2013-07-23 16:39:17 -07:00
|
|
|
dom::Element* topFrameElement = nullptr;
|
2012-12-29 01:02:16 -08:00
|
|
|
const char* error = GetValidatedAppInfo(aSerialized, aBrowser, &appId, &inBrowser);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aBrowser) {
|
|
|
|
nsRefPtr<TabParent> tabParent = static_cast<TabParent*>(aBrowser);
|
|
|
|
topFrameElement = tabParent->GetOwnerElement();
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
aResult = new LoadContext(aSerialized, topFrameElement, appId, inBrowser);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-10-09 16:46:24 -07:00
|
|
|
PHttpChannelParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::AllocPHttpChannelParent(PBrowserParent* aBrowser,
|
|
|
|
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;
|
|
|
|
const char *error = CreateChannelLoadContext(aBrowser, aSerialized,
|
|
|
|
loadContext);
|
|
|
|
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,
|
|
|
|
PBrowserParent* aBrowser,
|
|
|
|
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*
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::AllocPFTPChannelParent(PBrowserParent* aBrowser,
|
|
|
|
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;
|
|
|
|
const char *error = CreateChannelLoadContext(aBrowser, aSerialized,
|
|
|
|
loadContext);
|
|
|
|
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,
|
|
|
|
PBrowserParent* aBrowser,
|
|
|
|
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*
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::AllocPWebSocketParent(PBrowserParent* browser,
|
|
|
|
const SerializedLoadContext& serialized)
|
2011-05-04 06:36:23 -07:00
|
|
|
{
|
2012-12-29 01:02:16 -08:00
|
|
|
nsCOMPtr<nsILoadContext> loadContext;
|
|
|
|
const char *error = CreateChannelLoadContext(browser, serialized,
|
|
|
|
loadContext);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-04 06:36:23 -07:00
|
|
|
TabParent* tabParent = static_cast<TabParent*>(browser);
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-24 11:53:49 -07:00
|
|
|
PTCPSocketParent*
|
2013-07-29 10:36:43 -07:00
|
|
|
NeckoParent::AllocPTCPSocketParent()
|
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;
|
|
|
|
}
|
|
|
|
|
2012-12-22 05:56:21 -08:00
|
|
|
PRemoteOpenFileParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
NeckoParent::AllocPRemoteOpenFileParent(const URIParams& aURI,
|
|
|
|
PBrowserParent* aBrowser)
|
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
|
|
|
if (!aBrowser) {
|
2013-01-02 20:15:19 -08:00
|
|
|
printf_stderr("NeckoParent::AllocPRemoteOpenFile: "
|
|
|
|
"FATAL error: missing TabParent: KILLING CHILD PROCESS\n");
|
2012-12-22 05:56:21 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsRefPtr<TabParent> tabParent = static_cast<TabParent*>(aBrowser);
|
|
|
|
uint32_t appId = tabParent->OwnOrContainingAppId();
|
|
|
|
nsCOMPtr<nsIAppsService> appsService =
|
|
|
|
do_GetService(APPS_SERVICE_CONTRACTID);
|
|
|
|
if (!appsService) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsCOMPtr<mozIDOMApplication> domApp;
|
|
|
|
nsresult rv = appsService->GetAppByLocalId(appId, getter_AddRefs(domApp));
|
|
|
|
if (!domApp) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsCOMPtr<mozIApplication> mozApp = do_QueryInterface(domApp);
|
|
|
|
if (!mozApp) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
bool hasManage = false;
|
|
|
|
rv = mozApp->HasPermission("webapps-manage", &hasManage);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString requestedPath;
|
|
|
|
fileURL->GetPath(requestedPath);
|
|
|
|
NS_UnescapeURL(requestedPath);
|
|
|
|
|
|
|
|
if (hasManage) {
|
|
|
|
// 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;
|
|
|
|
rv = mozApp->GetBasePath(basePath);
|
|
|
|
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 "
|
|
|
|
"own application.zip: KILLING CHILD PROCESS\n",
|
|
|
|
requestedPath.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
|
|
|
|
NeckoParent::RecvPRemoteOpenFileConstructor(PRemoteOpenFileParent* aActor,
|
|
|
|
const URIParams& aFileURI,
|
|
|
|
PBrowserParent* aBrowser)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-08-18 12:05:15 -07:00
|
|
|
}} // mozilla::net
|