mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 09:49:14 +00:00
This change-bundle fixes the long standing problem where you couldn't
run webclient at the same time mozilla was running. It does this by introducing a new startup command, which must be called before the first call to BrowserControlFactory.setAppData(), like this: BrowserControlFactory.setProfile(startupProfile); BrowserControlFactory.setAppData(getBrowserBinDir()); This will cause the startupProfile to be created (if necessary) and used as webclient's mozilla profile. If not specified, a "webclient" profile is created and used. This profile sticks around on your system. SECTION: CHANGES M classes_spec/org/mozilla/webclient/BrowserControlFactory.java M classes_spec/org/mozilla/webclient/WebclientFactory.java M classes_spec/org/mozilla/webclient/impl/WebclientFactoryImpl.java - add setProfile(). M classes_spec/org/mozilla/webclient/impl/WrapperFactory.java M classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java - add setProfile() and getProfile(). M classes_spec/org/mozilla/webclient/impl/wrapper_native/ProfileManagerImpl.java - pass the wrapperFactory's profile property to the nativeStartup(). M src_moz/ProfileManagerImpl.cpp - logic to implement above changes M test/automated/src/classes/org/mozilla/webclient/ProfileManagerTest.java - test that the startupProfile feature works.
This commit is contained in:
parent
9a577efa0d
commit
2003722eca
@ -44,7 +44,7 @@ import java.io.FileNotFoundException;
|
||||
* simply call through to this implemenatation instance.</p>
|
||||
*
|
||||
*
|
||||
* @version $Id: BrowserControlFactory.java,v 1.10 2004/04/01 14:54:56 edburns%acm.org Exp $
|
||||
* @version $Id: BrowserControlFactory.java,v 1.11 2004/11/05 06:40:26 edburns%acm.org Exp $
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ -74,6 +74,11 @@ private BrowserControlFactory()
|
||||
// Class methods
|
||||
//
|
||||
|
||||
public static void setProfile(String profileName)
|
||||
{
|
||||
getInstance().setProfile(profileName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>Initialize the webclient API passing in the path to the browser
|
||||
|
@ -55,6 +55,14 @@ public interface WebclientFactory {
|
||||
public void setAppData(String absolutePathToNativeBrowserBinDir)
|
||||
throws FileNotFoundException, ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* <p>if called before {@link setAppData}, this will cause the
|
||||
* profile used for starting up the underlying browser to be set.
|
||||
* If not called, the default will be "webclient"</p>
|
||||
*/
|
||||
|
||||
public void setProfile(String profileName);
|
||||
|
||||
public void appTerminate() throws Exception;
|
||||
|
||||
public BrowserControl newBrowserControl()
|
||||
|
@ -84,6 +84,11 @@ public WebclientFactoryImpl()
|
||||
// Public methods
|
||||
//
|
||||
|
||||
|
||||
public void setProfile(String profileName)
|
||||
{
|
||||
getWrapperFactory().setProfile(profileName);
|
||||
}
|
||||
|
||||
public void setAppData(String absolutePathToNativeBrowserBinDir) throws FileNotFoundException, ClassNotFoundException
|
||||
{
|
||||
|
@ -47,6 +47,9 @@ public interface WrapperFactory {
|
||||
|
||||
public Object newImpl(String interfaceName,
|
||||
BrowserControl browserControl) throws ClassNotFoundException;
|
||||
|
||||
public String getProfile();
|
||||
public void setProfile(String profileName);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -47,7 +47,8 @@ public ProfileManagerImpl(WrapperFactory yourFactory)
|
||||
|
||||
public void startup() {
|
||||
Assert.assert_it(isNativeEventThread());
|
||||
nativeStartup(getWrapperFactory().getNativeWrapperFactory(), null, null);
|
||||
nativeStartup(getWrapperFactory().getNativeWrapperFactory(), null,
|
||||
getWrapperFactory().getProfile());
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
|
@ -85,6 +85,7 @@ public class WrapperFactoryImpl extends Object implements WrapperFactory {
|
||||
// Attribute Instance Variables
|
||||
|
||||
protected String platformCanvasClassName = null;
|
||||
protected String profileName = "webclient";
|
||||
protected boolean initialized = false;
|
||||
protected boolean terminated = false;
|
||||
|
||||
@ -259,6 +260,14 @@ public class WrapperFactoryImpl extends Object implements WrapperFactory {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setProfile(String profileName) {
|
||||
this.profileName = profileName;
|
||||
}
|
||||
|
||||
public String getProfile() {
|
||||
return profileName;
|
||||
}
|
||||
|
||||
public void initialize(String verifiedBinDirAbsolutePath) throws SecurityException, UnsatisfiedLinkError {
|
||||
if (initialized) {
|
||||
@ -327,6 +336,8 @@ public class WrapperFactoryImpl extends Object implements WrapperFactory {
|
||||
initialized = false;
|
||||
System.out.println("WrapperFactoryImpl.initialize: Can't start up singleton services: " + e + " " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void verifyInitialized() throws IllegalStateException
|
||||
|
@ -50,7 +50,7 @@ static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_ProfileManagerImpl_nativeStartup
|
||||
(JNIEnv *env, jobject obj, jint nativeContext,
|
||||
jstring profileDir , jstring profileName)
|
||||
jstring profileDir , jstring profileNameJstr)
|
||||
{
|
||||
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
|
||||
("ProfileManagerImpl_nativeStartup: entering\n"));
|
||||
@ -71,43 +71,67 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_ProfileMa
|
||||
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
|
||||
("ProfileManagerImpl_nativeStartup: GetProfileCount rv: %d\n",
|
||||
rv));
|
||||
|
||||
|
||||
PRUnichar *webclientProfile = nsnull;
|
||||
char *webclientProfileCstr = nsnull;
|
||||
|
||||
if (nsnull == profileNameJstr) {
|
||||
NS_NAMED_LITERAL_STRING(webclientStr, "webclient");
|
||||
webclientProfile = (PRUnichar *) webclientStr.get();
|
||||
webclientProfileCstr = "webclient";
|
||||
}
|
||||
else {
|
||||
webclientProfile = (PRUnichar *)
|
||||
::util_GetStringChars(env, profileNameJstr);
|
||||
webclientProfileCstr = (char *)
|
||||
::util_GetStringUTFChars(env, profileNameJstr);
|
||||
}
|
||||
|
||||
char *argv[3];
|
||||
int i, argc = 0;
|
||||
int i,j;
|
||||
PRBool hasWebclientProfile = PR_FALSE;
|
||||
argv[0] = PL_strdup(nsnull);
|
||||
if (numProfiles > 1) {
|
||||
argv[1] = PL_strdup("-p");
|
||||
|
||||
if (0 < numProfiles) {
|
||||
PRUnichar **Names;
|
||||
PRUint32 NamesLen = 0;
|
||||
rv = profile->GetProfileList(&NamesLen, &Names);
|
||||
|
||||
argv[1] = PL_strdup("-p");
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PR_ASSERT(NamesLen >= 1);
|
||||
// PENDING(edburns): fix for 70656. Really we should have a way
|
||||
// for the embedding app to specify which profile to use.
|
||||
// For now we just get the name of the first profile.
|
||||
char * temp = new char[100]; // de-allocated in following for loop
|
||||
for (i = 0; Names[0][i] != '\0'; i++) {
|
||||
temp[i] = (char) Names[0][i];
|
||||
|
||||
char * temp = new char[100]; // de-allocated following for loop
|
||||
for (i = 0; i < NamesLen; i++) {
|
||||
for (j = 0; Names[i][j] != '\0'; j++) {
|
||||
temp[j] = (char) Names[i][j];
|
||||
}
|
||||
temp[j] = '\0';
|
||||
if (0 == strcmp(webclientProfileCstr, temp)) {
|
||||
hasWebclientProfile = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
nsMemory::Free(Names);
|
||||
temp[i] = '\0';
|
||||
argv[2] = temp;
|
||||
argc = 3;
|
||||
}
|
||||
else {
|
||||
argv[2] = PL_strdup("default");
|
||||
}
|
||||
argv[2] = PL_strdup(webclientProfileCstr);
|
||||
}
|
||||
else {
|
||||
argc = 1;
|
||||
|
||||
if (!hasWebclientProfile) {
|
||||
rv = profile->CreateNewProfile(webclientProfile, nsnull, nsnull,
|
||||
PR_FALSE);
|
||||
if (NS_FAILED(rv)) {
|
||||
::util_ThrowExceptionToJava(env, "Can't statrup nsIProfile service.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
rv = cmdLine->Initialize(argc, argv);
|
||||
|
||||
rv = cmdLine->Initialize(3, argv);
|
||||
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
|
||||
("ProfileManagerImpl_nativeStartup: commandLineService initialize rv: %d\n",
|
||||
rv));
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
nsCRT::free(argv[i]);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -130,7 +154,14 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_ProfileMa
|
||||
::util_ThrowExceptionToJava(env, "Can't statrup nsIProfile service.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// only release if we allocated
|
||||
if (nsnull != profileNameJstr) {
|
||||
::util_ReleaseStringChars(env, profileNameJstr, webclientProfile);
|
||||
::util_ReleaseStringUTFChars(env, profileNameJstr,
|
||||
webclientProfileCstr);
|
||||
}
|
||||
|
||||
wcContext->sProfile = profile.get();
|
||||
NS_ADDREF(wcContext->sProfile);
|
||||
wcContext->sProfileInternal = profileInt.get();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: ProfileManagerTest.java,v 1.2 2004/02/26 04:21:24 edburns%acm.org Exp $
|
||||
* $Id: ProfileManagerTest.java,v 1.3 2004/11/05 06:40:27 edburns%acm.org Exp $
|
||||
*/
|
||||
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
@ -50,9 +50,11 @@ public class ProfileManagerTest extends WebclientTestCase {
|
||||
i = 0,
|
||||
len = 0;
|
||||
final String
|
||||
startupProfile = "testStartupProfile",
|
||||
name = "testProfile",
|
||||
newName = "testProfile2";
|
||||
BrowserControl firstBrowserControl = null;
|
||||
BrowserControlFactory.setProfile(startupProfile);
|
||||
BrowserControlFactory.setAppData(getBrowserBinDir());
|
||||
firstBrowserControl = BrowserControlFactory.newBrowserControl();
|
||||
assertNotNull(firstBrowserControl);
|
||||
@ -61,6 +63,8 @@ public class ProfileManagerTest extends WebclientTestCase {
|
||||
ProfileManager profileManager = (ProfileManager)
|
||||
firstBrowserControl.queryInterface(BrowserControl.PROFILE_MANAGER_NAME);
|
||||
assertNotNull(profileManager);
|
||||
|
||||
assertEquals(startupProfile, profileManager.getCurrentProfile());
|
||||
|
||||
// create a new profile
|
||||
profileManager.createNewProfile(name, null, null, false);
|
||||
@ -75,6 +79,9 @@ public class ProfileManagerTest extends WebclientTestCase {
|
||||
// test that we can set the current profile to the new profile
|
||||
profileManager.setCurrentProfile(name);
|
||||
|
||||
// delete the startupProfile
|
||||
profileManager.deleteProfile(startupProfile, true);
|
||||
|
||||
// test that the current profile is the new profile
|
||||
String currentProfile = profileManager.getCurrentProfile();
|
||||
assertTrue(currentProfile.equals(name));
|
||||
|
Loading…
x
Reference in New Issue
Block a user