mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
bug 258223 : bookmark keyword quicksearch need a way to specify character encoding : r=vlad, sr=neil, a=asa
This commit is contained in:
parent
fdbc87a6d5
commit
2ee8613602
@ -1588,10 +1588,31 @@ function getShortcutOrURI(url)
|
||||
shortcutURL = gBookmarksService.resolveKeyword(cmd);
|
||||
// Bug 123006 : %s replace and URI escape, %S replace with raw value
|
||||
if (shortcutURL && text) {
|
||||
shortcutURL = /%[sS]/.test(shortcutURL) ?
|
||||
shortcutURL.replace(/%s/g, encodeURIComponent(text))
|
||||
.replace(/%S/g, text) :
|
||||
null;
|
||||
var encodedText = null;
|
||||
var charset = "";
|
||||
const re = /^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/;
|
||||
var matches = shortcutURL.match(re);
|
||||
if (matches) {
|
||||
shortcutURL = matches[1];
|
||||
charset = matches[2];
|
||||
}
|
||||
else if (/%s/.test(shortcutURL)) {
|
||||
try {
|
||||
charset = BMSVC.getLastCharset(shortcutURL);
|
||||
} catch (ex) {
|
||||
}
|
||||
}
|
||||
|
||||
if (charset)
|
||||
encodedText = escape(convertFromUnicode(charset, text));
|
||||
else // default case: charset=UTF-8
|
||||
encodedText = encodeURIComponent(text);
|
||||
|
||||
if (encodedText && /%[sS]/.test(shortcutURL))
|
||||
shortcutURL = shortcutURL.replace(/%s/g, encodedText)
|
||||
.replace(/%S/g, text);
|
||||
else
|
||||
shortcutURL = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2656,3 +2677,17 @@ function updateSavePageItems()
|
||||
var autoDownload = pref.getBoolPref("browser.download.autoDownload");
|
||||
goSetMenuValue("savepage", autoDownload ? "valueSave" : "valueSaveAs");
|
||||
}
|
||||
|
||||
function convertFromUnicode(charset, str)
|
||||
{
|
||||
try {
|
||||
var unicodeConverter = Components
|
||||
.classes["@mozilla.org/intl/scriptableunicodeconverter"]
|
||||
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
|
||||
unicodeConverter.charset = charset;
|
||||
str = unicodeConverter.ConvertFromUnicode(str);
|
||||
return str + unicodeConverter.Finish();
|
||||
} catch(ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,8 @@ interface nsIBookmarksService : nsISupports
|
||||
|
||||
void updateLastVisitedDate(in string aURL, in wstring docCharset);
|
||||
|
||||
AString getLastCharset(in AUTF8String aURL);
|
||||
|
||||
string resolveKeyword(in wstring aName);
|
||||
|
||||
void importSystemBookmarks(in nsIRDFResource aParentFolder);
|
||||
|
@ -3666,6 +3666,45 @@ nsBookmarksService::UpdateBookmarkLastModifiedDate(nsIRDFResource *aSource)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBookmarksService::GetLastCharset(const nsACString &aURL, nsAString &aCharset)
|
||||
{
|
||||
aCharset.Truncate();
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> urlLiteral;
|
||||
nsresult rv = gRDF->GetLiteral(NS_ConvertUTF8toUCS2(aURL).get(),
|
||||
getter_AddRefs(urlLiteral));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> bookmark;
|
||||
rv = GetSource(kNC_URL, urlLiteral, PR_TRUE, getter_AddRefs(bookmark));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> nodeType;
|
||||
GetSynthesizedType(bookmark, getter_AddRefs(nodeType));
|
||||
if (nodeType == kNC_Bookmark) {
|
||||
nsCOMPtr<nsIRDFNode> charsetNode;
|
||||
rv = GetTarget(bookmark, kWEB_LastCharset, PR_TRUE,
|
||||
getter_AddRefs(charsetNode));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (charsetNode) {
|
||||
nsCOMPtr<nsIRDFLiteral> charsetData(do_QueryInterface(charsetNode));
|
||||
if (charsetData) {
|
||||
const PRUnichar *charset;
|
||||
charsetData->GetValueConst(&charset);
|
||||
aCharset.Assign(charset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBookmarksService::ResolveKeyword(const PRUnichar *aUserInput, char **aShortcutURL)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user