зеркало из https://github.com/mozilla/pjs.git
Enable fastloading of JS components. Bug 279839, r=shaver sr=brendan.
This commit is contained in:
Родитель
4ce8884b85
Коммит
3ca2aef100
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -48,23 +48,54 @@
|
|||
#include "nsIModule.h"
|
||||
#include "nsSupportsArray.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIFastLoadService.h"
|
||||
#include "nsIObjectInputStream.h"
|
||||
#include "nsIObjectOutputStream.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsIObserver.h"
|
||||
#ifndef XPCONNECT_STANDALONE
|
||||
#include "nsIPrincipal.h"
|
||||
#endif
|
||||
extern const char mozJSComponentLoaderContractID[];
|
||||
extern const char jsComponentTypeName[];
|
||||
|
||||
class nsIFastLoadService;
|
||||
|
||||
/* 6bd13476-1dd2-11b2-bbef-f0ccb5fa64b6 (thanks, mozbot) */
|
||||
|
||||
#define MOZJSCOMPONENTLOADER_CID \
|
||||
{0x6bd13476, 0x1dd2, 0x11b2, \
|
||||
{ 0xbb, 0xef, 0xf0, 0xcc, 0xb5, 0xfa, 0x64, 0xb6 }}
|
||||
#define MOZJSCOMPONENTLOADER_CONTRACTID "@mozilla.org/moz/jsloader;1"
|
||||
#define MOZJSCOMPONENTLOADER_TYPE_NAME "text/javascript"
|
||||
|
||||
class mozJSComponentLoader : public nsIComponentLoader {
|
||||
// nsIFastLoadFileIO implementation for component fastload
|
||||
class nsXPCFastLoadIO : public nsIFastLoadFileIO
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFASTLOADFILEIO
|
||||
|
||||
public:
|
||||
nsXPCFastLoadIO(nsIFile *file) : mFile(file) {}
|
||||
|
||||
void SetInputStream(nsIInputStream *stream) { mInputStream = stream; }
|
||||
void SetOutputStream(nsIOutputStream *stream) { mOutputStream = stream; }
|
||||
|
||||
private:
|
||||
~nsXPCFastLoadIO() {}
|
||||
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
nsCOMPtr<nsIOutputStream> mOutputStream;
|
||||
};
|
||||
|
||||
|
||||
class mozJSComponentLoader : public nsIComponentLoader,
|
||||
public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICOMPONENTLOADER
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
mozJSComponentLoader();
|
||||
virtual ~mozJSComponentLoader();
|
||||
|
@ -74,15 +105,31 @@ public:
|
|||
nsresult AttemptRegistration(nsIFile *component, PRBool deferred);
|
||||
nsresult UnregisterComponent(nsIFile *component);
|
||||
nsresult RegisterComponentsInDir(PRInt32 when, nsIFile *dir);
|
||||
JSObject *GlobalForLocation(const char *aLocation, nsIFile *component);
|
||||
nsIModule *ModuleForLocation(const char *aLocation, nsIFile *component);
|
||||
nsresult GlobalForLocation(const char *aLocation, nsIFile *aComponent,
|
||||
JSObject **aGlobal);
|
||||
nsIModule* ModuleForLocation(const char *aLocation, nsIFile *component,
|
||||
nsresult *status);
|
||||
PRBool HasChanged(const char *registryLocation, nsIFile *component);
|
||||
nsresult SetRegistryInfo(const char *registryLocation, nsIFile *component);
|
||||
nsresult RemoveRegistryInfo(nsIFile *component, const char *registryLocation);
|
||||
|
||||
nsresult StartFastLoad(nsIFastLoadService *flSvc);
|
||||
nsresult ReadScript(nsIFastLoadService *flSvc, const char *nativePath,
|
||||
nsIURI *uri, JSContext *cx, JSScript **script);
|
||||
nsresult WriteScript(nsIFastLoadService *flSvc, JSScript *script,
|
||||
nsIFile *component, const char *nativePath,
|
||||
nsIURI *uri, JSContext *cx);
|
||||
static void CloseFastLoad(nsITimer *timer, void *closure);
|
||||
void CloseFastLoad();
|
||||
|
||||
nsCOMPtr<nsIComponentManager> mCompMgr;
|
||||
nsCOMPtr<nsIComponentLoaderManager> mLoaderManager;
|
||||
nsCOMPtr<nsIJSRuntimeService> mRuntimeService;
|
||||
nsCOMPtr<nsIFile> mFastLoadFile;
|
||||
nsRefPtr<nsXPCFastLoadIO> mFastLoadIO;
|
||||
nsCOMPtr<nsIObjectInputStream> mFastLoadInput;
|
||||
nsCOMPtr<nsIObjectOutputStream> mFastLoadOutput;
|
||||
nsCOMPtr<nsITimer> mFastLoadTimer;
|
||||
#ifndef XPCONNECT_STANDALONE
|
||||
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
||||
#endif
|
||||
|
@ -94,31 +141,3 @@ public:
|
|||
PRBool mInitialized;
|
||||
nsSupportsArray mDeferredComponents;
|
||||
};
|
||||
|
||||
class JSCLContextHelper
|
||||
{
|
||||
public:
|
||||
JSCLContextHelper(JSContext* cx);
|
||||
~JSCLContextHelper();
|
||||
|
||||
operator JSContext*() const {return mContext;}
|
||||
|
||||
JSCLContextHelper(); // not implemnted
|
||||
private:
|
||||
JSContext* mContext;
|
||||
intN mContextThread;
|
||||
};
|
||||
|
||||
|
||||
class JSCLAutoErrorReporterSetter
|
||||
{
|
||||
public:
|
||||
JSCLAutoErrorReporterSetter(JSContext* cx, JSErrorReporter reporter)
|
||||
{mContext = cx; mOldReporter = JS_SetErrorReporter(cx, reporter);}
|
||||
~JSCLAutoErrorReporterSetter()
|
||||
{JS_SetErrorReporter(mContext, mOldReporter);}
|
||||
JSCLAutoErrorReporterSetter(); // not implemented
|
||||
private:
|
||||
JSContext* mContext;
|
||||
JSErrorReporter mOldReporter;
|
||||
};
|
||||
|
|
|
@ -64,8 +64,9 @@ RegisterJSLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
|
|||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsXPIDLCString previous;
|
||||
return catman->AddCategoryEntry("component-loader", jsComponentTypeName,
|
||||
mozJSComponentLoaderContractID,
|
||||
return catman->AddCategoryEntry("component-loader",
|
||||
MOZJSCOMPONENTLOADER_TYPE_NAME,
|
||||
MOZJSCOMPONENTLOADER_CONTRACTID,
|
||||
PR_TRUE, PR_TRUE, getter_Copies(previous));
|
||||
}
|
||||
|
||||
|
@ -79,14 +80,16 @@ UnregisterJSLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
|
|||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsXPIDLCString jsLoader;
|
||||
rv = catman->GetCategoryEntry("component-loader", jsComponentTypeName,
|
||||
rv = catman->GetCategoryEntry("component-loader",
|
||||
MOZJSCOMPONENTLOADER_TYPE_NAME,
|
||||
getter_Copies(jsLoader));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// only unregister if we're the current JS component loader
|
||||
if (!strcmp(jsLoader, mozJSComponentLoaderContractID)) {
|
||||
if (!strcmp(jsLoader, MOZJSCOMPONENTLOADER_CONTRACTID)) {
|
||||
return catman->DeleteCategoryEntry("component-loader",
|
||||
jsComponentTypeName, PR_TRUE);
|
||||
MOZJSCOMPONENTLOADER_TYPE_NAME,
|
||||
PR_TRUE);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ static const nsModuleComponentInfo components[] = {
|
|||
#ifdef MOZ_JSLOADER
|
||||
// jsloader stuff
|
||||
,{ "JS component loader", MOZJSCOMPONENTLOADER_CID,
|
||||
mozJSComponentLoaderContractID, mozJSComponentLoaderConstructor,
|
||||
MOZJSCOMPONENTLOADER_CONTRACTID, mozJSComponentLoaderConstructor,
|
||||
RegisterJSLoader, UnregisterJSLoader }
|
||||
#ifndef NO_SUBSCRIPT_LOADER
|
||||
,{ "JS subscript loader", MOZ_JSSUBSCRIPTLOADER_CID,
|
||||
|
|
|
@ -65,6 +65,12 @@
|
|||
// and we load localstore from somewhere else.
|
||||
#define NS_LOCALSTORE_UNSAFE_FILE "LStoreS"
|
||||
|
||||
// This directory service key is a lot like NS_APP_USER_PROFILE_LOCAL_50_DIR,
|
||||
// except that it will be available even when the profile hasn't been
|
||||
// "started", or after it has been shut down. If we're in "no-profile" mode,
|
||||
// such as showing the profile manager uI, this key will not be available.
|
||||
#define NS_APP_PROFILE_LOCAL_DIR_STARTUP "ProfLDS"
|
||||
|
||||
class nsACString;
|
||||
struct nsXREAppData;
|
||||
struct nsStaticModuleInfo;
|
||||
|
|
|
@ -256,6 +256,10 @@ nsXREDirProvider::GetFile(const char* aProperty, PRBool* aPersistent,
|
|||
else if (!strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP) && mProfileDir) {
|
||||
return mProfileDir->Clone(aFile);
|
||||
}
|
||||
else if (!strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP) &&
|
||||
mProfileLocalDir) {
|
||||
return mProfileLocalDir->Clone(aFile);
|
||||
}
|
||||
else if (mProfileNotified) {
|
||||
if (!strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR) ||
|
||||
!strcmp(aProperty, NS_APP_PREFS_50_DIR)) {
|
||||
|
|
|
@ -114,15 +114,33 @@ nsFastLoadService::NewFastLoadFile(const char* aBaseName, nsIFile* *aResult)
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
// Try "ProfDS" first, so that we can get the profile directory
|
||||
// during startup.
|
||||
nsCOMPtr<nsIFile> profFile;
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
||||
rv = NS_GetSpecialDirectory("ProfDS",
|
||||
getter_AddRefs(profFile));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (NS_FAILED(rv)) {
|
||||
// The directory service doesn't know about "ProfDS", so just ask
|
||||
// for the regular profile directory key. Note, however, that this
|
||||
// will fail if a profile hasn't yet been selected.
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
||||
getter_AddRefs(profFile));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Try "ProfLDS" first, so that we can get the local profile directory
|
||||
// during startup.
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_LOCAL_50_DIR,
|
||||
getter_AddRefs(file));
|
||||
rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) {
|
||||
// The directory service doesn't know about "ProfLDS", so just ask
|
||||
// for the regular local profile directory key. Note, however, that
|
||||
// this will fail if a profile hasn't yet been selected.
|
||||
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_LOCAL_50_DIR,
|
||||
getter_AddRefs(file));
|
||||
}
|
||||
if (NS_FAILED(rv))
|
||||
file = profFile;
|
||||
|
||||
|
|
|
@ -90,6 +90,9 @@ interface nsIBinaryInputStream : nsIInputStream {
|
|||
|
||||
%{C++
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsString.h"
|
||||
|
||||
inline nsresult
|
||||
NS_ReadOptionalCString(nsIBinaryInputStream* aStream, nsACString& aResult)
|
||||
{
|
||||
|
@ -117,5 +120,6 @@ NS_ReadOptionalString(nsIBinaryInputStream* aStream, nsAString& aResult)
|
|||
}
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
|
Загрузка…
Ссылка в новой задаче