зеркало из https://github.com/mozilla/pjs.git
Moved URI fixup code out of docshell and into a global service. b=51702, sr=waterson@netscape.com
This commit is contained in:
Родитель
1691baff22
Коммит
b9bf2ff444
|
@ -21,6 +21,7 @@
|
|||
#
|
||||
|
||||
nsCDocShell.idl
|
||||
nsCDefaultURIFixup.idl
|
||||
nsIDocShell.idl
|
||||
nsIDocShellLoadInfo.idl
|
||||
nsIDocShellTreeItem.idl
|
||||
|
@ -29,4 +30,5 @@ nsIDocShellTreeOwner.idl
|
|||
nsIMarkupDocumentViewer.idl
|
||||
nsIScrollable.idl
|
||||
nsITextScroll.idl
|
||||
nsIContentViewerEdit.idl
|
||||
nsIContentViewerEdit.idl
|
||||
nsIURIFixup.idl
|
||||
|
|
|
@ -30,6 +30,7 @@ include $(DEPTH)/config/autoconf.mk
|
|||
|
||||
XPIDLSRCS = \
|
||||
nsCDocShell.idl \
|
||||
nsCDefaultURIFixup.idl \
|
||||
nsIDocShell.idl \
|
||||
nsIDocShellLoadInfo.idl \
|
||||
nsIDocShellTreeItem.idl \
|
||||
|
@ -41,6 +42,7 @@ XPIDLSRCS = \
|
|||
nsITextScroll.idl \
|
||||
nsIWebNavigation.idl \
|
||||
nsIContentViewerEdit.idl \
|
||||
nsIURIFixup.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
@ -48,6 +50,7 @@ CPPSRCS = \
|
|||
nsWebShell.cpp \
|
||||
nsDocShellLoadInfo.cpp \
|
||||
nsDSURIContentListener.cpp \
|
||||
nsDefaultURIFixup.cpp \
|
||||
# nsDSWebProgressListener.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ LIBRARY_NAME=basedocshell_s
|
|||
|
||||
XPIDLSRCS= \
|
||||
.\nsCDocShell.idl \
|
||||
.\nsCDefaultURIFixup.idl \
|
||||
.\nsIDocShell.idl \
|
||||
.\nsIDocShellHistory.idl \
|
||||
.\nsIDocShellLoadInfo.idl \
|
||||
|
@ -38,6 +39,7 @@ XPIDLSRCS= \
|
|||
.\nsIScrollable.idl \
|
||||
.\nsITextScroll.idl \
|
||||
.\nsIWebNavigation.idl \
|
||||
.\nsIURIFixup.idl \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
|
@ -45,6 +47,7 @@ CPP_OBJS= \
|
|||
.\$(OBJDIR)\nsWebShell.obj \
|
||||
.\$(OBJDIR)\nsDocShellLoadInfo.obj \
|
||||
.\$(OBJDIR)\nsDSURIContentListener.obj \
|
||||
.\$(OBJDIR)\nsDefaultURIFixup.obj \
|
||||
# .\$(OBJDIR)\nsDSWebProgressListener.obj \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Adam Lock <adamlock@netscape.com>
|
||||
*/
|
||||
|
||||
%{ C++
|
||||
// {214C48A0-B57F-11d4-959C-0020183BF181}
|
||||
#define NS_DEFAULTURIFIXUP_CID \
|
||||
{ 0x214c48a0, 0xb57f, 0x11d4, { 0x95, 0x9c, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } }
|
||||
#define NS_URIFIXUP_CONTRACTID \
|
||||
"@mozilla.org/docshell/urifixup;1"
|
||||
%}
|
|
@ -0,0 +1,274 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Adam Lock <adamlock@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
|
||||
#include "nsIURIFixup.h"
|
||||
#include "nsDefaultURIFixup.h"
|
||||
|
||||
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
|
||||
/* Implementation file */
|
||||
NS_IMPL_ISUPPORTS1(nsDefaultURIFixup, nsIURIFixup)
|
||||
|
||||
nsDefaultURIFixup::nsDefaultURIFixup()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
/* member initializers and constructor code */
|
||||
}
|
||||
|
||||
|
||||
nsDefaultURIFixup::~nsDefaultURIFixup()
|
||||
{
|
||||
/* destructor code */
|
||||
}
|
||||
|
||||
|
||||
/* nsIURI createFixupURI (in string aURIText); */
|
||||
NS_IMETHODIMP nsDefaultURIFixup::CreateFixupURI(const PRUnichar *aStringURI, nsIURI **aURI)
|
||||
{
|
||||
*aURI = nsnull;
|
||||
|
||||
// Try and get the prefs service
|
||||
if (!mPrefs)
|
||||
{
|
||||
mPrefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
// Just try to create an URL out of it
|
||||
NS_NewURI(aURI, uriString, nsnull);
|
||||
if(*aURI)
|
||||
return NS_OK;
|
||||
|
||||
// Check for if it is a file URL
|
||||
FileURIFixup(uriString.GetUnicode(), aURI);
|
||||
if(*aURI)
|
||||
return NS_OK;
|
||||
|
||||
// See if it is a keyword
|
||||
// Test whether keywords need to be fixed up
|
||||
PRBool fixupKeywords = PR_FALSE;
|
||||
if (mPrefs)
|
||||
{
|
||||
NS_ENSURE_SUCCESS(mPrefs->GetBoolPref("keyword.enabled", &fixupKeywords), NS_ERROR_FAILURE);
|
||||
}
|
||||
if (fixupKeywords)
|
||||
{
|
||||
KeywordURIFixup(uriString.GetUnicode(), aURI);
|
||||
if(*aURI)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// See if a protocol needs to be added
|
||||
PRInt32 checkprotocol = uriString.Find("://",0);
|
||||
// if no scheme (protocol) is found, assume http or ftp.
|
||||
if (checkprotocol == -1) {
|
||||
// find host name
|
||||
PRInt32 hostPos = uriString.FindCharInSet("./:");
|
||||
if (hostPos == -1)
|
||||
hostPos = uriString.Length();
|
||||
|
||||
// extract host name
|
||||
nsAutoString hostSpec;
|
||||
uriString.Left(hostSpec, hostPos);
|
||||
|
||||
// insert url spec corresponding to host name
|
||||
if (hostSpec.EqualsIgnoreCase("ftp"))
|
||||
uriString.InsertWithConversion("ftp://", 0, 6);
|
||||
else
|
||||
uriString.InsertWithConversion("http://", 0, 7);
|
||||
} // end if checkprotocol
|
||||
|
||||
return NS_NewURI(aURI, uriString, nsnull);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsDefaultURIFixup::FileURIFixup(const PRUnichar* aStringURI,
|
||||
nsIURI** aURI)
|
||||
{
|
||||
nsAutoString uriSpecIn(aStringURI);
|
||||
nsAutoString uriSpecOut(aStringURI);
|
||||
|
||||
ConvertFileToStringURI(uriSpecIn, uriSpecOut);
|
||||
|
||||
if(0 == uriSpecOut.Find("file:", 0))
|
||||
{
|
||||
// if this is file url, we need to convert the URI
|
||||
// from Unicode to the FS charset
|
||||
nsCAutoString inFSCharset;
|
||||
NS_ENSURE_SUCCESS(ConvertStringURIToFileCharset(uriSpecOut, inFSCharset),
|
||||
NS_ERROR_FAILURE);
|
||||
|
||||
if(NS_SUCCEEDED(NS_NewURI(aURI, inFSCharset.GetBuffer(), nsnull)))
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
#define FILE_PROTOCOL "file://"
|
||||
|
||||
NS_IMETHODIMP nsDefaultURIFixup::ConvertFileToStringURI(nsString& aIn, nsString& aOut)
|
||||
{
|
||||
#ifdef XP_PC
|
||||
// Check for \ in the url-string or just a drive (PC)
|
||||
if(kNotFound != aIn.FindChar(PRUnichar('\\')) || ((aIn.Length() == 2 ) && (aIn.Last() == PRUnichar(':') || aIn.Last() == PRUnichar('|'))))
|
||||
{
|
||||
#elif XP_UNIX
|
||||
// Check if it starts with / or \ (UNIX)
|
||||
const PRUnichar * up = aIn.GetUnicode();
|
||||
if((PRUnichar('/') == *up) || (PRUnichar('\\') == *up))
|
||||
{
|
||||
#else
|
||||
if(0)
|
||||
{
|
||||
// Do nothing (All others for now)
|
||||
#endif
|
||||
|
||||
#ifdef XP_PC
|
||||
// Translate '\' to '/'
|
||||
aOut.ReplaceChar(PRUnichar('\\'), PRUnichar('/'));
|
||||
aOut.ReplaceChar(PRUnichar(':'), PRUnichar('|'));
|
||||
#endif
|
||||
|
||||
// Build the file URL
|
||||
aOut.InsertWithConversion(FILE_PROTOCOL,0);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsDefaultURIFixup::ConvertStringURIToFileCharset(nsString& aIn,
|
||||
nsCString& aOut)
|
||||
{
|
||||
aOut = "";
|
||||
// for file url, we need to convert the nsString to the file system
|
||||
// charset before we pass to NS_NewURI
|
||||
static nsAutoString fsCharset;
|
||||
// find out the file system charset first
|
||||
if(0 == fsCharset.Length())
|
||||
{
|
||||
fsCharset.AssignWithConversion("ISO-8859-1"); // set the fallback first.
|
||||
nsCOMPtr<nsIPlatformCharset> plat(do_GetService(kPlatformCharsetCID));
|
||||
NS_ENSURE_TRUE(plat, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(plat->GetCharset(kPlatformCharsetSel_FileName, fsCharset),
|
||||
NS_ERROR_FAILURE);
|
||||
}
|
||||
// We probably should cache ccm here.
|
||||
// get a charset converter from the manager
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm(do_GetService(kCharsetConverterManagerCID));
|
||||
NS_ENSURE_TRUE(ccm, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIUnicodeEncoder> fsEncoder;
|
||||
NS_ENSURE_SUCCESS(ccm->GetUnicodeEncoder(&fsCharset,
|
||||
getter_AddRefs(fsEncoder)), NS_ERROR_FAILURE);
|
||||
|
||||
PRInt32 bufLen = 0;
|
||||
NS_ENSURE_SUCCESS(fsEncoder->GetMaxLength(aIn.GetUnicode(), aIn.Length(),
|
||||
&bufLen), NS_ERROR_FAILURE);
|
||||
aOut.SetCapacity(bufLen+1);
|
||||
PRInt32 srclen = aIn.Length();
|
||||
NS_ENSURE_SUCCESS(fsEncoder->Convert(aIn.GetUnicode(), &srclen,
|
||||
(char*)aOut.GetBuffer(), &bufLen), NS_ERROR_FAILURE);
|
||||
|
||||
((char*)aOut.GetBuffer())[bufLen]='\0';
|
||||
aOut.SetLength(bufLen);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsDefaultURIFixup::KeywordURIFixup(const PRUnichar* aStringURI,
|
||||
nsIURI** aURI)
|
||||
{
|
||||
// These are keyword formatted strings
|
||||
// "what is mozilla"
|
||||
// "what is mozilla?"
|
||||
// "?mozilla"
|
||||
// "?What is mozilla"
|
||||
|
||||
// These are not keyword formatted strings
|
||||
// "www.blah.com" - anything with a dot in it
|
||||
// "nonQualifiedHost:80" - anything with a colon in it
|
||||
// "nonQualifiedHost?"
|
||||
// "nonQualifiedHost?args"
|
||||
// "nonQualifiedHost?some args"
|
||||
|
||||
nsAutoString uriString(aStringURI);
|
||||
if(uriString.FindChar('.') == -1 && uriString.FindChar(':') == -1)
|
||||
{
|
||||
PRInt32 qMarkLoc = uriString.FindChar('?');
|
||||
PRInt32 spaceLoc = uriString.FindChar(' ');
|
||||
|
||||
PRBool keyword = PR_FALSE;
|
||||
if(qMarkLoc == 0)
|
||||
keyword = PR_TRUE;
|
||||
else if((spaceLoc > 0) && ((qMarkLoc == -1) || (spaceLoc < qMarkLoc)))
|
||||
keyword = PR_TRUE;
|
||||
|
||||
if(keyword)
|
||||
{
|
||||
nsCAutoString keywordSpec("keyword:");
|
||||
char *utf8Spec = uriString.ToNewUTF8String();
|
||||
if(utf8Spec)
|
||||
{
|
||||
char* escapedUTF8Spec = nsEscape(utf8Spec, url_Path);
|
||||
if(escapedUTF8Spec)
|
||||
{
|
||||
keywordSpec.Append(escapedUTF8Spec);
|
||||
NS_NewURI(aURI, keywordSpec.GetBuffer(), nsnull);
|
||||
nsMemory::Free(escapedUTF8Spec);
|
||||
} // escapedUTF8Spec
|
||||
nsMemory::Free(utf8Spec);
|
||||
} // utf8Spec
|
||||
} // keyword
|
||||
} // FindChar
|
||||
|
||||
if(*aURI)
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
nsresult NS_NewURIFixup(nsIURIFixup **aURIFixup)
|
||||
{
|
||||
nsDefaultURIFixup *fixup = new nsDefaultURIFixup;
|
||||
if (fixup == nsnull)
|
||||
{
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return fixup->QueryInterface(NS_GET_IID(nsIURIFixup), (void **) aURIFixup);
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Adam Lock <adamlock@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef NSDEFAULTURIFIXUP_H
|
||||
#define NSDEFAULTURIFIXUP_H
|
||||
|
||||
#include "nsIPref.h"
|
||||
#include "nsIURIFixup.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsCDefaultURIFixup.h"
|
||||
|
||||
/* Header file */
|
||||
class nsDefaultURIFixup : public nsIURIFixup
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIURIFIXUP
|
||||
|
||||
nsDefaultURIFixup();
|
||||
|
||||
protected:
|
||||
virtual ~nsDefaultURIFixup();
|
||||
|
||||
private:
|
||||
/* additional members */
|
||||
NS_IMETHOD FileURIFixup(const PRUnichar* aStringURI, nsIURI** aURI);
|
||||
NS_IMETHOD ConvertFileToStringURI(nsString& aIn, nsString& aOut);
|
||||
NS_IMETHOD ConvertStringURIToFileCharset(nsString& aIn, nsCString& aOut);
|
||||
NS_IMETHOD KeywordURIFixup(const PRUnichar* aStringURI, nsIURI** aURI);
|
||||
|
||||
nsCOMPtr<nsIPref> mPrefs;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -50,6 +50,7 @@
|
|||
// Local Includes
|
||||
#include "nsDocShell.h"
|
||||
#include "nsDocShellLoadInfo.h"
|
||||
#include "nsCDefaultURIFixup.h"
|
||||
|
||||
// Helper Classes
|
||||
#include "nsDOMError.h"
|
||||
|
@ -57,14 +58,12 @@
|
|||
#include "nsHTTPEnums.h"
|
||||
|
||||
// Interfaces Needed
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIHTTPChannel.h"
|
||||
#include "nsIDataChannel.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsILayoutHistoryState.h"
|
||||
#include "nsILocaleService.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsIFileStream.h"
|
||||
|
||||
|
@ -84,8 +83,6 @@
|
|||
#include "nsIFocusController.h"
|
||||
|
||||
static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
|
||||
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
||||
static NS_DEFINE_CID(kDocumentCharsetInfoCID, NS_DOCUMENTCHARSETINFO_CID);
|
||||
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
|
||||
|
@ -3037,195 +3034,19 @@ NS_IMETHODIMP nsDocShell::CreateFixupURI(const PRUnichar* aStringURI,
|
|||
mViewMode = mLastViewMode;
|
||||
}
|
||||
|
||||
// Just try to create an URL out of it
|
||||
NS_NewURI(aURI, uriString, nsnull);
|
||||
if(*aURI)
|
||||
return NS_OK;
|
||||
|
||||
// Check for if it is a file URL
|
||||
FileURIFixup(uriString.GetUnicode(), aURI);
|
||||
if(*aURI)
|
||||
return NS_OK;
|
||||
|
||||
// See if it is a keyword
|
||||
KeywordURIFixup(uriString.GetUnicode(), aURI);
|
||||
if(*aURI)
|
||||
return NS_OK;
|
||||
|
||||
// See if a protocol needs to be added
|
||||
PRInt32 checkprotocol = uriString.Find("://",0);
|
||||
// if no scheme (protocol) is found, assume http or ftp.
|
||||
if (checkprotocol == -1) {
|
||||
// find host name
|
||||
PRInt32 hostPos = uriString.FindCharInSet("./:");
|
||||
if (hostPos == -1)
|
||||
hostPos = uriString.Length();
|
||||
|
||||
// extract host name
|
||||
nsAutoString hostSpec;
|
||||
uriString.Left(hostSpec, hostPos);
|
||||
|
||||
// insert url spec corresponding to host name
|
||||
if (hostSpec.EqualsIgnoreCase("ftp"))
|
||||
uriString.InsertWithConversion("ftp://", 0, 6);
|
||||
else
|
||||
uriString.InsertWithConversion("http://", 0, 7);
|
||||
} // end if checkprotocol
|
||||
return NS_NewURI(aURI, uriString, nsnull);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDocShell::FileURIFixup(const PRUnichar* aStringURI,
|
||||
nsIURI** aURI)
|
||||
{
|
||||
nsAutoString uriSpecIn(aStringURI);
|
||||
nsAutoString uriSpecOut(aStringURI);
|
||||
|
||||
ConvertFileToStringURI(uriSpecIn, uriSpecOut);
|
||||
|
||||
if(0 == uriSpecOut.Find("file:", 0))
|
||||
// Create the fixup object if necessary
|
||||
if (!mURIFixup)
|
||||
{
|
||||
mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID);
|
||||
if (!mURIFixup)
|
||||
{
|
||||
// if this is file url, we need to convert the URI
|
||||
// from Unicode to the FS charset
|
||||
nsCAutoString inFSCharset;
|
||||
NS_ENSURE_SUCCESS(ConvertStringURIToFileCharset(uriSpecOut, inFSCharset),
|
||||
NS_ERROR_FAILURE);
|
||||
|
||||
if(NS_SUCCEEDED(NS_NewURI(aURI, inFSCharset.GetBuffer(), nsnull)))
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
#define FILE_PROTOCOL "file://"
|
||||
|
||||
NS_IMETHODIMP nsDocShell::ConvertFileToStringURI(nsString& aIn, nsString& aOut)
|
||||
{
|
||||
#ifdef XP_PC
|
||||
// Check for \ in the url-string or just a drive (PC)
|
||||
if(kNotFound != aIn.FindChar(PRUnichar('\\')) || ((aIn.Length() == 2 ) && (aIn.Last() == PRUnichar(':') || aIn.Last() == PRUnichar('|'))))
|
||||
{
|
||||
#elif XP_UNIX
|
||||
// Check if it starts with / or \ (UNIX)
|
||||
const PRUnichar * up = aIn.GetUnicode();
|
||||
if((PRUnichar('/') == *up) || (PRUnichar('\\') == *up))
|
||||
{
|
||||
#else
|
||||
if(0)
|
||||
{
|
||||
// Do nothing (All others for now)
|
||||
#endif
|
||||
|
||||
#ifdef XP_PC
|
||||
// Translate '\' to '/'
|
||||
aOut.ReplaceChar(PRUnichar('\\'), PRUnichar('/'));
|
||||
aOut.ReplaceChar(PRUnichar(':'), PRUnichar('|'));
|
||||
#endif
|
||||
|
||||
// Build the file URL
|
||||
aOut.InsertWithConversion(FILE_PROTOCOL,0);
|
||||
// No fixup service so try and create a URI and see what happens
|
||||
return NS_NewURI(aURI, uriString, nsnull);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDocShell::ConvertStringURIToFileCharset(nsString& aIn,
|
||||
nsCString& aOut)
|
||||
{
|
||||
aOut = "";
|
||||
// for file url, we need to convert the nsString to the file system
|
||||
// charset before we pass to NS_NewURI
|
||||
static nsAutoString fsCharset;
|
||||
// find out the file system charset first
|
||||
if(0 == fsCharset.Length())
|
||||
{
|
||||
fsCharset.AssignWithConversion("ISO-8859-1"); // set the fallback first.
|
||||
nsCOMPtr<nsIPlatformCharset> plat(do_GetService(kPlatformCharsetCID));
|
||||
NS_ENSURE_TRUE(plat, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(plat->GetCharset(kPlatformCharsetSel_FileName, fsCharset),
|
||||
NS_ERROR_FAILURE);
|
||||
}
|
||||
// We probably should cache ccm here.
|
||||
// get a charset converter from the manager
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm(do_GetService(kCharsetConverterManagerCID));
|
||||
NS_ENSURE_TRUE(ccm, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIUnicodeEncoder> fsEncoder;
|
||||
NS_ENSURE_SUCCESS(ccm->GetUnicodeEncoder(&fsCharset,
|
||||
getter_AddRefs(fsEncoder)), NS_ERROR_FAILURE);
|
||||
|
||||
PRInt32 bufLen = 0;
|
||||
NS_ENSURE_SUCCESS(fsEncoder->GetMaxLength(aIn.GetUnicode(), aIn.Length(),
|
||||
&bufLen), NS_ERROR_FAILURE);
|
||||
aOut.SetCapacity(bufLen+1);
|
||||
PRInt32 srclen = aIn.Length();
|
||||
NS_ENSURE_SUCCESS(fsEncoder->Convert(aIn.GetUnicode(), &srclen,
|
||||
(char*)aOut.GetBuffer(), &bufLen), NS_ERROR_FAILURE);
|
||||
|
||||
((char*)aOut.GetBuffer())[bufLen]='\0';
|
||||
aOut.SetLength(bufLen);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDocShell::KeywordURIFixup(const PRUnichar* aStringURI,
|
||||
nsIURI** aURI)
|
||||
{
|
||||
NS_ENSURE_STATE(mPrefs);
|
||||
|
||||
PRBool keywordsEnabled = PR_FALSE;
|
||||
NS_ENSURE_SUCCESS(mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled),
|
||||
NS_ERROR_FAILURE);
|
||||
|
||||
if(!keywordsEnabled)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// These are keyword formatted strings
|
||||
// "what is mozilla"
|
||||
// "what is mozilla?"
|
||||
// "?mozilla"
|
||||
// "?What is mozilla"
|
||||
|
||||
// These are not keyword formatted strings
|
||||
// "www.blah.com" - anything with a dot in it
|
||||
// "nonQualifiedHost:80" - anything with a colon in it
|
||||
// "nonQualifiedHost?"
|
||||
// "nonQualifiedHost?args"
|
||||
// "nonQualifiedHost?some args"
|
||||
|
||||
nsAutoString uriString(aStringURI);
|
||||
if(uriString.FindChar('.') == -1 && uriString.FindChar(':') == -1)
|
||||
{
|
||||
PRInt32 qMarkLoc = uriString.FindChar('?');
|
||||
PRInt32 spaceLoc = uriString.FindChar(' ');
|
||||
|
||||
PRBool keyword = PR_FALSE;
|
||||
if(qMarkLoc == 0)
|
||||
keyword = PR_TRUE;
|
||||
else if((spaceLoc > 0) && ((qMarkLoc == -1) || (spaceLoc < qMarkLoc)))
|
||||
keyword = PR_TRUE;
|
||||
|
||||
if(keyword)
|
||||
{
|
||||
nsCAutoString keywordSpec("keyword:");
|
||||
char *utf8Spec = uriString.ToNewUTF8String();
|
||||
if(utf8Spec)
|
||||
{
|
||||
char* escapedUTF8Spec = nsEscape(utf8Spec, url_Path);
|
||||
if(escapedUTF8Spec)
|
||||
{
|
||||
keywordSpec.Append(escapedUTF8Spec);
|
||||
NS_NewURI(aURI, keywordSpec.GetBuffer(), nsnull);
|
||||
nsMemory::Free(escapedUTF8Spec);
|
||||
} // escapedUTF8Spec
|
||||
nsMemory::Free(utf8Spec);
|
||||
} // utf8Spec
|
||||
} // keyword
|
||||
} // FindChar
|
||||
|
||||
if(*aURI)
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
// Call the fixup object
|
||||
return mURIFixup->CreateFixupURI(aStringURI, aURI);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDocShell::GetCurrentDocumentOwner(nsISupports** aOwner)
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
#include "nsISHContainer.h"
|
||||
#include "nsIDocShellLoadInfo.h"
|
||||
#include "nsIDocShellHistory.h"
|
||||
#include "nsIURIFixup.h"
|
||||
|
||||
#define MAKE_LOAD_TYPE(type, flags) ((type) | ((flags) << 16))
|
||||
|
||||
|
@ -209,10 +210,6 @@ protected:
|
|||
#endif
|
||||
|
||||
NS_IMETHOD CreateFixupURI(const PRUnichar* aStringURI, nsIURI** aURI);
|
||||
NS_IMETHOD FileURIFixup(const PRUnichar* aStringURI, nsIURI** aURI);
|
||||
NS_IMETHOD ConvertFileToStringURI(nsString& aIn, nsString& aOut);
|
||||
NS_IMETHOD ConvertStringURIToFileCharset(nsString& aIn, nsCString& aOut);
|
||||
NS_IMETHOD KeywordURIFixup(const PRUnichar* aStringURI, nsIURI** aURI);
|
||||
NS_IMETHOD GetCurrentDocumentOwner(nsISupports** aOwner);
|
||||
NS_IMETHOD DoURILoad(nsIURI* aURI, nsIURI* aReferrer, nsISupports *aOwner,
|
||||
PRBool inheritOwnerFromDocument, nsURILoadCommand aLoadCmd,
|
||||
|
@ -283,6 +280,7 @@ protected:
|
|||
nsCOMPtr<nsISHistory> mSessionHistory;
|
||||
nsCOMPtr<nsIGlobalHistory> mGlobalHistory;
|
||||
nsCOMPtr<nsISupports> mLoadCookie; // the load cookie associated with the window context.
|
||||
nsCOMPtr<nsIURIFixup> mURIFixup;
|
||||
PRInt32 mMarginWidth;
|
||||
PRInt32 mMarginHeight;
|
||||
PRInt32 mItemType;
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Adam Lock <adamlock@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* Interface implemented by objects capable of fixing up strings into URIs
|
||||
*/
|
||||
[scriptable, uuid(2EFD4A40-A5E1-11d4-9589-0020183BF181)]
|
||||
interface nsIURIFixup : nsISupports
|
||||
{
|
||||
/*
|
||||
This method converts the specified string into a URI, first attempting
|
||||
to correct any errors in the syntax or other vagaries.
|
||||
|
||||
aURIText - String URI
|
||||
|
||||
Returns a wellformed URI or nsnull if it can't
|
||||
*/
|
||||
nsIURI createFixupURI(in wstring aURIText);
|
||||
};
|
||||
|
|
@ -23,8 +23,10 @@
|
|||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsWebShell.h"
|
||||
#include "nsDefaultURIFixup.h"
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebShell);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDefaultURIFixup);
|
||||
|
||||
// Currently no-one is instanciating docshell's directly because
|
||||
// nsWebShell is still our main "shell" class. nsWebShell is a subclass
|
||||
|
@ -37,7 +39,11 @@ static nsModuleComponentInfo gDocShellModuleInfo[] = {
|
|||
{ "WebShell",
|
||||
NS_WEB_SHELL_CID,
|
||||
"@mozilla.org/webshell;1",
|
||||
nsWebShellConstructor }
|
||||
nsWebShellConstructor },
|
||||
{ "Default keyword fixup",
|
||||
NS_DEFAULTURIFIXUP_CID,
|
||||
NS_URIFIXUP_CONTRACTID,
|
||||
nsDefaultURIFixupConstructor }
|
||||
};
|
||||
|
||||
// "docshell provider" to illustrate that this thing really *should*
|
||||
|
|
Загрузка…
Ссылка в новой задаче