From 4a686700e06296da0ae99d74bcc342012fcec9df Mon Sep 17 00:00:00 2001 From: "smfr%smfr.org" Date: Mon, 4 Apr 2005 01:52:35 +0000 Subject: [PATCH] Converting users of nsIPrefBranch to use the PreferenceManager (no bug). --- camino/src/browser/BrowserWindowController.mm | 37 +++++-------------- camino/src/browser/BrowserWrapper.mm | 26 ++++--------- camino/src/browser/ContentClickListener.mm | 24 ++++++------ camino/src/browser/KeychainService.mm | 7 +--- 4 files changed, 29 insertions(+), 65 deletions(-) diff --git a/camino/src/browser/BrowserWindowController.mm b/camino/src/browser/BrowserWindowController.mm index 9d55a3a0d5f..401307f74a6 100644 --- a/camino/src/browser/BrowserWindowController.mm +++ b/camino/src/browser/BrowserWindowController.mm @@ -73,7 +73,6 @@ #include "nsIDOMLocation.h" #include "nsIDOMElement.h" #include "nsIDOMEvent.h" -#include "nsIPrefBranch.h" #include "nsIContextMenuListener.h" #include "nsIDOMWindow.h" #include "CHBrowserService.h" @@ -90,7 +89,6 @@ #include "nsIContentViewerEdit.h" #include "nsIWebBrowser.h" #include "nsIInterfaceRequestorUtils.h" -#include "nsIPrefBranch.h" #include "nsServiceManagerUtils.h" #include "nsIURI.h" #include "nsIURIFixup.h" @@ -1584,9 +1582,7 @@ enum BWCOpenDest { - (void)loadSourceOfURL:(NSString*)urlStr { // first attempt to get the source that's already loaded - PRBool loadInBackground; - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); + BOOL loadInBackground = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL]; nsCOMPtr desc = [[mBrowserView getBrowserView] getPageDescriptor]; if (desc) { @@ -2272,9 +2268,8 @@ enum BWCOpenDest { BOOL loadHomepage = NO; if (contents == eNewTabHomepage) { - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - PRInt32 newTabPage = 0; // 0=about:blank, 1=home page, 2=last page visited - pref->GetIntPref("browser.tabs.startPage", &newTabPage); + // 0 = about:blank, 1 = home page, 2 = last page visited + int newTabPage = [[PreferenceManager sharedInstance] getIntPref:"browser.tabs.startPage" withSuccess:NULL]; loadHomepage = (newTabPage == 1); } @@ -2392,11 +2387,7 @@ enum BWCOpenDest { if (tabViewItem) { NSString* url = [[tabViewItem view] getCurrentURLSpec]; - - PRBool backgroundLoad = PR_FALSE; - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (pref) - pref->GetBoolPref("browser.tabs.loadInBackground", &backgroundLoad); + BOOL backgroundLoad = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL]; [self openNewWindowWithURL:url referrer:nil loadInBackground:backgroundLoad allowPopups:NO]; @@ -2846,12 +2837,7 @@ enum BWCOpenDest { if ([hrefStr length] == 0) return; - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); + BOOL loadInBackground = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL]; NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString]; @@ -3253,20 +3239,15 @@ enum BWCOpenDest { // - (BOOL) handleCommandReturn { - BOOL handled = NO; - // determine whether to load in background - PRBool loadInBG; - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBG); - + BOOL loadInBG = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL]; // determine whether to load in tab or window - PRBool loadInTab; - pref->GetBoolPref("browser.tabs.opentabfor.middleclick",&loadInTab); - + BOOL loadInTab = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.opentabfor.middleclick" withSuccess:NULL]; + BWCOpenDest destination = loadInTab ? kDestinationNewTab : kDestinationNewWindow; // see if command-return came in the url bar + BOOL handled = NO; if ([mURLBar fieldEditor] && [[self window] firstResponder] == [mURLBar fieldEditor]) { handled = YES; [self goToLocationFromToolbarURLField:mURLBar inView:destination inBackground:loadInBG]; diff --git a/camino/src/browser/BrowserWrapper.mm b/camino/src/browser/BrowserWrapper.mm index 5d37ac63bf5..edc32929ac6 100644 --- a/camino/src/browser/BrowserWrapper.mm +++ b/camino/src/browser/BrowserWrapper.mm @@ -49,6 +49,7 @@ #import "PageProxyIcon.h" #import "KeychainService.h" #import "AutoCompleteTextField.h" +#include "CHBrowserService.h" #include "nsCOMPtr.h" #include "nsIServiceManager.h" @@ -65,15 +66,8 @@ #include "nsIChromeEventHandler.h" #include "nsPIDOMWindow.h" #include "nsIDOMEventReceiver.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "CHBrowserService.h" #include "nsIWebProgressListener.h" -#include - -static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; - static NSString* const kOfflineNotificationName = @"offlineModeChanged"; @interface BrowserWrapper(Private) @@ -599,7 +593,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; - (void)updateOfflineStatus { - nsCOMPtr ioService(do_GetService(ioServiceContractID)); + nsCOMPtr ioService(do_GetService("@mozilla.org/network/io-service;1")); if (!ioService) return; PRBool offline = PR_FALSE; @@ -758,12 +752,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; - (CHBrowserView*)createBrowserWindow:(unsigned int)aMask { - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return NS_OK; // Something bad happened if we can't get prefs. - - PRBool showBlocker; - pref->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker); + BOOL showBlocker = [[PreferenceManager sharedInstance] getBooleanPref:"browser.popups.showPopupBlocker" withSuccess:NULL]; if (showBlocker) { nsCOMPtr domWindow = getter_AddRefs([mBrowserView getContentWindow]); @@ -776,14 +765,13 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; text: [NSString stringWithFormat: NSLocalizedString(@"PopupBlockMsg", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]]; // This is a one-time dialog. - pref->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE); + [[PreferenceManager sharedInstance] setPref:"browser.popups.showPopupBlocker" toBoolean:NO]; 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 prefService(do_QueryInterface(pref)); - prefService->SavePrefFile(nsnull); - if (confirm) return nil; } diff --git a/camino/src/browser/ContentClickListener.mm b/camino/src/browser/ContentClickListener.mm index a3256a7816b..daa7e58377c 100644 --- a/camino/src/browser/ContentClickListener.mm +++ b/camino/src/browser/ContentClickListener.mm @@ -36,23 +36,26 @@ * * ***** END LICENSE BLOCK ***** */ -#import "NSString+Utils.h" #include "nsCOMPtr.h" -#include "ContentClickListener.h" -#include "nsIDOMElement.h" + +#include "nsEmbedAPI.h" #include "nsString.h" #include "nsUnicharUtils.h" -#include "nsIPrefBranch.h" + +#include "nsIDOMElement.h" #include "nsIDOMMouseEvent.h" -#include "nsEmbedAPI.h" #include "nsIDOMEventTarget.h" // Common helper routines (also used by the context menu code) #include "GeckoUtils.h" +#import "NSString+Utils.h" +#import "PreferenceManager.h" #import "CHBrowserView.h" +#import "ContentClickListener.h" + NS_IMPL_ISUPPORTS2(ContentClickListener, nsIDOMMouseListener, nsIDOMEventListener) ContentClickListener::ContentClickListener(id aBrowserController) @@ -82,10 +85,6 @@ ContentClickListener::MouseClick(nsIDOMEvent* aEvent) // really uses these anyway? :) if (!linkContent || href.IsEmpty()) return NS_OK; - - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return NS_OK; // Something bad happened if we can't get prefs. PRUint16 button; nsCOMPtr mouseEvent(do_QueryInterface(aEvent)); @@ -100,10 +99,9 @@ ContentClickListener::MouseClick(nsIDOMEvent* aEvent) 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. - PRBool useTab = FALSE; - pref->GetBoolPref("browser.tabs.opentabfor.middleclick", &useTab); - PRBool loadInBackground = FALSE; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); + BOOL useTab = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.opentabfor.middleclick" withSuccess:NULL]; + BOOL loadInBackground = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL]; + NSString* referrer = [[[mBrowserController getBrowserWrapper] getBrowserView] getFocusedURLString]; if (shiftKey) diff --git a/camino/src/browser/KeychainService.mm b/camino/src/browser/KeychainService.mm index 548bb838556..ef7a7eefa5d 100644 --- a/camino/src/browser/KeychainService.mm +++ b/camino/src/browser/KeychainService.mm @@ -1093,15 +1093,12 @@ nsresult FindUsernamePasswordFields(nsIDOMHTMLFormElement* inFormElement, nsIDOMHTMLInputElement** outUsername, nsIDOMHTMLInputElement** outPassword, PRBool inStopWhenFound) { - PRBool autoCompleteOverride = PR_FALSE; - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (pref) - pref->GetBoolPref("wallet.crypto.autocompleteoverride", &autoCompleteOverride); - if ( !outUsername || !outPassword ) return NS_ERROR_FAILURE; *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 // "autocomplete=off" attribute on the form. nsAutoString autocomplete;