2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsXBLDocumentInfo.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsXBLPrototypeBinding.h"
|
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptRuntime.h"
|
|
|
|
#include "nsIDOMScriptObjectFactory.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIChromeRegistry.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2012-10-25 08:01:07 -07:00
|
|
|
#include "nsJSPrincipals.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDOMJSUtils.h"
|
2010-05-14 02:24:41 -07:00
|
|
|
#include "mozilla/Services.h"
|
2010-09-02 23:22:18 -07:00
|
|
|
#include "xpcpublic.h"
|
2011-11-03 13:39:08 -07:00
|
|
|
#include "mozilla/scache/StartupCache.h"
|
|
|
|
#include "mozilla/scache/StartupCacheUtils.h"
|
2012-01-13 04:44:14 -08:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2012-05-02 21:35:38 -07:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-10-26 10:49:57 -07:00
|
|
|
#include "mozilla/Util.h"
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
using namespace mozilla::scache;
|
2012-03-28 06:14:33 -07:00
|
|
|
using namespace mozilla;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
static const char kXBLCachePrefix[] = "xblcache";
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
|
|
|
|
|
|
|
|
// An XBLDocumentInfo object has a special context associated with it which we can use to pre-compile
|
|
|
|
// properties and methods of XBL bindings against.
|
|
|
|
class nsXBLDocGlobalObject : public nsIScriptGlobalObject,
|
|
|
|
public nsIScriptObjectPrincipal
|
|
|
|
{
|
|
|
|
public:
|
2012-05-16 10:42:10 -07:00
|
|
|
nsXBLDocGlobalObject(nsXBLDocumentInfo *aGlobalObjectOwner);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIScriptGlobalObject methods
|
2012-03-23 10:13:29 -07:00
|
|
|
virtual nsresult EnsureScriptEnvironment();
|
2012-05-05 02:00:04 -07:00
|
|
|
void ClearScriptContext()
|
|
|
|
{
|
|
|
|
mScriptContext = NULL;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
virtual nsIScriptContext *GetContext();
|
|
|
|
virtual JSObject *GetGlobalJSObject();
|
2011-04-14 05:04:08 -07:00
|
|
|
virtual void OnFinalize(JSObject* aObject);
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual void SetScriptsEnabled(bool aEnabled, bool aFireTimeouts);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIScriptObjectPrincipal methods
|
|
|
|
virtual nsIPrincipal* GetPrincipal();
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
static JSBool doCheckAccess(JSContext *cx, JSObject *obj, jsid id,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t accessType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXBLDocGlobalObject,
|
|
|
|
nsIScriptGlobalObject)
|
|
|
|
|
2007-08-09 15:30:30 -07:00
|
|
|
void ClearGlobalObjectOwner();
|
|
|
|
|
2012-03-18 07:17:05 -07:00
|
|
|
void UnmarkScriptContext();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
virtual ~nsXBLDocGlobalObject();
|
|
|
|
|
2012-03-23 10:13:29 -07:00
|
|
|
nsIScriptContext *GetScriptContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContext> mScriptContext;
|
2012-03-23 10:13:29 -07:00
|
|
|
JSObject *mJSObject;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-16 10:42:10 -07:00
|
|
|
nsXBLDocumentInfo* mGlobalObjectOwner; // weak reference
|
2007-03-22 10:30:00 -07:00
|
|
|
static JSClass gSharedGlobalClass;
|
|
|
|
};
|
|
|
|
|
|
|
|
JSBool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLDocGlobalObject::doCheckAccess(JSContext *cx, JSObject *obj, jsid id, uint32_t accessType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIScriptSecurityManager *ssm = nsContentUtils::GetSecurityManager();
|
|
|
|
if (!ssm) {
|
|
|
|
::JS_ReportError(cx, "Unable to verify access to a global object property.");
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure to actually operate on our object, and not some object further
|
|
|
|
// down on the proto chain.
|
2012-02-03 16:54:57 -08:00
|
|
|
while (JS_GetClass(obj) != &nsXBLDocGlobalObject::gSharedGlobalClass) {
|
2012-09-03 16:42:17 -07:00
|
|
|
if (!::JS_GetPrototype(cx, obj, &obj)) {
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!obj) {
|
|
|
|
::JS_ReportError(cx, "Invalid access to a global object property.");
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-03 16:54:57 -08:00
|
|
|
nsresult rv = ssm->CheckPropertyAccess(cx, obj, JS_GetClass(obj)->name,
|
2007-03-22 10:30:00 -07:00
|
|
|
id, accessType);
|
|
|
|
return NS_SUCCEEDED(rv);
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
nsXBLDocGlobalObject_getProperty(JSContext *cx, JSHandleObject obj,
|
2012-07-30 04:19:09 -07:00
|
|
|
JSHandleId id, JSMutableHandleValue vp)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return nsXBLDocGlobalObject::
|
|
|
|
doCheckAccess(cx, obj, id, nsIXPCSecurityManager::ACCESS_GET_PROPERTY);
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
nsXBLDocGlobalObject_setProperty(JSContext *cx, JSHandleObject obj,
|
2012-07-30 04:19:09 -07:00
|
|
|
JSHandleId id, JSBool strict, JSMutableHandleValue vp)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return nsXBLDocGlobalObject::
|
|
|
|
doCheckAccess(cx, obj, id, nsIXPCSecurityManager::ACCESS_SET_PROPERTY);
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
nsXBLDocGlobalObject_checkAccess(JSContext *cx, JSHandleObject obj, JSHandleId id,
|
2012-09-04 16:40:12 -07:00
|
|
|
JSAccessMode mode, JSMutableHandleValue vp)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t translated;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mode & JSACC_WRITE) {
|
|
|
|
translated = nsIXPCSecurityManager::ACCESS_SET_PROPERTY;
|
|
|
|
} else {
|
|
|
|
translated = nsIXPCSecurityManager::ACCESS_GET_PROPERTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsXBLDocGlobalObject::
|
|
|
|
doCheckAccess(cx, obj, id, translated);
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static void
|
2012-03-19 07:34:55 -07:00
|
|
|
nsXBLDocGlobalObject_finalize(JSFreeOp *fop, JSObject *obj)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-05 12:07:23 -08:00
|
|
|
nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(obj);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(nativeThis));
|
|
|
|
|
|
|
|
if (sgo)
|
2011-04-14 05:04:08 -07:00
|
|
|
sgo->OnFinalize(obj);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The addref was part of JSObject construction
|
|
|
|
NS_RELEASE(nativeThis);
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
nsXBLDocGlobalObject_resolve(JSContext *cx, JSHandleObject obj, JSHandleId id)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
JSBool did_resolve = JS_FALSE;
|
|
|
|
return JS_ResolveStandardClass(cx, obj, id, &did_resolve);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JSClass nsXBLDocGlobalObject::gSharedGlobalClass = {
|
|
|
|
"nsXBLPrototypeScript compilation scope",
|
2012-10-25 08:01:08 -07:00
|
|
|
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS |
|
|
|
|
JSCLASS_IMPLEMENTS_BARRIERS | JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0),
|
2007-03-22 10:30:00 -07:00
|
|
|
JS_PropertyStub, JS_PropertyStub,
|
|
|
|
nsXBLDocGlobalObject_getProperty, nsXBLDocGlobalObject_setProperty,
|
|
|
|
JS_EnumerateStub, nsXBLDocGlobalObject_resolve,
|
|
|
|
JS_ConvertStub, nsXBLDocGlobalObject_finalize,
|
2012-02-13 00:02:21 -08:00
|
|
|
nsXBLDocGlobalObject_checkAccess, NULL, NULL, NULL,
|
2012-10-25 08:01:08 -07:00
|
|
|
NULL
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXBLDocGlobalObject
|
|
|
|
//
|
|
|
|
|
2012-05-16 10:42:10 -07:00
|
|
|
nsXBLDocGlobalObject::nsXBLDocGlobalObject(nsXBLDocumentInfo *aGlobalObjectOwner)
|
2012-07-30 07:20:58 -07:00
|
|
|
: mJSObject(nullptr),
|
2007-08-09 15:30:30 -07:00
|
|
|
mGlobalObjectOwner(aGlobalObjectOwner) // weak reference
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsXBLDocGlobalObject::~nsXBLDocGlobalObject()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-05-25 09:05:42 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_1(nsXBLDocGlobalObject, mScriptContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-25 09:35:27 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXBLDocGlobalObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObject)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 03:11:31 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXBLDocGlobalObject)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXBLDocGlobalObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-06 15:21:43 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
XBL_ProtoErrorReporter(JSContext *cx,
|
|
|
|
const char *message,
|
|
|
|
JSErrorReport *report)
|
|
|
|
{
|
|
|
|
// Make an nsIScriptError and populate it with information from
|
|
|
|
// this error.
|
|
|
|
nsCOMPtr<nsIScriptError>
|
|
|
|
errorObject(do_CreateInstance("@mozilla.org/scripterror;1"));
|
|
|
|
nsCOMPtr<nsIConsoleService>
|
|
|
|
consoleService(do_GetService("@mozilla.org/consoleservice;1"));
|
|
|
|
|
|
|
|
if (errorObject && consoleService) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t column = report->uctokenptr - report->uclinebuf;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-09 16:29:12 -07:00
|
|
|
const PRUnichar* ucmessage =
|
|
|
|
static_cast<const PRUnichar*>(report->ucmessage);
|
|
|
|
const PRUnichar* uclinebuf =
|
|
|
|
static_cast<const PRUnichar*>(report->uclinebuf);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
errorObject->Init
|
2012-09-09 16:29:12 -07:00
|
|
|
(ucmessage ? nsDependentString(ucmessage) : EmptyString(),
|
|
|
|
NS_ConvertUTF8toUTF16(report->filename),
|
|
|
|
uclinebuf ? nsDependentString(uclinebuf) : EmptyString(),
|
2007-03-22 10:30:00 -07:00
|
|
|
report->lineno, column, report->flags,
|
|
|
|
"xbl javascript"
|
|
|
|
);
|
|
|
|
consoleService->LogMessage(errorObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIScriptGlobalObject methods
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIScriptContext *
|
2012-03-23 10:13:29 -07:00
|
|
|
nsXBLDocGlobalObject::GetScriptContext()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return GetContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-03-23 10:13:29 -07:00
|
|
|
nsXBLDocGlobalObject::EnsureScriptEnvironment()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-05 02:00:04 -07:00
|
|
|
if (mScriptContext) {
|
|
|
|
// Already initialized.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptRuntime> scriptRuntime;
|
2012-05-05 02:00:04 -07:00
|
|
|
NS_GetJSRuntime(getter_AddRefs(scriptRuntime));
|
|
|
|
NS_ENSURE_TRUE(scriptRuntime, NS_OK);
|
|
|
|
|
2012-11-04 01:05:23 -07:00
|
|
|
nsCOMPtr<nsIScriptContext> newCtx = scriptRuntime->CreateContext(false, nullptr);
|
2012-05-05 02:00:04 -07:00
|
|
|
MOZ_ASSERT(newCtx);
|
|
|
|
|
|
|
|
newCtx->WillInitializeContext();
|
|
|
|
// NOTE: We init this context with a NULL global, so we automatically
|
|
|
|
// hook up to the existing nsIScriptGlobalObject global setup by
|
|
|
|
// nsGlobalWindow.
|
2012-10-26 10:49:57 -07:00
|
|
|
DebugOnly<nsresult> rv = newCtx->InitContext();
|
2012-05-05 02:00:04 -07:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Script Language's InitContext failed");
|
|
|
|
newCtx->DidInitializeContext();
|
|
|
|
|
|
|
|
mScriptContext = newCtx;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-18 02:22:17 -07:00
|
|
|
JSContext *cx = mScriptContext->GetNativeContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
JSAutoRequest ar(cx);
|
|
|
|
|
|
|
|
// nsJSEnvironment set the error reporter to NS_ScriptErrorReporter so
|
|
|
|
// we must apparently override that with our own (although it isn't clear
|
|
|
|
// why - see bug 339647)
|
|
|
|
JS_SetErrorReporter(cx, XBL_ProtoErrorReporter);
|
2010-09-02 23:22:18 -07:00
|
|
|
|
2012-10-25 08:01:07 -07:00
|
|
|
mJSObject = JS_NewGlobalObject(cx, &gSharedGlobalClass,
|
|
|
|
nsJSPrincipals::get(GetPrincipal()));
|
2012-10-25 08:01:07 -07:00
|
|
|
if (!mJSObject)
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-16 10:42:10 -07:00
|
|
|
// Set the location information for the new global, so that tools like
|
|
|
|
// about:memory may use that information
|
|
|
|
nsIURI *ownerURI = mGlobalObjectOwner->DocumentURI();
|
|
|
|
xpc::SetLocationForGlobal(mJSObject, ownerURI);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
::JS_SetGlobalObject(cx, mJSObject);
|
|
|
|
|
|
|
|
// Add an owning reference from JS back to us. This'll be
|
|
|
|
// released when the JSObject is finalized.
|
2012-02-05 12:07:23 -08:00
|
|
|
::JS_SetPrivate(mJSObject, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIScriptContext *
|
|
|
|
nsXBLDocGlobalObject::GetContext()
|
|
|
|
{
|
|
|
|
// This whole fragile mess is predicated on the fact that
|
|
|
|
// GetContext() will be called before GetScriptObject() is.
|
|
|
|
if (! mScriptContext) {
|
2012-03-23 10:13:29 -07:00
|
|
|
nsresult rv = EnsureScriptEnvironment();
|
2007-03-22 10:30:00 -07:00
|
|
|
// JS is builtin so we make noise if it fails to initialize.
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to setup JS!?");
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(mScriptContext, "Failed to find a script context!?");
|
|
|
|
}
|
|
|
|
return mScriptContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-08-09 15:30:30 -07:00
|
|
|
nsXBLDocGlobalObject::ClearGlobalObjectOwner()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mGlobalObjectOwner = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-18 07:17:05 -07:00
|
|
|
void
|
|
|
|
nsXBLDocGlobalObject::UnmarkScriptContext()
|
|
|
|
{
|
|
|
|
if (mScriptContext) {
|
|
|
|
xpc_UnmarkGrayObject(mScriptContext->GetNativeGlobal());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JSObject *
|
|
|
|
nsXBLDocGlobalObject::GetGlobalJSObject()
|
|
|
|
{
|
|
|
|
// The prototype document has its own special secret script object
|
|
|
|
// that can be used to compile scripts and event handlers.
|
|
|
|
|
|
|
|
if (!mScriptContext)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-18 02:22:17 -07:00
|
|
|
JSContext* cx = mScriptContext->GetNativeContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!cx)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JSObject *ret = ::JS_GetGlobalObject(cx);
|
|
|
|
NS_ASSERTION(mJSObject == ret, "How did this magic switch happen?");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-14 05:04:08 -07:00
|
|
|
nsXBLDocGlobalObject::OnFinalize(JSObject* aObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aObject == mJSObject, "Wrong object finalized!");
|
2011-04-14 05:04:08 -07:00
|
|
|
mJSObject = NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXBLDocGlobalObject::SetScriptsEnabled(bool aEnabled, bool aFireTimeouts)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// We don't care...
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIScriptObjectPrincipal methods
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIPrincipal*
|
|
|
|
nsXBLDocGlobalObject::GetPrincipal()
|
|
|
|
{
|
|
|
|
if (!mGlobalObjectOwner) {
|
2007-09-28 06:45:01 -07:00
|
|
|
// XXXbz this should really save the principal when
|
|
|
|
// ClearGlobalObjectOwner() happens.
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 18:53:11 -07:00
|
|
|
nsRefPtr<nsXBLDocumentInfo> docInfo =
|
|
|
|
static_cast<nsXBLDocumentInfo*>(mGlobalObjectOwner);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-14 18:55:54 -07:00
|
|
|
nsCOMPtr<nsIDocument> document = docInfo->GetDocument();
|
|
|
|
if (!document)
|
|
|
|
return NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return document->NodePrincipal();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsChromeURI(nsIURI* aURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isChrome = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)))
|
|
|
|
return isChrome;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Implementation file */
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
TraverseProtos(nsHashKey *aKey, void *aData, void* aClosure)
|
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback *cb =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
|
|
|
|
nsXBLPrototypeBinding *proto = static_cast<nsXBLPrototypeBinding*>(aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
proto->Traverse(*cb);
|
|
|
|
return kHashEnumerateNext;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2008-01-29 18:05:43 -08:00
|
|
|
UnlinkProtoJSObjects(nsHashKey *aKey, void *aData, void* aClosure)
|
2007-09-28 06:45:01 -07:00
|
|
|
{
|
|
|
|
nsXBLPrototypeBinding *proto = static_cast<nsXBLPrototypeBinding*>(aData);
|
2008-01-29 18:05:43 -08:00
|
|
|
proto->UnlinkJSObjects();
|
2007-09-28 06:45:01 -07:00
|
|
|
return kHashEnumerateNext;
|
|
|
|
}
|
|
|
|
|
2007-10-29 06:45:07 -07:00
|
|
|
struct ProtoTracer
|
|
|
|
{
|
|
|
|
TraceCallback mCallback;
|
|
|
|
void *mClosure;
|
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-10-29 06:45:07 -07:00
|
|
|
TraceProtos(nsHashKey *aKey, void *aData, void* aClosure)
|
|
|
|
{
|
|
|
|
ProtoTracer* closure = static_cast<ProtoTracer*>(aClosure);
|
|
|
|
nsXBLPrototypeBinding *proto = static_cast<nsXBLPrototypeBinding*>(aData);
|
|
|
|
proto->Trace(closure->mCallback, closure->mClosure);
|
|
|
|
return kHashEnumerateNext;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLDocumentInfo)
|
2010-11-08 07:02:49 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXBLDocumentInfo)
|
2007-09-28 06:45:01 -07:00
|
|
|
if (tmp->mBindingTable) {
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mBindingTable->Enumerate(UnlinkProtoJSObjects, nullptr);
|
2007-09-28 06:45:01 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGlobalObject)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXBLDocumentInfo)
|
2012-01-13 04:44:14 -08:00
|
|
|
if (tmp->mDocument &&
|
|
|
|
nsCCUncollectableMarker::InGeneration(cb, tmp->mDocument->GetMarkedCCGeneration())) {
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument)
|
|
|
|
if (tmp->mBindingTable) {
|
|
|
|
tmp->mBindingTable->Enumerate(TraverseProtos, &cb);
|
|
|
|
}
|
2012-01-23 15:25:53 -08:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mGlobalObject");
|
2007-08-09 15:30:30 -07:00
|
|
|
cb.NoteXPCOMChild(static_cast<nsIScriptGlobalObject*>(tmp->mGlobalObject));
|
2007-10-29 06:45:07 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2007-10-29 06:45:07 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXBLDocumentInfo)
|
|
|
|
if (tmp->mBindingTable) {
|
|
|
|
ProtoTracer closure = { aCallback, aClosure };
|
|
|
|
tmp->mBindingTable->Enumerate(TraceProtos, &closure);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-11 03:04:28 -08:00
|
|
|
static void
|
2012-05-03 12:28:10 -07:00
|
|
|
UnmarkXBLJSObject(void* aP, const char* aName, void* aClosure)
|
2012-02-11 03:04:28 -08:00
|
|
|
{
|
2012-05-03 12:28:10 -07:00
|
|
|
xpc_UnmarkGrayObject(static_cast<JSObject*>(aP));
|
2012-02-11 03:04:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
UnmarkProtos(nsHashKey* aKey, void* aData, void* aClosure)
|
|
|
|
{
|
|
|
|
nsXBLPrototypeBinding* proto = static_cast<nsXBLPrototypeBinding*>(aData);
|
2012-07-30 07:20:58 -07:00
|
|
|
proto->Trace(UnmarkXBLJSObject, nullptr);
|
2012-02-11 03:04:28 -08:00
|
|
|
return kHashEnumerateNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLDocumentInfo::MarkInCCGeneration(uint32_t aGeneration)
|
2012-02-11 03:04:28 -08:00
|
|
|
{
|
|
|
|
if (mDocument) {
|
|
|
|
mDocument->MarkUncollectableForCCGeneration(aGeneration);
|
|
|
|
}
|
2012-03-18 07:17:05 -07:00
|
|
|
// Unmark any JS we hold
|
2012-02-11 03:04:28 -08:00
|
|
|
if (mBindingTable) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mBindingTable->Enumerate(UnmarkProtos, nullptr);
|
2012-02-11 03:04:28 -08:00
|
|
|
}
|
2012-03-18 07:17:05 -07:00
|
|
|
if (mGlobalObject) {
|
|
|
|
mGlobalObject->UnmarkScriptContext();
|
|
|
|
}
|
2012-02-11 03:04:28 -08:00
|
|
|
}
|
|
|
|
|
2007-04-25 09:35:27 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXBLDocumentInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2010-07-14 18:53:11 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObjectOwner)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 03:11:31 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXBLDocumentInfo)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXBLDocumentInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsXBLDocumentInfo::nsXBLDocumentInfo(nsIDocument* aDocument)
|
|
|
|
: mDocument(aDocument),
|
2011-10-17 07:59:28 -07:00
|
|
|
mScriptAccess(true),
|
|
|
|
mIsChrome(false),
|
2012-07-30 07:20:58 -07:00
|
|
|
mBindingTable(nullptr),
|
|
|
|
mFirstBinding(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIURI* uri = aDocument->GetDocumentURI();
|
|
|
|
if (IsChromeURI(uri)) {
|
|
|
|
// Cache whether or not this chrome XBL can execute scripts.
|
2010-05-14 02:24:41 -07:00
|
|
|
nsCOMPtr<nsIXULChromeRegistry> reg =
|
|
|
|
mozilla::services::GetXULChromeRegistryService();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (reg) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allow = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
reg->AllowScriptsForPackage(uri, &allow);
|
|
|
|
mScriptAccess = allow;
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsChrome = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLDocumentInfo::~nsXBLDocumentInfo()
|
|
|
|
{
|
|
|
|
/* destructor code */
|
|
|
|
if (mGlobalObject) {
|
|
|
|
// remove circular reference
|
2012-05-05 02:00:04 -07:00
|
|
|
mGlobalObject->ClearScriptContext();
|
2007-08-09 15:30:30 -07:00
|
|
|
mGlobalObject->ClearGlobalObjectOwner(); // just in case
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-10-29 06:45:07 -07:00
|
|
|
if (mBindingTable) {
|
|
|
|
NS_DROP_JS_OBJECTS(this, nsXBLDocumentInfo);
|
|
|
|
delete mBindingTable;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 18:55:54 -07:00
|
|
|
nsXBLPrototypeBinding*
|
|
|
|
nsXBLDocumentInfo::GetPrototypeBinding(const nsACString& aRef)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mBindingTable)
|
2010-07-14 18:55:54 -07:00
|
|
|
return NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aRef.IsEmpty()) {
|
|
|
|
// Return our first binding
|
2010-07-14 18:55:54 -07:00
|
|
|
return mFirstBinding;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsPromiseFlatCString& flat = PromiseFlatCString(aRef);
|
|
|
|
nsCStringKey key(flat.get());
|
2010-07-14 18:55:54 -07:00
|
|
|
return static_cast<nsXBLPrototypeBinding*>(mBindingTable->Get(&key));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
DeletePrototypeBinding(nsHashKey* aKey, void* aData, void* aClosure)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsXBLPrototypeBinding* binding = static_cast<nsXBLPrototypeBinding*>(aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
delete binding;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 18:55:54 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLDocumentInfo::SetPrototypeBinding(const nsACString& aRef, nsXBLPrototypeBinding* aBinding)
|
|
|
|
{
|
2007-10-29 06:45:07 -07:00
|
|
|
if (!mBindingTable) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mBindingTable = new nsObjectHashtable(nullptr, nullptr, DeletePrototypeBinding, nullptr);
|
2007-10-29 06:45:07 -07:00
|
|
|
|
|
|
|
NS_HOLD_JS_OBJECTS(this, nsXBLDocumentInfo);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const nsPromiseFlatCString& flat = PromiseFlatCString(aRef);
|
|
|
|
nsCStringKey key(flat.get());
|
2007-11-27 12:02:42 -08:00
|
|
|
NS_ENSURE_STATE(!mBindingTable->Get(&key));
|
2007-03-22 10:30:00 -07:00
|
|
|
mBindingTable->Put(&key, aBinding);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
void
|
|
|
|
nsXBLDocumentInfo::RemovePrototypeBinding(const nsACString& aRef)
|
|
|
|
{
|
|
|
|
if (mBindingTable) {
|
|
|
|
// Use a flat string to avoid making a copy.
|
|
|
|
const nsPromiseFlatCString& flat = PromiseFlatCString(aRef);
|
|
|
|
nsCStringKey key(flat);
|
|
|
|
mBindingTable->Remove(&key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Callback to enumerate over the bindings from this document and write them
|
|
|
|
// out to the cache.
|
|
|
|
bool
|
|
|
|
WriteBinding(nsHashKey *aKey, void *aData, void* aClosure)
|
|
|
|
{
|
|
|
|
nsXBLPrototypeBinding* binding = static_cast<nsXBLPrototypeBinding *>(aData);
|
|
|
|
binding->Write((nsIObjectOutputStream*)aClosure);
|
|
|
|
|
|
|
|
return kHashEnumerateNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
nsXBLDocumentInfo::ReadPrototypeBindings(nsIURI* aURI, nsXBLDocumentInfo** aDocInfo)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aDocInfo = nullptr;
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString spec(kXBLCachePrefix);
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult rv = PathifyURI(aURI, spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
StartupCache* startupCache = StartupCache::GetSingleton();
|
|
|
|
NS_ENSURE_TRUE(startupCache, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsAutoArrayPtr<char> buf;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len;
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = startupCache->GetBuffer(spec.get(), getter_Transfers(buf), &len);
|
|
|
|
// GetBuffer will fail if the binding is not in the cache.
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObjectInputStream> stream;
|
|
|
|
rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(stream));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
buf.forget();
|
|
|
|
|
|
|
|
// The file compatibility.ini stores the build id. This is checked in
|
|
|
|
// nsAppRunner.cpp and will delete the cache if a different build is
|
|
|
|
// present. However, we check that the version matches here to be safe.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t version;
|
2011-11-03 13:39:08 -07:00
|
|
|
rv = stream->Read32(&version);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (version != XBLBinding_Serialize_Version) {
|
|
|
|
// The version that exists is different than expected, likely created with a
|
|
|
|
// different build, so invalidate the cache.
|
|
|
|
startupCache->InvalidateCache();
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
nsContentUtils::GetSecurityManager()->
|
|
|
|
GetSystemPrincipal(getter_AddRefs(principal));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = NS_NewXBLDocument(getter_AddRefs(domdoc), aURI, nullptr, principal);
|
2011-11-03 13:39:08 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
2012-03-22 13:46:03 -07:00
|
|
|
NS_ASSERTION(doc, "Must have a document!");
|
|
|
|
nsRefPtr<nsXBLDocumentInfo> docInfo = new nsXBLDocumentInfo(doc);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
|
|
|
while (1) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t flags;
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult rv = stream->Read8(&flags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (flags == XBLBinding_Serialize_NoMoreBindings)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsXBLPrototypeBinding* binding = new nsXBLPrototypeBinding();
|
|
|
|
rv = binding->Read(stream, docInfo, doc, flags);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete binding;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
docInfo.swap(*aDocInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXBLDocumentInfo::WritePrototypeBindings()
|
|
|
|
{
|
|
|
|
// Only write out bindings with the system principal
|
|
|
|
if (!nsContentUtils::IsSystemPrincipal(mDocument->NodePrincipal()))
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString spec(kXBLCachePrefix);
|
2011-11-03 13:39:08 -07:00
|
|
|
nsresult rv = PathifyURI(DocumentURI(), spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
StartupCache* startupCache = StartupCache::GetSingleton();
|
|
|
|
NS_ENSURE_TRUE(startupCache, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObjectOutputStream> stream;
|
|
|
|
nsCOMPtr<nsIStorageStream> storageStream;
|
|
|
|
rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(stream),
|
|
|
|
getter_AddRefs(storageStream),
|
|
|
|
true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = stream->Write32(XBLBinding_Serialize_Version);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (mBindingTable)
|
|
|
|
mBindingTable->Enumerate(WriteBinding, stream);
|
|
|
|
|
|
|
|
// write a end marker at the end
|
|
|
|
rv = stream->Write8(XBLBinding_Serialize_NoMoreBindings);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
stream->Close();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len;
|
2011-11-03 13:39:08 -07:00
|
|
|
nsAutoArrayPtr<char> buf;
|
|
|
|
rv = NewBufferFromStorageStream(storageStream, getter_Transfers(buf), &len);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return startupCache->PutBuffer(spec.get(), buf, len);
|
|
|
|
}
|
|
|
|
|
2010-07-14 18:55:54 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLDocumentInfo::SetFirstPrototypeBinding(nsXBLPrototypeBinding* aBinding)
|
|
|
|
{
|
|
|
|
mFirstBinding = aBinding;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool FlushScopedSkinSheets(nsHashKey* aKey, void* aData, void* aClosure)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsXBLPrototypeBinding* proto = (nsXBLPrototypeBinding*)aData;
|
|
|
|
proto->FlushSkinSheets();
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 18:55:54 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLDocumentInfo::FlushSkinStylesheets()
|
|
|
|
{
|
|
|
|
if (mBindingTable)
|
|
|
|
mBindingTable->Enumerate(FlushScopedSkinSheets);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIScriptGlobalObjectOwner methods
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIScriptGlobalObject*
|
|
|
|
nsXBLDocumentInfo::GetScriptGlobalObject()
|
|
|
|
{
|
|
|
|
if (!mGlobalObject) {
|
2007-08-09 15:30:30 -07:00
|
|
|
nsXBLDocGlobalObject *global = new nsXBLDocGlobalObject(this);
|
|
|
|
if (!global)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-09 15:30:30 -07:00
|
|
|
mGlobalObject = global;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return mGlobalObject;
|
|
|
|
}
|