2006-10-06 09:34:32 +04: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 15:12:37 +04: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-11 02:22:35 +04:00
|
|
|
|
1999-10-13 11:17:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "jsapi.h"
|
2012-10-10 13:01:26 +04:00
|
|
|
#include "jswrapper.h"
|
1999-07-13 03:46:40 +04:00
|
|
|
#include "nsCRT.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2001-06-29 04:40:45 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2001-06-29 04:40:45 +04:00
|
|
|
#include "nsJSProtocolHandler.h"
|
2006-01-02 06:31:39 +03:00
|
|
|
#include "nsStringStream.h"
|
2001-06-29 04:40:45 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIStreamListener.h"
|
1999-07-13 03:46:40 +04:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIScriptContext.h"
|
1999-10-20 04:12:04 +04:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
1999-09-16 00:58:41 +04:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-11-18 10:36:41 +03:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-06-14 08:57:49 +04:00
|
|
|
#include "nsIWindowMediator.h"
|
2005-08-12 08:11:00 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2001-07-13 11:08:26 +04:00
|
|
|
#include "nsIConsoleService.h"
|
2001-09-01 01:01:10 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2002-03-06 10:48:55 +03:00
|
|
|
#include "prprf.h"
|
2002-03-23 00:41:06 +03:00
|
|
|
#include "nsEscape.h"
|
2003-05-15 05:23:26 +04:00
|
|
|
#include "nsIWebNavigation.h"
|
2004-02-11 09:09:51 +03:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIContentViewer.h"
|
2006-09-23 21:06:58 +04:00
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsContentUtils.h"
|
2014-10-16 22:14:52 +04:00
|
|
|
#include "nsNullPrincipal.h"
|
2006-09-23 21:06:58 +04:00
|
|
|
#include "nsJSUtils.h"
|
2006-10-17 04:55:14 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2007-02-16 04:01:39 +03:00
|
|
|
#include "nsIScriptChannel.h"
|
2007-07-03 03:48:51 +04:00
|
|
|
#include "nsIDocument.h"
|
2014-07-10 10:56:36 +04:00
|
|
|
#include "nsILoadInfo.h"
|
2008-11-19 01:54:36 +03:00
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsIWritablePropertyBag2.h"
|
2010-02-24 00:20:46 +03:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2012-08-20 22:34:32 +04:00
|
|
|
#include "nsSandboxFlags.h"
|
2014-03-07 16:34:31 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2014-07-10 10:56:37 +04:00
|
|
|
#include "nsILoadInfo.h"
|
2015-05-15 23:21:20 +03:00
|
|
|
#include "nsContentSecurityManager.h"
|
2008-11-19 01:54:36 +03:00
|
|
|
|
2015-03-07 00:33:00 +03:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
|
|
|
|
2014-03-07 16:34:31 +04:00
|
|
|
using mozilla::dom::AutoEntryScript;
|
2013-02-26 23:04:13 +04:00
|
|
|
|
2008-11-19 01:54:36 +03:00
|
|
|
static NS_DEFINE_CID(kJSURICID, NS_JSURI_CID);
|
2000-06-14 08:57:49 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
class nsJSThunk : public nsIInputStream
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
2000-03-29 07:58:50 +04:00
|
|
|
public:
|
2001-06-29 04:40:45 +04:00
|
|
|
nsJSThunk();
|
|
|
|
|
2013-07-19 06:21:20 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_FORWARD_SAFE_NSIINPUTSTREAM(mInnerStream)
|
2001-06-29 04:40:45 +04:00
|
|
|
|
2002-08-22 03:01:23 +04:00
|
|
|
nsresult Init(nsIURI* uri);
|
2007-02-16 04:01:39 +03:00
|
|
|
nsresult EvaluateScript(nsIChannel *aChannel,
|
|
|
|
PopupControlState aPopupState,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aExecutionPolicy,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner *aOriginalInnerWindow);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
protected:
|
2001-06-29 04:40:45 +04:00
|
|
|
virtual ~nsJSThunk();
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsIInputStream> mInnerStream;
|
2009-01-05 03:34:18 +03:00
|
|
|
nsCString mScript;
|
|
|
|
nsCString mURL;
|
1999-10-13 11:17:36 +04:00
|
|
|
};
|
1999-08-27 02:45:55 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
//
|
|
|
|
// nsISupports implementation...
|
|
|
|
//
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsJSThunk, nsIInputStream)
|
2001-06-29 04:40:45 +04:00
|
|
|
|
|
|
|
|
|
|
|
nsJSThunk::nsJSThunk()
|
1999-10-13 11:17:36 +04:00
|
|
|
{
|
|
|
|
}
|
1999-07-13 03:46:40 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
nsJSThunk::~nsJSThunk()
|
1999-10-13 11:17:36 +04:00
|
|
|
{
|
|
|
|
}
|
1999-07-13 03:46:40 +04:00
|
|
|
|
2002-08-22 03:01:23 +04:00
|
|
|
nsresult nsJSThunk::Init(nsIURI* uri)
|
2000-03-29 07:58:50 +04:00
|
|
|
{
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(uri);
|
|
|
|
|
2009-01-05 03:34:18 +03: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;
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-10-13 11:17:36 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2006-10-06 09:34:32 +04: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 18:59:28 +04:00
|
|
|
return false;
|
2006-10-06 09:34:32 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-10-06 09:34:32 +04:00
|
|
|
}
|
|
|
|
|
2006-10-19 04:49:12 +04:00
|
|
|
static
|
|
|
|
nsIScriptGlobalObject* GetGlobalObject(nsIChannel* aChannel)
|
1999-07-13 03:46:40 +04:00
|
|
|
{
|
2006-10-19 04:49:12 +04:00
|
|
|
// Get the global object owner from the channel
|
2013-05-27 14:07:01 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
NS_QueryNotificationCallbacks(aChannel, docShell);
|
|
|
|
if (!docShell) {
|
|
|
|
NS_WARNING("Unable to get a docShell from the channel!");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2013-05-27 14:07:01 +04:00
|
|
|
// So far so good: get the script global from its docshell
|
|
|
|
nsIScriptGlobalObject* global = docShell->GetScriptGlobalObject();
|
2001-06-29 04:40:45 +04:00
|
|
|
|
2004-07-16 21:03:10 +04:00
|
|
|
NS_ASSERTION(global,
|
2001-06-29 04:40:45 +04:00
|
|
|
"Unable to get an nsIScriptGlobalObject from the "
|
2013-05-27 14:07:01 +04:00
|
|
|
"docShell!");
|
2006-10-19 04:49:12 +04:00
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
|
2007-02-16 04:01:39 +03:00
|
|
|
PopupControlState aPopupState,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aExecutionPolicy,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner *aOriginalInnerWindow)
|
2006-10-19 04:49:12 +04:00
|
|
|
{
|
2007-02-16 04:01:39 +03:00
|
|
|
if (aExecutionPolicy == nsIScriptChannel::NO_EXECUTION) {
|
|
|
|
// Nothing to do here.
|
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2006-10-19 04:49:12 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
|
|
|
|
2007-02-16 04:01:39 +03:00
|
|
|
// Get principal of code for execution
|
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
aChannel->GetOwner(getter_AddRefs(owner));
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(owner);
|
|
|
|
if (!principal) {
|
2014-07-10 10:56:37 +04:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
if (loadInfo && loadInfo->GetForceInheritPrincipal()) {
|
2014-11-14 19:57:26 +03:00
|
|
|
principal = loadInfo->TriggeringPrincipal();
|
2014-07-10 10:56:37 +04: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-02-16 04:01:39 +03:00
|
|
|
}
|
|
|
|
|
2010-02-24 00:20:46 +03: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 21:09:44 +03:00
|
|
|
if (csp) {
|
2015-09-18 08:34:34 +03:00
|
|
|
bool allowsInlineScript = true;
|
|
|
|
rv = csp->GetAllowsInline(nsIContentPolicy::TYPE_SCRIPT,
|
|
|
|
EmptyString(), // aNonce
|
|
|
|
EmptyString(), // aContent
|
|
|
|
0, // aLineNumber
|
|
|
|
&allowsInlineScript);
|
2012-10-16 00:54:58 +04:00
|
|
|
|
|
|
|
//return early if inline scripts are not allowed
|
2015-09-18 08:34:34 +03:00
|
|
|
if (!allowsInlineScript) {
|
2011-01-31 21:09:44 +03:00
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
2012-10-16 00:54:58 +04:00
|
|
|
}
|
2010-02-24 00:20:46 +03:00
|
|
|
}
|
2006-10-19 04:49:12 +04:00
|
|
|
|
|
|
|
// Get the global object we should be running on.
|
|
|
|
nsIScriptGlobalObject* global = GetGlobalObject(aChannel);
|
2004-07-16 21:03:10 +04:00
|
|
|
if (!global) {
|
2001-06-29 04:40:45 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-20 22:34:32 +04:00
|
|
|
// Sandboxed document check: javascript: URI's are disabled
|
|
|
|
// in a sandboxed document unless 'allow-scripts' was specified.
|
|
|
|
nsIDocument* doc = aOriginalInnerWindow->GetExtantDoc();
|
2016-06-09 13:22:22 +03:00
|
|
|
if (doc && doc->HasScriptsBlockedBySandbox()) {
|
2012-08-20 22:34:32 +04:00
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2006-10-19 04:49:12 +04:00
|
|
|
// Push our popup control state
|
2013-03-16 08:31:38 +04:00
|
|
|
nsAutoPopupStatePusher popupStatePusher(aPopupState);
|
2006-10-19 04:49:12 +04:00
|
|
|
|
2007-06-11 00:59:37 +04:00
|
|
|
// Make sure we still have the same inner window as we used to.
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win = do_QueryInterface(global);
|
|
|
|
nsPIDOMWindowInner *innerWin = win->GetCurrentInnerWindow();
|
2005-08-12 08:11:00 +04:00
|
|
|
|
2007-06-11 00:59:37 +04:00
|
|
|
if (innerWin != aOriginalInnerWindow) {
|
2005-08-12 08:11:00 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> innerGlobal = do_QueryInterface(innerWin);
|
|
|
|
|
2016-08-30 17:44:52 +03:00
|
|
|
mozilla::DebugOnly<nsCOMPtr<nsIDOMWindow>> domWindow(do_QueryInterface(global, &rv));
|
2002-08-22 03:01:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2006-10-19 04:49:12 +04:00
|
|
|
// So far so good: get the script context from its owner.
|
2004-05-18 08:00:47 +04:00
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext = global->GetContext();
|
2004-02-10 01:48:53 +03:00
|
|
|
if (!scriptContext)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-07-19 09:48:49 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString script(mScript);
|
2002-08-22 03:01:23 +04:00
|
|
|
// Unescape the script
|
|
|
|
NS_UnescapeURL(script);
|
|
|
|
|
|
|
|
|
2001-07-13 11:08:26 +04:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager;
|
|
|
|
securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2014-03-07 16:34:31 +04: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
|
2015-07-09 09:41:43 +03:00
|
|
|
nsAutoMicroTask mt;
|
2016-06-02 17:34:39 +03:00
|
|
|
AutoEntryScript aes(innerGlobal, "javascript: URI", true);
|
2016-03-10 03:02:03 +03:00
|
|
|
JSContext* cx = aes.cx();
|
2013-05-04 11:52:57 +04:00
|
|
|
JS::Rooted<JSObject*> globalJSObject(cx, innerGlobal->GetGlobalJSObject());
|
2013-11-13 04:43:31 +04:00
|
|
|
NS_ENSURE_TRUE(globalJSObject, NS_ERROR_UNEXPECTED);
|
2013-05-04 11:52:57 +04:00
|
|
|
|
2014-07-04 09:21:57 +04:00
|
|
|
//-- Don't execute unless the script principal subsumes the
|
|
|
|
// principal of the context.
|
|
|
|
nsIPrincipal* objectPrincipal = nsContentUtils::ObjectPrincipal(globalJSObject);
|
2001-09-01 01:01:10 +04:00
|
|
|
|
2014-07-04 09:21:57 +04:00
|
|
|
bool subsumes;
|
|
|
|
rv = principal->Subsumes(objectPrincipal, &subsumes);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2007-02-16 04:01:39 +03:00
|
|
|
|
2014-07-04 09:21:57 +04:00
|
|
|
if (!subsumes) {
|
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
1999-10-13 11:17:36 +04:00
|
|
|
|
2016-02-29 14:25:11 +03:00
|
|
|
// Fail if someone tries to execute in a global with system principal.
|
|
|
|
if (nsContentUtils::IsSystemPrincipal(objectPrincipal)) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
2013-05-04 11:52:57 +04:00
|
|
|
JS::Rooted<JS::Value> v (cx, JS::UndefinedValue());
|
2006-09-23 21:06:58 +04:00
|
|
|
// Finally, we have everything needed to evaluate the expression.
|
2014-07-04 09:21:57 +04:00
|
|
|
JS::CompileOptions options(cx);
|
|
|
|
options.setFileAndLine(mURL.get(), 1)
|
|
|
|
.setVersion(JSVERSION_DEFAULT);
|
2014-11-13 01:04:29 +03:00
|
|
|
nsJSUtils::EvaluateOptions evalOptions(cx);
|
2014-07-04 09:21:57 +04:00
|
|
|
rv = nsJSUtils::EvaluateString(cx, NS_ConvertUTF8toUTF16(script),
|
|
|
|
globalJSObject, options, evalOptions, &v);
|
|
|
|
|
2016-05-10 05:25:40 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-01-25 14:17:40 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2016-05-10 05:25:40 +03:00
|
|
|
} else if (!v.isString()) {
|
2013-01-25 14:17:40 +04:00
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
} else {
|
2015-06-16 03:11:06 +03:00
|
|
|
MOZ_ASSERT(rv != NS_SUCCESS_DOM_SCRIPT_EVALUATION_THREW,
|
|
|
|
"How did we get a non-undefined return value?");
|
2014-07-05 19:30:54 +04:00
|
|
|
nsAutoJSString result;
|
2013-01-17 06:50:27 +04:00
|
|
|
if (!result.init(cx, v)) {
|
2013-01-17 06:50:26 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2006-10-06 09:34:32 +04:00
|
|
|
char *bytes;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t bytesLen;
|
2006-10-06 09:34:32 +04: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)
|
2006-05-04 23:12:26 +04:00
|
|
|
rv = NS_NewByteInputStream(getter_AddRefs(mInnerStream),
|
2006-10-06 09:34:32 +04:00
|
|
|
bytes, bytesLen,
|
2006-05-04 23:12:26 +04:00
|
|
|
NS_ASSIGNMENT_ADOPT);
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2006-09-23 21:06:58 +04:00
|
|
|
|
1999-07-13 03:46:40 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-07-19 04:53:11 +04:00
|
|
|
class nsJSChannel : public nsIChannel,
|
2007-02-16 04:01:39 +03:00
|
|
|
public nsIStreamListener,
|
2008-11-19 01:54:36 +03:00
|
|
|
public nsIScriptChannel,
|
|
|
|
public nsIPropertyBag2
|
2000-03-29 07:58:50 +04:00
|
|
|
{
|
|
|
|
public:
|
2001-06-29 04:40:45 +04:00
|
|
|
nsJSChannel();
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_DECL_NSIREQUEST
|
|
|
|
NS_DECL_NSICHANNEL
|
2006-07-19 04:53:11 +04:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2007-02-16 04:01:39 +03:00
|
|
|
NS_DECL_NSISCRIPTCHANNEL
|
2008-11-19 01:54:36 +03:00
|
|
|
NS_FORWARD_SAFE_NSIPROPERTYBAG(mPropertyBag)
|
|
|
|
NS_FORWARD_SAFE_NSIPROPERTYBAG2(mPropertyBag)
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
nsresult Init(nsIURI *aURI);
|
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
// Actually evaluate the script.
|
|
|
|
void EvaluateScript();
|
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsJSChannel();
|
|
|
|
|
2003-05-15 05:23:26 +04:00
|
|
|
nsresult StopAll();
|
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
void NotifyListener();
|
2007-07-03 03:48:51 +04:00
|
|
|
|
|
|
|
void CleanupStrongRefs();
|
2006-10-17 04:55:14 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIChannel> mStreamChannel;
|
2008-11-19 01:54:36 +03:00
|
|
|
nsCOMPtr<nsIPropertyBag2> mPropertyBag;
|
2006-07-19 04:53:11 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener; // Our final listener
|
2006-10-17 04:55:14 +04:00
|
|
|
nsCOMPtr<nsISupports> mContext; // The context passed to AsyncOpen
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mOriginalInnerWindow; // The inner window our load
|
|
|
|
// started against.
|
2007-07-03 03:48:51 +04:00
|
|
|
// If we blocked onload on a document in AsyncOpen, this is the document we
|
|
|
|
// did it on.
|
|
|
|
nsCOMPtr<nsIDocument> mDocumentOnloadBlockedOn;
|
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
nsresult mStatus; // Our status
|
2001-06-29 04:40:45 +04:00
|
|
|
|
2003-05-22 01:37:25 +04:00
|
|
|
nsLoadFlags mLoadFlags;
|
2006-10-17 04:55:14 +04:00
|
|
|
nsLoadFlags mActualLoadFlags; // See AsyncOpen
|
2003-05-22 01:37:25 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsJSThunk> mIOThunk;
|
2006-10-19 04:49:12 +04:00
|
|
|
PopupControlState mPopupState;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mExecutionPolicy;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsAsync;
|
|
|
|
bool mIsActive;
|
|
|
|
bool mOpenedStreamChannel;
|
2001-06-29 04:40:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
nsJSChannel::nsJSChannel() :
|
2006-10-17 04:55:14 +04:00
|
|
|
mStatus(NS_OK),
|
2003-07-15 01:06:21 +04:00
|
|
|
mLoadFlags(LOAD_NORMAL),
|
2006-10-17 04:55:14 +04:00
|
|
|
mActualLoadFlags(LOAD_NORMAL),
|
2006-10-19 04:49:12 +04:00
|
|
|
mPopupState(openOverridden),
|
2014-07-04 09:21:57 +04:00
|
|
|
mExecutionPolicy(NO_EXECUTION),
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAsync(true),
|
|
|
|
mIsActive(false),
|
|
|
|
mOpenedStreamChannel(false)
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJSChannel::~nsJSChannel()
|
|
|
|
{
|
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2003-05-15 05:23:26 +04:00
|
|
|
nsresult nsJSChannel::StopAll()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_UNEXPECTED;
|
2004-03-10 04:18:26 +03:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav;
|
2004-11-15 23:16:52 +03:00
|
|
|
NS_QueryNotificationCallbacks(mStreamChannel, webNav);
|
2003-05-15 05:23:26 +04:00
|
|
|
|
2004-03-10 04:18:26 +03:00
|
|
|
NS_ASSERTION(webNav, "Can't get nsIWebNavigation from channel!");
|
2003-05-15 05:23:26 +04:00
|
|
|
if (webNav) {
|
|
|
|
rv = webNav->Stop(nsIWebNavigation::STOP_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2001-06-29 04:40:45 +04:00
|
|
|
|
|
|
|
nsresult nsJSChannel::Init(nsIURI *aURI)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsJSURI> jsURI;
|
2008-11-19 01:54:36 +03:00
|
|
|
nsresult rv = aURI->QueryInterface(kJSURICID,
|
|
|
|
getter_AddRefs(jsURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-05-15 05:23:26 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
// Create the nsIStreamIO layer used by the nsIStreamIOChannel.
|
2003-05-15 05:23:26 +04:00
|
|
|
mIOThunk = new nsJSThunk();
|
2001-06-29 04:40:45 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
// Create a stock input stream channel...
|
2001-06-29 04:40:45 +04:00
|
|
|
// Remember, until AsyncOpen is called, the script will not be evaluated
|
|
|
|
// and the underlying Input Stream will not be created...
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2001-06-29 04:40:45 +04:00
|
|
|
|
2015-04-13 21:47:41 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> nullPrincipal = nsNullPrincipal::Create();
|
2014-10-16 22:14:52 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
// If the resultant script evaluation actually does return a value, we
|
|
|
|
// treat it as html.
|
2016-03-10 00:55:59 +03:00
|
|
|
// The following channel is never openend, so it does not matter what
|
|
|
|
// securityFlags we pass; let's follow the principle of least privilege.
|
2014-10-16 22:14:52 +04:00
|
|
|
rv = NS_NewInputStreamChannel(getter_AddRefs(channel),
|
|
|
|
aURI,
|
|
|
|
mIOThunk,
|
|
|
|
nullPrincipal,
|
2016-03-10 00:55:59 +03:00
|
|
|
nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
|
2014-10-16 22:14:52 +04:00
|
|
|
nsIContentPolicy::TYPE_OTHER,
|
2006-10-06 09:34:32 +04:00
|
|
|
NS_LITERAL_CSTRING("text/html"));
|
2001-06-29 04:40:45 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-08-22 03:01:23 +04:00
|
|
|
rv = mIOThunk->Init(aURI);
|
2001-06-29 04:40:45 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-01-18 05:15:14 +03:00
|
|
|
mStreamChannel = channel;
|
2008-11-19 01:54:36 +03:00
|
|
|
mPropertyBag = do_QueryInterface(channel);
|
|
|
|
nsCOMPtr<nsIWritablePropertyBag2> writableBag =
|
|
|
|
do_QueryInterface(channel);
|
|
|
|
if (writableBag && jsURI->GetBaseURI()) {
|
|
|
|
writableBag->SetPropertyAsInterface(NS_LITERAL_STRING("baseURI"),
|
|
|
|
jsURI->GetBaseURI());
|
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
}
|
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsISupports implementation...
|
|
|
|
//
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsJSChannel, nsIChannel, nsIRequest, nsIRequestObserver,
|
|
|
|
nsIStreamListener, nsIScriptChannel, nsIPropertyBag,
|
|
|
|
nsIPropertyBag2)
|
2001-06-29 04:40:45 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsIRequest implementation...
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-21 01:50:33 +03:00
|
|
|
nsJSChannel::GetName(nsACString &aResult)
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
|
|
|
return mStreamChannel->GetName(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsJSChannel::IsPending(bool *aResult)
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
2003-05-22 01:37:25 +04:00
|
|
|
*aResult = mIsActive;
|
|
|
|
return NS_OK;
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetStatus(nsresult *aResult)
|
|
|
|
{
|
2007-07-25 04:08:58 +04:00
|
|
|
if (NS_SUCCEEDED(mStatus) && mOpenedStreamChannel) {
|
|
|
|
return mStreamChannel->GetStatus(aResult);
|
|
|
|
}
|
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
*aResult = mStatus;
|
2007-07-25 04:08:58 +04:00
|
|
|
|
2003-05-22 01:37:25 +04:00
|
|
|
return NS_OK;
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-06-24 04:03:10 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::Cancel(nsresult aStatus)
|
|
|
|
{
|
2006-10-17 04:55:14 +04:00
|
|
|
mStatus = aStatus;
|
2003-05-15 05:23:26 +04:00
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
if (mOpenedStreamChannel) {
|
|
|
|
mStreamChannel->Cancel(aStatus);
|
|
|
|
}
|
|
|
|
|
2003-05-22 01:37:25 +04:00
|
|
|
return NS_OK;
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
2003-05-22 01:37:25 +04:00
|
|
|
nsJSChannel::Suspend()
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
2003-10-31 00:23:15 +03:00
|
|
|
return mStreamChannel->Suspend();
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
2003-05-22 01:37:25 +04:00
|
|
|
nsJSChannel::Resume()
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
2003-10-31 00:23:15 +03:00
|
|
|
return mStreamChannel->Resume();
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-06-24 04:03:10 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
//
|
|
|
|
// nsIChannel implementation
|
|
|
|
//
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetOriginalURI(nsIURI * *aURI)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetOriginalURI(aURI);
|
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetOriginalURI(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetOriginalURI(aURI);
|
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetURI(nsIURI * *aURI)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetURI(aURI);
|
|
|
|
}
|
2000-06-14 08:57:49 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
2001-08-21 10:20:53 +04:00
|
|
|
nsJSChannel::Open(nsIInputStream **aResult)
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
2007-02-16 04:01:39 +03:00
|
|
|
nsresult rv = mIOThunk->EvaluateScript(mStreamChannel, mPopupState,
|
2007-06-11 00:59:37 +04:00
|
|
|
mExecutionPolicy,
|
|
|
|
mOriginalInnerWindow);
|
2006-10-17 04:55:14 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return mStreamChannel->Open(aResult);
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2015-05-15 23:21:20 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::Open2(nsIInputStream** aStream)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
|
|
|
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return Open(aStream);
|
|
|
|
}
|
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
|
|
|
|
{
|
2015-08-13 07:36:33 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = nsIChannel::GetLoadInfo();
|
|
|
|
MOZ_ASSERT(!loadInfo || loadInfo->GetSecurityMode() == 0 ||
|
|
|
|
loadInfo->GetInitialSecurityCheckDone(),
|
|
|
|
"security flags in loadInfo but asyncOpen2() not called");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
NS_ENSURE_ARG(aListener);
|
2007-06-11 00:59:37 +04: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;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win(do_QueryInterface(global));
|
2007-06-11 00:59:37 +04:00
|
|
|
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;
|
|
|
|
}
|
2006-10-17 04:55:14 +04:00
|
|
|
|
2006-07-19 04:53:11 +04:00
|
|
|
mListener = aListener;
|
2006-10-17 04:55:14 +04:00
|
|
|
mContext = aContext;
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsActive = true;
|
2001-07-06 23:40:23 +04:00
|
|
|
|
2004-10-28 06:06:27 +04: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).
|
2006-10-17 04:55:14 +04:00
|
|
|
mActualLoadFlags = mLoadFlags;
|
2004-10-28 06:06:27 +04:00
|
|
|
mLoadFlags |= LOAD_BACKGROUND;
|
|
|
|
|
2003-05-22 01:37:25 +04:00
|
|
|
// Add the javascript channel to its loadgroup so that we know if
|
|
|
|
// network loads were canceled or not...
|
2006-10-17 04:55:14 +04:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2003-05-22 01:37:25 +04:00
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (loadGroup) {
|
2012-07-30 18:20:58 +04:00
|
|
|
nsresult rv = loadGroup->AddRequest(this, nullptr);
|
2007-07-25 04:08:58 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsActive = false;
|
2007-07-25 04:08:58 +04:00
|
|
|
CleanupStrongRefs();
|
|
|
|
return rv;
|
|
|
|
}
|
2006-10-17 04:55:14 +04:00
|
|
|
}
|
|
|
|
|
2013-04-24 08:22:37 +04:00
|
|
|
mDocumentOnloadBlockedOn = mOriginalInnerWindow->GetExtantDoc();
|
2007-07-03 03:48:51 +04: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 23:39:51 +04:00
|
|
|
// LOAD_DOCUMENT_URI flag, so a docloader we're loading in as the
|
2007-07-03 03:48:51 +04: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-14 02:42:07 +04:00
|
|
|
mPopupState = win->GetPopupControlState();
|
|
|
|
|
2010-04-21 03:21:35 +04:00
|
|
|
void (nsJSChannel::*method)();
|
2007-06-14 02:42:07 +04:00
|
|
|
if (mIsAsync) {
|
|
|
|
// post an event to do the rest
|
|
|
|
method = &nsJSChannel::EvaluateScript;
|
2013-04-24 08:22:37 +04:00
|
|
|
} else {
|
2007-06-14 02:42:07 +04: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-03 03:48:51 +04:00
|
|
|
CleanupStrongRefs();
|
2007-06-14 02:42:07 +04: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;
|
|
|
|
}
|
|
|
|
|
2016-05-05 11:45:00 +03:00
|
|
|
nsresult rv = NS_DispatchToCurrentThread(mozilla::NewRunnableMethod(this, method));
|
2006-10-17 04:55:14 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
loadGroup->RemoveRequest(this, nullptr, rv);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsActive = false;
|
2007-07-03 03:48:51 +04:00
|
|
|
CleanupStrongRefs();
|
2003-05-22 01:37:25 +04:00
|
|
|
}
|
2006-10-17 04:55:14 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-05-15 23:21:20 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::AsyncOpen2(nsIStreamListener *aListener)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStreamListener> listener = aListener;
|
|
|
|
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return AsyncOpen(listener, nullptr);
|
|
|
|
}
|
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
void
|
|
|
|
nsJSChannel::EvaluateScript()
|
|
|
|
{
|
2001-06-29 04:40:45 +04:00
|
|
|
// 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...
|
2000-04-21 09:18:15 +04:00
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
// 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)) {
|
2007-02-16 04:01:39 +03:00
|
|
|
nsresult rv = mIOThunk->EvaluateScript(mStreamChannel, mPopupState,
|
2007-06-11 00:59:37 +04:00
|
|
|
mExecutionPolicy,
|
|
|
|
mOriginalInnerWindow);
|
2006-10-17 04:55:14 +04:00
|
|
|
|
|
|
|
// Note that evaluation may have canceled us, so recheck mStatus again
|
|
|
|
if (NS_FAILED(rv) && NS_SUCCEEDED(mStatus)) {
|
|
|
|
mStatus = rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-22 01:37:25 +04:00
|
|
|
// Remove the javascript channel from its loadgroup...
|
2006-10-17 04:55:14 +04:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
2003-05-22 01:37:25 +04:00
|
|
|
if (loadGroup) {
|
2012-07-30 18:20:58 +04:00
|
|
|
loadGroup->RemoveRequest(this, nullptr, mStatus);
|
2003-05-22 01:37:25 +04:00
|
|
|
}
|
2003-05-15 05:23:26 +04:00
|
|
|
|
2004-10-28 06:06:27 +04:00
|
|
|
// Reset load flags to their original value...
|
2006-10-17 04:55:14 +04:00
|
|
|
mLoadFlags = mActualLoadFlags;
|
2004-10-28 06:06:27 +04:00
|
|
|
|
2003-05-22 01:37:25 +04:00
|
|
|
// We're no longer active, it's now up to the stream channel to do
|
|
|
|
// the loading, if needed.
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsActive = false;
|
2003-05-22 01:37:25 +04:00
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
if (NS_FAILED(mStatus)) {
|
2007-06-14 02:42:07 +04:00
|
|
|
if (mIsAsync) {
|
|
|
|
NotifyListener();
|
|
|
|
}
|
2006-10-17 04:55:14 +04: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-08 05:35:17 +04: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.
|
2006-10-17 04:55:14 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
NS_QueryNotificationCallbacks(mStreamChannel, docShell);
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
|
|
|
|
if (cv) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool okToUnload;
|
2006-10-17 04:55:14 +04:00
|
|
|
|
2015-09-24 23:32:09 +03:00
|
|
|
if (NS_SUCCEEDED(cv->PermitUnload(&okToUnload)) &&
|
2006-10-17 04:55:14 +04: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;
|
2004-02-11 09:09:51 +03:00
|
|
|
}
|
|
|
|
}
|
2003-05-15 23:38:35 +04:00
|
|
|
}
|
2003-05-15 05:23:26 +04:00
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
if (NS_SUCCEEDED(mStatus)) {
|
|
|
|
mStatus = StopAll();
|
2003-05-15 05:23:26 +04:00
|
|
|
}
|
2004-02-11 09:09:51 +03:00
|
|
|
}
|
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
if (NS_FAILED(mStatus)) {
|
2007-06-14 02:42:07 +04:00
|
|
|
if (mIsAsync) {
|
|
|
|
NotifyListener();
|
|
|
|
}
|
2006-10-17 04:55:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mStatus = mStreamChannel->AsyncOpen(this, mContext);
|
2007-06-14 02:42:07 +04:00
|
|
|
if (NS_SUCCEEDED(mStatus)) {
|
2006-10-17 04:55:14 +04:00
|
|
|
// mStreamChannel will call OnStartRequest and OnStopRequest on
|
|
|
|
// us, so we'll be sure to call them on our listener.
|
2011-10-17 18:59:28 +04:00
|
|
|
mOpenedStreamChannel = true;
|
2007-07-25 04:08:58 +04:00
|
|
|
|
|
|
|
// Now readd ourselves to the loadgroup so we can receive
|
|
|
|
// cancellation notifications.
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsActive = true;
|
2007-07-25 04:08:58 +04:00
|
|
|
if (loadGroup) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mStatus = loadGroup->AddRequest(this, nullptr);
|
2007-07-25 04:08:58 +04: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-14 02:42:07 +04:00
|
|
|
} else if (mIsAsync) {
|
|
|
|
NotifyListener();
|
2000-03-29 07:58:50 +04:00
|
|
|
}
|
2001-07-06 23:40:23 +04:00
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJSChannel::NotifyListener()
|
|
|
|
{
|
2007-07-03 03:48:51 +04:00
|
|
|
mListener->OnStartRequest(this, mContext);
|
|
|
|
mListener->OnStopRequest(this, mContext, mStatus);
|
2006-10-17 04:55:14 +04:00
|
|
|
|
2007-07-03 03:48:51 +04:00
|
|
|
CleanupStrongRefs();
|
|
|
|
}
|
2006-10-17 04:55:14 +04:00
|
|
|
|
2007-07-03 03:48:51 +04:00
|
|
|
void
|
|
|
|
nsJSChannel::CleanupStrongRefs()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
|
|
|
mContext = nullptr;
|
|
|
|
mOriginalInnerWindow = nullptr;
|
2007-07-03 03:48:51 +04:00
|
|
|
if (mDocumentOnloadBlockedOn) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mDocumentOnloadBlockedOn->UnblockOnload(false);
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocumentOnloadBlockedOn = nullptr;
|
2007-07-03 03:48:51 +04:00
|
|
|
}
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
|
|
|
{
|
2003-05-22 01:37:25 +04:00
|
|
|
*aLoadFlags = mLoadFlags;
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-04-21 09:18:15 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
|
|
|
|
{
|
2008-09-30 00:42:19 +04:00
|
|
|
// Figure out whether the LOAD_BACKGROUND bit in aLoadFlags is
|
|
|
|
// actually right.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bogusLoadBackground = false;
|
2008-09-30 00:42:19 +04: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-29 10:19:26 +04:00
|
|
|
bool loadGroupIsBackground = false;
|
2008-09-30 00:42:19 +04: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 19:40:54 +03: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;
|
|
|
|
|
2003-05-22 01:37:25 +04: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.
|
|
|
|
|
2006-10-17 04:55:14 +04:00
|
|
|
// 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.
|
|
|
|
|
2003-05-22 01:37:25 +04:00
|
|
|
mLoadFlags = aLoadFlags & ~LOAD_DOCUMENT_URI;
|
|
|
|
|
2008-09-30 00:42:19 +04:00
|
|
|
if (bogusLoadBackground) {
|
|
|
|
aLoadFlags = aLoadFlags & ~LOAD_BACKGROUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
mActualLoadFlags = aLoadFlags;
|
|
|
|
|
2003-05-22 01:37:25 +04: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.
|
|
|
|
|
2003-05-15 05:23:26 +04:00
|
|
|
return mStreamChannel->SetLoadFlags(aLoadFlags);
|
2001-06-29 04:40:45 +04:00
|
|
|
}
|
2000-04-21 09:18:15 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetLoadGroup(aLoadGroup);
|
|
|
|
}
|
2000-04-21 09:18:15 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
2007-12-04 00:57:17 +03:00
|
|
|
if (aLoadGroup) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool streamPending;
|
2007-12-04 00:57:17 +03: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 18:20:58 +04:00
|
|
|
aLoadGroup->AddRequest(mStreamChannel, nullptr);
|
2007-12-04 00:57:17 +03:00
|
|
|
if (curLoadGroup) {
|
2012-07-30 18:20:58 +04:00
|
|
|
curLoadGroup->RemoveRequest(mStreamChannel, nullptr,
|
2007-12-04 00:57:17 +03:00
|
|
|
NS_BINDING_RETARGETED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
return mStreamChannel->SetLoadGroup(aLoadGroup);
|
|
|
|
}
|
2000-04-21 09:18:15 +04:00
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetOwner(nsISupports* *aOwner)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetOwner(aOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetOwner(nsISupports* aOwner)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetOwner(aOwner);
|
|
|
|
}
|
|
|
|
|
2014-07-10 10:56:36 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetLoadInfo(nsILoadInfo* *aLoadInfo)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetLoadInfo(aLoadInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetLoadInfo(nsILoadInfo* aLoadInfo)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetLoadInfo(aLoadInfo);
|
|
|
|
}
|
|
|
|
|
2001-06-29 04:40:45 +04: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
|
2002-03-21 01:50:33 +03:00
|
|
|
nsJSChannel::GetContentType(nsACString &aContentType)
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentType(aContentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-21 01:50:33 +03:00
|
|
|
nsJSChannel::SetContentType(const nsACString &aContentType)
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentType(aContentType);
|
|
|
|
}
|
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetContentCharset(nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentCharset(aContentCharset);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetContentCharset(const nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentCharset(aContentCharset);
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:41:04 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJSChannel::GetContentDisposition(uint32_t *aContentDisposition)
|
2011-09-10 02:41:04 +04:00
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentDisposition(aContentDisposition);
|
|
|
|
}
|
|
|
|
|
2012-10-02 20:43:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetContentDisposition(uint32_t aContentDisposition)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentDisposition(aContentDisposition);
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:41:04 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentDispositionFilename(aContentDispositionFilename);
|
|
|
|
}
|
|
|
|
|
2012-10-02 20:43:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetContentDispositionFilename(const nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentDispositionFilename(aContentDispositionFilename);
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:41:04 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentDispositionHeader(aContentDispositionHeader);
|
|
|
|
}
|
|
|
|
|
2001-06-29 04:40:45 +04:00
|
|
|
NS_IMETHODIMP
|
2012-10-22 21:51:07 +04:00
|
|
|
nsJSChannel::GetContentLength(int64_t *aContentLength)
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentLength(aContentLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-22 21:51:07 +04:00
|
|
|
nsJSChannel::SetContentLength(int64_t aContentLength)
|
2001-06-29 04:40:45 +04:00
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentLength(aContentLength);
|
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2006-07-19 04:53:11 +04:00
|
|
|
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-06 06:41:02 +04:00
|
|
|
uint64_t aOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aCount)
|
2006-07-19 04:53:11 +04: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)
|
|
|
|
{
|
2006-07-19 17:27:53 +04:00
|
|
|
NS_ENSURE_TRUE(aRequest == mStreamChannel, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2007-07-03 03:48:51 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> listener = mListener;
|
2006-10-17 04:55:14 +04:00
|
|
|
|
2007-07-03 03:48:51 +04:00
|
|
|
CleanupStrongRefs();
|
2007-07-25 04:08:58 +04:00
|
|
|
|
|
|
|
// Make sure aStatus matches what GetStatus() returns
|
|
|
|
if (NS_FAILED(mStatus)) {
|
|
|
|
aStatus = mStatus;
|
|
|
|
}
|
2006-07-19 04:53:11 +04:00
|
|
|
|
2007-07-25 04:08:58 +04:00
|
|
|
nsresult rv = listener->OnStopRequest(this, aContext, aStatus);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (loadGroup) {
|
2012-07-30 18:20:58 +04:00
|
|
|
loadGroup->RemoveRequest(this, nullptr, mStatus);
|
2007-07-25 04:08:58 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsActive = false;
|
2007-07-25 04:08:58 +04:00
|
|
|
|
|
|
|
return rv;
|
2006-07-19 04:53:11 +04:00
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2007-02-16 04:01:39 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJSChannel::SetExecutionPolicy(uint32_t aPolicy)
|
2007-02-16 04:01:39 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aPolicy <= EXECUTE_NORMAL);
|
|
|
|
|
|
|
|
mExecutionPolicy = aPolicy;
|
2007-02-16 04:45:16 +03:00
|
|
|
return NS_OK;
|
2007-02-16 04:01:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJSChannel::GetExecutionPolicy(uint32_t* aPolicy)
|
2007-02-16 04:01:39 +03:00
|
|
|
{
|
|
|
|
*aPolicy = mExecutionPolicy;
|
2007-02-16 04:45:16 +03:00
|
|
|
return NS_OK;
|
2007-02-16 04:01:39 +03:00
|
|
|
}
|
|
|
|
|
2007-06-14 02:42:07 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsJSChannel::SetExecuteAsync(bool aIsAsync)
|
2007-06-14 02:42:07 +04:00
|
|
|
{
|
|
|
|
if (!mIsActive) {
|
|
|
|
mIsAsync = aIsAsync;
|
|
|
|
}
|
|
|
|
// else ignore this call
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(!mIsActive,
|
|
|
|
"Calling SetExecuteAsync on active channel?");
|
2007-06-14 02:42:07 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsJSChannel::GetExecuteAsync(bool* aIsAsync)
|
2007-06-14 02:42:07 +04:00
|
|
|
{
|
|
|
|
*aIsAsync = mIsAsync;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-07-13 03:46:40 +04:00
|
|
|
nsJSProtocolHandler::nsJSProtocolHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsJSProtocolHandler::Init()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJSProtocolHandler::~nsJSProtocolHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsJSProtocolHandler, nsIProtocolHandler)
|
1999-07-13 03:46:40 +04:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
nsresult
|
1999-07-13 03:46:40 +04:00
|
|
|
nsJSProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|
|
|
{
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
nsJSProtocolHandler* ph = new nsJSProtocolHandler();
|
|
|
|
NS_ADDREF(ph);
|
|
|
|
nsresult rv = ph->Init();
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = ph->QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
NS_RELEASE(ph);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-07-24 03:28:28 +04:00
|
|
|
nsresult
|
|
|
|
nsJSProtocolHandler::EnsureUTF8Spec(const nsAFlatCString &aSpec, const char *aCharset,
|
|
|
|
nsACString &aUTF8Spec)
|
|
|
|
{
|
|
|
|
aUTF8Spec.Truncate();
|
|
|
|
|
|
|
|
nsresult rv;
|
2002-09-08 19:08:45 +04:00
|
|
|
|
|
|
|
if (!mTextToSubURI) {
|
|
|
|
mTextToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
2002-07-24 03:28:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2002-09-08 19:08:45 +04:00
|
|
|
nsAutoString uStr;
|
|
|
|
rv = mTextToSubURI->UnEscapeNonAsciiURI(nsDependentCString(aCharset), aSpec, uStr);
|
2002-07-24 03:28:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-09-08 19:08:45 +04:00
|
|
|
if (!IsASCII(uStr))
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_EscapeURL(NS_ConvertUTF16toUTF8(uStr), esc_AlwaysCopy | esc_OnlyNonASCII, aUTF8Spec);
|
2002-07-24 03:28:28 +04:00
|
|
|
|
2002-09-08 19:08:45 +04:00
|
|
|
return NS_OK;
|
2002-07-24 03:28:28 +04:00
|
|
|
}
|
|
|
|
|
1999-07-13 03:46:40 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIProtocolHandler methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsJSProtocolHandler::GetScheme(nsACString &result)
|
1999-07-13 03:46:40 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = "javascript";
|
1999-07-13 03:46:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJSProtocolHandler::GetDefaultPort(int32_t *result)
|
1999-07-13 03:46:40 +04:00
|
|
|
{
|
|
|
|
*result = -1; // no port for javascript: URLs
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-08 00:42:57 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJSProtocolHandler::GetProtocolFlags(uint32_t *result)
|
2001-08-08 00:42:57 +04:00
|
|
|
{
|
2006-11-11 02:49:08 +03:00
|
|
|
*result = URI_NORELATIVE | URI_NOAUTH | URI_INHERITS_SECURITY_CONTEXT |
|
2009-01-15 23:07:53 +03:00
|
|
|
URI_LOADABLE_BY_ANYONE | URI_NON_PERSISTABLE | URI_OPENING_EXECUTES_SCRIPT;
|
2001-08-08 00:42:57 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-13 03:46:40 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsJSProtocolHandler::NewURI(const nsACString &aSpec,
|
2008-11-19 01:54:36 +03:00
|
|
|
const char *aCharset,
|
2002-03-06 10:48:55 +03:00
|
|
|
nsIURI *aBaseURI,
|
1999-07-13 03:46:40 +04:00
|
|
|
nsIURI **result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
// javascript: URLs (currently) have no additional structure beyond that
|
|
|
|
// provided by standard URLs, so there is no "outer" object given to
|
|
|
|
// CreateInstance.
|
1999-07-13 03:46:40 +04:00
|
|
|
|
2011-05-26 00:23:07 +04:00
|
|
|
nsCOMPtr<nsIURI> url = new nsJSURI(aBaseURI);
|
1999-07-13 03:46:40 +04:00
|
|
|
|
2002-07-24 03:28:28 +04:00
|
|
|
if (!aCharset || !nsCRT::strcasecmp("UTF-8", aCharset))
|
|
|
|
rv = url->SetSpec(aSpec);
|
2002-03-06 10:48:55 +03:00
|
|
|
else {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString utf8Spec;
|
2002-07-24 03:28:28 +04:00
|
|
|
rv = EnsureUTF8Spec(PromiseFlatCString(aSpec), aCharset, utf8Spec);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (utf8Spec.IsEmpty())
|
|
|
|
rv = url->SetSpec(aSpec);
|
|
|
|
else
|
|
|
|
rv = url->SetSpec(utf8Spec);
|
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
1999-07-13 03:46:40 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-05-26 00:23:07 +04:00
|
|
|
url.forget(result);
|
1999-07-13 03:46:40 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-23 04:16:57 +04:00
|
|
|
nsJSProtocolHandler::NewChannel2(nsIURI* uri,
|
|
|
|
nsILoadInfo* aLoadInfo,
|
|
|
|
nsIChannel** result)
|
1999-07-13 03:46:40 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2001-06-29 04:40:45 +04:00
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(uri);
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsJSChannel> channel = new nsJSChannel();
|
2001-06-29 04:40:45 +04:00
|
|
|
if (!channel) {
|
1999-10-13 11:17:36 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-05-31 17:57:02 +04:00
|
|
|
}
|
2001-06-29 04:40:45 +04:00
|
|
|
|
|
|
|
rv = channel->Init(uri);
|
2015-07-06 20:31:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-12-12 20:06:09 +03:00
|
|
|
|
|
|
|
// set the loadInfo on the new channel
|
|
|
|
rv = channel->SetLoadInfo(aLoadInfo);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2000-04-14 11:18:36 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2015-03-31 17:05:07 +03:00
|
|
|
channel.forget(result);
|
2000-04-14 11:18:36 +04:00
|
|
|
}
|
2001-06-29 04:40:45 +04:00
|
|
|
return rv;
|
1999-07-13 03:46:40 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 04:16:57 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
|
|
|
|
{
|
|
|
|
return NewChannel2(uri, nullptr, result);
|
|
|
|
}
|
|
|
|
|
2001-06-06 04:10:09 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJSProtocolHandler::AllowPort(int32_t port, const char *scheme, bool *_retval)
|
2001-06-06 04:10:09 +04:00
|
|
|
{
|
|
|
|
// don't override anything.
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2001-06-06 04:10:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-11-19 01:54:36 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// nsJSURI implementation
|
2011-05-26 00:23:07 +04:00
|
|
|
static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
|
|
|
|
NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
|
2008-11-19 01:54:36 +03:00
|
|
|
|
2011-05-26 00:23:07 +04:00
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsJSURI, mozilla::net::nsSimpleURI)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsJSURI, mozilla::net::nsSimpleURI)
|
2008-11-19 01:54:36 +03:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsJSURI)
|
|
|
|
if (aIID.Equals(kJSURICID))
|
|
|
|
foundInterface = static_cast<nsIURI*>(this);
|
2011-05-26 00:23:07 +04: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 18:20:58 +04:00
|
|
|
*aInstancePtr = nullptr;
|
2011-05-26 00:23:07 +04:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
2008-11-19 01:54:36 +03:00
|
|
|
else
|
2016-05-19 05:02:57 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(mozilla::net::nsSimpleURI)
|
2008-11-19 01:54:36 +03:00
|
|
|
|
|
|
|
// nsISerializable methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSURI::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
2016-05-19 05:02:57 +03:00
|
|
|
nsresult rv = mozilla::net::nsSimpleURI::Read(aStream);
|
2008-11-19 01:54:36 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveBase;
|
2008-11-19 01:54:36 +03:00
|
|
|
rv = aStream->ReadBoolean(&haveBase);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (haveBase) {
|
2014-03-15 23:00:17 +04:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
rv = aStream->ReadObject(true, getter_AddRefs(supports));
|
2008-11-19 01:54:36 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2014-03-15 23:00:17 +04:00
|
|
|
mBaseURI = do_QueryInterface(supports);
|
2008-11-19 01:54:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSURI::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
2016-05-19 05:02:57 +03:00
|
|
|
nsresult rv = mozilla::net::nsSimpleURI::Write(aStream);
|
2008-11-19 01:54:36 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = aStream->WriteBoolean(mBaseURI != nullptr);
|
2008-11-19 01:54:36 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (mBaseURI) {
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = aStream->WriteObject(mBaseURI, true);
|
2008-11-19 01:54:36 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-07 00:33:00 +03:00
|
|
|
// nsIIPCSerializableURI
|
|
|
|
void
|
|
|
|
nsJSURI::Serialize(mozilla::ipc::URIParams& aParams)
|
|
|
|
{
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
JSURIParams jsParams;
|
|
|
|
URIParams simpleParams;
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
mozilla::net::nsSimpleURI::Serialize(simpleParams);
|
2015-03-07 00:33:00 +03:00
|
|
|
|
|
|
|
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();
|
2016-05-19 05:02:57 +03:00
|
|
|
mozilla::net::nsSimpleURI::Deserialize(jsParams.simpleParams());
|
2015-03-07 00:33:00 +03:00
|
|
|
|
|
|
|
if (jsParams.baseURI().type() != OptionalURIParams::Tvoid_t) {
|
|
|
|
mBaseURI = DeserializeURI(jsParams.baseURI().get_URIParams());
|
|
|
|
} else {
|
|
|
|
mBaseURI = nullptr;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:20:06 +04:00
|
|
|
// nsSimpleURI methods:
|
2016-05-19 05:02:57 +03:00
|
|
|
/* virtual */ mozilla::net::nsSimpleURI*
|
2016-07-27 01:38:46 +03:00
|
|
|
nsJSURI::StartClone(mozilla::net::nsSimpleURI::RefHandlingEnum refHandlingMode,
|
|
|
|
const nsACString& newRef)
|
2008-11-19 01:54:36 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> baseClone;
|
|
|
|
if (mBaseURI) {
|
2011-05-26 12:20:06 +04:00
|
|
|
// Note: We preserve ref on *base* URI, regardless of ref handling mode.
|
2011-05-26 00:23:07 +04:00
|
|
|
nsresult rv = mBaseURI->Clone(getter_AddRefs(baseClone));
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-05-26 00:23:07 +04:00
|
|
|
}
|
2008-11-19 01:54:36 +03:00
|
|
|
}
|
|
|
|
|
2016-07-27 01:38:46 +03:00
|
|
|
nsJSURI* url = new nsJSURI(baseClone);
|
|
|
|
SetRefOnClone(url, refHandlingMode, newRef);
|
|
|
|
return url;
|
2008-11-19 01:54:36 +03:00
|
|
|
}
|
|
|
|
|
2011-05-26 12:20:06 +04:00
|
|
|
/* virtual */ nsresult
|
|
|
|
nsJSURI::EqualsInternal(nsIURI* aOther,
|
2016-05-19 05:02:57 +03:00
|
|
|
mozilla::net::nsSimpleURI::RefHandlingEnum aRefHandlingMode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aResult)
|
2011-04-28 03:10:01 +04:00
|
|
|
{
|
2011-05-26 12:20:06 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aOther);
|
|
|
|
NS_PRECONDITION(aResult, "null pointer for outparam");
|
2008-11-19 01:54:36 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsJSURI> otherJSURI;
|
2011-05-26 12:20:06 +04:00
|
|
|
nsresult rv = aOther->QueryInterface(kJSURICID,
|
|
|
|
getter_AddRefs(otherJSURI));
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aResult = false; // aOther is not a nsJSURI --> not equal.
|
2011-05-26 00:23:07 +04:00
|
|
|
return NS_OK;
|
2011-05-26 12:20:06 +04:00
|
|
|
}
|
2008-11-19 01:54:36 +03:00
|
|
|
|
2011-05-26 12:20:06 +04:00
|
|
|
// Compare the member data that our base class knows about.
|
2016-05-19 05:02:57 +03:00
|
|
|
if (!mozilla::net::nsSimpleURI::EqualsInternal(otherJSURI, aRefHandlingMode)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aResult = false;
|
2011-05-26 12:20:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-04-28 03:10:01 +04:00
|
|
|
|
2011-05-26 12:20:06 +04:00
|
|
|
// Compare the piece of additional member data that we add to base class.
|
|
|
|
nsIURI* otherBaseURI = otherJSURI->GetBaseURI();
|
2008-11-19 01:54:36 +03:00
|
|
|
|
2011-05-26 12:20:06 +04:00
|
|
|
if (mBaseURI) {
|
|
|
|
// (As noted in StartClone, we always honor refs on mBaseURI)
|
|
|
|
return mBaseURI->Equals(otherBaseURI, aResult);
|
2011-05-26 00:23:07 +04:00
|
|
|
}
|
2011-04-28 03:10:01 +04:00
|
|
|
|
2011-05-26 12:20:06 +04:00
|
|
|
*aResult = !otherBaseURI;
|
2008-11-19 01:54:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
|
|
|
{
|
|
|
|
*aClassIDNoAlloc = kJSURICID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-05-26 00:23:07 +04:00
|
|
|
|