Bug 742837 - Remove dead code and cleanup around nsDOMScriptObjectFactory; r=bz

This commit is contained in:
Ms2ger 2012-04-14 15:03:16 +02:00
Родитель d34687ef52
Коммит e51dcfe2da
7 изменённых файлов: 74 добавлений и 235 удалений

Просмотреть файл

@ -395,9 +395,6 @@ public:
static PRUint32 CopyNewlineNormalizedUnicodeTo(nsReadingIterator<PRUnichar>& aSrcStart, const nsReadingIterator<PRUnichar>& aSrcEnd, nsAString& aDest);
static nsISupports *
GetClassInfoInstance(nsDOMClassInfoID aID);
static const nsDependentSubstring TrimCharsInSet(const char* aSet,
const nsAString& aValue);

Просмотреть файл

@ -169,6 +169,7 @@
#include "nsIEditingSession.h"
#include "nsPIDOMWindow.h"
#include "nsGlobalWindow.h"
#include "nsPIWindowRoot.h"
#include "nsIDOMDocument.h"
#include "nsICachingChannel.h"
@ -10855,10 +10856,6 @@ nsDocShell::EnsureScriptEnvironment()
mInEnsureScriptEnv = true;
#endif
nsCOMPtr<nsIDOMScriptObjectFactory> factory =
do_GetService(kDOMScriptObjectFactoryCID);
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE);
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(mTreeOwner));
NS_ENSURE_TRUE(browserChrome, NS_ERROR_NOT_AVAILABLE);
@ -10871,20 +10868,15 @@ nsDocShell::EnsureScriptEnvironment()
// If our window is modal and we're not opened as chrome, make
// this window a modal content window.
factory->NewScriptGlobalObject(mItemType == typeChrome,
isModalContentWindow,
getter_AddRefs(mScriptGlobal));
NS_ENSURE_TRUE(mScriptGlobal, NS_ERROR_FAILURE);
nsRefPtr<nsGlobalWindow> window =
NS_NewScriptGlobalObject(mItemType == typeChrome, isModalContentWindow);
MOZ_ASSERT(window);
mScriptGlobal = window;
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(mScriptGlobal));
win->SetDocShell(static_cast<nsIDocShell *>(this));
window->SetDocShell(this);
// Ensure the script object is set up to run script.
nsresult rv;
rv = mScriptGlobal->EnsureScriptEnvironment();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
return mScriptGlobal->EnsureScriptEnvironment();
}

Просмотреть файл

@ -71,8 +71,7 @@ static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CI
nsIExceptionProvider* gExceptionProvider = nsnull;
nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() :
mLoadedAllLanguages(false)
nsDOMScriptObjectFactory::nsDOMScriptObjectFactory()
{
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
@ -80,25 +79,23 @@ nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() :
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
}
nsCOMPtr<nsIExceptionProvider> provider(new nsDOMExceptionProvider());
if (provider) {
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
nsCOMPtr<nsIExceptionProvider> provider = new nsDOMExceptionProvider();
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
if (xs) {
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_SVG);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_XPATH);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_INDEXEDDB);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_XPCONNECT);
}
NS_ASSERTION(!gExceptionProvider, "Registered twice?!");
provider.swap(gExceptionProvider);
if (xs) {
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_SVG);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_XPATH);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_INDEXEDDB);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_XPCONNECT);
}
NS_ASSERTION(!gExceptionProvider, "Registered twice?!");
provider.swap(gExceptionProvider);
// And pre-create the javascript language.
NS_CreateJSRuntime(getter_AddRefs(mLanguageArray[NS_STID_INDEX(nsIProgrammingLanguage::JAVASCRIPT)]));
NS_CreateJSRuntime(getter_AddRefs(mJSRuntime));
}
NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory)
@ -111,119 +108,6 @@ NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMScriptObjectFactory)
NS_IMPL_RELEASE(nsDOMScriptObjectFactory)
/**
* Notes about language registration (for language other than js):
* - All language are expected to register (at least) 2 contract IDs
* @mozilla.org/script-language;1?id=%d
* using the language ID as defined in nsIProgrammingLanguage, and
* @mozilla.org/script-language;1?script-type=%s
* using the "mime-type" of the script language
*
* Theoretically, a language could register multiple script-type
* names, although this is discouraged - each language should have one,
* canonical name.
*
* The most common case is that languages are looked up by ID. For this
* reason, we keep an array of languages indexed by this ID - the registry
* is only looked the first request for a language ID.
*
* The registry is looked up and getService called for each query by name.
* (As services are cached by CID, multiple contractIDs will still work
* correctly)
**/
NS_IMETHODIMP
nsDOMScriptObjectFactory::GetScriptRuntime(const nsAString &aLanguageName,
nsIScriptRuntime **aLanguage)
{
// Note that many callers have optimized detection for JS (along with
// supporting various alternate names for JS), so don't call this.
// One exception is for the new "script-type" attribute on a node - and
// there is no need to support backwards compatible names.
// As JS is the default language, this is still rarely called for JS -
// only when a node explicitly sets JS - so that is done last.
nsCAutoString contractid(NS_LITERAL_CSTRING(
"@mozilla.org/script-language;1?script-type="));
// Arbitrarily use utf8 encoding should the name have extended chars
AppendUTF16toUTF8(aLanguageName, contractid);
nsresult rv;
nsCOMPtr<nsIScriptRuntime> lang =
do_GetService(contractid.get(), &rv);
if (NS_FAILED(rv)) {
if (aLanguageName.Equals(NS_LITERAL_STRING("application/javascript")))
return GetScriptRuntimeByID(nsIProgrammingLanguage::JAVASCRIPT, aLanguage);
// Not JS and nothing else we know about.
NS_WARNING("No script language registered for this mime-type");
return NS_ERROR_FACTORY_NOT_REGISTERED;
}
// And stash it away in our array for fast lookup by ID.
PRUint32 lang_ndx = NS_STID_INDEX(nsIProgrammingLanguage::JAVASCRIPT);
if (mLanguageArray[lang_ndx] == nsnull) {
mLanguageArray[lang_ndx] = lang;
} else {
// All languages are services - we should have an identical object!
NS_ASSERTION(mLanguageArray[lang_ndx] == lang,
"Got a different language for this ID???");
}
*aLanguage = lang;
NS_IF_ADDREF(*aLanguage);
return NS_OK;
}
NS_IMETHODIMP
nsDOMScriptObjectFactory::GetScriptRuntimeByID(PRUint32 aLanguageID,
nsIScriptRuntime **aLanguage)
{
if (!NS_STID_VALID(aLanguageID)) {
NS_WARNING("Unknown script language");
return NS_ERROR_UNEXPECTED;
}
*aLanguage = mLanguageArray[NS_STID_INDEX(aLanguageID)];
if (!*aLanguage) {
nsCAutoString contractid(NS_LITERAL_CSTRING(
"@mozilla.org/script-language;1?id="));
char langIdStr[25]; // space for an int.
sprintf(langIdStr, "%d", aLanguageID);
contractid += langIdStr;
nsresult rv;
nsCOMPtr<nsIScriptRuntime> lang = do_GetService(contractid.get(), &rv);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to get the script language");
return rv;
}
// Stash it away in our array for fast lookup by ID.
mLanguageArray[NS_STID_INDEX(aLanguageID)] = lang;
*aLanguage = lang;
}
NS_IF_ADDREF(*aLanguage);
return NS_OK;
}
NS_IMETHODIMP
nsDOMScriptObjectFactory::GetIDForScriptType(const nsAString &aLanguageName,
PRUint32 *aScriptTypeID)
{
nsCOMPtr<nsIScriptRuntime> languageRuntime;
nsresult rv;
rv = GetScriptRuntime(aLanguageName, getter_AddRefs(languageRuntime));
if (NS_FAILED(rv))
return rv;
*aScriptTypeID = nsIProgrammingLanguage::JAVASCRIPT;
return NS_OK;
}
NS_IMETHODIMP
nsDOMScriptObjectFactory::NewScriptGlobalObject(bool aIsChrome,
bool aIsModalContentWindow,
nsIScriptGlobalObject **aGlobal)
{
return NS_NewScriptGlobalObject(aIsChrome, aIsModalContentWindow, aGlobal);
}
NS_IMETHODIMP_(nsISupports *)
nsDOMScriptObjectFactory::GetClassInfoInstance(nsDOMClassInfoID aID)
{
@ -316,7 +200,7 @@ CreateXPConnectException(nsresult aResult, nsIException *aDefaultException,
NS_ENSURE_SUCCESS(rv, rv);
}
NS_ADDREF(*_retval = exception);
exception.forget(_retval);
return NS_OK;
}
@ -341,31 +225,42 @@ nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName,
aConstructorCID);
}
// Factories
static nsresult
GetJSRuntime(nsIScriptRuntime** aLanguage)
{
nsCOMPtr<nsIDOMScriptObjectFactory> factory =
do_GetService(kDOMScriptObjectFactoryCID);
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE);
NS_IF_ADDREF(*aLanguage = factory->GetJSRuntime());
return NS_OK;
}
nsresult NS_GetScriptRuntime(const nsAString &aLanguageName,
nsIScriptRuntime **aLanguage)
{
nsresult rv;
*aLanguage = nsnull;
nsCOMPtr<nsIDOMScriptObjectFactory> factory = \
do_GetService(kDOMScriptObjectFactoryCID, &rv);
if (NS_FAILED(rv))
return rv;
return factory->GetScriptRuntime(aLanguageName, aLanguage);
*aLanguage = NULL;
NS_ENSURE_TRUE(aLanguageName.EqualsLiteral("application/javascript"),
NS_ERROR_FAILURE);
return GetJSRuntime(aLanguage);
}
nsresult NS_GetScriptRuntimeByID(PRUint32 aScriptTypeID,
nsIScriptRuntime **aLanguage)
{
nsresult rv;
*aLanguage = nsnull;
nsCOMPtr<nsIDOMScriptObjectFactory> factory = \
do_GetService(kDOMScriptObjectFactoryCID, &rv);
if (NS_FAILED(rv))
return rv;
return factory->GetScriptRuntimeByID(aScriptTypeID, aLanguage);
*aLanguage = NULL;
NS_ENSURE_TRUE(aScriptTypeID == nsIProgrammingLanguage::JAVASCRIPT,
NS_ERROR_FAILURE);
return GetJSRuntime(aLanguage);
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsDOMExceptionProvider, nsIExceptionProvider)
NS_IMETHODIMP

Просмотреть файл

@ -68,19 +68,6 @@ public:
NS_DECL_NSIOBSERVER
// nsIDOMScriptObjectFactory
NS_IMETHOD GetScriptRuntime(const nsAString &aLanguageName,
nsIScriptRuntime **aLanguage);
NS_IMETHOD GetScriptRuntimeByID(PRUint32 aLanguageID,
nsIScriptRuntime **aLanguage);
NS_IMETHOD GetIDForScriptType(const nsAString &aLanguageName,
PRUint32 *aLanguageID);
NS_IMETHOD NewScriptGlobalObject(bool aIsChrome,
bool aIsModalContentWindow,
nsIScriptGlobalObject **aGlobal);
NS_IMETHOD_(nsISupports *) GetClassInfoInstance(nsDOMClassInfoID aID);
NS_IMETHOD_(nsISupports *) GetExternalClassInfoInstance(const nsAString& aName);
@ -91,10 +78,6 @@ public:
PRUint32 aScriptableFlags,
bool aHasClassInterface,
const nsCID *aConstructorCID);
protected:
bool mLoadedAllLanguages;
nsCOMPtr<nsIScriptRuntime> mLanguageArray[NS_STID_ARRAY_UBOUND];
};
class nsDOMExceptionProvider : public nsIExceptionProvider

Просмотреть файл

@ -10740,33 +10740,6 @@ nsGlobalWindow::SetHasAudioAvailableEventListeners()
}
}
//*****************************************************************************
// nsGlobalWindow: Creator Function (This should go away)
//*****************************************************************************
nsresult
NS_NewScriptGlobalObject(bool aIsChrome, bool aIsModalContentWindow,
nsIScriptGlobalObject **aResult)
{
*aResult = nsnull;
nsGlobalWindow *global;
if (aIsChrome) {
global = new nsGlobalChromeWindow(nsnull);
} else if (aIsModalContentWindow) {
global = new nsGlobalModalWindow(nsnull);
} else {
global = new nsGlobalWindow(nsnull);
}
NS_ENSURE_TRUE(global, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(*aResult = global);
return NS_OK;
}
#define EVENT(name_, id_, type_, struct_) \
NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \
jsval *vp) { \

Просмотреть файл

@ -1058,8 +1058,20 @@ protected:
};
/* factory function */
nsresult
NS_NewScriptGlobalObject(bool aIsChrome, bool aIsModalContentWindow,
nsIScriptGlobalObject **aResult);
inline already_AddRefed<nsGlobalWindow>
NS_NewScriptGlobalObject(bool aIsChrome, bool aIsModalContentWindow)
{
nsRefPtr<nsGlobalWindow> global;
if (aIsChrome) {
global = new nsGlobalChromeWindow(nsnull);
} else if (aIsModalContentWindow) {
global = new nsGlobalModalWindow(nsnull);
} else {
global = new nsGlobalWindow(nsnull);
}
return global.forget();
}
#endif /* nsGlobalWindow_h___ */

Просмотреть файл

@ -41,14 +41,14 @@
#include "nsISupports.h"
#include "nsIDOMClassInfo.h"
#include "nsStringGlue.h"
#include "nsIScriptRuntime.h"
#define NS_IDOM_SCRIPT_OBJECT_FACTORY_IID \
{ 0x8c0eb687, 0xa859, 0x4a62, \
{ 0x99, 0x82, 0xea, 0xbf, 0x9e, 0xf5, 0x59, 0x5f } }
#define NS_IDOM_SCRIPT_OBJECT_FACTORY_IID \
{ 0x2a50e17c, 0x46ff, 0x4150, \
{ 0xbb, 0x46, 0xd8, 0x07, 0xb3, 0x36, 0xde, 0xab } }
class nsIScriptContext;
class nsIScriptGlobalObject;
class nsIScriptRuntime;
class nsIDOMEventListener;
typedef nsXPCClassInfo* (*nsDOMClassInfoExternalConstructorFnc)
@ -58,27 +58,6 @@ class nsIDOMScriptObjectFactory : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOM_SCRIPT_OBJECT_FACTORY_IID)
// Get a script language given its "name" (ie, the mime-type)
// Note that to fetch javascript from this function, you must currently
// use the name "application/javascript" (but also note that all existing
// callers of this function optimize the detection of JS, so do not
// ask this function for JS)
NS_IMETHOD GetScriptRuntime(const nsAString &aLanguageName,
nsIScriptRuntime **aLanguage) = 0;
// Get a script language given its nsIProgrammingLanguage ID.
NS_IMETHOD GetScriptRuntimeByID(PRUint32 aScriptTypeID,
nsIScriptRuntime **aLanguage) = 0;
// Get the ID for a language given its name - but like GetScriptRuntime,
// only "application/javascript" is currently supported for JS.
NS_IMETHOD GetIDForScriptType(const nsAString &aLanguageName,
PRUint32 *aScriptTypeID) = 0;
NS_IMETHOD NewScriptGlobalObject(bool aIsChrome,
bool aIsModalContentWindow,
nsIScriptGlobalObject **aGlobal) = 0;
NS_IMETHOD_(nsISupports *) GetClassInfoInstance(nsDOMClassInfoID aID) = 0;
NS_IMETHOD_(nsISupports *) GetExternalClassInfoInstance(const nsAString& aName) = 0;
@ -94,6 +73,14 @@ public:
PRUint32 aScriptableFlags,
bool aHasClassInterface,
const nsCID *aConstructorCID) = 0;
nsIScriptRuntime* GetJSRuntime()
{
return mJSRuntime;
}
protected:
nsCOMPtr<nsIScriptRuntime> mJSRuntime;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMScriptObjectFactory,