Ensure Password Manager isn't disabled when form fill is disabled

This commit is contained in:
ben%bengoodger.com 2003-12-31 22:02:03 +00:00
Родитель 630c5260cf
Коммит 04a0be1315
3 изменённых файлов: 84 добавлений и 49 удалений

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

@ -91,6 +91,8 @@ var gBrowser = null;
var gContextMenu = null;
var gChromeState = null; // chrome state before we went into print preview
var gFormFillPrefListener = null;
var gFormHistory = null;
var gFormFillEnabled = true;
@ -427,12 +429,10 @@ function delayedStartup()
toolbox.customizeDone = BrowserToolboxCustomizeDone;
// Enable/Disable Form Fill
gFormFillPrefListener = new FormFillPrefListener();
var pbi = gPrefService.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
pbi.addObserver(gFormFillPrefListener.domain, gFormFillPrefListener, false);
// Initialize
gFormFillPrefListener.toggleFormFill();
pbi.addObserver(gHomeButton.prefDomain, gHomeButton, false);
gHomeButton.updateTooltip();
@ -511,7 +511,12 @@ function Shutdown()
appCore.close();
}
const gFormFillPrefListener =
function FormFillPrefListener()
{
gBrowser.attachFormFill();
}
FormFillPrefListener.prototype =
{
domain: "browser.formfill.enable",
observe: function (aSubject, aTopic, aPrefName)
@ -529,10 +534,6 @@ const gFormFillPrefListener =
}
catch (e) {
}
if (gFormFillEnabled)
gBrowser.attachFormFill();
else
gBrowser.detachFormFill();
gBrowser.setAttribute("autocompleteenabled", gFormFillEnabled);
var searchBar = document.getElementById("search-bar");

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

@ -55,9 +55,12 @@
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranchInternal.h"
#include "nsVoidArray.h"
#define PREF_FORMFILL_ENABLE "browser.formfill.enable"
#define PREF_FORMFILL_BRANCH "browser.formfill."
#define PREF_FORMFILL_ENABLE "enable"
static const char *kFormHistoryFileName = "formhistory.dat";
@ -75,6 +78,9 @@ NS_IMPL_THREADSAFE_RELEASE(nsFormHistory)
mdb_column nsFormHistory::kToken_ValueColumn = 0;
mdb_column nsFormHistory::kToken_NameColumn = 0;
PRBool nsFormHistory::gFormHistoryEnabled = PR_FALSE;
PRBool nsFormHistory::gPrefsInitialized = PR_FALSE;
nsFormHistory::nsFormHistory() :
mEnv(nsnull),
mStore(nsnull),
@ -91,7 +97,7 @@ nsresult
nsFormHistory::Init()
{
gFormHistory = this;
nsCOMPtr<nsIObserverService> service = do_GetService("@mozilla.org/observer-service;1");
if (service)
service->AddObserver(this, NS_FORMSUBMIT_SUBJECT, PR_TRUE);
@ -131,6 +137,25 @@ nsFormHistory::ReleaseInstance()
NS_IF_RELEASE(gFormHistory);
}
/* static */ PRBool
nsFormHistory::FormHistoryEnabled()
{
if (!gPrefsInitialized) {
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
nsCOMPtr<nsIPrefBranch> branch;
prefService->GetBranch(PREF_FORMFILL_BRANCH, getter_AddRefs(branch));
branch->GetBoolPref(PREF_FORMFILL_ENABLE, &gFormHistoryEnabled);
nsCOMPtr<nsIPrefBranchInternal> branchInternal = do_QueryInterface(branch);
branchInternal->AddObserver(PREF_FORMFILL_BRANCH, gFormHistory, PR_TRUE);
gPrefsInitialized = PR_TRUE;
}
return gFormHistoryEnabled;
}
////////////////////////////////////////////////////////////////////////
//// nsIFormHistory
@ -308,6 +333,11 @@ nsFormHistory::EntryExists(const nsAString &aName, const nsAString &aValue, PRBo
NS_IMETHODIMP
nsFormHistory::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(aSubject);
branch->GetBoolPref(PREF_FORMFILL_ENABLE, &gFormHistoryEnabled);
}
return NS_OK;
}
@ -317,46 +347,42 @@ nsFormHistory::Observe(nsISupports *aSubject, const char *aTopic, const PRUnicha
NS_IMETHODIMP
nsFormHistory::Notify(nsIContent* aFormNode, nsIDOMWindowInternal* aWindow, nsIURI* aActionURL, PRBool* aCancelSubmit)
{
PRBool shouldSaveData = PR_TRUE;
nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (pref)
pref->GetBoolPref(PREF_FORMFILL_ENABLE, &shouldSaveData);
if (!FormHistoryEnabled())
return NS_OK;
if (shouldSaveData) {
nsresult rv = OpenDatabase(); // lazily ensure that the database is open
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMHTMLFormElement> formElt = do_QueryInterface(aFormNode);
NS_ENSURE_TRUE(formElt, NS_ERROR_FAILURE);
nsresult rv = OpenDatabase(); // lazily ensure that the database is open
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMHTMLFormElement> formElt = do_QueryInterface(aFormNode);
NS_ENSURE_TRUE(formElt, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMHTMLCollection> elts;
formElt->GetElements(getter_AddRefs(elts));
const char *textString = "text";
PRUint32 length;
elts->GetLength(&length);
for (PRUint32 i = 0; i < length; ++i) {
nsCOMPtr<nsIDOMNode> node;
elts->Item(i, getter_AddRefs(node));
nsCOMPtr<nsIDOMHTMLInputElement> inputElt = do_QueryInterface(node);
if (inputElt) {
// Filter only inputs that are of type "text"
nsAutoString type;
inputElt->GetType(type);
if (type.EqualsIgnoreCase(textString)) {
// If this input has a name/id and value, add it to the database
nsAutoString value;
inputElt->GetValue(value);
if (!value.IsEmpty()) {
nsAutoString name;
inputElt->GetName(name);
if (name.IsEmpty())
inputElt->GetId(name);
if (!name.IsEmpty())
AppendRow(name, value, nsnull);
}
nsCOMPtr<nsIDOMHTMLCollection> elts;
formElt->GetElements(getter_AddRefs(elts));
const char *textString = "text";
PRUint32 length;
elts->GetLength(&length);
for (PRUint32 i = 0; i < length; ++i) {
nsCOMPtr<nsIDOMNode> node;
elts->Item(i, getter_AddRefs(node));
nsCOMPtr<nsIDOMHTMLInputElement> inputElt = do_QueryInterface(node);
if (inputElt) {
// Filter only inputs that are of type "text"
nsAutoString type;
inputElt->GetType(type);
if (type.EqualsIgnoreCase(textString)) {
// If this input has a name/id and value, add it to the database
nsAutoString value;
inputElt->GetValue(value);
if (!value.IsEmpty()) {
nsAutoString name;
inputElt->GetName(name);
if (name.IsEmpty())
inputElt->GetId(name);
if (!name.IsEmpty())
AppendRow(name, value, nsnull);
}
}
}
@ -657,6 +683,9 @@ nsFormHistory::AutoCompleteSearch(const nsAString &aInputName,
nsIAutoCompleteMdbResult *aPrevResult,
nsIAutoCompleteResult **aResult)
{
if (!FormHistoryEnabled())
return NS_OK;
nsresult rv = OpenDatabase(); // lazily ensure that the database is open
NS_ENSURE_SUCCESS(rv, rv);

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

@ -92,9 +92,14 @@ protected:
PR_STATIC_CALLBACK(int) SortComparison(const void *v1, const void *v2, void *closureVoid);
static PRBool FormHistoryEnabled();
static nsFormHistory *gFormHistory;
static nsIMdbFactory *gMdbFactory;
static PRBool gFormHistoryEnabled;
static PRBool gPrefsInitialized;
nsIMdbEnv* mEnv;
nsIMdbStore* mStore;
nsIMdbTable* mTable;