mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-18 00:19:56 +00:00
Add a method on the fixup object to strip off wyciwyg from nsIURIs
Fixes bug 164006, wyciwyg: should not appear in tab title r=jag sr=bzbarsky
This commit is contained in:
parent
b394f6d78c
commit
a5cd43f732
@ -46,6 +46,52 @@ nsDefaultURIFixup::~nsDefaultURIFixup()
|
|||||||
/* destructor code */
|
/* destructor code */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* nsIURI createExposableURI (in nsIRUI aURI); */
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDefaultURIFixup::CreateExposableURI(nsIURI *aURI, nsIURI **aReturn)
|
||||||
|
{
|
||||||
|
NS_ENSURE_ARG_POINTER(aURI);
|
||||||
|
NS_ENSURE_ARG_POINTER(aReturn);
|
||||||
|
|
||||||
|
PRBool isWyciwyg = PR_FALSE;
|
||||||
|
aURI->SchemeIs("wyciwyg", &isWyciwyg);
|
||||||
|
|
||||||
|
if (!isWyciwyg)
|
||||||
|
{
|
||||||
|
*aReturn = aURI;
|
||||||
|
NS_ADDREF(*aReturn);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCAutoString path;
|
||||||
|
nsresult rv = aURI->GetPath(path);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
PRUint32 pathLength = path.Length();
|
||||||
|
if (pathLength <= 2)
|
||||||
|
{
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Path is of the form "//123/http://foo/bar", with a variable number of digits.
|
||||||
|
// To figure out where the "real" URL starts, search path for a '/', starting at
|
||||||
|
// the third character.
|
||||||
|
PRInt32 slashIndex = path.FindChar('/', 2);
|
||||||
|
if (slashIndex == kNotFound)
|
||||||
|
{
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the charset of the original URI so we can pass it to our fixed up URI.
|
||||||
|
nsCAutoString charset;
|
||||||
|
aURI->GetOriginCharset(charset);
|
||||||
|
|
||||||
|
rv = NS_NewURI(aReturn,
|
||||||
|
Substring(path, slashIndex + 1, pathLength - slashIndex - 1),
|
||||||
|
charset.get());
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* nsIURI createFixupURI (in wstring aURIText, in unsigned long aFixupFlags); */
|
/* nsIURI createFixupURI (in wstring aURIText, in unsigned long aFixupFlags); */
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
@ -69,6 +115,8 @@ nsDefaultURIFixup::CreateFixupURI(const nsAString& aStringURI, PRUint32 aFixupFl
|
|||||||
// Eliminate embedded newlines, which single-line text fields now allow:
|
// Eliminate embedded newlines, which single-line text fields now allow:
|
||||||
uriString.StripChars("\r\n");
|
uriString.StripChars("\r\n");
|
||||||
|
|
||||||
|
NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE);
|
||||||
|
|
||||||
// View-source is a pseudo scheme. We're interested in fixing up the stuff
|
// View-source is a pseudo scheme. We're interested in fixing up the stuff
|
||||||
// after it. The easiest way to do that is to call this method again with the
|
// after it. The easiest way to do that is to call this method again with the
|
||||||
// "view-source:" lopped off and then prepend it again afterwards.
|
// "view-source:" lopped off and then prepend it again afterwards.
|
||||||
|
@ -2344,8 +2344,28 @@ nsDocShell::LoadURI(const PRUnichar * aURI,
|
|||||||
nsIInputStream * aHeaderStream)
|
nsIInputStream * aHeaderStream)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
|
nsresult rv;
|
||||||
|
// Create the fixup object if necessary
|
||||||
|
if (!mURIFixup) {
|
||||||
|
mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID);
|
||||||
|
if (!mURIFixup) {
|
||||||
|
// No fixup service so try and create a URI and see what happens
|
||||||
|
nsAutoString uriString(aURI);
|
||||||
|
// Cleanup the empty spaces that might be on each end.
|
||||||
|
uriString.Trim(" ");
|
||||||
|
// Eliminate embedded newlines, which single-line text fields now allow:
|
||||||
|
uriString.StripChars("\r\n");
|
||||||
|
NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE);
|
||||||
|
|
||||||
nsresult rv = CreateFixupURI(nsDependentString(aURI), getter_AddRefs(uri));
|
rv = NS_NewURI(getter_AddRefs(uri), uriString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mURIFixup) {
|
||||||
|
// Call the fixup object
|
||||||
|
rv = mURIFixup->CreateFixupURI(nsDependentString(aURI),
|
||||||
|
nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP,
|
||||||
|
getter_AddRefs(uri));
|
||||||
|
}
|
||||||
|
|
||||||
if (NS_ERROR_UNKNOWN_PROTOCOL == rv ||
|
if (NS_ERROR_UNKNOWN_PROTOCOL == rv ||
|
||||||
NS_ERROR_MALFORMED_URI == rv) {
|
NS_ERROR_MALFORMED_URI == rv) {
|
||||||
@ -4914,32 +4934,6 @@ nsDocShell::InternalLoad(nsIURI * aURI,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsDocShell::CreateFixupURI(const nsAString& aStringURI, nsIURI ** aURI)
|
|
||||||
{
|
|
||||||
*aURI = nsnull;
|
|
||||||
nsAutoString uriString(aStringURI);
|
|
||||||
uriString.Trim(" "); // Cleanup the empty spaces that might be on each end.
|
|
||||||
|
|
||||||
// Eliminate embedded newlines, which single-line text fields now allow:
|
|
||||||
uriString.StripChars("\r\n");
|
|
||||||
|
|
||||||
NS_ENSURE_TRUE(uriString.Length() > 0, NS_ERROR_FAILURE);
|
|
||||||
|
|
||||||
// Create the fixup object if necessary
|
|
||||||
if (!mURIFixup) {
|
|
||||||
mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID);
|
|
||||||
if (!mURIFixup) {
|
|
||||||
// No fixup service so try and create a URI and see what happens
|
|
||||||
return NS_NewURI(aURI, uriString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the fixup object
|
|
||||||
return mURIFixup->CreateFixupURI(aStringURI,
|
|
||||||
nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP, aURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsDocShell::GetCurrentDocumentOwner(nsISupports ** aOwner)
|
nsDocShell::GetCurrentDocumentOwner(nsISupports ** aOwner)
|
||||||
{
|
{
|
||||||
|
@ -200,7 +200,6 @@ protected:
|
|||||||
NS_IMETHOD SetupNewViewer(nsIContentViewer * aNewViewer);
|
NS_IMETHOD SetupNewViewer(nsIContentViewer * aNewViewer);
|
||||||
|
|
||||||
NS_IMETHOD GetEldestPresContext(nsIPresContext** aPresContext);
|
NS_IMETHOD GetEldestPresContext(nsIPresContext** aPresContext);
|
||||||
NS_IMETHOD CreateFixupURI(const nsAString& aStringURI, nsIURI ** aURI);
|
|
||||||
NS_IMETHOD GetCurrentDocumentOwner(nsISupports ** aOwner);
|
NS_IMETHOD GetCurrentDocumentOwner(nsISupports ** aOwner);
|
||||||
virtual nsresult DoURILoad(nsIURI * aURI,
|
virtual nsresult DoURILoad(nsIURI * aURI,
|
||||||
nsIURI * aReferrer,
|
nsIURI * aReferrer,
|
||||||
|
@ -46,6 +46,18 @@ interface nsIURIFixup : nsISupports
|
|||||||
*/
|
*/
|
||||||
const unsigned long FIXUP_FLAGS_MAKE_ALTERNATE_URI = 2;
|
const unsigned long FIXUP_FLAGS_MAKE_ALTERNATE_URI = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an internal URI (e.g. a wyciwyg URI) into one which we can
|
||||||
|
* expose to the user, for example on the URL bar.
|
||||||
|
*
|
||||||
|
* @param aURI The URI to be converted
|
||||||
|
* @return nsIURI The converted, exposable URI
|
||||||
|
* @throws NS_ERROR_MALFORMED_URI when the exposable portion of aURI is malformed
|
||||||
|
* @throws NS_ERROR_UNKNOWN_PROTOCOL when we can't get a protocol handler service
|
||||||
|
* for the URI scheme.
|
||||||
|
*/
|
||||||
|
nsIURI createExposableURI(in nsIURI aURI);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the specified string into a URI, first attempting
|
* Converts the specified string into a URI, first attempting
|
||||||
* to correct any errors in the syntax or other vagaries. Returns
|
* to correct any errors in the syntax or other vagaries. Returns
|
||||||
|
@ -2485,12 +2485,16 @@ nsHttpChannel::SetReferrer(nsIURI *referrerIn, PRUint32 referrerType)
|
|||||||
// To figure out where the "real" URL starts, search path for a '/', starting at
|
// To figure out where the "real" URL starts, search path for a '/', starting at
|
||||||
// the third character.
|
// the third character.
|
||||||
PRInt32 slashIndex = path.FindChar('/', 2);
|
PRInt32 slashIndex = path.FindChar('/', 2);
|
||||||
if (slashIndex < 0) return NS_ERROR_FAILURE;
|
if (slashIndex == kNotFound) return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
// Get the charset of the original URI so we can pass it to our fixed up URI.
|
||||||
|
nsCAutoString charset;
|
||||||
|
referrer->GetOriginCharset(charset);
|
||||||
|
|
||||||
// Replace |referrer| with a URI without wyciwyg://123/.
|
// Replace |referrer| with a URI without wyciwyg://123/.
|
||||||
nsCAutoString newReferrer;
|
rv = NS_NewURI(getter_AddRefs(referrer),
|
||||||
path.Right(newReferrer, pathLength - slashIndex - 1);
|
Substring(path, slashIndex + 1, pathLength - slashIndex - 1),
|
||||||
rv = NS_NewURI(getter_AddRefs(referrer), newReferrer.get());
|
charset.get());
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ var gHaveUpdatedToolbarState = false;
|
|||||||
var gClickSelectsAll = false;
|
var gClickSelectsAll = false;
|
||||||
var gIgnoreFocus = false;
|
var gIgnoreFocus = false;
|
||||||
var gIgnoreClick = false;
|
var gIgnoreClick = false;
|
||||||
|
var gURIFixup = null;
|
||||||
|
|
||||||
var pref = null;
|
var pref = null;
|
||||||
|
|
||||||
@ -1163,12 +1164,19 @@ function BrowserLoadURL(aTriggeringEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (saveModifier) {
|
else if (saveModifier) {
|
||||||
// Firstly, fixup the url so that (e.g.) "www.foo.com" works
|
try {
|
||||||
const nsIURIFixup = Components.interfaces.nsIURIFixup;
|
// Firstly, fixup the url so that (e.g.) "www.foo.com" works
|
||||||
var uriFixup = Components.classes["@mozilla.org/docshell/urifixup;1"].getService(nsIURIFixup);
|
if (!gURIFixup)
|
||||||
url = uriFixup.createFixupURI(url, nsIURIFixup.FIXUP_FLAGS_MAKE_ALTERNATE_URI).spec;
|
gURIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
|
||||||
// Open filepicker to save the url
|
.getService(Components.interfaces.nsIURIFixup);
|
||||||
saveURL(url, "");
|
url = gURIFixup.createFixupURI(url, nsIURIFixup.FIXUP_FLAGS_MAKE_ALTERNATE_URI).spec;
|
||||||
|
// Open filepicker to save the url
|
||||||
|
saveURL(url, "");
|
||||||
|
}
|
||||||
|
catch(ex) {
|
||||||
|
// XXX Do nothing for now.
|
||||||
|
// Do we want to put up an alert in the future? Mmm, l10n...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// No modifier was pressed, load the URL normally and
|
// No modifier was pressed, load the URL normally and
|
||||||
|
@ -311,7 +311,22 @@ nsBrowserStatusHandler.prototype =
|
|||||||
{
|
{
|
||||||
this.setOverLink("", null);
|
this.setOverLink("", null);
|
||||||
|
|
||||||
var location = aLocation.spec;
|
var location = "";
|
||||||
|
|
||||||
|
if (aLocation) {
|
||||||
|
try {
|
||||||
|
if (!gURIFixup)
|
||||||
|
gURIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
|
||||||
|
.getService(Components.interfaces.nsIURIFixup);
|
||||||
|
// If the url has "wyciwyg://" as the protocol, strip it off.
|
||||||
|
// Nobody wants to see it on the urlbar for dynamically generated
|
||||||
|
// pages.
|
||||||
|
location = gURIFixup.createExposableURI(aLocation).spec;
|
||||||
|
}
|
||||||
|
catch(ex) {
|
||||||
|
location = aLocation.spec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.hideAboutBlank) {
|
if (this.hideAboutBlank) {
|
||||||
this.hideAboutBlank = false;
|
this.hideAboutBlank = false;
|
||||||
@ -332,11 +347,6 @@ nsBrowserStatusHandler.prototype =
|
|||||||
|
|
||||||
if (aWebProgress.DOMWindow == content) {
|
if (aWebProgress.DOMWindow == content) {
|
||||||
if (!this.userTyped.value) {
|
if (!this.userTyped.value) {
|
||||||
// If the url has "wyciwyg://" as the protocol, strip it off.
|
|
||||||
// Nobody wants to see it on the urlbar for dynamically generated
|
|
||||||
// pages.
|
|
||||||
if (/^\s*wyciwyg:\/\/\d+\//.test(location))
|
|
||||||
location = RegExp.rightContext;
|
|
||||||
this.urlBar.value = location;
|
this.urlBar.value = location;
|
||||||
// the above causes userTyped.value to become true, reset it
|
// the above causes userTyped.value to become true, reset it
|
||||||
this.userTyped.value = false;
|
this.userTyped.value = false;
|
||||||
|
@ -228,6 +228,10 @@
|
|||||||
onget="return this.webNavigation.document;"
|
onget="return this.webNavigation.document;"
|
||||||
readonly="true"/>
|
readonly="true"/>
|
||||||
|
|
||||||
|
<property name="contentTitle"
|
||||||
|
onget="return Components.lookupMethod(this.contentDocument, 'title').call(this.contentDocument);"
|
||||||
|
readonly="true"/>
|
||||||
|
|
||||||
<field name="mPrefs" readonly="true">
|
<field name="mPrefs" readonly="true">
|
||||||
Components.classes['@mozilla.org/preferences-service;1']
|
Components.classes['@mozilla.org/preferences-service;1']
|
||||||
.getService(Components.interfaces.nsIPrefService)
|
.getService(Components.interfaces.nsIPrefService)
|
||||||
|
@ -109,6 +109,10 @@
|
|||||||
.getService(Components.interfaces.nsIPrefService)
|
.getService(Components.interfaces.nsIPrefService)
|
||||||
.getBranch(null);
|
.getBranch(null);
|
||||||
</field>
|
</field>
|
||||||
|
<field name="mURIFixup" readonly="true">
|
||||||
|
Components.classes["@mozilla.org/docshell/urifixup;1"]
|
||||||
|
.getService(Components.interfaces.nsIURIFixup);
|
||||||
|
</field>
|
||||||
<field name="mTabBox">
|
<field name="mTabBox">
|
||||||
document.getAnonymousNodes(this)[1]
|
document.getAnonymousNodes(this)[1]
|
||||||
</field>
|
</field>
|
||||||
@ -351,7 +355,7 @@
|
|||||||
var newTitle = "";
|
var newTitle = "";
|
||||||
var docTitle;
|
var docTitle;
|
||||||
if (this.docShell.contentViewer)
|
if (this.docShell.contentViewer)
|
||||||
docTitle = this.contentDocument.title;
|
docTitle = this.contentTitle;
|
||||||
|
|
||||||
if (docTitle) {
|
if (docTitle) {
|
||||||
newTitle += this.ownerDocument.documentElement.getAttribute("titlepreface");
|
newTitle += this.ownerDocument.documentElement.getAttribute("titlepreface");
|
||||||
@ -390,9 +394,6 @@
|
|||||||
|
|
||||||
// Update the URL bar.
|
// Update the URL bar.
|
||||||
var loc = this.mCurrentBrowser.currentURI;
|
var loc = this.mCurrentBrowser.currentURI;
|
||||||
if (!loc)
|
|
||||||
loc = ({ spec: "" });
|
|
||||||
|
|
||||||
var webProgress = this.mCurrentBrowser.webProgress;
|
var webProgress = this.mCurrentBrowser.webProgress;
|
||||||
var securityUI = this.mCurrentBrowser.securityUI;
|
var securityUI = this.mCurrentBrowser.securityUI;
|
||||||
var i, p;
|
var i, p;
|
||||||
@ -545,18 +546,24 @@
|
|||||||
<body>
|
<body>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
var browser = this.getBrowserForTab(aTab);
|
var browser = this.getBrowserForTab(aTab);
|
||||||
|
var title = browser.contentTitle;
|
||||||
var crop = "end";
|
var crop = "end";
|
||||||
var titleViaGetter = browser.contentDocument.__proto__.__lookupGetter__('title').call(browser.contentDocument);
|
|
||||||
var title;
|
|
||||||
|
|
||||||
if (titleViaGetter)
|
if (!title) {
|
||||||
title = titleViaGetter
|
if (browser.currentURI.spec) {
|
||||||
else if (browser.currentURI.spec && browser.currentURI.spec != "about:blank") {
|
try {
|
||||||
title = browser.currentURI.spec;
|
title = this.mURIFixup.createExposableURI(browser.currentURI).spec;
|
||||||
crop = "center";
|
}
|
||||||
|
catch(ex) {
|
||||||
|
title = browser.currentURI.spec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (title && title != "about:blank")
|
||||||
|
crop = "center";
|
||||||
|
else // Still no title? Fall back to our untitled string.
|
||||||
|
title = this.mStringBundle.getString("tabs.untitled");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
title = this.mStringBundle.getString("tabs.untitled");
|
|
||||||
|
|
||||||
aTab.label = title;
|
aTab.label = title;
|
||||||
aTab.setAttribute("crop", crop);
|
aTab.setAttribute("crop", crop);
|
||||||
@ -1131,6 +1138,10 @@
|
|||||||
onget="return this.mCurrentBrowser.contentDocument;"
|
onget="return this.mCurrentBrowser.contentDocument;"
|
||||||
readonly="true"/>
|
readonly="true"/>
|
||||||
|
|
||||||
|
<property name="contentTitle"
|
||||||
|
onget="return this.mCurrentBrowser.contentTitle;"
|
||||||
|
readonly="true"/>
|
||||||
|
|
||||||
<property name="securityUI"
|
<property name="securityUI"
|
||||||
onget="return this.mCurrentBrowser.securityUI;"
|
onget="return this.mCurrentBrowser.securityUI;"
|
||||||
readonly="true"/>
|
readonly="true"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user