2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=4 sw=4 et tw=78: */
|
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/. */
|
2013-10-10 15:22:35 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "jsapi.h"
|
2012-10-10 02:01:26 -07:00
|
|
|
#include "jswrapper.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCRT.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsJSProtocolHandler.h"
|
|
|
|
#include "nsStringStream.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIWindowMediator.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsContentUtils.h"
|
2014-10-16 11:14:52 -07:00
|
|
|
#include "nsNullPrincipal.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsIScriptChannel.h"
|
2007-07-02 16:48:51 -07:00
|
|
|
#include "nsIDocument.h"
|
2014-07-09 23:56:36 -07:00
|
|
|
#include "nsILoadInfo.h"
|
2008-11-18 14:54:36 -08:00
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsIWritablePropertyBag2.h"
|
2010-02-23 13:20:46 -08:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2012-08-20 11:34:32 -07:00
|
|
|
#include "nsSandboxFlags.h"
|
2014-03-07 04:34:31 -08:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2014-07-09 23:56:37 -07:00
|
|
|
#include "nsILoadInfo.h"
|
2008-11-18 14:54:36 -08:00
|
|
|
|
2015-03-06 13:33:00 -08:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
|
|
|
|
2014-03-07 04:34:31 -08:00
|
|
|
using mozilla::dom::AutoEntryScript;
|
2013-02-26 11:04:13 -08:00
|
|
|
|
2008-11-18 14:54:36 -08:00
|
|
|
static NS_DEFINE_CID(kJSURICID, NS_JSURI_CID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsJSThunk : public nsIInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsJSThunk();
|
|
|
|
|
2013-07-18 19:21:20 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_FORWARD_SAFE_NSIINPUTSTREAM(mInnerStream)
|
|
|
|
|
|
|
|
nsresult Init(nsIURI* uri);
|
|
|
|
nsresult EvaluateScript(nsIChannel *aChannel,
|
|
|
|
PopupControlState aPopupState,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aExecutionPolicy,
|
2007-06-10 13:59:37 -07:00
|
|
|
nsPIDOMWindow *aOriginalInnerWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsJSThunk();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> mInnerStream;
|
2009-01-04 16:34:18 -08:00
|
|
|
nsCString mScript;
|
|
|
|
nsCString mURL;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsISupports implementation...
|
|
|
|
//
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsJSThunk, nsIInputStream)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
nsJSThunk::nsJSThunk()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJSThunk::~nsJSThunk()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsJSThunk::Init(nsIURI* uri)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(uri);
|
|
|
|
|
2009-01-04 16:34:18 -08:00
|
|
|
// Get the script string to evaluate...
|
|
|
|
nsresult rv = uri->GetPath(mScript);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Get the url.
|
|
|
|
rv = uri->GetSpec(mURL);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
IsISO88591(const nsString& aString)
|
|
|
|
{
|
|
|
|
for (nsString::const_char_iterator c = aString.BeginReading(),
|
|
|
|
c_end = aString.EndReading();
|
|
|
|
c < c_end; ++c) {
|
|
|
|
if (*c > 255)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
nsIScriptGlobalObject* GetGlobalObject(nsIChannel* aChannel)
|
|
|
|
{
|
|
|
|
// Get the global object owner from the channel
|
2013-05-27 03:07:01 -07:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
NS_QueryNotificationCallbacks(aChannel, docShell);
|
|
|
|
if (!docShell) {
|
|
|
|
NS_WARNING("Unable to get a docShell from the channel!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-27 03:07:01 -07:00
|
|
|
// So far so good: get the script global from its docshell
|
|
|
|
nsIScriptGlobalObject* global = docShell->GetScriptGlobalObject();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(global,
|
|
|
|
"Unable to get an nsIScriptGlobalObject from the "
|
2013-05-27 03:07:01 -07:00
|
|
|
"docShell!");
|
2007-03-22 10:30:00 -07:00
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
|
|
|
|
PopupControlState aPopupState,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aExecutionPolicy,
|
2007-06-10 13:59:37 -07:00
|
|
|
nsPIDOMWindow *aOriginalInnerWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aExecutionPolicy == nsIScriptChannel::NO_EXECUTION) {
|
|
|
|
// Nothing to do here.
|
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
|
|
|
|
|
|
|
// Get principal of code for execution
|
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
aChannel->GetOwner(getter_AddRefs(owner));
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(owner);
|
|
|
|
if (!principal) {
|
2014-07-09 23:56:37 -07:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
if (loadInfo && loadInfo->GetForceInheritPrincipal()) {
|
2014-11-14 08:57:26 -08:00
|
|
|
principal = loadInfo->TriggeringPrincipal();
|
2014-07-09 23:56:37 -07:00
|
|
|
} else {
|
|
|
|
// No execution without a principal!
|
|
|
|
NS_ASSERTION(!owner, "Non-principal owner?");
|
|
|
|
NS_WARNING("No principal to execute JS with");
|
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-23 13:20:46 -08:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// CSP check: javascript: URIs disabled unless "inline" scripts are
|
|
|
|
// allowed.
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
|
|
|
rv = principal->GetCsp(getter_AddRefs(csp));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-01-31 10:09:44 -08:00
|
|
|
if (csp) {
|
2012-10-15 13:54:58 -07:00
|
|
|
bool allowsInline = true;
|
|
|
|
bool reportViolations = false;
|
|
|
|
rv = csp->GetAllowsInlineScript(&reportViolations, &allowsInline);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (reportViolations) {
|
|
|
|
// gather information to log with violation report
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
principal->GetURI(getter_AddRefs(uri));
|
|
|
|
nsAutoCString asciiSpec;
|
|
|
|
uri->GetAsciiSpec(asciiSpec);
|
|
|
|
csp->LogViolationDetails(nsIContentSecurityPolicy::VIOLATION_TYPE_INLINE_SCRIPT,
|
|
|
|
NS_ConvertUTF8toUTF16(asciiSpec),
|
|
|
|
NS_ConvertUTF8toUTF16(mURL),
|
2013-11-08 15:44:39 -08:00
|
|
|
0,
|
2014-01-02 11:14:06 -08:00
|
|
|
EmptyString(),
|
2013-11-08 15:44:39 -08:00
|
|
|
EmptyString());
|
2012-10-15 13:54:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//return early if inline scripts are not allowed
|
|
|
|
if (!allowsInline) {
|
2011-01-31 10:09:44 -08:00
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
2012-10-15 13:54:58 -07:00
|
|
|
}
|
2010-02-23 13:20:46 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Get the global object we should be running on.
|
|
|
|
nsIScriptGlobalObject* global = GetGlobalObject(aChannel);
|
|
|
|
if (!global) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-20 11:34:32 -07:00
|
|
|
// Sandboxed document check: javascript: URI's are disabled
|
|
|
|
// in a sandboxed document unless 'allow-scripts' was specified.
|
|
|
|
nsIDocument* doc = aOriginalInnerWindow->GetExtantDoc();
|
|
|
|
if (doc && (doc->GetSandboxFlags() & SANDBOXED_SCRIPTS)) {
|
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Push our popup control state
|
2013-03-15 21:31:38 -07:00
|
|
|
nsAutoPopupStatePusher popupStatePusher(aPopupState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-10 13:59:37 -07:00
|
|
|
// Make sure we still have the same inner window as we used to.
|
2013-03-15 21:31:38 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(global);
|
2007-06-10 13:59:37 -07:00
|
|
|
nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-10 13:59:37 -07:00
|
|
|
if (innerWin != aOriginalInnerWindow) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> innerGlobal = do_QueryInterface(innerWin);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(global, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// So far so good: get the script context from its owner.
|
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext = global->GetContext();
|
|
|
|
if (!scriptContext)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString script(mScript);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Unescape the script
|
|
|
|
NS_UnescapeURL(script);
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager;
|
|
|
|
securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2014-03-07 04:34:31 -08:00
|
|
|
// New script entry point required, due to the "Create a script" step of
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/#javascript-protocol
|
|
|
|
AutoEntryScript entryScript(innerGlobal, true,
|
|
|
|
scriptContext->GetNativeContext());
|
|
|
|
JSContext* cx = entryScript.cx();
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JSObject*> globalJSObject(cx, innerGlobal->GetGlobalJSObject());
|
2013-11-12 16:43:31 -08:00
|
|
|
NS_ENSURE_TRUE(globalJSObject, NS_ERROR_UNEXPECTED);
|
2013-05-04 00:52:57 -07:00
|
|
|
|
2014-07-03 22:21:57 -07:00
|
|
|
//-- Don't execute unless the script principal subsumes the
|
|
|
|
// principal of the context.
|
|
|
|
nsIPrincipal* objectPrincipal = nsContentUtils::ObjectPrincipal(globalJSObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-03 22:21:57 -07:00
|
|
|
bool subsumes;
|
|
|
|
rv = principal->Subsumes(objectPrincipal, &subsumes);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-03 22:21:57 -07:00
|
|
|
if (!subsumes) {
|
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JS::Value> v (cx, JS::UndefinedValue());
|
2007-03-22 10:30:00 -07:00
|
|
|
// Finally, we have everything needed to evaluate the expression.
|
2014-07-03 22:21:57 -07:00
|
|
|
JS::CompileOptions options(cx);
|
|
|
|
options.setFileAndLine(mURL.get(), 1)
|
|
|
|
.setVersion(JSVERSION_DEFAULT);
|
2014-11-12 14:04:29 -08:00
|
|
|
nsJSUtils::EvaluateOptions evalOptions(cx);
|
2014-07-03 22:21:57 -07:00
|
|
|
evalOptions.setCoerceToString(true);
|
|
|
|
rv = nsJSUtils::EvaluateString(cx, NS_ConvertUTF8toUTF16(script),
|
|
|
|
globalJSObject, options, evalOptions, &v);
|
|
|
|
|
|
|
|
// If there's an error on cx as a result of that call, report
|
|
|
|
// it now -- either we're just running under the event loop,
|
|
|
|
// so we shouldn't propagate JS exceptions out of here, or we
|
|
|
|
// can't be sure that our caller is JS (and if it's not we'll
|
|
|
|
// lose the error), or it might be JS that then proceeds to
|
|
|
|
// cause an error of its own (which will also make us lose
|
|
|
|
// this error).
|
|
|
|
::JS_ReportPendingException(cx);
|
2013-01-21 03:56:28 -08:00
|
|
|
|
2013-01-25 02:17:40 -08:00
|
|
|
if (NS_FAILED(rv) || !(v.isString() || v.isUndefined())) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
} else if (v.isUndefined()) {
|
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
} else {
|
2014-07-05 08:30:54 -07:00
|
|
|
nsAutoJSString result;
|
2013-01-16 18:50:27 -08:00
|
|
|
if (!result.init(cx, v)) {
|
2013-01-16 18:50:26 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
char *bytes;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t bytesLen;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_NAMED_LITERAL_CSTRING(isoCharset, "ISO-8859-1");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(utf8Charset, "UTF-8");
|
|
|
|
const nsCString *charset;
|
|
|
|
if (IsISO88591(result)) {
|
|
|
|
// For compatibility, if the result is ISO-8859-1, we use
|
|
|
|
// ISO-8859-1, so that people can compatibly create images
|
|
|
|
// using javascript: URLs.
|
|
|
|
bytes = ToNewCString(result);
|
|
|
|
bytesLen = result.Length();
|
|
|
|
charset = &isoCharset;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bytes = ToNewUTF8String(result, &bytesLen);
|
|
|
|
charset = &utf8Charset;
|
|
|
|
}
|
|
|
|
aChannel->SetContentCharset(*charset);
|
|
|
|
if (bytes)
|
|
|
|
rv = NS_NewByteInputStream(getter_AddRefs(mInnerStream),
|
|
|
|
bytes, bytesLen,
|
|
|
|
NS_ASSIGNMENT_ADOPT);
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class nsJSChannel : public nsIChannel,
|
|
|
|
public nsIStreamListener,
|
2008-11-18 14:54:36 -08:00
|
|
|
public nsIScriptChannel,
|
|
|
|
public nsIPropertyBag2
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsJSChannel();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUEST
|
|
|
|
NS_DECL_NSICHANNEL
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSISCRIPTCHANNEL
|
2008-11-18 14:54:36 -08:00
|
|
|
NS_FORWARD_SAFE_NSIPROPERTYBAG(mPropertyBag)
|
|
|
|
NS_FORWARD_SAFE_NSIPROPERTYBAG2(mPropertyBag)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult Init(nsIURI *aURI);
|
|
|
|
|
|
|
|
// Actually evaluate the script.
|
|
|
|
void EvaluateScript();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsJSChannel();
|
|
|
|
|
|
|
|
nsresult StopAll();
|
|
|
|
|
|
|
|
void NotifyListener();
|
2007-07-02 16:48:51 -07:00
|
|
|
|
|
|
|
void CleanupStrongRefs();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIChannel> mStreamChannel;
|
2008-11-18 14:54:36 -08:00
|
|
|
nsCOMPtr<nsIPropertyBag2> mPropertyBag;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener; // Our final listener
|
|
|
|
nsCOMPtr<nsISupports> mContext; // The context passed to AsyncOpen
|
2007-06-10 13:59:37 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> mOriginalInnerWindow; // The inner window our load
|
|
|
|
// started against.
|
2007-07-02 16:48:51 -07:00
|
|
|
// If we blocked onload on a document in AsyncOpen, this is the document we
|
|
|
|
// did it on.
|
|
|
|
nsCOMPtr<nsIDocument> mDocumentOnloadBlockedOn;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult mStatus; // Our status
|
|
|
|
|
|
|
|
nsLoadFlags mLoadFlags;
|
|
|
|
nsLoadFlags mActualLoadFlags; // See AsyncOpen
|
|
|
|
|
|
|
|
nsRefPtr<nsJSThunk> mIOThunk;
|
|
|
|
PopupControlState mPopupState;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mExecutionPolicy;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsAsync;
|
|
|
|
bool mIsActive;
|
|
|
|
bool mOpenedStreamChannel;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsJSChannel::nsJSChannel() :
|
|
|
|
mStatus(NS_OK),
|
|
|
|
mLoadFlags(LOAD_NORMAL),
|
|
|
|
mActualLoadFlags(LOAD_NORMAL),
|
|
|
|
mPopupState(openOverridden),
|
2014-07-03 22:21:57 -07:00
|
|
|
mExecutionPolicy(NO_EXECUTION),
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsAsync(true),
|
|
|
|
mIsActive(false),
|
|
|
|
mOpenedStreamChannel(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJSChannel::~nsJSChannel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsJSChannel::StopAll()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_UNEXPECTED;
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav;
|
|
|
|
NS_QueryNotificationCallbacks(mStreamChannel, webNav);
|
|
|
|
|
|
|
|
NS_ASSERTION(webNav, "Can't get nsIWebNavigation from channel!");
|
|
|
|
if (webNav) {
|
|
|
|
rv = webNav->Stop(nsIWebNavigation::STOP_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsJSChannel::Init(nsIURI *aURI)
|
|
|
|
{
|
2008-11-18 14:54:36 -08:00
|
|
|
nsRefPtr<nsJSURI> jsURI;
|
|
|
|
nsresult rv = aURI->QueryInterface(kJSURICID,
|
|
|
|
getter_AddRefs(jsURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Create the nsIStreamIO layer used by the nsIStreamIOChannel.
|
|
|
|
mIOThunk = new nsJSThunk();
|
|
|
|
if (!mIOThunk)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// Create a stock input stream channel...
|
|
|
|
// Remember, until AsyncOpen is called, the script will not be evaluated
|
|
|
|
// and the underlying Input Stream will not be created...
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
|
2014-10-16 11:14:52 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> nullPrincipal =
|
|
|
|
do_CreateInstance("@mozilla.org/nullprincipal;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the resultant script evaluation actually does return a value, we
|
|
|
|
// treat it as html.
|
2014-10-16 11:14:52 -07:00
|
|
|
rv = NS_NewInputStreamChannel(getter_AddRefs(channel),
|
|
|
|
aURI,
|
|
|
|
mIOThunk,
|
|
|
|
nullPrincipal,
|
|
|
|
nsILoadInfo::SEC_NORMAL,
|
|
|
|
nsIContentPolicy::TYPE_OTHER,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_LITERAL_CSTRING("text/html"));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mIOThunk->Init(aURI);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mStreamChannel = channel;
|
2008-11-18 14:54:36 -08:00
|
|
|
mPropertyBag = do_QueryInterface(channel);
|
|
|
|
nsCOMPtr<nsIWritablePropertyBag2> writableBag =
|
|
|
|
do_QueryInterface(channel);
|
|
|
|
if (writableBag && jsURI->GetBaseURI()) {
|
|
|
|
writableBag->SetPropertyAsInterface(NS_LITERAL_STRING("baseURI"),
|
|
|
|
jsURI->GetBaseURI());
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsISupports implementation...
|
|
|
|
//
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsJSChannel, nsIChannel, nsIRequest, nsIRequestObserver,
|
|
|
|
nsIStreamListener, nsIScriptChannel, nsIPropertyBag,
|
|
|
|
nsIPropertyBag2)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsIRequest implementation...
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetName(nsACString &aResult)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetName(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsJSChannel::IsPending(bool *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aResult = mIsActive;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetStatus(nsresult *aResult)
|
|
|
|
{
|
2007-07-24 17:08:58 -07:00
|
|
|
if (NS_SUCCEEDED(mStatus) && mOpenedStreamChannel) {
|
|
|
|
return mStreamChannel->GetStatus(aResult);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*aResult = mStatus;
|
2007-07-24 17:08:58 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::Cancel(nsresult aStatus)
|
|
|
|
{
|
|
|
|
mStatus = aStatus;
|
|
|
|
|
|
|
|
if (mOpenedStreamChannel) {
|
|
|
|
mStreamChannel->Cancel(aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::Suspend()
|
|
|
|
{
|
|
|
|
return mStreamChannel->Suspend();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::Resume()
|
|
|
|
{
|
|
|
|
return mStreamChannel->Resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsIChannel implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetOriginalURI(nsIURI * *aURI)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetOriginalURI(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetOriginalURI(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetOriginalURI(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetURI(nsIURI * *aURI)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetURI(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::Open(nsIInputStream **aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = mIOThunk->EvaluateScript(mStreamChannel, mPopupState,
|
2007-06-10 13:59:37 -07:00
|
|
|
mExecutionPolicy,
|
|
|
|
mOriginalInnerWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return mStreamChannel->Open(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aListener);
|
2007-06-10 13:59:37 -07:00
|
|
|
|
|
|
|
// First make sure that we have a usable inner window; we'll want to make
|
|
|
|
// sure that we execute against that inner and no other.
|
|
|
|
nsIScriptGlobalObject* global = GetGlobalObject(this);
|
|
|
|
if (!global) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(global));
|
|
|
|
NS_ASSERTION(win, "Our global is not a window??");
|
|
|
|
|
|
|
|
// Make sure we create a new inner window if one doesn't already exist (see
|
|
|
|
// bug 306630).
|
|
|
|
mOriginalInnerWindow = win->EnsureInnerWindow();
|
|
|
|
if (!mOriginalInnerWindow) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mListener = aListener;
|
|
|
|
mContext = aContext;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsActive = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Temporarily set the LOAD_BACKGROUND flag to suppress load group observer
|
|
|
|
// notifications (and hence nsIWebProgressListener notifications) from
|
|
|
|
// being dispatched. This is required since we suppress LOAD_DOCUMENT_URI,
|
|
|
|
// which means that the DocLoader would not generate document start and
|
|
|
|
// stop notifications (see bug 257875).
|
|
|
|
mActualLoadFlags = mLoadFlags;
|
|
|
|
mLoadFlags |= LOAD_BACKGROUND;
|
|
|
|
|
|
|
|
// Add the javascript channel to its loadgroup so that we know if
|
|
|
|
// network loads were canceled or not...
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (loadGroup) {
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = loadGroup->AddRequest(this, nullptr);
|
2007-07-24 17:08:58 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsActive = false;
|
2007-07-24 17:08:58 -07:00
|
|
|
CleanupStrongRefs();
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-04-23 21:22:37 -07:00
|
|
|
mDocumentOnloadBlockedOn = mOriginalInnerWindow->GetExtantDoc();
|
2007-07-02 16:48:51 -07:00
|
|
|
if (mDocumentOnloadBlockedOn) {
|
|
|
|
// If we're a document channel, we need to actually block onload on our
|
|
|
|
// _parent_ document. This is because we don't actually set our
|
2007-07-03 12:39:51 -07:00
|
|
|
// LOAD_DOCUMENT_URI flag, so a docloader we're loading in as the
|
2007-07-02 16:48:51 -07:00
|
|
|
// document channel will claim to not be busy, and our parent's onload
|
|
|
|
// could fire too early.
|
|
|
|
nsLoadFlags loadFlags;
|
|
|
|
mStreamChannel->GetLoadFlags(&loadFlags);
|
|
|
|
if (loadFlags & LOAD_DOCUMENT_URI) {
|
|
|
|
mDocumentOnloadBlockedOn =
|
|
|
|
mDocumentOnloadBlockedOn->GetParentDocument();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mDocumentOnloadBlockedOn) {
|
|
|
|
mDocumentOnloadBlockedOn->BlockOnload();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-13 15:42:07 -07:00
|
|
|
mPopupState = win->GetPopupControlState();
|
|
|
|
|
2010-04-20 16:21:35 -07:00
|
|
|
void (nsJSChannel::*method)();
|
2007-06-13 15:42:07 -07:00
|
|
|
if (mIsAsync) {
|
|
|
|
// post an event to do the rest
|
|
|
|
method = &nsJSChannel::EvaluateScript;
|
2013-04-23 21:22:37 -07:00
|
|
|
} else {
|
2007-06-13 15:42:07 -07:00
|
|
|
EvaluateScript();
|
|
|
|
if (mOpenedStreamChannel) {
|
|
|
|
// That will handle notifying things
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_FAILED(mStatus), "We should have failed _somehow_");
|
|
|
|
|
|
|
|
// mStatus is going to be NS_ERROR_DOM_RETVAL_UNDEFINED if we didn't
|
|
|
|
// have any content resulting from the execution and NS_BINDING_ABORTED
|
|
|
|
// if something we did causes our own load to be stopped. Return
|
|
|
|
// success in those cases, and error out in all others.
|
|
|
|
if (mStatus != NS_ERROR_DOM_RETVAL_UNDEFINED &&
|
|
|
|
mStatus != NS_BINDING_ABORTED) {
|
|
|
|
// Note that calling EvaluateScript() handled removing us from the
|
|
|
|
// loadgroup and marking us as not active anymore.
|
2007-07-02 16:48:51 -07:00
|
|
|
CleanupStrongRefs();
|
2007-06-13 15:42:07 -07:00
|
|
|
return mStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're returning success from asyncOpen(), but we didn't open a
|
|
|
|
// stream channel. We'll have to notify ourselves, but make sure to do
|
|
|
|
// it asynchronously.
|
|
|
|
method = &nsJSChannel::NotifyListener;
|
|
|
|
}
|
|
|
|
|
2010-04-20 16:21:35 -07:00
|
|
|
nsCOMPtr<nsIRunnable> ev = NS_NewRunnableMethod(this, method);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_DispatchToCurrentThread(ev);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
loadGroup->RemoveRequest(this, nullptr, rv);
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsActive = false;
|
2007-07-02 16:48:51 -07:00
|
|
|
CleanupStrongRefs();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJSChannel::EvaluateScript()
|
|
|
|
{
|
|
|
|
// Synchronously execute the script...
|
|
|
|
// mIsActive is used to indicate the the request is 'busy' during the
|
|
|
|
// the script evaluation phase. This means that IsPending() will
|
|
|
|
// indicate the the request is busy while the script is executing...
|
|
|
|
|
|
|
|
// Note that we want to be in the loadgroup and pending while we evaluate
|
|
|
|
// the script, so that we find out if the loadgroup gets canceled by the
|
|
|
|
// script execution (in which case we shouldn't pump out data even if the
|
|
|
|
// script returns it).
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mStatus)) {
|
|
|
|
nsresult rv = mIOThunk->EvaluateScript(mStreamChannel, mPopupState,
|
2007-06-10 13:59:37 -07:00
|
|
|
mExecutionPolicy,
|
|
|
|
mOriginalInnerWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Note that evaluation may have canceled us, so recheck mStatus again
|
|
|
|
if (NS_FAILED(rv) && NS_SUCCEEDED(mStatus)) {
|
|
|
|
mStatus = rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the javascript channel from its loadgroup...
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (loadGroup) {
|
2012-07-30 07:20:58 -07:00
|
|
|
loadGroup->RemoveRequest(this, nullptr, mStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset load flags to their original value...
|
|
|
|
mLoadFlags = mActualLoadFlags;
|
|
|
|
|
|
|
|
// We're no longer active, it's now up to the stream channel to do
|
|
|
|
// the loading, if needed.
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsActive = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(mStatus)) {
|
2007-06-13 15:42:07 -07:00
|
|
|
if (mIsAsync) {
|
|
|
|
NotifyListener();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// EvaluateScript() succeeded, and we were not canceled, that
|
|
|
|
// means there's data to parse as a result of evaluating the
|
|
|
|
// script.
|
|
|
|
|
|
|
|
// Get the stream channels load flags (!= mLoadFlags).
|
|
|
|
nsLoadFlags loadFlags;
|
|
|
|
mStreamChannel->GetLoadFlags(&loadFlags);
|
|
|
|
|
2012-12-07 17:35:17 -08:00
|
|
|
uint32_t disposition;
|
|
|
|
if (NS_FAILED(mStreamChannel->GetContentDisposition(&disposition)))
|
|
|
|
disposition = nsIChannel::DISPOSITION_INLINE;
|
|
|
|
if (loadFlags & LOAD_DOCUMENT_URI && disposition != nsIChannel::DISPOSITION_ATTACHMENT) {
|
|
|
|
// We're loaded as the document channel and not expecting to download
|
|
|
|
// the result. If we go on, we'll blow away the current document. Make
|
|
|
|
// sure that's ok. If so, stop all pending network loads.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
NS_QueryNotificationCallbacks(mStreamChannel, docShell);
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
|
|
|
|
if (cv) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool okToUnload;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
if (NS_SUCCEEDED(cv->PermitUnload(false, &okToUnload)) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
!okToUnload) {
|
|
|
|
// The user didn't want to unload the current
|
|
|
|
// page, translate this into an undefined
|
|
|
|
// return from the javascript: URL...
|
|
|
|
mStatus = NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mStatus)) {
|
|
|
|
mStatus = StopAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(mStatus)) {
|
2007-06-13 15:42:07 -07:00
|
|
|
if (mIsAsync) {
|
|
|
|
NotifyListener();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mStatus = mStreamChannel->AsyncOpen(this, mContext);
|
2007-06-13 15:42:07 -07:00
|
|
|
if (NS_SUCCEEDED(mStatus)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// mStreamChannel will call OnStartRequest and OnStopRequest on
|
|
|
|
// us, so we'll be sure to call them on our listener.
|
2011-10-17 07:59:28 -07:00
|
|
|
mOpenedStreamChannel = true;
|
2007-07-24 17:08:58 -07:00
|
|
|
|
|
|
|
// Now readd ourselves to the loadgroup so we can receive
|
|
|
|
// cancellation notifications.
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsActive = true;
|
2007-07-24 17:08:58 -07:00
|
|
|
if (loadGroup) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mStatus = loadGroup->AddRequest(this, nullptr);
|
2007-07-24 17:08:58 -07:00
|
|
|
|
|
|
|
// If AddRequest failed, that's OK. The key is to make sure we get
|
|
|
|
// cancelled if needed, and that call just canceled us if it
|
|
|
|
// failed. We'll still get notified by the stream channel when it
|
|
|
|
// finishes.
|
|
|
|
}
|
|
|
|
|
2007-06-13 15:42:07 -07:00
|
|
|
} else if (mIsAsync) {
|
|
|
|
NotifyListener();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJSChannel::NotifyListener()
|
|
|
|
{
|
2007-07-02 16:48:51 -07:00
|
|
|
mListener->OnStartRequest(this, mContext);
|
|
|
|
mListener->OnStopRequest(this, mContext, mStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-02 16:48:51 -07:00
|
|
|
CleanupStrongRefs();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-02 16:48:51 -07:00
|
|
|
void
|
|
|
|
nsJSChannel::CleanupStrongRefs()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mListener = nullptr;
|
|
|
|
mContext = nullptr;
|
|
|
|
mOriginalInnerWindow = nullptr;
|
2007-07-02 16:48:51 -07:00
|
|
|
if (mDocumentOnloadBlockedOn) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mDocumentOnloadBlockedOn->UnblockOnload(false);
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocumentOnloadBlockedOn = nullptr;
|
2007-07-02 16:48:51 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
|
|
|
{
|
|
|
|
*aLoadFlags = mLoadFlags;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
|
|
|
|
{
|
2008-09-29 13:42:19 -07:00
|
|
|
// Figure out whether the LOAD_BACKGROUND bit in aLoadFlags is
|
|
|
|
// actually right.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool bogusLoadBackground = false;
|
2008-09-29 13:42:19 -07:00
|
|
|
if (mIsActive && !(mActualLoadFlags & LOAD_BACKGROUND) &&
|
|
|
|
(aLoadFlags & LOAD_BACKGROUND)) {
|
|
|
|
// We're getting a LOAD_BACKGROUND, but it's probably just our own fake
|
|
|
|
// flag being mirrored to us. The one exception is if our loadgroup is
|
|
|
|
// LOAD_BACKGROUND.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool loadGroupIsBackground = false;
|
2008-09-29 13:42:19 -07:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (loadGroup) {
|
|
|
|
nsLoadFlags loadGroupFlags;
|
|
|
|
loadGroup->GetLoadFlags(&loadGroupFlags);
|
|
|
|
loadGroupIsBackground = ((loadGroupFlags & LOAD_BACKGROUND) != 0);
|
|
|
|
}
|
|
|
|
bogusLoadBackground = !loadGroupIsBackground;
|
|
|
|
}
|
2011-01-04 08:40:54 -08:00
|
|
|
|
|
|
|
// Classifying a javascript: URI doesn't help us, and requires
|
|
|
|
// NSS to boot, which we don't have in content processes. See
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=617838.
|
|
|
|
aLoadFlags &= ~LOAD_CLASSIFY_URI;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Since the javascript channel is never the actual channel that
|
|
|
|
// any data is loaded through, don't ever set the
|
|
|
|
// LOAD_DOCUMENT_URI flag on it, since that could lead to two
|
|
|
|
// 'document channels' in the loadgroup if a javascript: URL is
|
|
|
|
// loaded while a document is being loaded in the same window.
|
|
|
|
|
|
|
|
// XXXbz this, and a whole lot of other hackery, could go away if we'd just
|
|
|
|
// cancel the current document load on javascript: load start like IE does.
|
|
|
|
|
|
|
|
mLoadFlags = aLoadFlags & ~LOAD_DOCUMENT_URI;
|
|
|
|
|
2008-09-29 13:42:19 -07:00
|
|
|
if (bogusLoadBackground) {
|
|
|
|
aLoadFlags = aLoadFlags & ~LOAD_BACKGROUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
mActualLoadFlags = aLoadFlags;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// ... but the underlying stream channel should get this bit, if
|
|
|
|
// set, since that'll be the real document channel if the
|
|
|
|
// javascript: URL generated data.
|
|
|
|
|
|
|
|
return mStreamChannel->SetLoadFlags(aLoadFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetLoadGroup(aLoadGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
2007-12-03 13:57:17 -08:00
|
|
|
if (aLoadGroup) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool streamPending;
|
2007-12-03 13:57:17 -08:00
|
|
|
nsresult rv = mStreamChannel->IsPending(&streamPending);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (streamPending) {
|
|
|
|
nsCOMPtr<nsILoadGroup> curLoadGroup;
|
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(curLoadGroup));
|
|
|
|
|
|
|
|
if (aLoadGroup != curLoadGroup) {
|
|
|
|
// Move the stream channel to our new loadgroup. Make sure to
|
|
|
|
// add it before removing it, so that we don't trigger onload
|
|
|
|
// by accident.
|
2012-07-30 07:20:58 -07:00
|
|
|
aLoadGroup->AddRequest(mStreamChannel, nullptr);
|
2007-12-03 13:57:17 -08:00
|
|
|
if (curLoadGroup) {
|
2012-07-30 07:20:58 -07:00
|
|
|
curLoadGroup->RemoveRequest(mStreamChannel, nullptr,
|
2007-12-03 13:57:17 -08:00
|
|
|
NS_BINDING_RETARGETED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return mStreamChannel->SetLoadGroup(aLoadGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetOwner(nsISupports* *aOwner)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetOwner(aOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetOwner(nsISupports* aOwner)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetOwner(aOwner);
|
|
|
|
}
|
|
|
|
|
2014-07-09 23:56:36 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetLoadInfo(nsILoadInfo* *aLoadInfo)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetLoadInfo(aLoadInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetLoadInfo(nsILoadInfo* aLoadInfo)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetLoadInfo(aLoadInfo);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aCallbacks)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetNotificationCallbacks(aCallbacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aCallbacks)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetNotificationCallbacks(aCallbacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetSecurityInfo(aSecurityInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetContentType(nsACString &aContentType)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentType(aContentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetContentType(const nsACString &aContentType)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentType(aContentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetContentCharset(nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentCharset(aContentCharset);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetContentCharset(const nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentCharset(aContentCharset);
|
|
|
|
}
|
|
|
|
|
2011-09-09 15:41:04 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsJSChannel::GetContentDisposition(uint32_t *aContentDisposition)
|
2011-09-09 15:41:04 -07:00
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentDisposition(aContentDisposition);
|
|
|
|
}
|
|
|
|
|
2012-10-02 09:43:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetContentDisposition(uint32_t aContentDisposition)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentDisposition(aContentDisposition);
|
|
|
|
}
|
|
|
|
|
2011-09-09 15:41:04 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentDispositionFilename(aContentDispositionFilename);
|
|
|
|
}
|
|
|
|
|
2012-10-02 09:43:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetContentDispositionFilename(const nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentDispositionFilename(aContentDispositionFilename);
|
|
|
|
}
|
|
|
|
|
2011-09-09 15:41:04 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentDispositionHeader(aContentDispositionHeader);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-10-22 10:51:07 -07:00
|
|
|
nsJSChannel::GetContentLength(int64_t *aContentLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentLength(aContentLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-22 10:51:07 -07:00
|
|
|
nsJSChannel::SetContentLength(int64_t aContentLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentLength(aContentLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::OnStartRequest(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aRequest == mStreamChannel, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
return mListener->OnStartRequest(this, aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::OnDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInputStream,
|
2012-09-05 19:41:02 -07:00
|
|
|
uint64_t aOffset,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aRequest == mStreamChannel, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
return mListener->OnDataAvailable(this, aContext, aInputStream, aOffset,
|
|
|
|
aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::OnStopRequest(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aRequest == mStreamChannel, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2007-07-02 16:48:51 -07:00
|
|
|
nsCOMPtr<nsIStreamListener> listener = mListener;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-02 16:48:51 -07:00
|
|
|
CleanupStrongRefs();
|
2007-07-24 17:08:58 -07:00
|
|
|
|
|
|
|
// Make sure aStatus matches what GetStatus() returns
|
|
|
|
if (NS_FAILED(mStatus)) {
|
|
|
|
aStatus = mStatus;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-24 17:08:58 -07:00
|
|
|
nsresult rv = listener->OnStopRequest(this, aContext, aStatus);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (loadGroup) {
|
2012-07-30 07:20:58 -07:00
|
|
|
loadGroup->RemoveRequest(this, nullptr, mStatus);
|
2007-07-24 17:08:58 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsActive = false;
|
2007-07-24 17:08:58 -07:00
|
|
|
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsJSChannel::SetExecutionPolicy(uint32_t aPolicy)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aPolicy <= EXECUTE_NORMAL);
|
|
|
|
|
|
|
|
mExecutionPolicy = aPolicy;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsJSChannel::GetExecutionPolicy(uint32_t* aPolicy)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aPolicy = mExecutionPolicy;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-13 15:42:07 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsJSChannel::SetExecuteAsync(bool aIsAsync)
|
2007-06-13 15:42:07 -07:00
|
|
|
{
|
|
|
|
if (!mIsActive) {
|
|
|
|
mIsAsync = aIsAsync;
|
|
|
|
}
|
|
|
|
// else ignore this call
|
|
|
|
NS_WARN_IF_FALSE(!mIsActive, "Calling SetExecuteAsync on active channel?");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsJSChannel::GetExecuteAsync(bool* aIsAsync)
|
2007-06-13 15:42:07 -07:00
|
|
|
{
|
|
|
|
*aIsAsync = mIsAsync;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsJSProtocolHandler::nsJSProtocolHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsJSProtocolHandler::Init()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJSProtocolHandler::~nsJSProtocolHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsJSProtocolHandler, nsIProtocolHandler)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsJSProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|
|
|
{
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
nsJSProtocolHandler* ph = new nsJSProtocolHandler();
|
|
|
|
if (!ph)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(ph);
|
|
|
|
nsresult rv = ph->Init();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = ph->QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
NS_RELEASE(ph);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsJSProtocolHandler::EnsureUTF8Spec(const nsAFlatCString &aSpec, const char *aCharset,
|
|
|
|
nsACString &aUTF8Spec)
|
|
|
|
{
|
|
|
|
aUTF8Spec.Truncate();
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (!mTextToSubURI) {
|
|
|
|
mTextToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
nsAutoString uStr;
|
|
|
|
rv = mTextToSubURI->UnEscapeNonAsciiURI(nsDependentCString(aCharset), aSpec, uStr);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!IsASCII(uStr))
|
|
|
|
NS_EscapeURL(NS_ConvertUTF16toUTF8(uStr), esc_AlwaysCopy | esc_OnlyNonASCII, aUTF8Spec);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIProtocolHandler methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSProtocolHandler::GetScheme(nsACString &result)
|
|
|
|
{
|
|
|
|
result = "javascript";
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsJSProtocolHandler::GetDefaultPort(int32_t *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*result = -1; // no port for javascript: URLs
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsJSProtocolHandler::GetProtocolFlags(uint32_t *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*result = URI_NORELATIVE | URI_NOAUTH | URI_INHERITS_SECURITY_CONTEXT |
|
2009-01-15 12:07:53 -08:00
|
|
|
URI_LOADABLE_BY_ANYONE | URI_NON_PERSISTABLE | URI_OPENING_EXECUTES_SCRIPT;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSProtocolHandler::NewURI(const nsACString &aSpec,
|
2008-11-18 14:54:36 -08:00
|
|
|
const char *aCharset,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIURI *aBaseURI,
|
|
|
|
nsIURI **result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// javascript: URLs (currently) have no additional structure beyond that
|
|
|
|
// provided by standard URLs, so there is no "outer" object given to
|
|
|
|
// CreateInstance.
|
|
|
|
|
2011-05-25 13:23:07 -07:00
|
|
|
nsCOMPtr<nsIURI> url = new nsJSURI(aBaseURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!aCharset || !nsCRT::strcasecmp("UTF-8", aCharset))
|
|
|
|
rv = url->SetSpec(aSpec);
|
|
|
|
else {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString utf8Spec;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = EnsureUTF8Spec(PromiseFlatCString(aSpec), aCharset, utf8Spec);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (utf8Spec.IsEmpty())
|
|
|
|
rv = url->SetSpec(aSpec);
|
|
|
|
else
|
|
|
|
rv = url->SetSpec(utf8Spec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-05-25 13:23:07 -07:00
|
|
|
url.forget(result);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-22 17:16:57 -07:00
|
|
|
nsJSProtocolHandler::NewChannel2(nsIURI* uri,
|
|
|
|
nsILoadInfo* aLoadInfo,
|
|
|
|
nsIChannel** result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsJSChannel * channel;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(uri);
|
|
|
|
|
|
|
|
channel = new nsJSChannel();
|
|
|
|
if (!channel) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(channel);
|
|
|
|
|
|
|
|
rv = channel->Init(uri);
|
2014-12-12 09:06:09 -08:00
|
|
|
|
|
|
|
// set the loadInfo on the new channel
|
|
|
|
rv = channel->SetLoadInfo(aLoadInfo);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*result = channel;
|
|
|
|
NS_ADDREF(*result);
|
|
|
|
}
|
|
|
|
NS_RELEASE(channel);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-10-22 17:16:57 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
|
|
|
|
{
|
|
|
|
return NewChannel2(uri, nullptr, result);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsJSProtocolHandler::AllowPort(int32_t port, const char *scheme, bool *_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// don't override anything.
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-11-18 14:54:36 -08:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// nsJSURI implementation
|
2011-05-25 13:23:07 -07:00
|
|
|
static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
|
|
|
|
NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
|
2008-11-18 14:54:36 -08:00
|
|
|
|
2011-05-25 13:23:07 -07:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsJSURI, nsSimpleURI)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsJSURI, nsSimpleURI)
|
2008-11-18 14:54:36 -08:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsJSURI)
|
|
|
|
if (aIID.Equals(kJSURICID))
|
|
|
|
foundInterface = static_cast<nsIURI*>(this);
|
2011-05-25 13:23:07 -07:00
|
|
|
else if (aIID.Equals(kThisSimpleURIImplementationCID)) {
|
|
|
|
// Need to return explicitly here, because if we just set foundInterface
|
|
|
|
// to null the NS_INTERFACE_MAP_END_INHERITING will end up calling into
|
|
|
|
// nsSimplURI::QueryInterface and finding something for this CID.
|
2012-07-30 07:20:58 -07:00
|
|
|
*aInstancePtr = nullptr;
|
2011-05-25 13:23:07 -07:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
2008-11-18 14:54:36 -08:00
|
|
|
else
|
2011-05-25 13:23:07 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsSimpleURI)
|
2008-11-18 14:54:36 -08:00
|
|
|
|
|
|
|
// nsISerializable methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSURI::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
2011-05-25 13:23:07 -07:00
|
|
|
nsresult rv = nsSimpleURI::Read(aStream);
|
2008-11-18 14:54:36 -08:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveBase;
|
2008-11-18 14:54:36 -08:00
|
|
|
rv = aStream->ReadBoolean(&haveBase);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (haveBase) {
|
2014-03-15 12:00:17 -07:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
rv = aStream->ReadObject(true, getter_AddRefs(supports));
|
2008-11-18 14:54:36 -08:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2014-03-15 12:00:17 -07:00
|
|
|
mBaseURI = do_QueryInterface(supports);
|
2008-11-18 14:54:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSURI::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
2011-05-25 13:23:07 -07:00
|
|
|
nsresult rv = nsSimpleURI::Write(aStream);
|
2008-11-18 14:54:36 -08:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = aStream->WriteBoolean(mBaseURI != nullptr);
|
2008-11-18 14:54:36 -08:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (mBaseURI) {
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = aStream->WriteObject(mBaseURI, true);
|
2008-11-18 14:54:36 -08:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-06 13:33:00 -08:00
|
|
|
// nsIIPCSerializableURI
|
|
|
|
void
|
|
|
|
nsJSURI::Serialize(mozilla::ipc::URIParams& aParams)
|
|
|
|
{
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
JSURIParams jsParams;
|
|
|
|
URIParams simpleParams;
|
|
|
|
|
|
|
|
nsSimpleURI::Serialize(simpleParams);
|
|
|
|
|
|
|
|
jsParams.simpleParams() = simpleParams;
|
|
|
|
if (mBaseURI) {
|
|
|
|
SerializeURI(mBaseURI, jsParams.baseURI());
|
|
|
|
} else {
|
|
|
|
jsParams.baseURI() = mozilla::void_t();
|
|
|
|
}
|
|
|
|
|
|
|
|
aParams = jsParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsJSURI::Deserialize(const mozilla::ipc::URIParams& aParams)
|
|
|
|
{
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
if (aParams.type() != URIParams::TJSURIParams) {
|
|
|
|
NS_ERROR("Received unknown parameters from the other process!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const JSURIParams& jsParams = aParams.get_JSURIParams();
|
|
|
|
nsSimpleURI::Deserialize(jsParams.simpleParams());
|
|
|
|
|
|
|
|
if (jsParams.baseURI().type() != OptionalURIParams::Tvoid_t) {
|
|
|
|
mBaseURI = DeserializeURI(jsParams.baseURI().get_URIParams());
|
|
|
|
} else {
|
|
|
|
mBaseURI = nullptr;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-26 01:20:06 -07:00
|
|
|
// nsSimpleURI methods:
|
2011-05-25 13:23:07 -07:00
|
|
|
/* virtual */ nsSimpleURI*
|
|
|
|
nsJSURI::StartClone(nsSimpleURI::RefHandlingEnum /* ignored */)
|
2008-11-18 14:54:36 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> baseClone;
|
|
|
|
if (mBaseURI) {
|
2011-05-26 01:20:06 -07:00
|
|
|
// Note: We preserve ref on *base* URI, regardless of ref handling mode.
|
2011-05-25 13:23:07 -07:00
|
|
|
nsresult rv = mBaseURI->Clone(getter_AddRefs(baseClone));
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-05-25 13:23:07 -07:00
|
|
|
}
|
2008-11-18 14:54:36 -08:00
|
|
|
}
|
|
|
|
|
2011-05-25 13:23:07 -07:00
|
|
|
return new nsJSURI(baseClone);
|
2008-11-18 14:54:36 -08:00
|
|
|
}
|
|
|
|
|
2011-05-26 01:20:06 -07:00
|
|
|
/* virtual */ nsresult
|
|
|
|
nsJSURI::EqualsInternal(nsIURI* aOther,
|
|
|
|
nsSimpleURI::RefHandlingEnum aRefHandlingMode,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aResult)
|
2011-04-27 16:10:01 -07:00
|
|
|
{
|
2011-05-26 01:20:06 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aOther);
|
|
|
|
NS_PRECONDITION(aResult, "null pointer for outparam");
|
2008-11-18 14:54:36 -08:00
|
|
|
|
2011-05-26 01:20:06 -07:00
|
|
|
nsRefPtr<nsJSURI> otherJSURI;
|
|
|
|
nsresult rv = aOther->QueryInterface(kJSURICID,
|
|
|
|
getter_AddRefs(otherJSURI));
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aResult = false; // aOther is not a nsJSURI --> not equal.
|
2011-05-25 13:23:07 -07:00
|
|
|
return NS_OK;
|
2011-05-26 01:20:06 -07:00
|
|
|
}
|
2008-11-18 14:54:36 -08:00
|
|
|
|
2011-05-26 01:20:06 -07:00
|
|
|
// Compare the member data that our base class knows about.
|
|
|
|
if (!nsSimpleURI::EqualsInternal(otherJSURI, aRefHandlingMode)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aResult = false;
|
2011-05-26 01:20:06 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-04-27 16:10:01 -07:00
|
|
|
|
2011-05-26 01:20:06 -07:00
|
|
|
// Compare the piece of additional member data that we add to base class.
|
|
|
|
nsIURI* otherBaseURI = otherJSURI->GetBaseURI();
|
2008-11-18 14:54:36 -08:00
|
|
|
|
2011-05-26 01:20:06 -07:00
|
|
|
if (mBaseURI) {
|
|
|
|
// (As noted in StartClone, we always honor refs on mBaseURI)
|
|
|
|
return mBaseURI->Equals(otherBaseURI, aResult);
|
2011-05-25 13:23:07 -07:00
|
|
|
}
|
2011-04-27 16:10:01 -07:00
|
|
|
|
2011-05-26 01:20:06 -07:00
|
|
|
*aResult = !otherBaseURI;
|
2008-11-18 14:54:36 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
|
|
|
{
|
|
|
|
*aClassIDNoAlloc = kJSURICID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-05-25 13:23:07 -07:00
|
|
|
|