Merge for back out of changeset 06433d3dafd9 (bug 504422) because the patch is wrong.

This commit is contained in:
Shawn Wilsher 2009-07-22 14:05:11 -07:00
commit 969b91a21d
2 changed files with 25 additions and 33 deletions

View File

@ -71,29 +71,29 @@ namespace places {
} }
/* static */ /* static */
void nsString
MatchAutoCompleteFunction::fixupURISpec(const nsDependentCString &aURISpec, MatchAutoCompleteFunction::fixupURISpec(const nsDependentCString &aURISpec)
nsString &_fixedSpec)
{ {
nsCString unescapedSpec; nsCAutoString unescapedSpec;
(void)NS_UnescapeURL(aURISpec, esc_SkipControl | esc_AlwaysCopy, (void)NS_UnescapeURL(aURISpec, esc_SkipControl | esc_AlwaysCopy,
unescapedSpec); unescapedSpec);
// If this unescaped string is valid UTF-8, we'll convert it. Otherwise, // If this unescaped string is valid UTF-8, we'll convert it. Otherwise,
// we will simply convert our original string. // we will simply convert our original string.
NS_ASSERTION(_fixedSpec.IsEmpty(), nsString fixedSpec;
"Passing a non-empty string as an out parameter!");
if (IsUTF8(unescapedSpec)) if (IsUTF8(unescapedSpec))
CopyUTF8toUTF16(unescapedSpec, _fixedSpec); CopyUTF8toUTF16(unescapedSpec, fixedSpec);
else else
CopyUTF8toUTF16(aURISpec, _fixedSpec); CopyUTF8toUTF16(aURISpec, fixedSpec);
if (StringBeginsWith(_fixedSpec, NS_LITERAL_STRING("http://"))) if (StringBeginsWith(fixedSpec, NS_LITERAL_STRING("http://")))
_fixedSpec.Cut(0, 7); fixedSpec.Cut(0, 7);
else if (StringBeginsWith(_fixedSpec, NS_LITERAL_STRING("https://"))) else if (StringBeginsWith(fixedSpec, NS_LITERAL_STRING("https://")))
_fixedSpec.Cut(0, 8); fixedSpec.Cut(0, 8);
else if (StringBeginsWith(_fixedSpec, NS_LITERAL_STRING("ftp://"))) else if (StringBeginsWith(fixedSpec, NS_LITERAL_STRING("ftp://")))
_fixedSpec.Cut(0, 6); fixedSpec.Cut(0, 6);
return fixedSpec;
} }
/* static */ /* static */
@ -214,15 +214,10 @@ namespace places {
#define HAS_BEHAVIOR(aBitName) \ #define HAS_BEHAVIOR(aBitName) \
(searchBehavior & mozIPlacesAutoComplete::BEHAVIOR_##aBitName) (searchBehavior & mozIPlacesAutoComplete::BEHAVIOR_##aBitName)
// Temporaries used to get the strings. nsDependentString searchString;
const PRUnichar *wStr; (void)aArguments->GetString(kArgSearchString, searchString);
const char *str; nsDependentCString url;
PRUint32 len; (void)aArguments->GetUTF8String(kArgIndexURL, url);
(void)aArguments->GetSharedString(kArgSearchString, &len, &wStr);
nsDependentString searchString(wStr, len / sizeof(PRUnichar));
(void)aArguments->GetSharedUTF8String(kArgIndexURL, &len, &str);
nsDependentCString url(str, len);
// We only want to filter javascript: URLs if we are not supposed to search // We only want to filter javascript: URLs if we are not supposed to search
// for them, and the search does not start with "javascript:". // for them, and the search does not start with "javascript:".
@ -237,8 +232,8 @@ namespace places {
PRInt32 visitCount = aArguments->AsInt32(kArgIndexVisitCount); PRInt32 visitCount = aArguments->AsInt32(kArgIndexVisitCount);
bool typed = aArguments->AsInt32(kArgIndexTyped) ? true : false; bool typed = aArguments->AsInt32(kArgIndexTyped) ? true : false;
bool bookmark = aArguments->AsInt32(kArgIndexBookmark) ? true : false; bool bookmark = aArguments->AsInt32(kArgIndexBookmark) ? true : false;
(void)aArguments->GetSharedString(kArgIndexTags, &len, &wStr); nsDependentString tags;
nsDependentString tags(wStr, len / sizeof(PRUnichar)); (void)aArguments->GetString(kArgIndexTags, tags);
// Make sure we match all the filter requirements. If a given restriction // Make sure we match all the filter requirements. If a given restriction
// is active, make sure the corresponding condition is not true. // is active, make sure the corresponding condition is not true.
@ -255,15 +250,14 @@ namespace places {
} }
// Clean up our URI spec and prepare it for searching. // Clean up our URI spec and prepare it for searching.
nsString fixedURI; nsString fixedURI = fixupURISpec(url);
fixupURISpec(url, fixedURI);
// Obtain our search function. // Obtain our search function.
PRInt32 matchBehavior = aArguments->AsInt32(kArgIndexMatchBehavior); PRInt32 matchBehavior = aArguments->AsInt32(kArgIndexMatchBehavior);
searchFunctionPtr searchFunction = getSearchFunction(matchBehavior); searchFunctionPtr searchFunction = getSearchFunction(matchBehavior);
(void)aArguments->GetSharedString(kArgIndexTitle, &len, &wStr); nsDependentString title;
nsDependentString title(wStr, len / sizeof(PRUnichar)); (void)aArguments->GetString(kArgIndexTitle, title);
// Determine if every token matches either the bookmark title, tags, page // Determine if every token matches either the bookmark title, tags, page
// title, or page URL. // title, or page URL.

View File

@ -197,11 +197,9 @@ private:
* *
* @param aURISpec * @param aURISpec
* The spec of the URI to prepare for searching. * The spec of the URI to prepare for searching.
* @param _fixedSpec * @return the new string to use for the URI spec.
* An out parameter that is the fixed up string.
*/ */
static void fixupURISpec(const nsDependentCString &aURISpec, static nsString fixupURISpec(const nsDependentCString &aURISpec);
nsString &_fixedSpec);
}; };
} // namespace places } // namespace places