make "home" button do the right thing. turn pref manager object into a

shared object owned by the main controller so other objects can easily
get to it to ask about prefs. reworked the code that gets the homepage
so that it conditionally checks if it should check the startup page
mode (obviously the home button doesn't want that). bug# 148936.
This commit is contained in:
pinkerton%netscape.com 2002-06-04 18:36:29 +00:00
Родитель e3aaa9697a
Коммит 8558bac154
16 изменённых файлов: 176 добавлений и 124 удалений

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

@ -38,6 +38,7 @@
#import "BrowserWindowController.h"
#import "CHBrowserWrapper.h"
#import "CHIconTabViewItem.h"
#import "CHPreferenceManager.h"
#include "nsIWebNavigation.h"
#include "nsIDOMElement.h"
@ -55,7 +56,6 @@
#include "CHGeckoUtils.h"
#include "nsIWebProgressListener.h"
static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
@ -608,7 +608,7 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
- (IBAction)home:(id)aSender
{
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:[[CHPreferenceManager sharedInstance] homePage:NO]] flags:NSLoadFlagsNone];
}
- (IBAction)toggleSidebar:(id)aSender

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

@ -14,6 +14,8 @@
ICInstance internetConfig;
}
+ (CHPreferenceManager *)sharedInstance;
- (id) init;
- (void) dealloc;
- (BOOL) initInternetConfig;
@ -21,6 +23,6 @@
- (void) syncMozillaPrefs;
// - (BOOL) getICBoolPref:(ConstStr255Param) prefKey;
- (NSString *) getICStringPref:(ConstStr255Param) prefKey;
- (NSString *) homePage;
- (NSString *) homePage:(BOOL) checkStartupPagePref;
@end

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

@ -15,6 +15,13 @@ extern const char *prefContractID;
@implementation CHPreferenceManager
+ (CHPreferenceManager *) sharedInstance {
static CHPreferenceManager *sSharedInstance = nil;
return ( sSharedInstance ? sSharedInstance : (sSharedInstance = [[[CHPreferenceManager alloc] init] autorelease] ));
}
- (id) init
{
if ((self = [super init])) {
@ -258,33 +265,36 @@ extern const char *prefContractID;
return string;
}
- (NSString *) homePage
{
NSString *url;
char *buf;
PRInt32 mode;
nsresult rv;
NSLog(@"getting home page");
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
if (!prefs)
return @"about:blank";
// copied from Gecko: mode 0 is blank page, mode 1 is home page.
// 2 is "last page visited" but we don't care about that.
- (NSString *) homePage:(BOOL)checkStartupPagePref
{
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
if (!prefs)
return @"about:blank";
NSString *url = nil;
PRInt32 mode = 1;
// In some cases, we need to check browser.startup.page to see if
// we want to use the homepage or if the user wants a blank window.
// mode 0 is blank page, mode 1 is home page. 2 is "last page visited"
// but we don't care about that. Default to 1 unless |checkStartupPagePref|
// is true.
nsresult rv = NS_OK;
if ( checkStartupPagePref )
rv = prefs->GetIntPref("browser.startup.page", &mode);
// if the pref isn't set, default to mode 1
NSLog(@"startup.page: %d", (int)mode);
if (NS_FAILED(rv) || mode == 1) {
prefs->GetCharPref("browser.startup.homepage", &buf);
if (buf && *buf)
url = [NSString stringWithCString:buf];
else
url = @"about:blank";
free (buf);
return url;
} else
return @"about:blank";
if (NS_FAILED(rv) || mode == 1) {
char *buf = nsnull;
prefs->GetCharPref("browser.startup.homepage", &buf);
if (buf && *buf)
url = [NSString stringWithCString:buf];
else
url = @"about:blank";
free (buf);
return url;
}
else
return @"about:blank";
}
@end

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

@ -70,7 +70,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
-(void)awakeFromNib
{
mPreferenceManager = [[CHPreferenceManager alloc] init];
mPreferenceManager = [[CHPreferenceManager sharedInstance] retain];
[self newWindow: self];
@ -107,8 +107,9 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
[[mainWindow windowController] autosaveWindowFrame];
// Now open the new window.
BrowserWindowController* controller = [self openBrowserWindowWithURLString: [mPreferenceManager homePage]];
if ([[mPreferenceManager homePage] isEqualToString: @"about:blank"])
NSString* homePage = [mPreferenceManager homePage:YES];
BrowserWindowController* controller = [self openBrowserWindowWithURLString:homePage];
if ([homePage isEqualToString: @"about:blank"])
[controller focusURLBar];
else
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];

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

@ -70,7 +70,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
-(void)awakeFromNib
{
mPreferenceManager = [[CHPreferenceManager alloc] init];
mPreferenceManager = [[CHPreferenceManager sharedInstance] retain];
[self newWindow: self];
@ -107,8 +107,9 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
[[mainWindow windowController] autosaveWindowFrame];
// Now open the new window.
BrowserWindowController* controller = [self openBrowserWindowWithURLString: [mPreferenceManager homePage]];
if ([[mPreferenceManager homePage] isEqualToString: @"about:blank"])
NSString* homePage = [mPreferenceManager homePage:YES];
BrowserWindowController* controller = [self openBrowserWindowWithURLString:homePage];
if ([homePage isEqualToString: @"about:blank"])
[controller focusURLBar];
else
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];

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

@ -38,6 +38,7 @@
#import "BrowserWindowController.h"
#import "CHBrowserWrapper.h"
#import "CHIconTabViewItem.h"
#import "CHPreferenceManager.h"
#include "nsIWebNavigation.h"
#include "nsIDOMElement.h"
@ -55,7 +56,6 @@
#include "CHGeckoUtils.h"
#include "nsIWebProgressListener.h"
static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
@ -608,7 +608,7 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
- (IBAction)home:(id)aSender
{
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:[[CHPreferenceManager sharedInstance] homePage:NO]] flags:NSLoadFlagsNone];
}
- (IBAction)toggleSidebar:(id)aSender

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

@ -14,6 +14,8 @@
ICInstance internetConfig;
}
+ (CHPreferenceManager *)sharedInstance;
- (id) init;
- (void) dealloc;
- (BOOL) initInternetConfig;
@ -21,6 +23,6 @@
- (void) syncMozillaPrefs;
// - (BOOL) getICBoolPref:(ConstStr255Param) prefKey;
- (NSString *) getICStringPref:(ConstStr255Param) prefKey;
- (NSString *) homePage;
- (NSString *) homePage:(BOOL) checkStartupPagePref;
@end

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

@ -15,6 +15,13 @@ extern const char *prefContractID;
@implementation CHPreferenceManager
+ (CHPreferenceManager *) sharedInstance {
static CHPreferenceManager *sSharedInstance = nil;
return ( sSharedInstance ? sSharedInstance : (sSharedInstance = [[[CHPreferenceManager alloc] init] autorelease] ));
}
- (id) init
{
if ((self = [super init])) {
@ -258,33 +265,36 @@ extern const char *prefContractID;
return string;
}
- (NSString *) homePage
{
NSString *url;
char *buf;
PRInt32 mode;
nsresult rv;
NSLog(@"getting home page");
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
if (!prefs)
return @"about:blank";
// copied from Gecko: mode 0 is blank page, mode 1 is home page.
// 2 is "last page visited" but we don't care about that.
- (NSString *) homePage:(BOOL)checkStartupPagePref
{
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
if (!prefs)
return @"about:blank";
NSString *url = nil;
PRInt32 mode = 1;
// In some cases, we need to check browser.startup.page to see if
// we want to use the homepage or if the user wants a blank window.
// mode 0 is blank page, mode 1 is home page. 2 is "last page visited"
// but we don't care about that. Default to 1 unless |checkStartupPagePref|
// is true.
nsresult rv = NS_OK;
if ( checkStartupPagePref )
rv = prefs->GetIntPref("browser.startup.page", &mode);
// if the pref isn't set, default to mode 1
NSLog(@"startup.page: %d", (int)mode);
if (NS_FAILED(rv) || mode == 1) {
prefs->GetCharPref("browser.startup.homepage", &buf);
if (buf && *buf)
url = [NSString stringWithCString:buf];
else
url = @"about:blank";
free (buf);
return url;
} else
return @"about:blank";
if (NS_FAILED(rv) || mode == 1) {
char *buf = nsnull;
prefs->GetCharPref("browser.startup.homepage", &buf);
if (buf && *buf)
url = [NSString stringWithCString:buf];
else
url = @"about:blank";
free (buf);
return url;
}
else
return @"about:blank";
}
@end

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

@ -38,6 +38,7 @@
#import "BrowserWindowController.h"
#import "CHBrowserWrapper.h"
#import "CHIconTabViewItem.h"
#import "CHPreferenceManager.h"
#include "nsIWebNavigation.h"
#include "nsIDOMElement.h"
@ -55,7 +56,6 @@
#include "CHGeckoUtils.h"
#include "nsIWebProgressListener.h"
static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
@ -608,7 +608,7 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
- (IBAction)home:(id)aSender
{
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:[[CHPreferenceManager sharedInstance] homePage:NO]] flags:NSLoadFlagsNone];
}
- (IBAction)toggleSidebar:(id)aSender

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

@ -14,6 +14,8 @@
ICInstance internetConfig;
}
+ (CHPreferenceManager *)sharedInstance;
- (id) init;
- (void) dealloc;
- (BOOL) initInternetConfig;
@ -21,6 +23,6 @@
- (void) syncMozillaPrefs;
// - (BOOL) getICBoolPref:(ConstStr255Param) prefKey;
- (NSString *) getICStringPref:(ConstStr255Param) prefKey;
- (NSString *) homePage;
- (NSString *) homePage:(BOOL) checkStartupPagePref;
@end

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

@ -15,6 +15,13 @@ extern const char *prefContractID;
@implementation CHPreferenceManager
+ (CHPreferenceManager *) sharedInstance {
static CHPreferenceManager *sSharedInstance = nil;
return ( sSharedInstance ? sSharedInstance : (sSharedInstance = [[[CHPreferenceManager alloc] init] autorelease] ));
}
- (id) init
{
if ((self = [super init])) {
@ -258,33 +265,36 @@ extern const char *prefContractID;
return string;
}
- (NSString *) homePage
{
NSString *url;
char *buf;
PRInt32 mode;
nsresult rv;
NSLog(@"getting home page");
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
if (!prefs)
return @"about:blank";
// copied from Gecko: mode 0 is blank page, mode 1 is home page.
// 2 is "last page visited" but we don't care about that.
- (NSString *) homePage:(BOOL)checkStartupPagePref
{
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
if (!prefs)
return @"about:blank";
NSString *url = nil;
PRInt32 mode = 1;
// In some cases, we need to check browser.startup.page to see if
// we want to use the homepage or if the user wants a blank window.
// mode 0 is blank page, mode 1 is home page. 2 is "last page visited"
// but we don't care about that. Default to 1 unless |checkStartupPagePref|
// is true.
nsresult rv = NS_OK;
if ( checkStartupPagePref )
rv = prefs->GetIntPref("browser.startup.page", &mode);
// if the pref isn't set, default to mode 1
NSLog(@"startup.page: %d", (int)mode);
if (NS_FAILED(rv) || mode == 1) {
prefs->GetCharPref("browser.startup.homepage", &buf);
if (buf && *buf)
url = [NSString stringWithCString:buf];
else
url = @"about:blank";
free (buf);
return url;
} else
return @"about:blank";
if (NS_FAILED(rv) || mode == 1) {
char *buf = nsnull;
prefs->GetCharPref("browser.startup.homepage", &buf);
if (buf && *buf)
url = [NSString stringWithCString:buf];
else
url = @"about:blank";
free (buf);
return url;
}
else
return @"about:blank";
}
@end

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

@ -70,7 +70,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
-(void)awakeFromNib
{
mPreferenceManager = [[CHPreferenceManager alloc] init];
mPreferenceManager = [[CHPreferenceManager sharedInstance] retain];
[self newWindow: self];
@ -107,8 +107,9 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
[[mainWindow windowController] autosaveWindowFrame];
// Now open the new window.
BrowserWindowController* controller = [self openBrowserWindowWithURLString: [mPreferenceManager homePage]];
if ([[mPreferenceManager homePage] isEqualToString: @"about:blank"])
NSString* homePage = [mPreferenceManager homePage:YES];
BrowserWindowController* controller = [self openBrowserWindowWithURLString:homePage];
if ([homePage isEqualToString: @"about:blank"])
[controller focusURLBar];
else
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];

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

@ -70,7 +70,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
-(void)awakeFromNib
{
mPreferenceManager = [[CHPreferenceManager alloc] init];
mPreferenceManager = [[CHPreferenceManager sharedInstance] retain];
[self newWindow: self];
@ -107,8 +107,9 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
[[mainWindow windowController] autosaveWindowFrame];
// Now open the new window.
BrowserWindowController* controller = [self openBrowserWindowWithURLString: [mPreferenceManager homePage]];
if ([[mPreferenceManager homePage] isEqualToString: @"about:blank"])
NSString* homePage = [mPreferenceManager homePage:YES];
BrowserWindowController* controller = [self openBrowserWindowWithURLString:homePage];
if ([homePage isEqualToString: @"about:blank"])
[controller focusURLBar];
else
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];

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

@ -38,6 +38,7 @@
#import "BrowserWindowController.h"
#import "CHBrowserWrapper.h"
#import "CHIconTabViewItem.h"
#import "CHPreferenceManager.h"
#include "nsIWebNavigation.h"
#include "nsIDOMElement.h"
@ -55,7 +56,6 @@
#include "CHGeckoUtils.h"
#include "nsIWebProgressListener.h"
static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
@ -608,7 +608,7 @@ static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
- (IBAction)home:(id)aSender
{
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
[[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:[[CHPreferenceManager sharedInstance] homePage:NO]] flags:NSLoadFlagsNone];
}
- (IBAction)toggleSidebar:(id)aSender

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

@ -14,6 +14,8 @@
ICInstance internetConfig;
}
+ (CHPreferenceManager *)sharedInstance;
- (id) init;
- (void) dealloc;
- (BOOL) initInternetConfig;
@ -21,6 +23,6 @@
- (void) syncMozillaPrefs;
// - (BOOL) getICBoolPref:(ConstStr255Param) prefKey;
- (NSString *) getICStringPref:(ConstStr255Param) prefKey;
- (NSString *) homePage;
- (NSString *) homePage:(BOOL) checkStartupPagePref;
@end

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

@ -15,6 +15,13 @@ extern const char *prefContractID;
@implementation CHPreferenceManager
+ (CHPreferenceManager *) sharedInstance {
static CHPreferenceManager *sSharedInstance = nil;
return ( sSharedInstance ? sSharedInstance : (sSharedInstance = [[[CHPreferenceManager alloc] init] autorelease] ));
}
- (id) init
{
if ((self = [super init])) {
@ -258,33 +265,36 @@ extern const char *prefContractID;
return string;
}
- (NSString *) homePage
{
NSString *url;
char *buf;
PRInt32 mode;
nsresult rv;
NSLog(@"getting home page");
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
if (!prefs)
return @"about:blank";
// copied from Gecko: mode 0 is blank page, mode 1 is home page.
// 2 is "last page visited" but we don't care about that.
- (NSString *) homePage:(BOOL)checkStartupPagePref
{
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(prefContractID));
if (!prefs)
return @"about:blank";
NSString *url = nil;
PRInt32 mode = 1;
// In some cases, we need to check browser.startup.page to see if
// we want to use the homepage or if the user wants a blank window.
// mode 0 is blank page, mode 1 is home page. 2 is "last page visited"
// but we don't care about that. Default to 1 unless |checkStartupPagePref|
// is true.
nsresult rv = NS_OK;
if ( checkStartupPagePref )
rv = prefs->GetIntPref("browser.startup.page", &mode);
// if the pref isn't set, default to mode 1
NSLog(@"startup.page: %d", (int)mode);
if (NS_FAILED(rv) || mode == 1) {
prefs->GetCharPref("browser.startup.homepage", &buf);
if (buf && *buf)
url = [NSString stringWithCString:buf];
else
url = @"about:blank";
free (buf);
return url;
} else
return @"about:blank";
if (NS_FAILED(rv) || mode == 1) {
char *buf = nsnull;
prefs->GetCharPref("browser.startup.homepage", &buf);
if (buf && *buf)
url = [NSString stringWithCString:buf];
else
url = @"about:blank";
free (buf);
return url;
}
else
return @"about:blank";
}
@end