bug 316184: wrap and crop long URLs in the External Protocol Request dialog so they don't cause the dialog to render its buttons offscreen

r=bzbarsky
sr=bzbarsky
This commit is contained in:
myk%mozilla.org 2006-09-11 13:29:15 +00:00
Родитель f5001af100
Коммит a49123478d
3 изменённых файлов: 42 добавлений и 2 удалений

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

@ -53,7 +53,7 @@ proxyResolveFailure=Firefox is configured to use a proxy server that can't be fo
proxyConnectFailure=Firefox is configured to use a proxy server that is refusing connections.
contentEncodingError=The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression. Please contact the website owners to inform them of this problem.
externalProtocolTitle=External Protocol Request
externalProtocolPrompt=An external application must be launched to handle %1$S: links. Requested link:\n\n\n%2$S\nApplication: %3$S\n\n\nIf you were not expecting this request it may be an attempt to exploit a weakness in that other program. Cancel this request unless you are sure it is not malicious.\n
externalProtocolPrompt=An external application must be launched to handle %1$S: links.\n\n\nRequested link:\n\n%2$S\n\nApplication: %3$S\n\n\nIf you were not expecting this request it may be an attempt to exploit a weakness in that other program. Cancel this request unless you are sure it is not malicious.\n
#LOCALIZATION NOTE (externalProtocolUnknown): The following string is shown if the application name can't be determined
externalProtocolUnknown=<Unknown>
externalProtocolChkMsg=Remember my choice for all links of this type.

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

@ -53,7 +53,7 @@ proxyResolveFailure=The proxy server you have configured could not be found. Ple
proxyConnectFailure=The connection was refused when attempting to contact the proxy server you have configured. Please check your proxy settings and try again.
contentEncodingError=The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression. Please contact the website owners to inform them of this problem.
externalProtocolTitle=External Protocol Request
externalProtocolPrompt=An external application must be launched to handle %1$S: links. Requested link:\n\n\n%2$S\nApplication: %3$S\n\n\nIf you were not expecting this request it may be an attempt to exploit a weakness in that other program. Cancel this request unless you are sure it is not malicious.\n
externalProtocolPrompt=An external application must be launched to handle %1$S: links.\n\n\nRequested link:\n\n%2$S\n\nApplication: %3$S\n\n\nIf you were not expecting this request it may be an attempt to exploit a weakness in that other program. Cancel this request unless you are sure it is not malicious.\n
#LOCALIZATION NOTE (externalProtocolUnknown): The following string is shown if the application name can't be determined
externalProtocolUnknown=<Unknown>
externalProtocolChkMsg=Remember my choice for all links of this type.

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

@ -1229,6 +1229,46 @@ PRBool nsExternalHelperAppService::promptForScheme(nsIURI* aURI,
aURI->GetSpec(spec);
NS_ConvertUTF8toUTF16 uri(spec);
// The maximum amount of space the URI should take up in the dialog.
const PRUint32 maxWidth = 75;
const PRUint32 maxLines = 12; // (not counting ellipsis line)
const PRUint32 maxLength = maxWidth * maxLines;
// If the URI seems too long, insert zero-width spaces to make it wrappable
// and crop it in the middle (replacing the cropped portion with an ellipsis),
// so the dialog doesn't grow so wide or tall it renders buttons off-screen.
if (uri.Length() > maxWidth) {
PRUint32 charIdx = maxWidth;
PRUint32 lineIdx = 1;
PRInt32 numCharsToCrop = uri.Length() - maxLength;
while (charIdx < uri.Length()) {
// Don't insert characters in the middle of a surrogate pair.
if (IS_LOW_SURROGATE(uri[charIdx]))
--charIdx;
if (numCharsToCrop > 0 && lineIdx == maxLines / 2) {
NS_NAMED_LITERAL_STRING(ellipsis, "\n...\n");
// Don't end the crop in the middle of a surrogate pair.
if (IS_HIGH_SURROGATE(uri[charIdx + numCharsToCrop - 1]))
++numCharsToCrop;
uri.Replace(charIdx, numCharsToCrop, ellipsis);
charIdx += ellipsis.Length();
}
else {
// 0x200B is the zero-width breakable space character.
uri.Insert(PRUnichar(0x200B), charIdx);
charIdx += 1;
}
charIdx += maxWidth;
++lineIdx;
}
}
nsCAutoString asciischeme;
aURI->GetScheme(asciischeme);
NS_ConvertUTF8toUTF16 scheme(asciischeme);