Make profile manager works in the portable.

This commit is contained in:
Fedor 2019-07-08 13:06:58 +03:00
parent 3950e0958b
commit acaad7bf66
17 changed files with 106 additions and 150 deletions

View File

@ -1145,9 +1145,8 @@ BrowserGlue.prototype = {
isDefaultError = true;
}
//CENTAURY PORTABLE CODE
let isPortable= winShellService.isPortableMode();
if (!isPortable) {
var profService = Cc["@mozilla.org/toolkit/profile-service;1"].getService(Ci.nsIToolkitProfileService);
if (profService.portable()!=1) {
if (isDefault) {
let now = (Math.floor(Date.now() / 1000)).toString();
Services.prefs.setCharPref("browser.shell.mostRecentDateSetAsDefault", now);

View File

@ -632,7 +632,8 @@ var gMainPane = {
defaultBrowserBox.hidden = true;
return;
}
if (shellSvc.isPortableMode()) return;
var profService = Components.classes["@mozilla.org/toolkit/profile-service;1"].getService(Components.interfaces.nsIToolkitProfileService);
if (profService.portable()==1) return;
let setDefaultPane = document.getElementById("setDefaultPane");
let isDefault = shellSvc.isDefaultBrowser(false, true);
setDefaultPane.selectedIndex = isDefault ? 1 : 0;
@ -651,13 +652,15 @@ var gMainPane = {
let alwaysCheckPref = document.getElementById("browser.shell.checkDefaultBrowser");
alwaysCheckPref.value = true;
let shellSvc = getShellService();
let sPortable;
var profService = Components.classes["@mozilla.org/toolkit/profile-service;1"].getService(Components.interfaces.nsIToolkitProfileService);
let isPortable;
if (!shellSvc)
return;
try {
isPortable = shellSvc.isPortableMode();
if (isPortable) {
isPortable = profService.portable();
if (isPortable==1) {
Components.utils.import("resource:///modules/RecentWindow.jsm");
var win = RecentWindow.getMostRecentBrowserWindow();
var brandBundle = win.document.getElementById("bundle_brand");

View File

@ -11,8 +11,6 @@ interface nsIFile;
[scriptable, uuid(2d1a95e4-5bd8-4eeb-b0a8-c1455fd2a357)]
interface nsIShellService : nsISupports
{
boolean isPortableMode();
void cancelPortableMode();
/**
* Determines whether or not Firefox is the "Default Browser."
* This is simply whether or not Firefox is registered to handle

View File

@ -8,6 +8,7 @@
[scriptable, uuid(f8a26b94-49e5-4441-8fbc-315e0b4f22ef)]
interface nsIWindowsShellService : nsIShellService
{
void cancelPortableMode();
/**
* Provides the shell service an opportunity to do some Win7+ shortcut
* maintenance needed on initial startup of the browser.

View File

@ -394,35 +394,6 @@ nsWindowsShellService::CancelPortableMode()
return NS_OK;
}
NS_IMETHODIMP
nsWindowsShellService::IsPortableMode(bool* aIsPortable)
{
nsresult rv;
*aIsPortable=false;
nsCOMPtr<nsIFile> portmodemark;
rv = NS_GetSpecialDirectory(NS_OS_CURRENT_PROCESS_DIR,
getter_AddRefs(portmodemark));
NS_ENSURE_SUCCESS(rv, rv);
rv = portmodemark->AppendNative(NS_LITERAL_CSTRING("pmprt.mod"));
NS_ENSURE_SUCCESS(rv, rv);
bool fileExists;
rv = portmodemark->Exists(&fileExists);
NS_ENSURE_SUCCESS(rv, rv);
// nsAutoString path1;
// rv = portmodemark->GetPath(path1);
// ::MessageBoxW(NULL,path1.get(),L"Teest",MB_OKCANCEL);
if (fileExists){
*aIsPortable=true;
}
return NS_OK;
}
/*
* Query's the AAR for the default status.
* This only checks for BasiliskURL and if aCheckAllTypes is set, then

View File

@ -600,9 +600,9 @@ BrowserGlue.prototype = {
} catch (ex) {
isDefaultError = true;
}
//MYPAL PORTABLE CODE
let isPortable= winShellService.isPortableMode();
if (!isPortable) {
var profService = Cc["@mozilla.org/toolkit/profile-service;1"].getService(Ci.nsIToolkitProfileService);
if (profService.portable()!=1) {
if (isDefault) {
let now = (Math.floor(Date.now() / 1000)).toString();
Services.prefs.setCharPref("browser.shell.mostRecentDateSetAsDefault", now);

View File

@ -722,7 +722,8 @@ var gAdvancedPane = {
document.getElementById("alwaysCheckDefault").disabled = true;
return;
}
if (winShellSvc.isPortableMode()) return;
var profService = Components.classes["@mozilla.org/toolkit/profile-service;1"].getService(Components.interfaces.nsIToolkitProfileService);
if (profService.portable()==1) return;
let selectedIndex =
shellSvc.isDefaultBrowser(false, true) ? 1 : 0;
setDefaultPane.selectedIndex = selectedIndex;
@ -733,14 +734,14 @@ var gAdvancedPane = {
*/
setDefaultBrowser: function()
{
//MYPAL PORTABLE CODE
let shellSvc = getShellService();
let sPortable;
var profService = Components.classes["@mozilla.org/toolkit/profile-service;1"].getService(Components.interfaces.nsIToolkitProfileService);
let isPortable;
if (!shellSvc)
return;
try {
isPortable = winShellSvc.isPortableMode();
if (isPortable) {
isPortable = profService.portable();
if (isPortable==1) {
Components.utils.import("resource:///modules/RecentWindow.jsm");
var win = RecentWindow.getMostRecentBrowserWindow();
var brandBundle = win.document.getElementById("bundle_brand");

View File

@ -8,8 +8,6 @@
[scriptable, uuid(f8a26b94-49e5-4441-8fbc-315e0b4f22ef)]
interface nsIWindowsShellService : nsIShellService
{
//MYPAL PORTABLE CODE
boolean isPortableMode();
void cancelPortableMode();
/**
* Provides the shell service an opportunity to do some Win7+ shortcut

View File

@ -402,7 +402,6 @@ nsWindowsShellService::IsDefaultBrowserVista(bool aCheckAllTypes,
return true;
}
//MYPAL PORTABLE CODE
NS_IMETHODIMP
nsWindowsShellService::CancelPortableMode()
{
@ -428,36 +427,6 @@ nsWindowsShellService::CancelPortableMode()
return NS_OK;
}
NS_IMETHODIMP
nsWindowsShellService::IsPortableMode(bool* aIsPortable)
{
nsresult rv;
*aIsPortable=false;
nsCOMPtr<nsIFile> portmodemark;
rv = NS_GetSpecialDirectory(NS_OS_CURRENT_PROCESS_DIR,
getter_AddRefs(portmodemark));
NS_ENSURE_SUCCESS(rv, rv);
rv = portmodemark->AppendNative(NS_LITERAL_CSTRING("pmprt.mod"));
NS_ENSURE_SUCCESS(rv, rv);
bool fileExists;
rv = portmodemark->Exists(&fileExists);
NS_ENSURE_SUCCESS(rv, rv);
// nsAutoString path1;
// rv = portmodemark->GetPath(path1);
// ::MessageBoxW(NULL,path1.get(),L"Teest",MB_OKCANCEL);
if (fileExists){
*aIsPortable=true;
}
return NS_OK;
}
NS_IMETHODIMP
nsWindowsShellService::IsDefaultBrowser(bool aStartupCheck,
bool aForAllTypes,

View File

@ -44,6 +44,7 @@ NS_IMPL_ISUPPORTS(mozHunspellDirProvider,
nsIDirectoryServiceProvider,
nsIDirectoryServiceProvider2)
NS_IMETHODIMP
mozHunspellDirProvider::GetFile(const char *aKey, bool *aPersist,
nsIFile* *aResult)

View File

@ -26,9 +26,14 @@ function initWizard()
try {
gProfileService = C[ToolkitProfileService].getService(I.nsIToolkitProfileService);
gProfileManagerBundle = document.getElementById("bundle_profileManager");
var pathProp="DefProfRt"
var dirService = C["@mozilla.org/file/directory_service;1"].getService(I.nsIProperties);
gDefaultProfileParent = dirService.get("DefProfRt", I.nsIFile);
var profService = C["@mozilla.org/toolkit/profile-service;1"].getService(I.nsIToolkitProfileService);
if (profService.portable()>0){
pathProp="CurProcD";
gDefaultProfileParent = dirService.get(pathProp, I.nsIFile).parent;
}
else gDefaultProfileParent = dirService.get(pathProp, I.nsIFile);
// Initialize the profile location display.
gProfileDisplay = document.getElementById("profileDisplay").firstChild;

View File

@ -101,6 +101,8 @@ interface nsIToolkitProfileService : nsISupports
* Flush the profiles list file.
*/
void flush();
uint32_t portable();
};
%{C++

View File

@ -112,7 +112,7 @@ public:
private:
friend class nsToolkitProfile;
friend class nsToolkitProfileFactory;
friend nsresult NS_NewToolkitProfileService(nsIToolkitProfileService**,int);
friend nsresult NS_NewToolkitProfileService(nsIToolkitProfileService**,uint32_t);
nsToolkitProfileService() :
mDirty(false),
@ -126,7 +126,7 @@ private:
gService = nullptr;
}
nsresult Init(int portable);
nsresult Init(uint32_t portable);
nsresult CreateTimesInternal(nsIFile *profileDir);
@ -382,19 +382,30 @@ NS_IMPL_ISUPPORTS(nsToolkitProfileService,
nsIToolkitProfileService)
nsresult
nsToolkitProfileService::Init(int portable)
nsToolkitProfileService::Init(uint32_t portable)
{
//MYPAL CODE
if(portable>0) return NS_OK;
NS_ASSERTION(gDirServiceProvider, "No dirserviceprovider!");
nsresult rv;
rv = gDirServiceProvider->GetUserAppDataDirectory(getter_AddRefs(mAppData));
NS_ENSURE_SUCCESS(rv, rv);
if(portable>0){
nsCOMPtr<nsIFile> appFile;
bool per = false;
rv = gDirServiceProvider->GetFile(XRE_EXECUTABLE_FILE, &per, getter_AddRefs(appFile));
NS_ENSURE_SUCCESS(rv, rv);
rv = appFile->GetParent(getter_AddRefs(mAppData));
NS_ENSURE_SUCCESS(rv, rv);
rv = appFile->GetParent(getter_AddRefs(mTempData));
NS_ENSURE_SUCCESS(rv, rv);
rv = gDirServiceProvider->GetUserLocalDataDirectory(getter_AddRefs(mTempData));
NS_ENSURE_SUCCESS(rv, rv);
}
else{
rv = gDirServiceProvider->GetUserAppDataDirectory(getter_AddRefs(mAppData));
NS_ENSURE_SUCCESS(rv, rv);
rv = gDirServiceProvider->GetUserLocalDataDirectory(getter_AddRefs(mTempData));
NS_ENSURE_SUCCESS(rv, rv);
}
rv = mAppData->Clone(getter_AddRefs(mListFile));
NS_ENSURE_SUCCESS(rv, rv);
@ -1015,6 +1026,13 @@ nsToolkitProfileService::Flush()
return NS_OK;
}
NS_IMETHODIMP
nsToolkitProfileService::Portable(uint32_t *aResult)
{
return gDirServiceProvider->Portable(aResult);
}
NS_IMPL_ISUPPORTS(nsToolkitProfileFactory, nsIFactory)
NS_IMETHODIMP
@ -1052,7 +1070,7 @@ NS_NewToolkitProfileFactory(nsIFactory* *aResult)
}
nsresult
NS_NewToolkitProfileService(nsIToolkitProfileService* *aResult,int portable)
NS_NewToolkitProfileService(nsIToolkitProfileService* *aResult,uint32_t portable)
{
nsToolkitProfileService* profileService = new nsToolkitProfileService();
if (!profileService)

View File

@ -211,6 +211,7 @@ char **gRestartArgv;
bool gIsGtest = false;
nsString gAbsoluteArgv0Path;
uint32_t portable;
#if defined(MOZ_WIDGET_GTK)
#include <glib.h>
@ -1920,7 +1921,7 @@ static nsAutoCString gResetOldProfileName;
// 6) display the profile-manager UI
static nsresult
SelectProfile(nsIProfileLock* *aResult, nsIToolkitProfileService* aProfileSvc, nsINativeAppSupport* aNative,
bool* aStartOffline, nsACString* aProfileName,int prt)
bool* aStartOffline, nsACString* aProfileName)
{
StartupTimeline::Record(StartupTimeline::SELECT_PROFILE);
@ -2010,6 +2011,14 @@ SelectProfile(nsIProfileLock* *aResult, nsIToolkitProfileService* aProfileSvc, n
return NS_LockProfilePath(lf, localDir, nullptr, aResult);
}
nsCOMPtr<nsIFile> exeFile;
nsIFile* rootDir=nullptr;
if (portable>0){
XRE_GetBinaryPath(gArgv[0], getter_AddRefs(exeFile));
exeFile->GetParent(&rootDir);
rootDir->AppendNative(NS_LITERAL_CSTRING("Profile"));
}
ar = CheckArg("profile", true, &arg);
if (ar == ARG_BAD) {
PR_fprintf(PR_STDERR, "Error: argument --profile requires a path\n");
@ -2044,39 +2053,6 @@ SelectProfile(nsIProfileLock* *aResult, nsIToolkitProfileService* aProfileSvc, n
return ProfileLockedDialog(lf, lf, unlocker, aNative, aResult);
}
//MYPAL PORTABLE CODE START
if (prt>0) {
//lstrcmpW(L"Teest",L"Teest");
nsCOMPtr<nsIFile> exeFile;
rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(exeFile));
rv = exeFile->GetParent(getter_AddRefs(lf));
lf->AppendNative(*aProfileName);
// nsAutoString path1;
// rv = lf->GetPath(path1);
// ::MessageBoxW(NULL,path1.get(),L"Teest",MB_OKCANCEL);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIProfileUnlocker> unlocker;
bool exists;
lf->Exists(&exists);
if (!exists) {
rv = lf->Create(nsIFile::DIRECTORY_TYPE, 0700);
NS_ENSURE_SUCCESS(rv, rv);
}
// If a profile path is specified directory on the command line, then
// assume that the temp directory is the same as the given directory.
rv = NS_LockProfilePath(lf, lf, getter_AddRefs(unlocker), aResult);
if (NS_SUCCEEDED(rv))
return rv;
return ProfileLockedDialog(lf, lf, unlocker, aNative, aResult);
}
//MYPAL PORTABLE CODE END
ar = CheckArg("createprofile", true, &arg);
if (ar == ARG_BAD) {
PR_fprintf(PR_STDERR, "Error: argument --createprofile requires a profile name\n");
@ -2099,7 +2075,15 @@ SelectProfile(nsIProfileLock* *aResult, nsIToolkitProfileService* aProfileSvc, n
// main profile directory.
rv = aProfileSvc->CreateProfile(lf, nsDependentCSubstring(arg, delim),
getter_AddRefs(profile));
} else {
}
else if(portable>0) {
nsCOMPtr<nsIFile> lf;
rootDir->GetParent(getter_AddRefs(lf));
lf->AppendNative(nsDependentCString(arg));
rv = aProfileSvc->CreateProfile(lf, nsDependentCString(arg),
getter_AddRefs(profile));
}
else {
rv = aProfileSvc->CreateProfile(nullptr, nsDependentCString(arg),
getter_AddRefs(profile));
}
@ -2228,7 +2212,7 @@ SelectProfile(nsIProfileLock* *aResult, nsIToolkitProfileService* aProfileSvc, n
// create a default profile
nsCOMPtr<nsIToolkitProfile> profile;
nsresult rv = aProfileSvc->CreateProfile(nullptr, // choose a default dir for us
nsresult rv = aProfileSvc->CreateProfile(rootDir, // choose a default dir for us
#ifdef MOZ_DEV_EDITION
NS_LITERAL_CSTRING("dev-edition-default"),
#else
@ -2761,7 +2745,6 @@ public:
int XRE_main(int argc, char* argv[], const nsXREAppData* aAppData);
int XRE_mainInit(bool* aExitFlag);
int XRE_mainStartup(bool* aExitFlag);
int portable();
nsresult XRE_mainRun();
nsCOMPtr<nsINativeAppSupport> mNativeApp;
@ -2793,21 +2776,6 @@ public:
#endif
};
//MYPAL CODE
int XREMain::portable(){
bool portable;
nsCOMPtr<nsIFile> portmodemark;
mDirProvider.GetAppDir()->Clone(getter_AddRefs(portmodemark));
portmodemark->AppendNative(NS_LITERAL_CSTRING("pmprt.mod"));
portmodemark->Exists(&portable);
if (portable) return 1;
mDirProvider.GetAppDir()->Clone(getter_AddRefs(portmodemark));
portmodemark->AppendNative(NS_LITERAL_CSTRING("pmundprt.mod"));
portmodemark->Exists(&portable);
if (portable) return 2;
else return 0;
}
/*
* XRE_mainInit - Initial setup and command line parameter processing.
* Main() will exit early if either return value != 0 or if aExitFlag is
@ -3126,7 +3094,10 @@ XREMain::XRE_mainInit(bool* aExitFlag)
}
//MYPAL CODE
//lstrcmpW(L"Teest",L"Teest");
if (portable()==1) SaveToEnv("MOZ_NO_REMOTE=1");
mDirProvider.Portable(&portable);
if (portable==1) SaveToEnv("MOZ_NO_REMOTE=1");
ar = CheckArg("new-instance", true);
if (ar == ARG_BAD) {
@ -3519,11 +3490,8 @@ XREMain::XRE_mainStartup(bool* aExitFlag)
return 0;
}
#endif
//MYPAL CODE
int prt=portable();
if (prt>0) mProfileName.Assign("\Profile");
rv = NS_NewToolkitProfileService(getter_AddRefs(mProfileSvc),prt);
rv = NS_NewToolkitProfileService(getter_AddRefs(mProfileSvc),portable);
if (rv == NS_ERROR_FILE_ACCESS_DENIED) {
PR_fprintf(PR_STDERR, "Error: Access was denied while trying to open files in " \
"your profile directory.\n");
@ -3535,7 +3503,7 @@ XREMain::XRE_mainStartup(bool* aExitFlag)
}
rv = SelectProfile(getter_AddRefs(mProfileLock), mProfileSvc, mNativeApp, &mStartOffline,
&mProfileName,prt);
&mProfileName);
if (rv == NS_ERROR_LAUNCHED_CHILD_PROCESS ||
rv == NS_ERROR_ABORT) {
*aExitFlag = true;

View File

@ -65,7 +65,7 @@ extern bool gIsGtest;
nsresult NS_CreateNativeAppSupport(nsINativeAppSupport* *aResult);
nsresult
NS_NewToolkitProfileService(nsIToolkitProfileService* *aResult,int portable);
NS_NewToolkitProfileService(nsIToolkitProfileService* *aResult,uint32_t portable);
nsresult
NS_NewToolkitProfileFactory(nsIFactory* *aResult);

View File

@ -279,6 +279,26 @@ GetSystemParentDirectory(nsIFile** aFile)
}
#endif
nsresult
nsXREDirProvider::Portable(uint32_t *aResult)
{
bool portable;
nsCOMPtr<nsIFile> portmodemark;
GetAppDir()->Clone(getter_AddRefs(portmodemark));
portmodemark->AppendNative(NS_LITERAL_CSTRING("pmprt.mod"));
portmodemark->Exists(&portable);
if (portable){
*aResult=1;
return NS_OK;
}
GetAppDir()->Clone(getter_AddRefs(portmodemark));
portmodemark->AppendNative(NS_LITERAL_CSTRING("pmundprt.mod"));
portmodemark->Exists(&portable);
if (portable) *aResult=2;
else *aResult=0;
return NS_OK;
}
NS_IMETHODIMP
nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
nsIFile** aFile)

View File

@ -37,6 +37,8 @@ public:
static nsXREDirProvider* GetSingleton();
nsresult Portable(uint32_t *aResult);
nsresult GetUserProfilesRootDir(nsIFile** aResult,
const nsACString* aProfileName,
const nsACString* aAppName,