Add support to the autocomplete widget, interfaces, and LDAP autocomplete session for returning "failure items" which allow the user to select an error entry and have it fire an arbitrary command, rather than actually filling in the text of the item. Part of bug 79935. r=hewitt@netscape.com, sr=bievenu@netscape.com
git-svn-id: svn://10.0.0.236/trunk@103291 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
*
|
||||
* Original Author: Jean-Francois Ducarroz (ducarroz@netscape.com)
|
||||
*
|
||||
* Contributor(s):
|
||||
* Contributor(s): Dan Mosedale <dmose@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
@@ -34,6 +34,12 @@ interface nsIAutoCompleteStatus {
|
||||
const long noMatch = 0;
|
||||
const long matchFound = 1;
|
||||
const long ignored = 2;
|
||||
|
||||
// like failed, in that no successful matches were found, however,
|
||||
// results should be displayed anyway, because they contain info about
|
||||
// the failure in question
|
||||
//
|
||||
const long failureItems = 3;
|
||||
};
|
||||
|
||||
[scriptable, uuid(4BA0A181-097C-11d4-A449-CD1A8B47ED7C)]
|
||||
|
||||
@@ -62,4 +62,31 @@ interface nsILDAPAutoCompFormatter : nsISupports {
|
||||
*/
|
||||
void getAttributes(out unsigned long aCount,
|
||||
[retval, array, size_is(aCount)] out string aAttrs);
|
||||
|
||||
/**
|
||||
* This method formats an error condition into an nsIAutoCompleteItem
|
||||
* for display to the user. Specifically, the state that the session
|
||||
* was in when the error occured (aState) is formatted into a general
|
||||
* error message which is put in the value attribute of the item,
|
||||
* and the specific error (aErrorCode) is formatted into another message
|
||||
* which is put in an nsISupportsWString in the param attribute of the
|
||||
* item.
|
||||
*
|
||||
* @param aState state of autocomplete session when error occurred
|
||||
* @param aErrorCode specific error encountered
|
||||
*
|
||||
* @return newly generated item
|
||||
*/
|
||||
nsIAutoCompleteItem formatException(in long aState,
|
||||
in nsresult aErrorCode);
|
||||
|
||||
/**
|
||||
* Possible states that can be passed in aState to formatException
|
||||
*/
|
||||
const long STATE_UNBOUND = 0;
|
||||
const long STATE_INITIALIZING = 1;
|
||||
const long STATE_BINDING = 2;
|
||||
const long STATE_BOUND = 3;
|
||||
const long STATE_SEARCHING = 4;
|
||||
|
||||
};
|
||||
|
||||
@@ -72,8 +72,10 @@
|
||||
this.ifSetAttribute("hideHistory", true);
|
||||
|
||||
// turn js handler attributes into functions
|
||||
attr = this.getAttribute("ontextcommand");
|
||||
var attr = this.getAttribute("ontextcommand");
|
||||
if (attr) this.ontextcommand = new Function("userAction", attr);
|
||||
attr = this.getAttribute("onerrorcommand");
|
||||
if (attr) this.onerrorcommand = new Function("errItem", attr);
|
||||
attr = this.getAttribute("ontextrevert");
|
||||
if (attr) this.ontextrevert = new Function(attr);
|
||||
attr = this.getAttribute("oninit");
|
||||
@@ -109,7 +111,8 @@
|
||||
this.mSessions = {};
|
||||
this.mListeners = {};
|
||||
this.mLastResults = {};
|
||||
|
||||
this.mLastStatus = {};
|
||||
|
||||
for (var i in list) {
|
||||
var name = list[i];
|
||||
if (name != "") {
|
||||
@@ -124,6 +127,7 @@
|
||||
this.mSessions[name] = session;
|
||||
this.mListeners[name] = new (this.mAutoCompleteListener)(name);
|
||||
this.mLastResults[name] = null;
|
||||
this.mLastStatus[name] = null;
|
||||
++this.sessionCount;
|
||||
}
|
||||
}
|
||||
@@ -259,6 +263,7 @@
|
||||
<property name="mSessions">null</property>
|
||||
<property name="mListeners">null</property>
|
||||
<property name="mLastResults">null</property>
|
||||
<property name="mLastStatus">null</property>
|
||||
<property name="mLastKeyCode">null</property>
|
||||
<property name="mAutoCompleteTimer">0</property>
|
||||
<property name="mMenuOpen">false</property>
|
||||
@@ -273,6 +278,7 @@
|
||||
<property name="oninit">null</property>
|
||||
<property name="ontextcommand">null</property>
|
||||
<property name="ontextrevert">null</property>
|
||||
<property name="onerrorcommand">null</property>
|
||||
|
||||
<property name="mAutoCompleteListener"><![CDATA[
|
||||
var listener = function(aSession) { this.sessionName = aSession };
|
||||
@@ -315,6 +321,17 @@
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<!-- get the autocomplete session status returned by the session
|
||||
that a given item came from -->
|
||||
<method name="getSessionStatusAt">
|
||||
<parameter name="aIndex"/>
|
||||
<body><![CDATA[
|
||||
var obj = this.convertIndexToSession(aIndex);
|
||||
return obj ? this.mLastStatus[obj.session] : null;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
|
||||
<!-- get a value from the autocomplete results as a string via an absolute index-->
|
||||
<method name="getResultValueAt">
|
||||
<parameter name="aIndex"/>
|
||||
@@ -389,6 +406,7 @@
|
||||
this.mSessions[name] = aSession;
|
||||
this.mListeners[name] = new (this.mAutoCompleteListener)(name);
|
||||
this.mLastResults[name] = null;
|
||||
this.mLastStatus[name] = null;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
@@ -401,6 +419,7 @@
|
||||
delete this.mSessions[name];
|
||||
delete this.mListeners[name];
|
||||
delete this.mLastResults[name];
|
||||
delete this.mLastStatus[name];
|
||||
--this.sessionCount;
|
||||
break;
|
||||
}
|
||||
@@ -417,10 +436,12 @@
|
||||
this.mSessions = {};
|
||||
this.mListeners = {};
|
||||
this.mLastResults = {};
|
||||
this.mLastStatus = {};
|
||||
for (var name in aCopyFrom.mSessions) {
|
||||
this.mSessions[name] = aCopyFrom.mSessions[name];
|
||||
this.mListeners[name] = new (this.mAutoCompleteListener)(name);
|
||||
this.mLastResults[name] = null;
|
||||
this.mLastStatus[name] = null;
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
@@ -491,6 +512,7 @@
|
||||
this.isSearching = true;
|
||||
this.mSessionReturns = this.sessionCount;
|
||||
this.mFailureCount = 0;
|
||||
this.mFailureItems = 0;
|
||||
|
||||
// tell each session to start searching...
|
||||
for (var name in this.mSessions)
|
||||
@@ -531,7 +553,9 @@
|
||||
|
||||
if (firstReturn)
|
||||
this.clearResults(false); // clear results, but don't repaint yet
|
||||
|
||||
|
||||
this.mLastStatus[aSessionName] = aStatus;
|
||||
|
||||
// check the many criteria for failure
|
||||
if (aStatus == Components.interfaces.nsIAutoCompleteStatus.failed ||
|
||||
aStatus == Components.interfaces.nsIAutoCompleteStatus.ignored ||
|
||||
@@ -543,6 +567,9 @@
|
||||
this.mLastResults[aSessionName] = null;
|
||||
this.searchFailed();
|
||||
return;
|
||||
} else if (aStatus ==
|
||||
Components.interfaces.nsIAutoCompleteStatus.failureItems){
|
||||
++this.mFailureItems;
|
||||
}
|
||||
|
||||
this.mLastResults[aSessionName] = aResults;
|
||||
@@ -567,8 +594,9 @@
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<!-- called each time a search fails. If all searches have failed,
|
||||
clear the list and close the popup -->
|
||||
<!-- called each time a search fails, except when failure items need
|
||||
to be displayed. If all searches have failed, clear the list
|
||||
and close the popup -->
|
||||
<method name="searchFailed">
|
||||
<body><![CDATA[
|
||||
// if it's the last session to return, time to clean up...
|
||||
@@ -662,12 +690,22 @@
|
||||
<!-- when the user clicks an entry in the autocomplete popup -->
|
||||
<method name="onResultClick">
|
||||
<body><![CDATA[
|
||||
// set textbox value to either override value, or the clicked result
|
||||
// set textbox value to either override value, or the clicked result
|
||||
var errItem=null;
|
||||
var val = this.resultsPopup.getOverrideValue();
|
||||
if (val)
|
||||
this.value = val;
|
||||
else if (this.resultsPopup.selectedIndex != null && !this.noMatch) {
|
||||
this.value = this.getResultValueAt(this.resultsPopup.selectedIndex);
|
||||
if (val)
|
||||
this.value = val;
|
||||
else if (this.resultsPopup.selectedIndex != null &&
|
||||
!this.noMatch) {
|
||||
if (this.getSessionStatusAt(this.resultsPopup.selectedIndex) ==
|
||||
Components.interfaces.nsIAutoCompleteStatus.failureItems) {
|
||||
this.value = this.currentSearchString;
|
||||
this.mTransientValue = true;
|
||||
errItem = this.getResultAt(this.resultsPopup.selectedIndex);
|
||||
} else {
|
||||
this.value = this.getResultValueAt(
|
||||
this.resultsPopup.selectedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
this.mNeedToFinish = false;
|
||||
@@ -677,6 +715,9 @@
|
||||
|
||||
this.currentSearchString = "";
|
||||
|
||||
if (errItem) {
|
||||
this.fireErrorCommand(errItem);
|
||||
}
|
||||
this.fireTextCommand("clicking");
|
||||
]]></body>
|
||||
</method>
|
||||
@@ -766,9 +807,21 @@
|
||||
break;
|
||||
|
||||
case KeyEvent.DOM_VK_RETURN:
|
||||
|
||||
// if this is a failure item, save it for fireErrorCommand
|
||||
var errItem = null;
|
||||
if (this.resultsPopup.selectedIndex != null &&
|
||||
this.getSessionStatusAt(this.resultsPopup.selectedIndex) ==
|
||||
Components.interfaces.nsIAutoCompleteStatus.failureItems) {
|
||||
errItem = this.getResultAt(this.resultsPopup.selectedIndex);
|
||||
}
|
||||
|
||||
killEvent = this.mMenuOpen;
|
||||
this.finishAutoComplete(true, true);
|
||||
this.closeResultPopup();
|
||||
if (errItem) {
|
||||
this.fireErrorCommand(errItem);
|
||||
}
|
||||
break;
|
||||
|
||||
case KeyEvent.DOM_VK_ESCAPE:
|
||||
@@ -831,7 +884,12 @@
|
||||
// determine which value to place in the textbox
|
||||
this.ignoreInputEvent = true;
|
||||
if (selected != null) {
|
||||
this.value = this.getResultValueAt(selected);
|
||||
if (this.getSessionStatusAt(selected) ==
|
||||
Components.interfaces.nsIAutoCompleteStatus.failureItems) {
|
||||
this.value = this.currentSearchString;
|
||||
} else {
|
||||
this.value = this.getResultValueAt(selected);
|
||||
}
|
||||
this.mTransientValue = true;
|
||||
} else {
|
||||
this.value = this.currentSearchString;
|
||||
@@ -891,7 +949,9 @@
|
||||
<!-- -->
|
||||
<method name="openResultPopup">
|
||||
<body><![CDATA[
|
||||
if (!this.mMenuOpen && this.showPopup && this.focused && (this.getResultCount("") >= this.minResultsForPopup) ) {
|
||||
if (!this.mMenuOpen && this.showPopup && this.focused &&
|
||||
(this.getResultCount("") >= this.minResultsForPopup
|
||||
|| this.mFailureItems)) {
|
||||
if (this.flexPopup) {
|
||||
var w = this.boxObject.width;
|
||||
if (w != this.resultsPopup.boxObject.width)
|
||||
@@ -941,8 +1001,10 @@
|
||||
<!-- -->
|
||||
<method name="clearResultData">
|
||||
<body><![CDATA[
|
||||
for (var name in this.mSessions)
|
||||
for (var name in this.mSessions) {
|
||||
this.mLastResults[name] = null;
|
||||
this.mLastStatus[name] = null;
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
@@ -986,6 +1048,14 @@
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<!-- execute the external command handler -->
|
||||
<method name="fireErrorCommand">
|
||||
<parameter name="aErrorItem"/>
|
||||
<body><![CDATA[
|
||||
return this.onerrorcommand ? this.onerrorcommand(aErrorItem) : null;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<!-- execute the external command handler -->
|
||||
<method name="fireTextRevert">
|
||||
<body><![CDATA[
|
||||
@@ -1056,6 +1126,7 @@
|
||||
var svc = Components.classes["@mozilla.org/atom-service;1"].getService(i);
|
||||
return svc.getAtom(aVal);
|
||||
} catch(ex) { }
|
||||
return null; // XXX equivalent to falling off the end?
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- ----- BEGIN LICENSE BLOCK -----
|
||||
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
-
|
||||
- The contents of this file are subject to the Mozilla Public License Version
|
||||
- 1.1 (the "License"); you may not use this file except in compliance with
|
||||
- the License. You may obtain a copy of the License at
|
||||
- http://www.mozilla.org/MPL/
|
||||
-
|
||||
- Software distributed under the License is distributed on an "AS IS" basis,
|
||||
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
- for the specific language governing rights and limitations under the
|
||||
- License.
|
||||
-
|
||||
- The Original Code is mozilla.org code
|
||||
-
|
||||
- The Initial Developer of the Original Code is Netscape
|
||||
- Communications Corp. Portions created by Netscape are
|
||||
- Copyright (C) 2001 Netscape Communications Corp.
|
||||
- All Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
-
|
||||
- Alternatively, the contents of this file may be used under the terms of
|
||||
- either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
- or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
- in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
- of those above. If you wish to allow use of your version of this file only
|
||||
- under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
- use your version of this file under the terms of the MPL, indicate your
|
||||
- decision by deleting the provisions above and replace them with the notice
|
||||
- and other provisions required by the LGPL or the GPL. If you do not delete
|
||||
- the provisions above, a recipient may use your version of this file under
|
||||
- the terms of any one of the MPL, the GPL or the LGPL.
|
||||
-
|
||||
- ----- END LICENSE BLOCK ----- -->
|
||||
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the locales being supplied -->
|
||||
<RDF:Seq about="urn:mozilla:locale:root">
|
||||
<RDF:li resource="urn:mozilla:locale:en-US"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- locale information -->
|
||||
<RDF:Description about="urn:mozilla:locale:en-US">
|
||||
<chrome:packages>
|
||||
<RDF:Seq about="urn:mozilla:locale:en-US:packages">
|
||||
<RDF:li resource="urn:mozilla:locale:en-US:mozldap"/>
|
||||
</RDF:Seq>
|
||||
</chrome:packages>
|
||||
</RDF:Description>
|
||||
|
||||
<!-- Version Information. State that we work only with major version of this
|
||||
package. -->
|
||||
<RDF:Description about="urn:mozilla:locale:en-US:mozldap"
|
||||
chrome:localeVersion="0.9.5"/>
|
||||
</RDF:RDF>
|
||||
@@ -0,0 +1,145 @@
|
||||
# ----- BEGIN LICENSE BLOCK -----
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is the mozilla.org autocomplete code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Dan Mosedale <dmose@netscape.com>
|
||||
# Robin Foster-Clark <robinf@netscape.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the LGPL or the GPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ----- END LICENSE BLOCK -----
|
||||
|
||||
# These are error strings for problems that happen while in the
|
||||
# various states declared in nsILDAPAutoCompFormatter.idl. Note that
|
||||
# the number that indexes each error state is the same as the number
|
||||
# corresponding to that state in nsILDAPAutoCompFormatter.idl.
|
||||
|
||||
## @name ERR_STATE_UNBOUND
|
||||
## @loc none
|
||||
0=LDAP initialization problem
|
||||
|
||||
## @name ERR_STATE_INITIALIZING
|
||||
## @loc none
|
||||
1=LDAP server connection failed
|
||||
|
||||
## @name ERR_STATE_BINDING
|
||||
## @loc none
|
||||
2=LDAP server connection failed
|
||||
|
||||
## @name ERR_STATE_BOUND
|
||||
## @loc none
|
||||
3=LDAP server communications problem
|
||||
|
||||
## @name ERR_STATE_SEARCHING
|
||||
## @loc none
|
||||
4=LDAP server search problem
|
||||
|
||||
|
||||
# The format of the alert dialog itself
|
||||
#
|
||||
## @name ALERT_FORMAT
|
||||
## @loc None of %1$S, %2$S, %3$S, and %4$S should be localized. %1$S is the
|
||||
## ERROR_CODE string below, %2$S is the error code itself, %3$S is an
|
||||
## LDAP SDK error message from
|
||||
## chrome://mozldap/locale/ldapErrors.properties", and %4$S is a hint
|
||||
## relating to that specific error, found in this file.
|
||||
alertFormat=%1$S %2$S: %3$S\n\n %4$S
|
||||
|
||||
# This string is used in ALERT_FORMAT
|
||||
#
|
||||
## @name ERROR_CODE
|
||||
## @loc none
|
||||
errCode=Error code
|
||||
|
||||
|
||||
## The following errors are for error codes other than LDAP-specific ones.
|
||||
## Someday mozilla will actually have a system for mapping nsresults to
|
||||
## error strings that's actually widely used, unlike nsIErrorService. But
|
||||
## until it does, these strings live here...
|
||||
|
||||
## @name HOST_NOT_FOUND
|
||||
## @loc none
|
||||
5000=Host not found
|
||||
|
||||
## @name GENERIC_ERROR
|
||||
## @loc none
|
||||
9999=Unknown error
|
||||
|
||||
|
||||
# Hints to for the user, associated with specific error codes (ie error code
|
||||
# + 10000)
|
||||
|
||||
|
||||
## @name TIMELIMIT_EXCEEDED_HINT
|
||||
## @loc none
|
||||
10003=Please try again later, or else contact your System Administrator.
|
||||
|
||||
## @name STRONGAUTH_REQUIRED_HINT
|
||||
## @loc none
|
||||
10008=Strong authentication is not currently supported.
|
||||
|
||||
## @name INVALID_SYNTAX_HINT
|
||||
## @loc none
|
||||
10021=Verify that the search filter is correct, and then try again, or else contact your System Administrator. To verify that the search filter is correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit, and then click Advanced to display the Search Filter.
|
||||
|
||||
## @name NO_SUCH_OBJECT_HINT
|
||||
## @loc none
|
||||
10032=Verify that the Base DN is correct, and then try again, or else contact your System Administrator. To verify that the Base DN is correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit to display the Base DN.
|
||||
|
||||
## @name BUSY_HINT
|
||||
## @loc none
|
||||
10051=Please try again later.
|
||||
|
||||
## @name SERVER_DOWN_HINT
|
||||
## @loc none
|
||||
10081=Verify that the Hostname and Port Number are correct, and then try again, or else contact your System Administrator. To verify that the Hostname and Port Number are correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit to display the Hostname. Click Advanced to display the Port Number.
|
||||
|
||||
## @name TIMEOUT_HINT
|
||||
## @loc none
|
||||
10085=Please try again later.
|
||||
|
||||
## @name FILTER_ERROR_HINT
|
||||
## @loc none
|
||||
10087=Verify that the search filter is correct, and then try again, or else contact your System Administrator. To verify that the search filter is correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit, and then click Advanced to display the Search Filter.
|
||||
|
||||
## @name NO_MEMORY_HINT
|
||||
## @loc none
|
||||
10090=Please close some other windows and/or applications and try again.
|
||||
|
||||
## @name CONNECT_ERROR_HINT
|
||||
## @loc none
|
||||
10091=Verify that the Hostname and Port Number are correct, and then try again, or else contact your System Administrator. To verify that the Hostname and Port Number are correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit to display the Hostname. Click Advanced to display the Port Number.
|
||||
|
||||
## @name HOST_NOT_FOUND_HINT
|
||||
## @loc none
|
||||
15000=Verify that the Hostname is correct, and then try again, or else contact your System Administrator. To verify that the Hostname is correct, from the Edit menu, choose Preferences, then choose Mail & Newsgroups, and then choose Addressing. Click Edit Directories, and select the LDAP server being used. Click Edit to display the Hostname.
|
||||
|
||||
## @name GENERIC_HINT
|
||||
## @loc none
|
||||
19999=Please contact your System Administrator.
|
||||
@@ -102,7 +102,7 @@ nsLDAPAutoCompleteSession::OnStartLookup(const PRUnichar *searchString,
|
||||
kNotFound ||
|
||||
mMinStringLength && nsCRT::strlen(searchString) < mMinStringLength) {
|
||||
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::ignored);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::ignored, 0, mState);
|
||||
return NS_OK;
|
||||
} else {
|
||||
mSearchString = searchString; // save it for later use
|
||||
@@ -113,7 +113,8 @@ nsLDAPAutoCompleteSession::OnStartLookup(const PRUnichar *searchString,
|
||||
if (mState == SEARCHING || mState == BINDING) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::OnStartLookup(): called while "
|
||||
"search already in progress; no lookup started.");
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems,
|
||||
NS_ERROR_FAILURE, mState);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -133,7 +134,8 @@ nsLDAPAutoCompleteSession::OnStartLookup(const PRUnichar *searchString,
|
||||
if ( NS_FAILED(rv) ) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::OnStartLookup(): couldn't "
|
||||
"get search string from previousSearchResult");
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems,
|
||||
NS_ERROR_FAILURE, mState);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -422,8 +424,8 @@ nsLDAPAutoCompleteSession::OnLDAPInit(nsresult aStatus)
|
||||
// Check the status from the initialization of the LDAP connection
|
||||
//
|
||||
if (NS_FAILED(aStatus)) {
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, aStatus,
|
||||
UNBOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -432,8 +434,8 @@ nsLDAPAutoCompleteSession::OnLDAPInit(nsresult aStatus)
|
||||
mOperation = do_CreateInstance("@mozilla.org/network/ldap-operation;1",
|
||||
&rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -447,8 +449,8 @@ nsLDAPAutoCompleteSession::OnLDAPInit(nsresult aStatus)
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPInit(): couldn't "
|
||||
"create proxy to this object for callback");
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -456,8 +458,8 @@ nsLDAPAutoCompleteSession::OnLDAPInit(nsresult aStatus)
|
||||
//
|
||||
rv = mOperation->Init(mConnection, selfProxy);
|
||||
if (NS_FAILED(rv)) {
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_UNEXPECTED; // this should never happen
|
||||
}
|
||||
|
||||
@@ -481,14 +483,14 @@ nsLDAPAutoCompleteSession::OnLDAPInit(nsresult aStatus)
|
||||
PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
|
||||
("nsLDAPAutoCompleteSession::OnLDAPInit(): mSimpleBind "
|
||||
"failed, rv = 0x%lx", rv));
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_OK;
|
||||
|
||||
case NS_ERROR_UNEXPECTED:
|
||||
default:
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
@@ -518,8 +520,8 @@ nsLDAPAutoCompleteSession::OnLDAPBind(nsILDAPMessage *aMessage)
|
||||
|
||||
// reset to the default state
|
||||
//
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems,
|
||||
NS_ERROR_FAILURE, UNBOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -528,8 +530,6 @@ nsLDAPAutoCompleteSession::OnLDAPBind(nsILDAPMessage *aMessage)
|
||||
//
|
||||
if ( errCode != nsILDAPErrors::SUCCESS) {
|
||||
|
||||
// XXXdmose should this be propagated to the UI somehow?
|
||||
//
|
||||
PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_WARNING,
|
||||
("nsLDAPAutoCompleteSession::OnLDAPBind(): error binding to "
|
||||
"LDAP server, errCode = %d", errCode));
|
||||
@@ -537,7 +537,9 @@ nsLDAPAutoCompleteSession::OnLDAPBind(nsILDAPMessage *aMessage)
|
||||
// reset to the default state
|
||||
//
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems,
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LDAP, errCode),
|
||||
UNBOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -558,8 +560,8 @@ nsLDAPAutoCompleteSession::OnLDAPSearchEntry(nsILDAPMessage *aMessage)
|
||||
PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
|
||||
("nsLDAPAutoCompleteSession::OnLDAPSearchEntry entered\n"));
|
||||
|
||||
// make sure this is only getting called after StartSearch has initialized
|
||||
// the result set
|
||||
// make sure this is only getting called after StartLDAPSearch has
|
||||
// initialized the result set
|
||||
//
|
||||
NS_ASSERTION(mResultsArray,
|
||||
"nsLDAPAutoCompleteSession::OnLDAPSearchEntry(): "
|
||||
@@ -610,10 +612,30 @@ nsLDAPAutoCompleteSession::OnLDAPSearchResult(nsILDAPMessage *aMessage)
|
||||
// and default index appropriately
|
||||
//
|
||||
AutoCompleteStatus status;
|
||||
PRInt32 lderrno;
|
||||
|
||||
switch (mEntriesReturned) {
|
||||
|
||||
case 0:
|
||||
// note that we only look at the error code if there are no results for
|
||||
// this session; if we got results and then an error happened, this
|
||||
// is ignored, in part because it seems likely to be confusing to the
|
||||
// user, and in part because it is likely to be scrolled out of view
|
||||
// anyway
|
||||
//
|
||||
aMessage->GetErrorCode(&lderrno);
|
||||
if (lderrno != nsILDAPErrors::SUCCESS) {
|
||||
|
||||
PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
|
||||
("nsLDAPAutoCompleteSession::OnLDAPSearchResult(): "
|
||||
"lderrno=%d\n", lderrno));
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems,
|
||||
NS_ERROR_GENERATE_FAILURE(
|
||||
NS_ERROR_MODULE_LDAP, lderrno),
|
||||
BOUND);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// we could potentially keep track of non-fatal errors to the
|
||||
// search, and if there has been more than 1, and there are no entries,
|
||||
// we could return |failed| instead of |noMatch|. It's unclear to me
|
||||
@@ -631,8 +653,8 @@ nsLDAPAutoCompleteSession::OnLDAPSearchResult(nsILDAPMessage *aMessage)
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPSearchResult(): "
|
||||
"mResults->SetDefaultItemIndex(0) failed");
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -647,35 +669,17 @@ nsLDAPAutoCompleteSession::OnLDAPSearchResult(nsILDAPMessage *aMessage)
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPSearchResult(): "
|
||||
"mResults->SetDefaultItemIndex(-1) failed");
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// This seems to be necessary for things to work, though I'm not sure
|
||||
// why that's true.
|
||||
//
|
||||
rv = mResults->SetSearchString(mSearchString.get());
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPSearchResult(): couldn't "
|
||||
"set search string in results object");
|
||||
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// XXXdmose just hang out with a bound connection forever? waiting
|
||||
// for nsILDAPService landing to decide on this
|
||||
//
|
||||
mState = BOUND;
|
||||
|
||||
// call the mListener's OnAutoComplete and clean up
|
||||
//
|
||||
FinishAutoCompleteLookup(status);
|
||||
// XXXdmose should we really leave the connection BOUND here?
|
||||
FinishAutoCompleteLookup(status, NS_OK, BOUND);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -698,8 +702,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't "
|
||||
"create @mozilla.org/network/ldap-operation;1");
|
||||
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -713,8 +717,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't "
|
||||
"create proxy to this object for callback");
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -724,9 +728,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't "
|
||||
"initialize LDAP operation");
|
||||
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
@@ -736,8 +739,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
nsXPIDLCString urlFilter;
|
||||
rv = mServerURL->GetFilter(getter_Copies(urlFilter));
|
||||
if ( NS_FAILED(rv) ){
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
@@ -748,8 +751,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): couldn't "
|
||||
"get @mozilla.org/network/ldap-service;1");
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -763,11 +766,11 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
// the filter works as a term to &
|
||||
//
|
||||
if (urlFilter[0] != '(') {
|
||||
prefix = NS_LITERAL_STRING("(&(") +
|
||||
NS_ConvertUTF8toUCS2(urlFilter) +
|
||||
prefix = NS_LITERAL_STRING("(&(") +
|
||||
NS_ConvertUTF8toUCS2(urlFilter) +
|
||||
NS_LITERAL_STRING(")");
|
||||
} else {
|
||||
prefix = NS_LITERAL_STRING("(&") +
|
||||
prefix = NS_LITERAL_STRING("(&") +
|
||||
NS_ConvertUTF8toUCS2(urlFilter);
|
||||
}
|
||||
|
||||
@@ -786,8 +789,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
switch(rv) {
|
||||
|
||||
case NS_ERROR_OUT_OF_MEMORY:
|
||||
mState=BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return rv;
|
||||
|
||||
case NS_ERROR_NOT_AVAILABLE:
|
||||
@@ -795,8 +798,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
("nsLDAPAutoCompleteSession::StartLDAPSearch(): "
|
||||
"createFilter generated filter longer than max filter "
|
||||
"size of %d", MAX_AUTOCOMPLETE_FILTER_SIZE));
|
||||
mState=BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return rv;
|
||||
|
||||
case NS_ERROR_INVALID_ARG:
|
||||
@@ -807,36 +810,20 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
//
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): "
|
||||
"createFilter returned unexpected value");
|
||||
|
||||
mState=BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// create a result set
|
||||
// If the results array for this search hasn't already been created, do
|
||||
// so now. Note that we don't return ::failureItems here, because if
|
||||
// there's no array, there's nowhere to put the items.
|
||||
//
|
||||
mResults = do_CreateInstance(NS_AUTOCOMPLETERESULTS_CONTRACTID, &rv);
|
||||
|
||||
rv = CreateResultsArray();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch() couldn't"
|
||||
" create " NS_AUTOCOMPLETERESULTS_CONTRACTID);
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// get a pointer to the array in question now, so that we don't have to
|
||||
// keep re-fetching it every time an entry callback happens
|
||||
//
|
||||
rv = mResults->GetItems(getter_AddRefs(mResultsArray));
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch() couldn't "
|
||||
"get results array.");
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
return NS_ERROR_FAILURE;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed, rv, BOUND);
|
||||
}
|
||||
|
||||
// nothing returned yet!
|
||||
@@ -848,8 +835,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
nsXPIDLCString dn;
|
||||
rv = mServerURL->GetDn(getter_Copies(dn));
|
||||
if ( NS_FAILED(rv) ){
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
@@ -859,7 +846,8 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
rv = mServerURL->GetScope(&scope);
|
||||
if ( NS_FAILED(rv) ){
|
||||
mState = BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
@@ -876,11 +864,10 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
|
||||
case NS_ERROR_LDAP_ENCODING_ERROR:
|
||||
PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
|
||||
("nsLDAPAutoCompleteSession::StartSearch(): SearchExt "
|
||||
("nsLDAPAutoCompleteSession::StartLDAPSearch(): SearchExt "
|
||||
"returned NS_ERROR_LDAP_ENCODING_ERROR"));
|
||||
|
||||
mState=BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_OK;
|
||||
|
||||
case NS_ERROR_LDAP_SERVER_DOWN:
|
||||
@@ -888,17 +875,15 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
// LDAP XPCOM SDK.
|
||||
|
||||
PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
|
||||
("nsLDAPAutoCompleteSession::StartSearch(): SearchExt "
|
||||
("nsLDAPAutoCompleteSession::StartLDAPSearch(): SearchExt "
|
||||
"returned NS_ERROR_LDAP_SERVER_DOWN"));
|
||||
|
||||
mState=UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_OK;
|
||||
|
||||
case NS_ERROR_OUT_OF_MEMORY:
|
||||
|
||||
mState=BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
BOUND);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
case NS_ERROR_LDAP_NOT_SUPPORTED:
|
||||
@@ -908,11 +893,10 @@ nsLDAPAutoCompleteSession::StartLDAPSearch()
|
||||
|
||||
// all this stuff indicates code bugs
|
||||
//
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartSearch(): SearchExt "
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch(): SearchExt "
|
||||
"returned unexpected value");
|
||||
|
||||
mState=BOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, 0,
|
||||
BOUND);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
@@ -935,8 +919,8 @@ nsLDAPAutoCompleteSession::InitConnection()
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::InitConnection(): could "
|
||||
"not create @mozilla.org/network/ldap-connection;1");
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -945,8 +929,8 @@ nsLDAPAutoCompleteSession::InitConnection()
|
||||
if (!mServerURL) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::InitConnection(): mServerURL "
|
||||
"is NULL");
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
@@ -955,8 +939,8 @@ nsLDAPAutoCompleteSession::InitConnection()
|
||||
nsXPIDLCString host;
|
||||
rv = mServerURL->GetHost(getter_Copies(host));
|
||||
if (NS_FAILED(rv)) {
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -965,8 +949,8 @@ nsLDAPAutoCompleteSession::InitConnection()
|
||||
PRInt32 port;
|
||||
rv = mServerURL->GetPort(&port);
|
||||
if (NS_FAILED(rv)) {
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -980,8 +964,8 @@ nsLDAPAutoCompleteSession::InitConnection()
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::InitConnection(): couldn't "
|
||||
"create proxy to this object for callback");
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -999,40 +983,142 @@ nsLDAPAutoCompleteSession::InitConnection()
|
||||
PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
|
||||
("nsLDAPAutoCompleteSession::InitConnection(): mSimpleBind "
|
||||
"failed, rv = 0x%lx", rv));
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return rv;
|
||||
|
||||
case NS_ERROR_ILLEGAL_VALUE:
|
||||
default:
|
||||
mState = UNBOUND;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failed);
|
||||
return rv;
|
||||
FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems, rv,
|
||||
UNBOUND);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
|
||||
// set our state to initializing
|
||||
// set our state
|
||||
//
|
||||
mState = INITIALIZING;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsLDAPAutoCompleteSession::FinishAutoCompleteLookup(AutoCompleteStatus
|
||||
aACStatus)
|
||||
nsresult
|
||||
nsLDAPAutoCompleteSession::CreateResultsArray(void)
|
||||
{
|
||||
nsresult rv=NS_OK; // temp for return value
|
||||
nsresult rv;
|
||||
|
||||
// create a result set
|
||||
//
|
||||
mResults = do_CreateInstance(NS_AUTOCOMPLETERESULTS_CONTRACTID, &rv);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch() couldn't"
|
||||
" create " NS_AUTOCOMPLETERESULTS_CONTRACTID);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// This seems to be necessary for things to work, though I'm not sure
|
||||
// why that's true.
|
||||
//
|
||||
rv = mResults->SetSearchString(mSearchString.get());
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::OnLDAPSearchResult(): couldn't "
|
||||
"set search string in results object");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// get a pointer to the array in question now, so that we don't have to
|
||||
// keep re-fetching it every time an entry callback happens
|
||||
//
|
||||
rv = mResults->GetItems(getter_AddRefs(mResultsArray));
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::StartLDAPSearch() couldn't "
|
||||
"get results array.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsLDAPAutoCompleteSession::FinishAutoCompleteLookup(
|
||||
AutoCompleteStatus aACStatus, const nsresult aResult,
|
||||
enum SessionState aEndState)
|
||||
{
|
||||
nsCOMPtr<nsIAutoCompleteItem> errorItem; // pointer to item we may create
|
||||
nsresult rv; // temp for return value
|
||||
|
||||
// if there's a listener, inform the listener that the search is over
|
||||
//
|
||||
rv = NS_OK;
|
||||
if (mListener) {
|
||||
|
||||
switch (aACStatus) {
|
||||
|
||||
if (aACStatus == nsIAutoCompleteStatus::matchFound) {
|
||||
case nsIAutoCompleteStatus::matchFound:
|
||||
rv = mListener->OnAutoComplete(mResults, aACStatus);
|
||||
} else {
|
||||
break;
|
||||
|
||||
case nsIAutoCompleteStatus::failureItems:
|
||||
// if the results array hasn't already been created, make one
|
||||
// to return the error message. If there's an error, fallback
|
||||
// to ::failed
|
||||
//
|
||||
if (!mResults) {
|
||||
rv = CreateResultsArray();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::"
|
||||
"FinishAutoCompleteLookup():"
|
||||
" CreateResultsArray() failed");
|
||||
rv = mListener->OnAutoComplete(0,
|
||||
nsIAutoCompleteStatus::failed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// create the error item
|
||||
//
|
||||
rv = mFormatter->FormatException(mState, aResult,
|
||||
getter_AddRefs(errorItem));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
// try and append the error item; falling back to ::failed
|
||||
// if there's a problem
|
||||
//
|
||||
rv = mResultsArray->AppendElement(errorItem);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::"
|
||||
"FinishAutoCompleteLookup():"
|
||||
" mItems->AppendElement() failed");
|
||||
rv = mListener->OnAutoComplete(0,
|
||||
nsIAutoCompleteStatus::failed);
|
||||
break;
|
||||
}
|
||||
|
||||
// we don't want the autocomplete widget trying to
|
||||
// automagically use the error item for anything. If
|
||||
// something goes wrong here, continue on anyway.
|
||||
//
|
||||
(void)mResults->SetDefaultItemIndex(-1);
|
||||
|
||||
rv = mListener->OnAutoComplete(mResults,
|
||||
nsIAutoCompleteStatus::failureItems);
|
||||
break;
|
||||
}
|
||||
|
||||
// fallback to ::failed
|
||||
NS_ERROR("nsLDAPAutoCompleteSession::FinishAutoCompleteLookup(): "
|
||||
"error calling FormatException()");
|
||||
|
||||
rv = mListener->OnAutoComplete(0, nsIAutoCompleteStatus::failed);
|
||||
break;
|
||||
|
||||
case nsIAutoCompleteStatus::failed:
|
||||
default:
|
||||
rv = mListener->OnAutoComplete(0, aACStatus);
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
// if there's no listener, something's wrong
|
||||
//
|
||||
@@ -1048,6 +1134,10 @@ nsLDAPAutoCompleteSession::FinishAutoCompleteLookup(AutoCompleteStatus
|
||||
"error calling mListener->OnAutoComplete()");
|
||||
}
|
||||
|
||||
// set the state approrpiately
|
||||
//
|
||||
mState = aEndState;
|
||||
|
||||
// we're done with various things; cause nsCOMPtr to release them
|
||||
//
|
||||
mResultsArray = 0;
|
||||
@@ -1057,8 +1147,9 @@ nsLDAPAutoCompleteSession::FinishAutoCompleteLookup(AutoCompleteStatus
|
||||
|
||||
// If we are unbound, drop the connection (if any)
|
||||
//
|
||||
if (mState == UNBOUND)
|
||||
if (mState == UNBOUND) {
|
||||
mConnection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// methods for nsILDAPAutoCompleteSession
|
||||
|
||||
@@ -52,8 +52,13 @@ class nsLDAPAutoCompleteSession : public nsILDAPMessageListener,
|
||||
virtual ~nsLDAPAutoCompleteSession();
|
||||
|
||||
protected:
|
||||
enum SessionState { UNBOUND, INITIALIZING, BINDING, BOUND,
|
||||
SEARCHING } mState;
|
||||
enum SessionState {
|
||||
UNBOUND = nsILDAPAutoCompFormatter::STATE_UNBOUND,
|
||||
INITIALIZING = nsILDAPAutoCompFormatter::STATE_INITIALIZING,
|
||||
BINDING = nsILDAPAutoCompFormatter::STATE_BINDING,
|
||||
BOUND = nsILDAPAutoCompFormatter::STATE_BOUND,
|
||||
SEARCHING = nsILDAPAutoCompFormatter::STATE_SEARCHING
|
||||
} mState;
|
||||
PRUint32 mEntriesReturned; // # of entries returned?
|
||||
nsCOMPtr<nsILDAPConnection> mConnection; // connection used for search
|
||||
nsCOMPtr<nsILDAPOperation> mOperation; // current ldap op
|
||||
@@ -91,7 +96,16 @@ class nsLDAPAutoCompleteSession : public nsILDAPMessageListener,
|
||||
nsresult IsMessageCurrent(nsILDAPMessage *aMessage, PRBool *aIsCurrent);
|
||||
|
||||
// finish a search by calling mListener->OnAutoComplete, resetting state,
|
||||
// and freeing resources.
|
||||
void FinishAutoCompleteLookup(AutoCompleteStatus aACStatus);
|
||||
// and freeing resources. if aACStatus ==
|
||||
// nsIAutoCompleteStatus::failureItems, then the formatter is called with
|
||||
// aResult and aEndState to create an autocomplete item with the error
|
||||
// info in it. See nsILDAPAutoCompFormatter.idl for more info on this.
|
||||
void FinishAutoCompleteLookup(AutoCompleteStatus aACStatus,
|
||||
const nsresult aResult,
|
||||
enum SessionState aEndState);
|
||||
|
||||
// create and initialize the results array
|
||||
nsresult CreateResultsArray(void);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -158,6 +158,7 @@ en-US.jar:
|
||||
locale/en-US/global/finddialog.dtd (find/resources/locale/en-US/finddialog.dtd)
|
||||
locale/en-US/global/finddialog.properties (find/resources/locale/en-US/finddialog.properties)
|
||||
locale/en-US/global/replacedialog.dtd (find/resources/locale/en-US/replacedialog.dtd)
|
||||
locale/en-US/global/ldapAutoCompErrs.properties (autocomplete/resources/locale/en-US/ldapAutoCompErrs.properties)
|
||||
|
||||
toolkit.jar:
|
||||
content/global/console.js (console/resources/content/console.js)
|
||||
|
||||
Reference in New Issue
Block a user