Bug 578565: Devirtualize methods and remove outparams on nsXBLDocumentInfo. r=jst

--HG--
extra : rebase_source : a9da7b104c9fa819283ed2d7c413078974ab26f2
This commit is contained in:
Kyle Huey 2010-07-14 18:55:54 -07:00
parent 16c927f68b
commit e12a6f76f1
9 changed files with 36 additions and 52 deletions

View File

@ -1373,11 +1373,8 @@ nsXBLBinding::DoInitJSClass(JSContext *cx, JSObject *global, JSObject *obj,
PRBool
nsXBLBinding::AllowScripts()
{
PRBool result;
mPrototypeBinding->GetAllowScripts(&result);
if (!result) {
return result;
}
if (!mPrototypeBinding->GetAllowScripts())
return PR_FALSE;
// Nasty hack. Use the JSContext of the bound node, since the
// security manager API expects to get the docshell type from
@ -1404,8 +1401,8 @@ nsXBLBinding::AllowScripts()
JSContext* cx = (JSContext*) context->GetNativeContext();
nsCOMPtr<nsIDocument> ourDocument;
mPrototypeBinding->XBLDocumentInfo()->GetDocument(getter_AddRefs(ourDocument));
nsCOMPtr<nsIDocument> ourDocument =
mPrototypeBinding->XBLDocumentInfo()->GetDocument();
PRBool canExecute;
nsresult rv =
mgr->CanExecuteScripts(cx, ourDocument->NodePrincipal(), &canExecute);

View File

@ -411,9 +411,9 @@ nsXBLDocGlobalObject::GetPrincipal()
nsRefPtr<nsXBLDocumentInfo> docInfo =
static_cast<nsXBLDocumentInfo*>(mGlobalObjectOwner);
nsCOMPtr<nsIDocument> document;
rv = docInfo->GetDocument(getter_AddRefs(document));
NS_ENSURE_SUCCESS(rv, nsnull);
nsCOMPtr<nsIDocument> document = docInfo->GetDocument();
if (!document)
return NULL;
return document->NodePrincipal();
}
@ -531,24 +531,20 @@ nsXBLDocumentInfo::~nsXBLDocumentInfo()
}
}
NS_IMETHODIMP
nsXBLDocumentInfo::GetPrototypeBinding(const nsACString& aRef, nsXBLPrototypeBinding** aResult)
nsXBLPrototypeBinding*
nsXBLDocumentInfo::GetPrototypeBinding(const nsACString& aRef)
{
*aResult = nsnull;
if (!mBindingTable)
return NS_OK;
return NULL;
if (aRef.IsEmpty()) {
// Return our first binding
*aResult = mFirstBinding;
return NS_OK;
return mFirstBinding;
}
const nsPromiseFlatCString& flat = PromiseFlatCString(aRef);
nsCStringKey key(flat.get());
*aResult = static_cast<nsXBLPrototypeBinding*>(mBindingTable->Get(&key));
return NS_OK;
return static_cast<nsXBLPrototypeBinding*>(mBindingTable->Get(&key));
}
static PRBool
@ -559,13 +555,11 @@ DeletePrototypeBinding(nsHashKey* aKey, void* aData, void* aClosure)
return PR_TRUE;
}
NS_IMETHODIMP
nsresult
nsXBLDocumentInfo::SetPrototypeBinding(const nsACString& aRef, nsXBLPrototypeBinding* aBinding)
{
if (!mBindingTable) {
mBindingTable = new nsObjectHashtable(nsnull, nsnull, DeletePrototypeBinding, nsnull);
if (!mBindingTable)
return NS_ERROR_OUT_OF_MEMORY;
NS_HOLD_JS_OBJECTS(this, nsXBLDocumentInfo);
}
@ -578,12 +572,10 @@ nsXBLDocumentInfo::SetPrototypeBinding(const nsACString& aRef, nsXBLPrototypeBin
return NS_OK;
}
NS_IMETHODIMP
void
nsXBLDocumentInfo::SetFirstPrototypeBinding(nsXBLPrototypeBinding* aBinding)
{
mFirstBinding = aBinding;
return NS_OK;
}
PRBool FlushScopedSkinSheets(nsHashKey* aKey, void* aData, void* aClosure)
@ -593,13 +585,11 @@ PRBool FlushScopedSkinSheets(nsHashKey* aKey, void* aData, void* aClosure)
return PR_TRUE;
}
NS_IMETHODIMP
void
nsXBLDocumentInfo::FlushSkinStylesheets()
{
if (mBindingTable)
mBindingTable->Enumerate(FlushScopedSkinSheets);
return NS_OK;
}
//----------------------------------------------------------------------

View File

@ -57,20 +57,22 @@ public:
nsXBLDocumentInfo(nsIDocument* aDocument);
virtual ~nsXBLDocumentInfo();
NS_IMETHOD GetDocument(nsIDocument** aResult) { NS_ADDREF(*aResult = mDocument); return NS_OK; }
already_AddRefed<nsIDocument> GetDocument()
{ NS_ADDREF(mDocument); return mDocument.get(); }
NS_IMETHOD GetScriptAccess(PRBool* aResult) { *aResult = mScriptAccess; return NS_OK; }
PRBool GetScriptAccess() { return mScriptAccess; }
NS_IMETHOD_(nsIURI*) DocumentURI() { return mDocument->GetDocumentURI(); }
nsIURI* DocumentURI() { return mDocument->GetDocumentURI(); }
NS_IMETHOD GetPrototypeBinding(const nsACString& aRef, nsXBLPrototypeBinding** aResult);
NS_IMETHOD SetPrototypeBinding(const nsACString& aRef, nsXBLPrototypeBinding* aBinding);
nsXBLPrototypeBinding* GetPrototypeBinding(const nsACString& aRef);
nsresult SetPrototypeBinding(const nsACString& aRef,
nsXBLPrototypeBinding* aBinding);
NS_IMETHOD SetFirstPrototypeBinding(nsXBLPrototypeBinding* aBinding);
void SetFirstPrototypeBinding(nsXBLPrototypeBinding* aBinding);
NS_IMETHOD FlushSkinStylesheets();
void FlushSkinStylesheets();
NS_IMETHOD_(PRBool) IsChrome() { return mIsChrome; }
PRBool IsChrome() { return mIsChrome; }
// nsIScriptGlobalObjectOwner methods
virtual nsIScriptGlobalObject* GetScriptGlobalObject();

View File

@ -439,10 +439,10 @@ nsXBLPrototypeBinding::SetBindingElement(nsIContent* aElement)
mInheritStyle = PR_FALSE;
}
nsresult
nsXBLPrototypeBinding::GetAllowScripts(PRBool* aResult)
PRBool
nsXBLPrototypeBinding::GetAllowScripts()
{
return mXBLDocInfoWeak->GetScriptAccess(aResult);
return mXBLDocInfoWeak->GetScriptAccess();
}
PRBool

View File

@ -81,7 +81,7 @@ public:
// binding URIs.
PRBool CompareBindingURI(nsIURI* aURI) const;
nsresult GetAllowScripts(PRBool* aResult);
PRBool GetAllowScripts();
nsresult BindingAttached(nsIContent* aBoundElement);
nsresult BindingDetached(nsIContent* aBoundElement);

View File

@ -105,8 +105,8 @@ nsXBLPrototypeResources::FlushSkinSheets()
if (mStyleSheetList.Length() == 0)
return NS_OK;
nsCOMPtr<nsIDocument> doc;
mLoader->mBinding->XBLDocumentInfo()->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDocument> doc =
mLoader->mBinding->XBLDocumentInfo()->GetDocument();
mozilla::css::Loader* cssLoader = doc->CSSLoader();
// We have scoped stylesheets. Reload any chrome stylesheets we

View File

@ -108,8 +108,7 @@ nsXBLResourceLoader::LoadResources(PRBool* aResult)
*aResult = PR_TRUE;
// Declare our loaders.
nsCOMPtr<nsIDocument> doc;
mBinding->XBLDocumentInfo()->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDocument> doc = mBinding->XBLDocumentInfo()->GetDocument();
mozilla::css::Loader* cssLoader = doc->CSSLoader();
nsIURI *docURL = doc->GetDocumentURI();

View File

@ -877,13 +877,10 @@ nsXBLService::GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
return NS_ERROR_FAILURE;
// Get our doc info and determine our script access.
nsCOMPtr<nsIDocument> doc;
docInfo->GetDocument(getter_AddRefs(doc));
PRBool allowScripts;
docInfo->GetScriptAccess(&allowScripts);
nsCOMPtr<nsIDocument> doc = docInfo->GetDocument();
PRBool allowScripts = docInfo->GetScriptAccess();
nsXBLPrototypeBinding* protoBinding;
docInfo->GetPrototypeBinding(ref, &protoBinding);
nsXBLPrototypeBinding* protoBinding = docInfo->GetPrototypeBinding(ref);
NS_ASSERTION(protoBinding, "Unable to locate an XBL binding.");
if (!protoBinding)

View File

@ -148,8 +148,7 @@ nsXBLSpecialDocInfo::GetHandlers(nsXBLDocumentInfo* aInfo,
const nsACString& aRef,
nsXBLPrototypeHandler** aResult)
{
nsXBLPrototypeBinding* binding;
aInfo->GetPrototypeBinding(aRef, &binding);
nsXBLPrototypeBinding* binding = aInfo->GetPrototypeBinding(aRef);
NS_ASSERTION(binding, "No binding found for the XBL window key handler.");
if (!binding)