Converting users of nsIPrefBranch to use the PreferenceManager (no bug).

This commit is contained in:
smfr%smfr.org 2005-04-04 01:52:35 +00:00
Родитель 559d42561b
Коммит 4a686700e0
4 изменённых файлов: 29 добавлений и 65 удалений

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

@ -73,7 +73,6 @@
#include "nsIDOMLocation.h" #include "nsIDOMLocation.h"
#include "nsIDOMElement.h" #include "nsIDOMElement.h"
#include "nsIDOMEvent.h" #include "nsIDOMEvent.h"
#include "nsIPrefBranch.h"
#include "nsIContextMenuListener.h" #include "nsIContextMenuListener.h"
#include "nsIDOMWindow.h" #include "nsIDOMWindow.h"
#include "CHBrowserService.h" #include "CHBrowserService.h"
@ -90,7 +89,6 @@
#include "nsIContentViewerEdit.h" #include "nsIContentViewerEdit.h"
#include "nsIWebBrowser.h" #include "nsIWebBrowser.h"
#include "nsIInterfaceRequestorUtils.h" #include "nsIInterfaceRequestorUtils.h"
#include "nsIPrefBranch.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsIURIFixup.h" #include "nsIURIFixup.h"
@ -1584,9 +1582,7 @@ enum BWCOpenDest {
- (void)loadSourceOfURL:(NSString*)urlStr - (void)loadSourceOfURL:(NSString*)urlStr
{ {
// first attempt to get the source that's already loaded // first attempt to get the source that's already loaded
PRBool loadInBackground; BOOL loadInBackground = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
nsCOMPtr<nsISupports> desc = [[mBrowserView getBrowserView] getPageDescriptor]; nsCOMPtr<nsISupports> desc = [[mBrowserView getBrowserView] getPageDescriptor];
if (desc) { if (desc) {
@ -2272,9 +2268,8 @@ enum BWCOpenDest {
BOOL loadHomepage = NO; BOOL loadHomepage = NO;
if (contents == eNewTabHomepage) if (contents == eNewTabHomepage)
{ {
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1")); // 0 = about:blank, 1 = home page, 2 = last page visited
PRInt32 newTabPage = 0; // 0=about:blank, 1=home page, 2=last page visited int newTabPage = [[PreferenceManager sharedInstance] getIntPref:"browser.tabs.startPage" withSuccess:NULL];
pref->GetIntPref("browser.tabs.startPage", &newTabPage);
loadHomepage = (newTabPage == 1); loadHomepage = (newTabPage == 1);
} }
@ -2392,11 +2387,7 @@ enum BWCOpenDest {
if (tabViewItem) if (tabViewItem)
{ {
NSString* url = [[tabViewItem view] getCurrentURLSpec]; NSString* url = [[tabViewItem view] getCurrentURLSpec];
BOOL backgroundLoad = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
PRBool backgroundLoad = PR_FALSE;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (pref)
pref->GetBoolPref("browser.tabs.loadInBackground", &backgroundLoad);
[self openNewWindowWithURL:url referrer:nil loadInBackground:backgroundLoad allowPopups:NO]; [self openNewWindowWithURL:url referrer:nil loadInBackground:backgroundLoad allowPopups:NO];
@ -2846,12 +2837,7 @@ enum BWCOpenDest {
if ([hrefStr length] == 0) if ([hrefStr length] == 0)
return; return;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1")); BOOL loadInBackground = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
if (!pref)
return; // Something bad happened if we can't get prefs.
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString]; NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString];
@ -3253,20 +3239,15 @@ enum BWCOpenDest {
// //
- (BOOL) handleCommandReturn - (BOOL) handleCommandReturn
{ {
BOOL handled = NO;
// determine whether to load in background // determine whether to load in background
PRBool loadInBG; BOOL loadInBG = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBG);
// determine whether to load in tab or window // determine whether to load in tab or window
PRBool loadInTab; BOOL loadInTab = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.opentabfor.middleclick" withSuccess:NULL];
pref->GetBoolPref("browser.tabs.opentabfor.middleclick",&loadInTab);
BWCOpenDest destination = loadInTab ? kDestinationNewTab : kDestinationNewWindow; BWCOpenDest destination = loadInTab ? kDestinationNewTab : kDestinationNewWindow;
// see if command-return came in the url bar // see if command-return came in the url bar
BOOL handled = NO;
if ([mURLBar fieldEditor] && [[self window] firstResponder] == [mURLBar fieldEditor]) { if ([mURLBar fieldEditor] && [[self window] firstResponder] == [mURLBar fieldEditor]) {
handled = YES; handled = YES;
[self goToLocationFromToolbarURLField:mURLBar inView:destination inBackground:loadInBG]; [self goToLocationFromToolbarURLField:mURLBar inView:destination inBackground:loadInBG];

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

@ -49,6 +49,7 @@
#import "PageProxyIcon.h" #import "PageProxyIcon.h"
#import "KeychainService.h" #import "KeychainService.h"
#import "AutoCompleteTextField.h" #import "AutoCompleteTextField.h"
#include "CHBrowserService.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@ -65,15 +66,8 @@
#include "nsIChromeEventHandler.h" #include "nsIChromeEventHandler.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "nsIDOMEventReceiver.h" #include "nsIDOMEventReceiver.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "CHBrowserService.h"
#include "nsIWebProgressListener.h" #include "nsIWebProgressListener.h"
#include <QuickDraw.h>
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
static NSString* const kOfflineNotificationName = @"offlineModeChanged"; static NSString* const kOfflineNotificationName = @"offlineModeChanged";
@interface BrowserWrapper(Private) @interface BrowserWrapper(Private)
@ -599,7 +593,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged";
- (void)updateOfflineStatus - (void)updateOfflineStatus
{ {
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID)); nsCOMPtr<nsIIOService> ioService(do_GetService("@mozilla.org/network/io-service;1"));
if (!ioService) if (!ioService)
return; return;
PRBool offline = PR_FALSE; PRBool offline = PR_FALSE;
@ -758,12 +752,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged";
- (CHBrowserView*)createBrowserWindow:(unsigned int)aMask - (CHBrowserView*)createBrowserWindow:(unsigned int)aMask
{ {
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1")); BOOL showBlocker = [[PreferenceManager sharedInstance] getBooleanPref:"browser.popups.showPopupBlocker" withSuccess:NULL];
if (!pref)
return NS_OK; // Something bad happened if we can't get prefs.
PRBool showBlocker;
pref->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker);
if (showBlocker) { if (showBlocker) {
nsCOMPtr<nsIDOMWindow> domWindow = getter_AddRefs([mBrowserView getContentWindow]); nsCOMPtr<nsIDOMWindow> domWindow = getter_AddRefs([mBrowserView getContentWindow]);
@ -776,14 +765,13 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged";
text: [NSString stringWithFormat: NSLocalizedString(@"PopupBlockMsg", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]]; text: [NSString stringWithFormat: NSLocalizedString(@"PopupBlockMsg", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]];
// This is a one-time dialog. // This is a one-time dialog.
pref->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE); [[PreferenceManager sharedInstance] setPref:"browser.popups.showPopupBlocker" toBoolean:NO];
if (confirm) if (confirm)
pref->SetBoolPref("dom.disable_open_during_load", PR_TRUE); [[PreferenceManager sharedInstance] setPref:"dom.disable_open_during_load" toBoolean:YES];
[[PreferenceManager sharedInstance] savePrefsFile];
nsCOMPtr<nsIPrefService> prefService(do_QueryInterface(pref));
prefService->SavePrefFile(nsnull);
if (confirm) if (confirm)
return nil; return nil;
} }

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

@ -36,23 +36,26 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#import "NSString+Utils.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "ContentClickListener.h"
#include "nsIDOMElement.h" #include "nsEmbedAPI.h"
#include "nsString.h" #include "nsString.h"
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"
#include "nsIPrefBranch.h"
#include "nsIDOMElement.h"
#include "nsIDOMMouseEvent.h" #include "nsIDOMMouseEvent.h"
#include "nsEmbedAPI.h"
#include "nsIDOMEventTarget.h" #include "nsIDOMEventTarget.h"
// Common helper routines (also used by the context menu code) // Common helper routines (also used by the context menu code)
#include "GeckoUtils.h" #include "GeckoUtils.h"
#import "NSString+Utils.h"
#import "PreferenceManager.h"
#import "CHBrowserView.h" #import "CHBrowserView.h"
#import "ContentClickListener.h"
NS_IMPL_ISUPPORTS2(ContentClickListener, nsIDOMMouseListener, nsIDOMEventListener) NS_IMPL_ISUPPORTS2(ContentClickListener, nsIDOMMouseListener, nsIDOMEventListener)
ContentClickListener::ContentClickListener(id aBrowserController) ContentClickListener::ContentClickListener(id aBrowserController)
@ -82,10 +85,6 @@ ContentClickListener::MouseClick(nsIDOMEvent* aEvent)
// really uses these anyway? :) // really uses these anyway? :)
if (!linkContent || href.IsEmpty()) if (!linkContent || href.IsEmpty())
return NS_OK; return NS_OK;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (!pref)
return NS_OK; // Something bad happened if we can't get prefs.
PRUint16 button; PRUint16 button;
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent)); nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent));
@ -100,10 +99,9 @@ ContentClickListener::MouseClick(nsIDOMEvent* aEvent)
if ((metaKey && button == 0) || button == 1) { if ((metaKey && button == 0) || button == 1) {
// The command key is down or we got a middle click. Open the link in a new window or tab. // The command key is down or we got a middle click. Open the link in a new window or tab.
PRBool useTab = FALSE; BOOL useTab = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.opentabfor.middleclick" withSuccess:NULL];
pref->GetBoolPref("browser.tabs.opentabfor.middleclick", &useTab); BOOL loadInBackground = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
PRBool loadInBackground = FALSE;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
NSString* referrer = [[[mBrowserController getBrowserWrapper] getBrowserView] getFocusedURLString]; NSString* referrer = [[[mBrowserController getBrowserWrapper] getBrowserView] getFocusedURLString];
if (shiftKey) if (shiftKey)

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

@ -1093,15 +1093,12 @@ nsresult
FindUsernamePasswordFields(nsIDOMHTMLFormElement* inFormElement, nsIDOMHTMLInputElement** outUsername, FindUsernamePasswordFields(nsIDOMHTMLFormElement* inFormElement, nsIDOMHTMLInputElement** outUsername,
nsIDOMHTMLInputElement** outPassword, PRBool inStopWhenFound) nsIDOMHTMLInputElement** outPassword, PRBool inStopWhenFound)
{ {
PRBool autoCompleteOverride = PR_FALSE;
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (pref)
pref->GetBoolPref("wallet.crypto.autocompleteoverride", &autoCompleteOverride);
if ( !outUsername || !outPassword ) if ( !outUsername || !outPassword )
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
*outUsername = *outPassword = nsnull; *outUsername = *outPassword = nsnull;
PRBool autoCompleteOverride = [[PreferenceManager sharedInstance] getBooleanPref:"wallet.crypto.autocompleteoverride" withSuccess:NULL];
// pages can specify that they don't want autofill by setting a // pages can specify that they don't want autofill by setting a
// "autocomplete=off" attribute on the form. // "autocomplete=off" attribute on the form.
nsAutoString autocomplete; nsAutoString autocomplete;