2006-10-06 05:34:32 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=4 sw=4 et tw=78: */
|
2001-09-25 22:43:09 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-07-12 23:46:40 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-07-12 23:46:40 +00:00
|
|
|
*
|
2001-09-25 22:43:09 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-07-12 23:46:40 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 22:43:09 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2000-06-14 04:57:49 +00:00
|
|
|
* Contributor(s):
|
2000-01-11 20:49:15 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-25 22:43:09 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 22:43:09 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 22:43:09 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 22:43:09 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-10-13 07:17:36 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2003-05-15 01:23:26 +00:00
|
|
|
#include "nsAutoPtr.h"
|
1999-10-13 07:17:36 +00:00
|
|
|
#include "jsapi.h"
|
1999-07-12 23:46:40 +00:00
|
|
|
#include "nsCRT.h"
|
2001-06-29 00:40:45 +00:00
|
|
|
#include "nsDOMError.h"
|
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2001-06-29 00:40:45 +00:00
|
|
|
#include "nsJSProtocolHandler.h"
|
2006-01-02 03:31:39 +00:00
|
|
|
#include "nsStringStream.h"
|
2001-06-29 00:40:45 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
1999-07-12 23:46:40 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1999-08-26 22:45:55 +00:00
|
|
|
#include "nsIGenericFactory.h"
|
1999-07-12 23:46:40 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIScriptContext.h"
|
1999-10-20 00:12:04 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
1999-12-03 19:02:31 +00:00
|
|
|
#include "nsIScriptGlobalObjectOwner.h"
|
1999-09-15 20:58:41 +00:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-11-18 07:36:41 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-06-14 04:57:49 +00:00
|
|
|
#include "nsIWindowMediator.h"
|
2005-08-12 04:11:00 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2002-06-27 18:07:32 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
2001-07-13 07:08:26 +00:00
|
|
|
#include "nsIConsoleService.h"
|
2001-08-31 21:01:10 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2002-03-06 07:48:55 +00:00
|
|
|
#include "prprf.h"
|
2002-03-22 21:41:06 +00:00
|
|
|
#include "nsEscape.h"
|
2003-05-15 01:23:26 +00:00
|
|
|
#include "nsIWebNavigation.h"
|
2004-02-11 06:09:51 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIContentViewer.h"
|
2006-09-23 17:06:58 +00:00
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsJSUtils.h"
|
2006-10-17 00:55:14 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2006-12-13 15:52:55 +00:00
|
|
|
#include "nsIJSContextStack.h"
|
2007-02-16 01:01:39 +00:00
|
|
|
#include "nsIScriptChannel.h"
|
2007-07-02 23:48:51 +00:00
|
|
|
#include "nsIDocument.h"
|
2000-06-14 04:57:49 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
class nsJSThunk : public nsIInputStream
|
2001-06-29 00:40:45 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
public:
|
2001-06-29 00:40:45 +00:00
|
|
|
nsJSThunk();
|
|
|
|
|
(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 00:43:30 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_FORWARD_SAFE_NSIINPUTSTREAM(mInnerStream)
|
2001-06-29 00:40:45 +00:00
|
|
|
|
2002-08-21 23:01:23 +00:00
|
|
|
nsresult Init(nsIURI* uri);
|
2007-02-16 01:01:39 +00:00
|
|
|
nsresult EvaluateScript(nsIChannel *aChannel,
|
|
|
|
PopupControlState aPopupState,
|
2007-06-10 20:59:37 +00:00
|
|
|
PRUint32 aExecutionPolicy,
|
|
|
|
nsPIDOMWindow *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 00:43:30 +00:00
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
protected:
|
2001-06-29 00:40:45 +00:00
|
|
|
virtual ~nsJSThunk();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2003-01-18 02:15:14 +00:00
|
|
|
nsCOMPtr<nsIInputStream> mInnerStream;
|
1999-10-13 07:17:36 +00:00
|
|
|
};
|
1999-08-26 22:45:55 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
//
|
|
|
|
// nsISupports implementation...
|
|
|
|
//
|
2003-09-07 22:05:34 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsJSThunk, nsIInputStream)
|
2001-06-29 00:40:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
nsJSThunk::nsJSThunk()
|
1999-10-13 07:17:36 +00:00
|
|
|
{
|
|
|
|
}
|
1999-07-12 23:46:40 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
nsJSThunk::~nsJSThunk()
|
1999-10-13 07:17:36 +00:00
|
|
|
{
|
|
|
|
}
|
1999-07-12 23:46:40 +00:00
|
|
|
|
2002-08-21 23:01:23 +00:00
|
|
|
nsresult nsJSThunk::Init(nsIURI* uri)
|
2000-03-29 03:58:50 +00:00
|
|
|
{
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(uri);
|
|
|
|
|
|
|
|
mURI = uri;
|
2000-03-29 03:58:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-10-13 07:17:36 +00:00
|
|
|
|
2006-10-06 05:34:32 +00:00
|
|
|
static PRBool
|
|
|
|
IsISO88591(const nsString& aString)
|
|
|
|
{
|
|
|
|
for (nsString::const_char_iterator c = aString.BeginReading(),
|
|
|
|
c_end = aString.EndReading();
|
|
|
|
c < c_end; ++c) {
|
|
|
|
if (*c > 255)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-10-19 00:49:12 +00:00
|
|
|
static
|
|
|
|
nsIScriptGlobalObject* GetGlobalObject(nsIChannel* aChannel)
|
1999-07-12 23:46:40 +00:00
|
|
|
{
|
2006-10-19 00:49:12 +00:00
|
|
|
// Get the global object owner from the channel
|
2000-03-29 03:58:50 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner;
|
2004-11-15 20:16:52 +00:00
|
|
|
NS_QueryNotificationCallbacks(aChannel, globalOwner);
|
2004-03-10 01:18:26 +00:00
|
|
|
NS_ASSERTION(globalOwner,
|
2001-06-29 00:40:45 +00:00
|
|
|
"Unable to get an nsIScriptGlobalObjectOwner from the "
|
2004-03-10 01:18:26 +00:00
|
|
|
"channel!");
|
|
|
|
if (!globalOwner) {
|
2006-10-19 00:49:12 +00:00
|
|
|
return nsnull;
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
|
|
|
// So far so good: get the script context from its owner.
|
2004-07-16 17:03:10 +00:00
|
|
|
nsIScriptGlobalObject* global = globalOwner->GetScriptGlobalObject();
|
2001-06-29 00:40:45 +00:00
|
|
|
|
2004-07-16 17:03:10 +00:00
|
|
|
NS_ASSERTION(global,
|
2001-06-29 00:40:45 +00:00
|
|
|
"Unable to get an nsIScriptGlobalObject from the "
|
|
|
|
"ScriptGlobalObjectOwner!");
|
2006-10-19 00:49:12 +00:00
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel,
|
2007-02-16 01:01:39 +00:00
|
|
|
PopupControlState aPopupState,
|
2007-06-10 20:59:37 +00:00
|
|
|
PRUint32 aExecutionPolicy,
|
|
|
|
nsPIDOMWindow *aOriginalInnerWindow)
|
2006-10-19 00:49:12 +00:00
|
|
|
{
|
2007-02-16 01:01:39 +00:00
|
|
|
if (aExecutionPolicy == nsIScriptChannel::NO_EXECUTION) {
|
|
|
|
// Nothing to do here.
|
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2006-10-19 00:49:12 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
|
|
|
|
2007-02-16 01:01:39 +00:00
|
|
|
// Get principal of code for execution
|
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
aChannel->GetOwner(getter_AddRefs(owner));
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(owner);
|
|
|
|
if (!principal) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2006-10-19 00:49:12 +00:00
|
|
|
// Get the script string to evaluate...
|
|
|
|
nsCAutoString script;
|
2007-02-16 01:01:39 +00:00
|
|
|
nsresult rv = mURI->GetPath(script);
|
2006-10-19 00:49:12 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Get the global object we should be running on.
|
|
|
|
nsIScriptGlobalObject* global = GetGlobalObject(aChannel);
|
2004-07-16 17:03:10 +00:00
|
|
|
if (!global) {
|
2001-06-29 00:40:45 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(global));
|
2005-08-31 23:55:23 +00:00
|
|
|
|
2006-10-19 00:49:12 +00:00
|
|
|
// Push our popup control state
|
|
|
|
nsAutoPopupStatePusher popupStatePusher(win, aPopupState);
|
|
|
|
|
2007-06-10 20:59:37 +00:00
|
|
|
// Make sure we still have the same inner window as we used to.
|
|
|
|
nsPIDOMWindow *innerWin = win->GetCurrentInnerWindow();
|
2005-08-12 04:11:00 +00:00
|
|
|
|
2007-06-10 20:59:37 +00:00
|
|
|
if (innerWin != aOriginalInnerWindow) {
|
2005-08-12 04:11:00 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> innerGlobal = do_QueryInterface(innerWin);
|
|
|
|
|
|
|
|
JSObject *globalJSObject = innerGlobal->GetGlobalJSObject();
|
2003-05-12 22:23:52 +00:00
|
|
|
|
2002-08-21 23:01:23 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(global, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2006-10-19 00:49:12 +00:00
|
|
|
// So far so good: get the script context from its owner.
|
2004-05-18 04:00:47 +00:00
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext = global->GetContext();
|
2004-02-09 22:48:53 +00:00
|
|
|
if (!scriptContext)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-07-19 05:48:49 +00:00
|
|
|
|
2002-08-21 23:01:23 +00:00
|
|
|
// Unescape the script
|
|
|
|
NS_UnescapeURL(script);
|
|
|
|
|
|
|
|
// Get the url.
|
|
|
|
nsCAutoString url;
|
|
|
|
rv = mURI->GetSpec(url);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-07-13 07:08:26 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager;
|
|
|
|
securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2007-02-16 01:01:39 +00:00
|
|
|
PRBool useSandbox =
|
|
|
|
(aExecutionPolicy == nsIScriptChannel::EXECUTE_IN_SANDBOX);
|
2001-07-13 07:08:26 +00:00
|
|
|
|
2007-02-16 01:01:39 +00:00
|
|
|
if (!useSandbox) {
|
|
|
|
//-- Don't outside a sandbox unless the script principal subsumes the
|
|
|
|
// principal of the context.
|
2001-07-13 07:08:26 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> objectPrincipal;
|
2007-02-16 01:01:39 +00:00
|
|
|
rv = securityManager->
|
|
|
|
GetObjectPrincipal((JSContext*)scriptContext->GetNativeContext(),
|
|
|
|
globalJSObject,
|
|
|
|
getter_AddRefs(objectPrincipal));
|
2001-07-13 07:08:26 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-08-31 21:01:10 +00:00
|
|
|
|
2007-02-16 01:01:39 +00:00
|
|
|
PRBool subsumes;
|
|
|
|
rv = principal->Subsumes(objectPrincipal, &subsumes);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
useSandbox = !subsumes;
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
1999-10-13 07:17:36 +00:00
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
nsString result;
|
2006-09-23 17:06:58 +00:00
|
|
|
PRBool isUndefined;
|
|
|
|
|
|
|
|
// Finally, we have everything needed to evaluate the expression.
|
|
|
|
|
|
|
|
if (useSandbox) {
|
2007-02-16 01:01:39 +00:00
|
|
|
// We were asked to use a sandbox, or the channel owner isn't allowed
|
|
|
|
// to execute in this context. Evaluate the javascript URL in a
|
|
|
|
// sandbox to prevent it from accessing data it doesn't have
|
|
|
|
// permissions to access.
|
2003-05-12 22:23:52 +00:00
|
|
|
|
2007-01-30 16:38:15 +00:00
|
|
|
// First check to make sure it's OK to evaluate this script to
|
|
|
|
// start with. For example, script could be disabled.
|
2006-09-23 17:06:58 +00:00
|
|
|
JSContext *cx = (JSContext*)scriptContext->GetNativeContext();
|
2007-01-30 16:38:15 +00:00
|
|
|
|
|
|
|
PRBool ok;
|
|
|
|
rv = securityManager->CanExecuteScripts(cx, principal, &ok);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
// Treat this as returning undefined from the script. That's what
|
|
|
|
// nsJSContext does.
|
|
|
|
return NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIXPConnect *xpc = nsContentUtils::XPConnect();
|
|
|
|
|
2006-09-23 17:06:58 +00:00
|
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> sandbox;
|
|
|
|
rv = xpc->CreateSandbox(cx, principal, getter_AddRefs(sandbox));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
jsval rval = JSVAL_VOID;
|
|
|
|
nsAutoGCRoot root(&rval, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-12-13 15:52:55 +00:00
|
|
|
// Push our JSContext on the context stack so the JS_ValueToString call (and
|
|
|
|
// JS_ReportPendingException, if relevant) will use the principal of cx.
|
|
|
|
// Note that we do this as late as possible to make popping simpler.
|
|
|
|
nsCOMPtr<nsIJSContextStack> stack =
|
|
|
|
do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = stack->Push(cx);
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-09-23 17:06:58 +00:00
|
|
|
rv = xpc->EvalInSandboxObject(NS_ConvertUTF8toUTF16(script), cx,
|
|
|
|
sandbox, &rval);
|
|
|
|
|
|
|
|
// Propagate and report exceptions that happened in the
|
|
|
|
// sandbox.
|
|
|
|
if (JS_IsExceptionPending(cx)) {
|
|
|
|
JS_ReportPendingException(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
isUndefined = rval == JSVAL_VOID;
|
|
|
|
|
|
|
|
if (!isUndefined && NS_SUCCEEDED(rv)) {
|
|
|
|
JSAutoRequest ar(cx);
|
|
|
|
|
|
|
|
JSString *str = JS_ValueToString(cx, rval);
|
|
|
|
if (!str) {
|
|
|
|
// Report any pending exceptions.
|
|
|
|
if (JS_IsExceptionPending(cx)) {
|
|
|
|
JS_ReportPendingException(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't know why this failed, so just use a
|
|
|
|
// generic error code. It'll be translated to a
|
|
|
|
// different one below anyways.
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
|
|
|
result = nsDependentJSString(str);
|
|
|
|
}
|
|
|
|
}
|
2006-12-13 15:52:55 +00:00
|
|
|
|
|
|
|
stack->Pop(nsnull);
|
2006-09-23 17:06:58 +00:00
|
|
|
} else {
|
|
|
|
// No need to use the sandbox, evaluate the script directly in
|
|
|
|
// the given scope.
|
|
|
|
rv = scriptContext->EvaluateString(NS_ConvertUTF8toUTF16(script),
|
|
|
|
globalJSObject, // obj
|
|
|
|
principal,
|
|
|
|
url.get(), // url
|
|
|
|
1, // line no
|
|
|
|
nsnull,
|
|
|
|
&result,
|
|
|
|
&isUndefined);
|
2000-06-14 04:57:49 +00:00
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
// 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((JSContext*)scriptContext->GetNativeContext());
|
|
|
|
}
|
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
rv = NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
2006-09-23 17:06:58 +00:00
|
|
|
else if (isUndefined) {
|
2001-06-29 00:40:45 +00:00
|
|
|
rv = NS_ERROR_DOM_RETVAL_UNDEFINED;
|
|
|
|
}
|
|
|
|
else {
|
2006-10-06 05:34:32 +00:00
|
|
|
char *bytes;
|
|
|
|
PRUint32 bytesLen;
|
|
|
|
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 19:12:26 +00:00
|
|
|
rv = NS_NewByteInputStream(getter_AddRefs(mInnerStream),
|
2006-10-06 05:34:32 +00:00
|
|
|
bytes, bytesLen,
|
2006-05-04 19:12:26 +00:00
|
|
|
NS_ASSIGNMENT_ADOPT);
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2006-09-23 17:06:58 +00:00
|
|
|
|
1999-07-12 23:46:40 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-07-19 00:53:11 +00:00
|
|
|
class nsJSChannel : public nsIChannel,
|
2007-02-16 01:01:39 +00:00
|
|
|
public nsIStreamListener,
|
|
|
|
public nsIScriptChannel
|
2000-03-29 03:58:50 +00:00
|
|
|
{
|
|
|
|
public:
|
2001-06-29 00:40:45 +00:00
|
|
|
nsJSChannel();
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_DECL_NSIREQUEST
|
|
|
|
NS_DECL_NSICHANNEL
|
2006-07-19 00:53:11 +00:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2007-02-16 01:01:39 +00:00
|
|
|
NS_DECL_NSISCRIPTCHANNEL
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
nsresult Init(nsIURI *aURI);
|
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
// Actually evaluate the script.
|
|
|
|
void EvaluateScript();
|
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
protected:
|
|
|
|
virtual ~nsJSChannel();
|
|
|
|
|
2003-05-15 01:23:26 +00:00
|
|
|
nsresult StopAll();
|
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
void NotifyListener();
|
2007-07-02 23:48:51 +00:00
|
|
|
|
|
|
|
void CleanupStrongRefs();
|
2006-10-17 00:55:14 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIChannel> mStreamChannel;
|
2006-07-19 00:53:11 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener; // Our final listener
|
2006-10-17 00:55:14 +00:00
|
|
|
nsCOMPtr<nsISupports> mContext; // The context passed to AsyncOpen
|
2007-06-10 20:59:37 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> mOriginalInnerWindow; // The inner window our load
|
|
|
|
// started against.
|
2007-07-02 23:48:51 +00:00
|
|
|
// If we blocked onload on a document in AsyncOpen, this is the document we
|
|
|
|
// did it on.
|
|
|
|
nsCOMPtr<nsIDocument> mDocumentOnloadBlockedOn;
|
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
nsresult mStatus; // Our status
|
2001-06-29 00:40:45 +00:00
|
|
|
|
2003-05-21 21:37:25 +00:00
|
|
|
nsLoadFlags mLoadFlags;
|
2006-10-17 00:55:14 +00:00
|
|
|
nsLoadFlags mActualLoadFlags; // See AsyncOpen
|
2003-05-21 21:37:25 +00:00
|
|
|
|
2003-05-15 01:23:26 +00:00
|
|
|
nsRefPtr<nsJSThunk> mIOThunk;
|
2006-10-19 00:49:12 +00:00
|
|
|
PopupControlState mPopupState;
|
2007-02-16 01:01:39 +00:00
|
|
|
PRUint32 mExecutionPolicy;
|
2007-06-13 22:42:07 +00:00
|
|
|
PRPackedBool mIsAsync;
|
2003-05-21 21:37:25 +00:00
|
|
|
PRPackedBool mIsActive;
|
2007-02-16 01:01:39 +00:00
|
|
|
PRPackedBool mOpenedStreamChannel;
|
2001-06-29 00:40:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nsJSChannel::nsJSChannel() :
|
2006-10-17 00:55:14 +00:00
|
|
|
mStatus(NS_OK),
|
2003-07-14 21:06:21 +00:00
|
|
|
mLoadFlags(LOAD_NORMAL),
|
2006-10-17 00:55:14 +00:00
|
|
|
mActualLoadFlags(LOAD_NORMAL),
|
2006-10-19 00:49:12 +00:00
|
|
|
mPopupState(openOverridden),
|
2007-04-05 22:49:32 +00:00
|
|
|
mExecutionPolicy(EXECUTE_IN_SANDBOX),
|
2007-06-13 22:42:07 +00:00
|
|
|
mIsAsync(PR_TRUE),
|
2003-05-21 21:37:25 +00:00
|
|
|
mIsActive(PR_FALSE),
|
2006-10-17 00:55:14 +00:00
|
|
|
mOpenedStreamChannel(PR_FALSE)
|
2001-06-29 00:40:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJSChannel::~nsJSChannel()
|
|
|
|
{
|
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2003-05-15 01:23:26 +00:00
|
|
|
nsresult nsJSChannel::StopAll()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_UNEXPECTED;
|
2004-03-10 01:18:26 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav;
|
2004-11-15 20:16:52 +00:00
|
|
|
NS_QueryNotificationCallbacks(mStreamChannel, webNav);
|
2003-05-15 01:23:26 +00:00
|
|
|
|
2004-03-10 01:18:26 +00:00
|
|
|
NS_ASSERTION(webNav, "Can't get nsIWebNavigation from channel!");
|
2003-05-15 01:23:26 +00:00
|
|
|
if (webNav) {
|
|
|
|
rv = webNav->Stop(nsIWebNavigation::STOP_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2001-06-29 00:40:45 +00:00
|
|
|
|
|
|
|
nsresult nsJSChannel::Init(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2003-05-15 01:23:26 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
// Create the nsIStreamIO layer used by the nsIStreamIOChannel.
|
2003-05-15 01:23:26 +00:00
|
|
|
mIOThunk = new nsJSThunk();
|
|
|
|
if (!mIOThunk)
|
2001-06-29 00:40:45 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// Create a stock input stream channel...
|
2001-06-29 00:40:45 +00:00
|
|
|
// Remember, until AsyncOpen is called, the script will not be evaluated
|
|
|
|
// and the underlying Input Stream will not be created...
|
2003-01-18 02:15:14 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2001-06-29 00:40:45 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// If the resultant script evaluation actually does return a value, we
|
|
|
|
// treat it as html.
|
|
|
|
rv = NS_NewInputStreamChannel(getter_AddRefs(channel), aURI, mIOThunk,
|
2006-10-06 05:34:32 +00:00
|
|
|
NS_LITERAL_CSTRING("text/html"));
|
2001-06-29 00:40:45 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-08-21 23:01:23 +00:00
|
|
|
rv = mIOThunk->Init(aURI);
|
2001-06-29 00:40:45 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-01-18 02:15:14 +00:00
|
|
|
mStreamChannel = channel;
|
2000-03-29 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsISupports implementation...
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsJSChannel)
|
|
|
|
NS_IMPL_RELEASE(nsJSChannel)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsJSChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIChannel)
|
2006-07-19 00:53:11 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
2007-02-16 01:01:39 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptChannel)
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsIRequest implementation...
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsJSChannel::GetName(nsACString &aResult)
|
2001-06-29 00:40:45 +00:00
|
|
|
{
|
|
|
|
return mStreamChannel->GetName(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::IsPending(PRBool *aResult)
|
|
|
|
{
|
2003-05-21 21:37:25 +00:00
|
|
|
*aResult = mIsActive;
|
|
|
|
return NS_OK;
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetStatus(nsresult *aResult)
|
|
|
|
{
|
2006-10-17 00:55:14 +00:00
|
|
|
*aResult = mStatus;
|
2003-05-21 21:37:25 +00:00
|
|
|
return NS_OK;
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-06-24 00:03:10 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::Cancel(nsresult aStatus)
|
|
|
|
{
|
2006-10-17 00:55:14 +00:00
|
|
|
mStatus = aStatus;
|
2003-05-15 01:23:26 +00:00
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
if (mOpenedStreamChannel) {
|
|
|
|
mStreamChannel->Cancel(aStatus);
|
|
|
|
}
|
|
|
|
|
2003-05-21 21:37:25 +00:00
|
|
|
return NS_OK;
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
2003-05-21 21:37:25 +00:00
|
|
|
nsJSChannel::Suspend()
|
2001-06-29 00:40:45 +00:00
|
|
|
{
|
2003-10-30 21:23:15 +00:00
|
|
|
return mStreamChannel->Suspend();
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
2003-05-21 21:37:25 +00:00
|
|
|
nsJSChannel::Resume()
|
2001-06-29 00:40:45 +00:00
|
|
|
{
|
2003-10-30 21:23:15 +00:00
|
|
|
return mStreamChannel->Resume();
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-06-24 00:03:10 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
//
|
|
|
|
// nsIChannel implementation
|
|
|
|
//
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetOriginalURI(nsIURI * *aURI)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetOriginalURI(aURI);
|
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetOriginalURI(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetOriginalURI(aURI);
|
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetURI(nsIURI * *aURI)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetURI(aURI);
|
|
|
|
}
|
2000-06-14 04:57:49 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
2001-08-21 06:20:53 +00:00
|
|
|
nsJSChannel::Open(nsIInputStream **aResult)
|
2001-06-29 00:40:45 +00:00
|
|
|
{
|
2007-02-16 01:01:39 +00:00
|
|
|
nsresult rv = mIOThunk->EvaluateScript(mStreamChannel, mPopupState,
|
2007-06-10 20:59:37 +00:00
|
|
|
mExecutionPolicy,
|
|
|
|
mOriginalInnerWindow);
|
2006-10-17 00:55:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return mStreamChannel->Open(aResult);
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
|
|
|
|
{
|
2006-10-17 00:55:14 +00:00
|
|
|
NS_ENSURE_ARG(aListener);
|
2007-06-10 20:59:37 +00: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;
|
|
|
|
}
|
2006-10-17 00:55:14 +00:00
|
|
|
|
2006-07-19 00:53:11 +00:00
|
|
|
mListener = aListener;
|
2006-10-17 00:55:14 +00:00
|
|
|
mContext = aContext;
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
mIsActive = PR_TRUE;
|
2001-07-06 19:40:23 +00:00
|
|
|
|
2004-10-28 02:06:27 +00: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 00:55:14 +00:00
|
|
|
mActualLoadFlags = mLoadFlags;
|
2004-10-28 02:06:27 +00:00
|
|
|
mLoadFlags |= LOAD_BACKGROUND;
|
|
|
|
|
2003-05-21 21:37:25 +00:00
|
|
|
// Add the javascript channel to its loadgroup so that we know if
|
|
|
|
// network loads were canceled or not...
|
2006-10-17 00:55:14 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2003-05-21 21:37:25 +00:00
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (loadGroup) {
|
2006-10-17 00:55:14 +00:00
|
|
|
loadGroup->AddRequest(this, nsnull);
|
|
|
|
}
|
|
|
|
|
2007-07-02 23:48:51 +00:00
|
|
|
mDocumentOnloadBlockedOn =
|
|
|
|
do_QueryInterface(mOriginalInnerWindow->GetExtantDocument());
|
|
|
|
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 19:39:51 +00:00
|
|
|
// LOAD_DOCUMENT_URI flag, so a docloader we're loading in as the
|
2007-07-02 23:48:51 +00: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 22:42:07 +00:00
|
|
|
mPopupState = win->GetPopupControlState();
|
|
|
|
|
|
|
|
nsRunnableMethod<nsJSChannel>::Method method;
|
|
|
|
if (mIsAsync) {
|
|
|
|
// post an event to do the rest
|
|
|
|
method = &nsJSChannel::EvaluateScript;
|
|
|
|
} else {
|
|
|
|
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 23:48:51 +00:00
|
|
|
CleanupStrongRefs();
|
2007-06-13 22:42:07 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> ev = new nsRunnableMethod<nsJSChannel>(this, method);
|
2006-10-17 00:55:14 +00:00
|
|
|
nsresult rv = NS_DispatchToCurrentThread(ev);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
loadGroup->RemoveRequest(this, nsnull, rv);
|
|
|
|
mIsActive = PR_FALSE;
|
2007-07-02 23:48:51 +00:00
|
|
|
CleanupStrongRefs();
|
2003-05-21 21:37:25 +00:00
|
|
|
}
|
2006-10-17 00:55:14 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJSChannel::EvaluateScript()
|
|
|
|
{
|
2001-06-29 00:40:45 +00: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 05:18:15 +00:00
|
|
|
|
2006-10-17 00:55:14 +00: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 01:01:39 +00:00
|
|
|
nsresult rv = mIOThunk->EvaluateScript(mStreamChannel, mPopupState,
|
2007-06-10 20:59:37 +00:00
|
|
|
mExecutionPolicy,
|
|
|
|
mOriginalInnerWindow);
|
2006-10-17 00:55:14 +00:00
|
|
|
|
|
|
|
// Note that evaluation may have canceled us, so recheck mStatus again
|
|
|
|
if (NS_FAILED(rv) && NS_SUCCEEDED(mStatus)) {
|
|
|
|
mStatus = rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-21 21:37:25 +00:00
|
|
|
// Remove the javascript channel from its loadgroup...
|
2006-10-17 00:55:14 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
mStreamChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
2003-05-21 21:37:25 +00:00
|
|
|
if (loadGroup) {
|
2006-10-17 00:55:14 +00:00
|
|
|
loadGroup->RemoveRequest(this, nsnull, mStatus);
|
2003-05-21 21:37:25 +00:00
|
|
|
}
|
2003-05-15 01:23:26 +00:00
|
|
|
|
2004-10-28 02:06:27 +00:00
|
|
|
// Reset load flags to their original value...
|
2006-10-17 00:55:14 +00:00
|
|
|
mLoadFlags = mActualLoadFlags;
|
2004-10-28 02:06:27 +00:00
|
|
|
|
2003-05-21 21:37:25 +00:00
|
|
|
// We're no longer active, it's now up to the stream channel to do
|
|
|
|
// the loading, if needed.
|
|
|
|
mIsActive = PR_FALSE;
|
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
if (NS_FAILED(mStatus)) {
|
2007-06-13 22:42:07 +00:00
|
|
|
if (mIsAsync) {
|
|
|
|
NotifyListener();
|
|
|
|
}
|
2006-10-17 00:55:14 +00: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);
|
|
|
|
|
|
|
|
if (loadFlags & LOAD_DOCUMENT_URI) {
|
|
|
|
// We're loaded as the document channel. If we go on,
|
|
|
|
// we'll blow away the current document. Make sure that's
|
|
|
|
// ok. If so, stop all pending network loads.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
NS_QueryNotificationCallbacks(mStreamChannel, docShell);
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
|
|
|
|
if (cv) {
|
|
|
|
PRBool okToUnload;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(cv->PermitUnload(&okToUnload)) &&
|
|
|
|
!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 06:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-15 19:38:35 +00:00
|
|
|
}
|
2003-05-15 01:23:26 +00:00
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
if (NS_SUCCEEDED(mStatus)) {
|
|
|
|
mStatus = StopAll();
|
2003-05-15 01:23:26 +00:00
|
|
|
}
|
2004-02-11 06:09:51 +00:00
|
|
|
}
|
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
if (NS_FAILED(mStatus)) {
|
2007-06-13 22:42:07 +00:00
|
|
|
if (mIsAsync) {
|
|
|
|
NotifyListener();
|
|
|
|
}
|
2006-10-17 00:55:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mStatus = mStreamChannel->AsyncOpen(this, mContext);
|
2007-06-13 22:42:07 +00:00
|
|
|
if (NS_SUCCEEDED(mStatus)) {
|
2006-10-17 00:55:14 +00:00
|
|
|
// mStreamChannel will call OnStartRequest and OnStopRequest on
|
|
|
|
// us, so we'll be sure to call them on our listener.
|
|
|
|
mOpenedStreamChannel = PR_TRUE;
|
2007-06-13 22:42:07 +00:00
|
|
|
} else if (mIsAsync) {
|
|
|
|
NotifyListener();
|
2000-03-29 03:58:50 +00:00
|
|
|
}
|
2001-07-06 19:40:23 +00:00
|
|
|
|
2006-10-17 00:55:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJSChannel::NotifyListener()
|
|
|
|
{
|
2007-07-02 23:48:51 +00:00
|
|
|
mListener->OnStartRequest(this, mContext);
|
|
|
|
mListener->OnStopRequest(this, mContext, mStatus);
|
2006-10-17 00:55:14 +00:00
|
|
|
|
2007-07-02 23:48:51 +00:00
|
|
|
CleanupStrongRefs();
|
|
|
|
}
|
2006-10-17 00:55:14 +00:00
|
|
|
|
2007-07-02 23:48:51 +00:00
|
|
|
void
|
|
|
|
nsJSChannel::CleanupStrongRefs()
|
|
|
|
{
|
|
|
|
mListener = nsnull;
|
2006-10-17 00:55:14 +00:00
|
|
|
mContext = nsnull;
|
2007-06-10 20:59:37 +00:00
|
|
|
mOriginalInnerWindow = nsnull;
|
2007-07-02 23:48:51 +00:00
|
|
|
if (mDocumentOnloadBlockedOn) {
|
|
|
|
mDocumentOnloadBlockedOn->UnblockOnload(PR_FALSE);
|
|
|
|
mDocumentOnloadBlockedOn = nsnull;
|
|
|
|
}
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
|
|
|
{
|
2003-05-21 21:37:25 +00:00
|
|
|
*aLoadFlags = mLoadFlags;
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-04-21 05:18:15 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
|
|
|
|
{
|
2003-05-21 21:37:25 +00: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 00:55:14 +00: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-21 21:37:25 +00:00
|
|
|
mLoadFlags = aLoadFlags & ~LOAD_DOCUMENT_URI;
|
|
|
|
|
|
|
|
// ... 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 01:23:26 +00:00
|
|
|
return mStreamChannel->SetLoadFlags(aLoadFlags);
|
2001-06-29 00:40:45 +00:00
|
|
|
}
|
2000-04-21 05:18:15 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetLoadGroup(aLoadGroup);
|
|
|
|
}
|
2000-04-21 05:18:15 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetLoadGroup(aLoadGroup);
|
|
|
|
}
|
2000-04-21 05:18:15 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetOwner(nsISupports* *aOwner)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetOwner(aOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetOwner(nsISupports* aOwner)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetOwner(aOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-20 22:50:33 +00:00
|
|
|
nsJSChannel::GetContentType(nsACString &aContentType)
|
2001-06-29 00:40:45 +00:00
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentType(aContentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsJSChannel::SetContentType(const nsACString &aContentType)
|
2001-06-29 00:40:45 +00:00
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentType(aContentType);
|
|
|
|
}
|
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetContentCharset(nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentCharset(aContentCharset);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetContentCharset(const nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentCharset(aContentCharset);
|
|
|
|
}
|
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetContentLength(PRInt32 *aContentLength)
|
|
|
|
{
|
|
|
|
return mStreamChannel->GetContentLength(aContentLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetContentLength(PRInt32 aContentLength)
|
|
|
|
{
|
|
|
|
return mStreamChannel->SetContentLength(aContentLength);
|
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2006-07-19 00:53:11 +00: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,
|
|
|
|
PRUint32 aOffset,
|
|
|
|
PRUint32 aCount)
|
|
|
|
{
|
|
|
|
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 13:27:53 +00:00
|
|
|
NS_ENSURE_TRUE(aRequest == mStreamChannel, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2007-07-02 23:48:51 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> listener = mListener;
|
2006-10-17 00:55:14 +00:00
|
|
|
|
2007-07-02 23:48:51 +00:00
|
|
|
CleanupStrongRefs();
|
2006-07-19 00:53:11 +00:00
|
|
|
|
|
|
|
return listener->OnStopRequest(this, aContext, aStatus);
|
|
|
|
}
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2007-02-16 01:01:39 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetExecutionPolicy(PRUint32 aPolicy)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aPolicy <= EXECUTE_NORMAL);
|
|
|
|
|
|
|
|
mExecutionPolicy = aPolicy;
|
2007-02-16 01:45:16 +00:00
|
|
|
return NS_OK;
|
2007-02-16 01:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetExecutionPolicy(PRUint32* aPolicy)
|
|
|
|
{
|
|
|
|
*aPolicy = mExecutionPolicy;
|
2007-02-16 01:45:16 +00:00
|
|
|
return NS_OK;
|
2007-02-16 01:01:39 +00:00
|
|
|
}
|
|
|
|
|
2007-06-13 22:42:07 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::SetExecuteAsync(PRBool aIsAsync)
|
|
|
|
{
|
|
|
|
if (!mIsActive) {
|
|
|
|
mIsAsync = aIsAsync;
|
|
|
|
}
|
|
|
|
// else ignore this call
|
|
|
|
NS_WARN_IF_FALSE(!mIsActive, "Calling SetExecuteAsync on active channel?");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSChannel::GetExecuteAsync(PRBool* aIsAsync)
|
|
|
|
{
|
|
|
|
*aIsAsync = mIsAsync;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-07-12 23:46:40 +00:00
|
|
|
nsJSProtocolHandler::nsJSProtocolHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsJSProtocolHandler::Init()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJSProtocolHandler::~nsJSProtocolHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-08-21 01:48:11 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsJSProtocolHandler, nsIProtocolHandler)
|
1999-07-12 23:46:40 +00:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsJSProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|
|
|
{
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
nsJSProtocolHandler* ph = new nsJSProtocolHandler();
|
1999-08-26 22:45:55 +00:00
|
|
|
if (!ph)
|
1999-07-12 23:46:40 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-07-23 23:28:28 +00:00
|
|
|
nsresult
|
|
|
|
nsJSProtocolHandler::EnsureUTF8Spec(const nsAFlatCString &aSpec, const char *aCharset,
|
|
|
|
nsACString &aUTF8Spec)
|
|
|
|
{
|
|
|
|
aUTF8Spec.Truncate();
|
|
|
|
|
|
|
|
nsresult rv;
|
2002-09-08 15:08:45 +00:00
|
|
|
|
|
|
|
if (!mTextToSubURI) {
|
|
|
|
mTextToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
2002-07-23 23:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2002-09-08 15:08:45 +00:00
|
|
|
nsAutoString uStr;
|
|
|
|
rv = mTextToSubURI->UnEscapeNonAsciiURI(nsDependentCString(aCharset), aSpec, uStr);
|
2002-07-23 23:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-09-08 15:08:45 +00:00
|
|
|
if (!IsASCII(uStr))
|
2006-02-03 14:18:39 +00:00
|
|
|
NS_EscapeURL(NS_ConvertUTF16toUTF8(uStr), esc_AlwaysCopy | esc_OnlyNonASCII, aUTF8Spec);
|
2002-07-23 23:28:28 +00:00
|
|
|
|
2002-09-08 15:08:45 +00:00
|
|
|
return NS_OK;
|
2002-07-23 23:28:28 +00:00
|
|
|
}
|
|
|
|
|
1999-07-12 23:46:40 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIProtocolHandler methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 07:48:55 +00:00
|
|
|
nsJSProtocolHandler::GetScheme(nsACString &result)
|
1999-07-12 23:46:40 +00:00
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
result = "javascript";
|
1999-07-12 23:46:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSProtocolHandler::GetDefaultPort(PRInt32 *result)
|
|
|
|
{
|
|
|
|
*result = -1; // no port for javascript: URLs
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-07 20:42:57 +00:00
|
|
|
NS_IMETHODIMP
|
2001-09-13 02:21:05 +00:00
|
|
|
nsJSProtocolHandler::GetProtocolFlags(PRUint32 *result)
|
2001-08-07 20:42:57 +00:00
|
|
|
{
|
2006-11-10 23:49:08 +00:00
|
|
|
*result = URI_NORELATIVE | URI_NOAUTH | URI_INHERITS_SECURITY_CONTEXT |
|
2007-04-15 12:31:18 +00:00
|
|
|
URI_LOADABLE_BY_ANYONE | URI_NON_PERSISTABLE;
|
2001-08-07 20:42:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-12 23:46:40 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 07:48:55 +00:00
|
|
|
nsJSProtocolHandler::NewURI(const nsACString &aSpec,
|
|
|
|
const char *aCharset, // ignore charset info
|
|
|
|
nsIURI *aBaseURI,
|
1999-07-12 23:46:40 +00:00
|
|
|
nsIURI **result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-08-26 22:45:55 +00: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-12 23:46:40 +00:00
|
|
|
|
|
|
|
nsIURI* url;
|
2006-06-18 21:18:22 +00:00
|
|
|
rv = CallCreateInstance(NS_SIMPLEURI_CONTRACTID, &url);
|
2002-09-02 22:15:07 +00:00
|
|
|
|
1999-08-26 22:45:55 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-07-12 23:46:40 +00:00
|
|
|
|
2002-07-23 23:28:28 +00:00
|
|
|
if (!aCharset || !nsCRT::strcasecmp("UTF-8", aCharset))
|
|
|
|
rv = url->SetSpec(aSpec);
|
2002-03-06 07:48:55 +00:00
|
|
|
else {
|
2002-07-23 23:28:28 +00:00
|
|
|
nsCAutoString utf8Spec;
|
|
|
|
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 07:48:55 +00:00
|
|
|
}
|
|
|
|
|
1999-07-12 23:46:40 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = url;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 03:58:50 +00:00
|
|
|
nsJSProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
|
1999-07-12 23:46:40 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2001-06-29 00:40:45 +00:00
|
|
|
nsJSChannel * channel;
|
|
|
|
|
2000-03-29 03:58:50 +00: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 00:43:30 +00:00
|
|
|
|
2001-06-29 00:40:45 +00:00
|
|
|
channel = new nsJSChannel();
|
|
|
|
if (!channel) {
|
1999-10-13 07:17:36 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-05-31 13:57:02 +00:00
|
|
|
}
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_ADDREF(channel);
|
|
|
|
|
|
|
|
rv = channel->Init(uri);
|
2000-04-14 07:18:36 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-06-29 00:40:45 +00:00
|
|
|
*result = channel;
|
|
|
|
NS_ADDREF(*result);
|
2000-04-14 07:18:36 +00:00
|
|
|
}
|
2001-06-29 00:40:45 +00:00
|
|
|
NS_RELEASE(channel);
|
|
|
|
return rv;
|
1999-07-12 23:46:40 +00:00
|
|
|
}
|
|
|
|
|
2001-06-06 00:10:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJSProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval)
|
|
|
|
{
|
|
|
|
// don't override anything.
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|