Bug 1300989 - Part 1: Add guid interface, f?=MattN draft
authorsteveck-chung <schung@mozilla.com>
Thu, 29 Dec 2016 12:13:32 +0800
changeset 454419 f81491cdfeb8c93aaddbf955a26ec71bbfc4f1ed
parent 454138 383768c608df77caf18f48ba97dfb8c0e6d1c26a
child 540703 bc25c1cc374bad2212512f8de0d0c89cc6b90e5b
push id39922
push userbmo:schung@mozilla.com
push dateThu, 29 Dec 2016 08:28:14 +0000
bugs1300989
milestone53.0a1
Bug 1300989 - Part 1: Add guid interface, f?=MattN MozReview-Commit-ID: Gy1dqyXXqP6
browser/extensions/formautofill/content/FormAutofillContent.js
toolkit/components/autocomplete/nsAutoCompleteController.cpp
toolkit/components/autocomplete/nsAutoCompleteSimpleResult.cpp
toolkit/components/autocomplete/nsIAutoCompleteController.idl
toolkit/components/autocomplete/nsIAutoCompleteResult.idl
toolkit/components/autocomplete/nsIAutoCompleteSimpleResult.idl
toolkit/components/filepicker/nsFileView.cpp
toolkit/components/satchel/AutoCompletePopup.jsm
toolkit/components/satchel/nsFormAutoCompleteResult.jsm
toolkit/content/browser-content.js
--- a/browser/extensions/formautofill/content/FormAutofillContent.js
+++ b/browser/extensions/formautofill/content/FormAutofillContent.js
@@ -225,20 +225,21 @@ AutofillProfileAutoCompleteSearch.protot
    * @param {Object} previousResult a previous result to use for faster searchinig
    * @param {Object} listener the listener to notify when the search is complete
    */
   startSearch(searchString, searchParam, previousResult, listener) {
     // TODO: These mock data should be replaced by form autofill API
     let labels = ["Mary", "John"];
     let values = ["Mary S.", "John S."];
     let comments = ["123 Sesame Street.", "331 E. Evelyn Avenue"];
+    let guids = ["test-guid-1", "test-guid-2"];
     let result = new FormAutoCompleteResult(searchString,
                                             Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
                                             0, "", values, labels,
-                                            comments);
+                                            comments, guids);
 
     listener.onSearchResult(this, result);
   },
 
   /**
    * Stops an asynchronous search that is in progress
    */
   stopSearch() {
--- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
@@ -735,17 +735,17 @@ nsAutoCompleteController::HandleDelete(b
     if (minResults) {
       ClosePopup();
     }
   }
 
   return NS_OK;
 }
 
-nsresult 
+nsresult
 nsAutoCompleteController::GetResultAt(int32_t aIndex, nsIAutoCompleteResult** aResult,
                                       int32_t* aRowIndex)
 {
   int32_t searchIndex;
   RowIndexToSearch(aIndex, &searchIndex, aRowIndex);
   NS_ENSURE_TRUE(searchIndex >= 0 && *aRowIndex >= 0, NS_ERROR_FAILURE);
 
   *aResult = mResults.SafeObjectAt(searchIndex);
@@ -776,16 +776,27 @@ nsAutoCompleteController::GetCommentAt(i
   nsIAutoCompleteResult* result;
   nsresult rv = GetResultAt(aIndex, &result, &rowIndex);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return result->GetCommentAt(rowIndex, _retval);
 }
 
 NS_IMETHODIMP
+nsAutoCompleteController::GetGuidAt(int32_t aIndex, nsAString & _retval)
+{
+  int32_t rowIndex;
+  nsIAutoCompleteResult* result;
+  nsresult rv = GetResultAt(aIndex, &result, &rowIndex);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return result->GetGuidAt(rowIndex, _retval);
+}
+
+NS_IMETHODIMP
 nsAutoCompleteController::GetStyleAt(int32_t aIndex, nsAString & _retval)
 {
   int32_t rowIndex;
   nsIAutoCompleteResult* result;
   nsresult rv = GetResultAt(aIndex, &result, &rowIndex);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return result->GetStyleAt(rowIndex, _retval);
--- a/toolkit/components/autocomplete/nsAutoCompleteSimpleResult.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteSimpleResult.cpp
@@ -15,31 +15,34 @@
 NS_IMPL_ISUPPORTS(nsAutoCompleteSimpleResult,
                   nsIAutoCompleteResult,
                   nsIAutoCompleteSimpleResult)
 
 struct AutoCompleteSimpleResultMatch
 {
   AutoCompleteSimpleResultMatch(const nsAString& aValue,
                                 const nsAString& aComment,
+                                const nsAString& aGuid,
                                 const nsAString& aImage,
                                 const nsAString& aStyle,
                                 const nsAString& aFinalCompleteValue,
                                 const nsAString& aLabel)
     : mValue(aValue)
     , mComment(aComment)
+    , mGuid(aGuid)
     , mImage(aImage)
     , mStyle(aStyle)
     , mFinalCompleteValue(aFinalCompleteValue)
     , mLabel(aLabel)
   {
   }
 
   nsString mValue;
   nsString mComment;
+  nsString mGuid;
   nsString mImage;
   nsString mStyle;
   nsString mFinalCompleteValue;
   nsString mLabel;
 };
 
 nsAutoCompleteSimpleResult::nsAutoCompleteSimpleResult() :
   mDefaultIndex(-1),
@@ -82,32 +85,34 @@ nsAutoCompleteSimpleResult::AppendResult
     }
   }
 
   // Copy matches.
   uint32_t matchCount = 0;
   rv = aResult->GetMatchCount(&matchCount);
   NS_ENSURE_SUCCESS(rv, rv);
   for (size_t i = 0; i < matchCount; ++i) {
-    nsAutoString value, comment, image, style, finalCompleteValue, label;
+    nsAutoString value, comment, guid, image, style, finalCompleteValue, label;
 
     rv = aResult->GetValueAt(i, value);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aResult->GetCommentAt(i, comment);
     NS_ENSURE_SUCCESS(rv, rv);
+    rv = aResult->GetGuidAt(i, guid);
+    NS_ENSURE_SUCCESS(rv, rv);
     rv = aResult->GetImageAt(i, image);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aResult->GetStyleAt(i, style);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aResult->GetFinalCompleteValueAt(i, finalCompleteValue);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aResult->GetLabelAt(i, label);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = AppendMatch(value, comment, image, style, finalCompleteValue, label);
+    rv = AppendMatch(value, comment, guid, image, style, finalCompleteValue, label);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 // searchString
 NS_IMETHODIMP
@@ -165,41 +170,43 @@ nsAutoCompleteSimpleResult::SetErrorDesc
   mErrorDescription.Assign(aErrorDescription);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAutoCompleteSimpleResult::InsertMatchAt(int32_t aIndex,
                                           const nsAString& aValue,
                                           const nsAString& aComment,
+                                          const nsAString& aGuid,
                                           const nsAString& aImage,
                                           const nsAString& aStyle,
                                           const nsAString& aFinalCompleteValue,
                                           const nsAString& aLabel)
 {
   CHECK_MATCH_INDEX(aIndex, true);
 
-  AutoCompleteSimpleResultMatch match(aValue, aComment, aImage, aStyle, aFinalCompleteValue, aLabel);
+  AutoCompleteSimpleResultMatch match(aValue, aComment, aGuid, aImage, aStyle, aFinalCompleteValue, aLabel);
 
   if (!mMatches.InsertElementAt(aIndex, match)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAutoCompleteSimpleResult::AppendMatch(const nsAString& aValue,
                                         const nsAString& aComment,
+                                        const nsAString& aGuid,
                                         const nsAString& aImage,
                                         const nsAString& aStyle,
                                         const nsAString& aFinalCompleteValue,
                                         const nsAString& aLabel)
 {
-  return InsertMatchAt(mMatches.Length(), aValue, aComment, aImage, aStyle,
+  return InsertMatchAt(mMatches.Length(), aValue, aComment, aGuid, aImage, aStyle,
                        aFinalCompleteValue, aLabel);
 }
 
 NS_IMETHODIMP
 nsAutoCompleteSimpleResult::GetMatchCount(uint32_t *aMatchCount)
 {
   *aMatchCount = mMatches.Length();
   return NS_OK;
@@ -228,16 +235,24 @@ NS_IMETHODIMP
 nsAutoCompleteSimpleResult::GetCommentAt(int32_t aIndex, nsAString& _retval)
 {
   CHECK_MATCH_INDEX(aIndex, false);
   _retval = mMatches[aIndex].mComment;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsAutoCompleteSimpleResult::GetGuidAt(int32_t aIndex, nsAString& _retval)
+{
+  CHECK_MATCH_INDEX(aIndex, false);
+  _retval = mMatches[aIndex].mGuid;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsAutoCompleteSimpleResult::GetImageAt(int32_t aIndex, nsAString& _retval)
 {
   CHECK_MATCH_INDEX(aIndex, false);
   _retval = mMatches[aIndex].mImage;
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/toolkit/components/autocomplete/nsIAutoCompleteController.idl
+++ b/toolkit/components/autocomplete/nsIAutoCompleteController.idl
@@ -135,16 +135,21 @@ interface nsIAutoCompleteController : ns
   AString getLabelAt(in long index);
 
   /*
    * Get the comment of the result at a given index in the last completed search
    */
   AString getCommentAt(in long index);
 
   /*
+   * Get the guid of the result at a given index in the last completed search
+   */
+  AString getGuidAt(in long index);
+
+  /*
    * Get the style hint for the result at a given index in the last completed search
    */
   AString getStyleAt(in long index);
 
   /*
    * Get the url of the image of the result at a given index in the last completed search
    */
   AString getImageAt(in long index);
--- a/toolkit/components/autocomplete/nsIAutoCompleteResult.idl
+++ b/toolkit/components/autocomplete/nsIAutoCompleteResult.idl
@@ -11,23 +11,23 @@ interface nsIAutoCompleteResult : nsISup
    * Possible values for the searchResult attribute
    */
   const unsigned short RESULT_IGNORED = 1; /* indicates invalid searchString */
   const unsigned short RESULT_FAILURE = 2; /* indicates failure */
   const unsigned short RESULT_NOMATCH = 3; /* indicates success with no matches
                                               and that the search is complete */
   const unsigned short RESULT_SUCCESS = 4; /* indicates success with matches
                                               and that the search is complete */
-  const unsigned short RESULT_NOMATCH_ONGOING = 5; /* indicates success 
+  const unsigned short RESULT_NOMATCH_ONGOING = 5; /* indicates success
                                                       with no matches
-                                                      and that the search 
+                                                      and that the search
                                                       is still ongoing */
-  const unsigned short RESULT_SUCCESS_ONGOING = 6; /* indicates success 
+  const unsigned short RESULT_SUCCESS_ONGOING = 6; /* indicates success
                                                       with matches
-                                                      and that the search 
+                                                      and that the search
                                                       is still ongoing */
   /**
    * The original search string
    */
   readonly attribute AString searchString;
 
   /**
    * The result of the search
@@ -60,16 +60,21 @@ interface nsIAutoCompleteResult : nsISup
   AString getLabelAt(in long index);
 
   /**
    * Get the comment of the result at the given index
    */
   AString getCommentAt(in long index);
 
   /**
+   * Get the guid of the result at the given index
+   */
+  AString getGuidAt(in long index);
+
+  /**
    * Get the style hint for the result at the given index
    */
   AString getStyleAt(in long index);
 
   /**
    * Get the image of the result at the given index
    */
   AString getImageAt(in long index);
--- a/toolkit/components/autocomplete/nsIAutoCompleteSimpleResult.idl
+++ b/toolkit/components/autocomplete/nsIAutoCompleteSimpleResult.idl
@@ -37,57 +37,63 @@ interface nsIAutoCompleteSimpleResult : 
   /**
    * A writer for the readonly attribute 'searchResult' which should contain
    * one of the constants nsIAutoCompleteResult.RESULT_* indicating the success
    * of the search.
    */
   void setSearchResult(in unsigned short aSearchResult);
 
   /**
-   * Inserts a match consisting of the given value, comment, image, style and
+   * Inserts a match consisting of the given value, comment, guid, image, style and
    * the value to use for defaultIndex completion at a given position.
    * @param aIndex
    *        The index to insert at
    * @param aValue
    *        The value to autocomplete to
    * @param aComment
    *        Comment shown in the autocomplete widget to describe this match
+   * @param aGuid
+   *        Guid shown in the autocomplete widget to describe this match
    * @param aImage
    *        Image shown in the autocomplete widget for this match.
    * @param aStyle
    *        Describes how to style the match in the autocomplete widget
    * @param aFinalCompleteValue
    *        Value used when the user confirms selecting this match. If not
    *        provided, aValue will be used.
    */
   void insertMatchAt(in long aIndex,
                      in AString aValue,
                      in AString aComment,
+                     [optional] in AString aGuid,
                      [optional] in AString aImage,
                      [optional] in AString aStyle,
                      [optional] in AString aFinalCompleteValue,
                      [optional] in AString aLabel);
 
   /**
-   * Appends a match consisting of the given value, comment, image, style and
+   * Appends a match consisting of the given value, comment, guid, image, style and
    * the value to use for defaultIndex completion.
    * @param aValue
    *        The value to autocomplete to
    * @param aComment
    *        Comment shown in the autocomplete widget to describe this match
+   * @param aGuid
+   *        Guid shown in the autocomplete widget to describe this match
    * @param aImage
    *        Image shown in the autocomplete widget for this match.
    * @param aStyle
    *        Describes how to style the match in the autocomplete widget
    * @param aFinalCompleteValue
    *        Value used when the user confirms selecting this match. If not
    *        provided, aValue will be used.
    */
   void appendMatch(in AString aValue,
                    in AString aComment,
+                   [optional] in AString aGuid,
                    [optional] in AString aImage,
                    [optional] in AString aStyle,
                    [optional] in AString aFinalCompleteValue,
                    [optional] in AString aLabel);
 
   /**
    * Gets the listener for changes in the result.
    */
--- a/toolkit/components/filepicker/nsFileView.cpp
+++ b/toolkit/components/filepicker/nsFileView.cpp
@@ -23,17 +23,17 @@
 #include "nsAutoPtr.h"
 #include "nsIMutableArray.h"
 #include "nsTArray.h"
 #include "mozilla/Attributes.h"
 
 #include "nsWildCard.h"
 
 class nsIDOMDataTransfer;
- 
+
 #define NS_FILECOMPLETE_CID { 0xcb60980e, 0x18a5, 0x4a77, \
                             { 0x91, 0x10, 0x81, 0x46, 0x61, 0x4c, 0xa7, 0xf0 } }
 #define NS_FILECOMPLETE_CONTRACTID "@mozilla.org/autocomplete/search;1?name=file"
 
 class nsFileResult final : public nsIAutoCompleteResult
 {
 public:
   // aSearchString is the text typed into the autocomplete widget
@@ -147,16 +147,21 @@ NS_IMETHODIMP nsFileResult::GetLabelAt(i
 }
 
 NS_IMETHODIMP nsFileResult::GetCommentAt(int32_t index, nsAString & aComment)
 {
   aComment.Truncate();
   return NS_OK;
 }
 
+NS_IMETHODIMP nsFileResult::GetGuidAt(int32_t index, nsAString & aGuid)
+{
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsFileResult::GetStyleAt(int32_t index, nsAString & aStyle)
 {
   if (mValues[index].Last() == '/')
     aStyle.AssignLiteral("directory");
   else
     aStyle.AssignLiteral("file");
   return NS_OK;
 }
@@ -213,20 +218,20 @@ class nsFileView : public nsIFileView,
 {
 public:
   nsFileView();
   nsresult Init();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIFILEVIEW
   NS_DECL_NSITREEVIEW
-  
+
 protected:
   virtual ~nsFileView();
-  
+
   void FilterFiles();
   void ReverseArray(nsTArray<nsCOMPtr<nsIFile> >& aArray);
   void SortArray(nsTArray<nsCOMPtr<nsIFile> >& aArray);
   void SortInternal();
 
   nsTArray<nsCOMPtr<nsIFile> > mFileList;
   nsTArray<nsCOMPtr<nsIFile> > mDirList;
   nsTArray<nsCOMPtr<nsIFile> > mFilteredFiles;
@@ -309,17 +314,17 @@ nsFileView::SetShowHiddenFiles(bool aSho
 {
   if (aShowHidden != mShowHiddenFiles) {
     mShowHiddenFiles = aShowHidden;
 
     // This could be better optimized, but since the hidden
     // file functionality is not currently used, this will be fine.
     SetDirectory(mDirectoryPath);
   }
-    
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFileView::GetShowHiddenFiles(bool* aShowHidden)
 {
   *aShowHidden = mShowHiddenFiles;
   return NS_OK;
@@ -661,17 +666,17 @@ nsFileView::Drop(int32_t aRow, int32_t a
 NS_IMETHODIMP
 nsFileView::GetParentIndex(int32_t aRowIndex, int32_t* aParentIndex)
 {
   *aParentIndex = -1;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsFileView::HasNextSibling(int32_t aRowIndex, int32_t aAfterIndex, 
+nsFileView::HasNextSibling(int32_t aRowIndex, int32_t aAfterIndex,
                            bool* aHasSibling)
 {
   *aHasSibling = (aAfterIndex < (mTotalRows - 1));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFileView::GetLevel(int32_t aIndex, int32_t* aLevel)
@@ -838,23 +843,23 @@ nsFileView::FilterFiles()
   mFilteredFiles.Clear();
   uint32_t filterCount = mCurrentFilters.Length();
 
   for (uint32_t i = 0; i < count; ++i) {
     nsIFile* file = mFileList[i];
     bool isHidden = false;
     if (!mShowHiddenFiles)
       file->IsHidden(&isHidden);
-    
+
     nsAutoString ucsLeafName;
     if(NS_FAILED(file->GetLeafName(ucsLeafName))) {
       // need to check return value for GetLeafName()
       continue;
     }
-    
+
     if (!isHidden) {
       for (uint32_t j = 0; j < filterCount; ++j) {
         bool matched = false;
         if (!nsCRT::strcmp(mCurrentFilters.ElementAt(j),
                            u"..apps"))
         {
           file->IsExecutable(&matched);
         } else
@@ -885,17 +890,17 @@ nsFileView::ReverseArray(nsTArray<nsCOMP
   }
 }
 
 static int
 SortNameCallback(const void* aElement1, const void* aElement2, void* aContext)
 {
   nsIFile* file1 = *static_cast<nsIFile* const *>(aElement1);
   nsIFile* file2 = *static_cast<nsIFile* const *>(aElement2);
-  
+
   nsAutoString leafName1, leafName2;
   file1->GetLeafName(leafName1);
   file2->GetLeafName(leafName2);
 
   return Compare(leafName1, leafName2);
 }
 
 static int
--- a/toolkit/components/satchel/AutoCompletePopup.jsm
+++ b/toolkit/components/satchel/AutoCompletePopup.jsm
@@ -41,16 +41,20 @@ var AutoCompleteResultView = {
 
   getCommentAt(index) {
     // The richlist autocomplete popup uses comment for its main
     // display of an item, which is why we're returning the label
     // here instead.
     return this.results[index].label;
   },
 
+  getGuidAt(index) {
+    return this.results[index].guid;
+  },
+
   getStyleAt(index) {
     return this.results[index].style;
   },
 
   getImageAt(index) {
     return this.results[index].image;
   },
 
--- a/toolkit/components/satchel/nsFormAutoCompleteResult.jsm
+++ b/toolkit/components/satchel/nsFormAutoCompleteResult.jsm
@@ -12,24 +12,26 @@ Components.utils.import("resource://gre/
 this.FormAutoCompleteResult =
  function FormAutoCompleteResult(searchString,
                                  searchResult,
                                  defaultIndex,
                                  errorDescription,
                                  values,
                                  labels,
                                  comments,
+                                 guids,
                                  prevResult) {
   this.searchString = searchString;
   this._searchResult = searchResult;
   this._defaultIndex = defaultIndex;
   this._errorDescription = errorDescription;
   this._values = values;
   this._labels = labels;
   this._comments = comments;
+  this._guids = guids;
   this._formHistResult = prevResult;
 
   if (prevResult) {
     this.entries = prevResult.wrappedJSObject.entries;
   } else {
     this.entries = [];
   }
 }
@@ -119,16 +121,26 @@ FormAutoCompleteResult.prototype = {
    * @return          the comment at the specified index
    */
   getCommentAt: function(index) {
     this._checkIndexBounds(index);
     return this._comments[index];
   },
 
   /**
+   * Retrieves a guid (metadata instance)
+   * @param  index    the index of the guid requested
+   * @return          the guid at the specified index
+   */
+  getGuidAt: function(index) {
+    this._checkIndexBounds(index);
+    return this._guids[index];
+  },
+
+  /**
    * Retrieves a style hint specific to a particular index.
    * @param  index    the index of the style hint requested
    * @return          the style hint at the specified index
    */
   getStyleAt: function(index) {
     this._checkIndexBounds(index);
 
     if (this._formHistResult && index < this._formHistResult.matchCount) {
@@ -175,13 +187,14 @@ FormAutoCompleteResult.prototype = {
     if (removeFromDatabase && this._formHistResult &&
         index < this._formHistResult.matchCount) {
       // Delete the history result from the DB
       this._formHistResult.removeValueAt(index, true);
     }
     this._values.splice(index, 1);
     this._labels.splice(index, 1);
     this._comments.splice(index, 1);
+    this._guids.splice(index, 1);
   },
 
   // nsISupports
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteResult])
 };
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -1592,16 +1592,17 @@ let AutoCompletePopup = {
       return results;
     }
 
     for (let i = 0; i < controller.matchCount; ++i) {
       let result = {};
       result.value = controller.getValueAt(i);
       result.label = controller.getLabelAt(i);
       result.comment = controller.getCommentAt(i);
+      result.guid = controller.getGuidAt(i);
       result.style = controller.getStyleAt(i);
       result.image = controller.getImageAt(i);
       results.push(result);
     }
 
     return results;
   },
 }