зеркало из https://github.com/mozilla/pjs.git
Landing url parsing branch. 73845. r=alecf@netscape.com, sr=darin@netscape.com, a=blizzard@rednat.com.
This fixes many crashes caused by illegal uses of the nsStdURL. This also allows a plugable protocol to provide their own url parser.
This commit is contained in:
Родитель
1dedb98d77
Коммит
c306e0513b
|
@ -208,20 +208,13 @@ NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIURL> url;
|
||||
|
||||
rv = nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(url));
|
||||
nsCOMPtr<nsIURI> url;
|
||||
nsCAutoString str; str.AssignWithConversion(valueStr);
|
||||
rv = NS_NewURI(getter_AddRefs(url), str);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return NS_OK;
|
||||
|
||||
nsCAutoString str; str.AssignWithConversion(valueStr);
|
||||
rv = url->SetSpec(str);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISupports> sup;
|
||||
sup = do_QueryInterface(url, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
|
@ -1317,21 +1310,13 @@ NS_IMETHODIMP nsChromeRegistry::WriteInfoToDataSource(const char *aDocURI,
|
|||
PRBool aRemove)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURL> url;
|
||||
|
||||
rv = nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(url));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsCAutoString str(aDocURI);
|
||||
rv = url->SetSpec(str);
|
||||
rv = NS_NewURI(getter_AddRefs(uri), str);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFDataSource> dataSource;
|
||||
rv = GetDynamicDataSource(url, aIsOverlay, aUseProfile, getter_AddRefs(dataSource));
|
||||
rv = GetDynamicDataSource(uri, aIsOverlay, aUseProfile, getter_AddRefs(dataSource));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!dataSource)
|
||||
|
@ -2511,14 +2496,8 @@ nsChromeRegistry::GetProfileRoot(nsCString& aFileURL)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsXPIDLCString urlSpec;
|
||||
nsCOMPtr<nsIFileURL> url = do_CreateInstance("@mozilla.org/network/standard-url;1", &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = url->SetFile(userChromeDir);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = url->GetSpec(getter_Copies(urlSpec));
|
||||
nsXPIDLCString urlSpec;
|
||||
rv = userChromeDir->GetURL(getter_Copies(urlSpec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
aFileURL = urlSpec;
|
||||
|
@ -2538,14 +2517,8 @@ nsChromeRegistry::GetInstallRoot(nsCString& aFileURL)
|
|||
if (NS_FAILED(rv) || !appChromeDir)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLCString urlSpec;
|
||||
nsCOMPtr<nsIFileURL> url = do_CreateInstance("@mozilla.org/network/standard-url;1", &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = url->SetFile(appChromeDir);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = url->GetSpec(getter_Copies(urlSpec));
|
||||
nsXPIDLCString urlSpec;
|
||||
rv = appChromeDir->GetURL(getter_Copies(urlSpec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
aFileURL = urlSpec;
|
||||
|
@ -2835,16 +2808,11 @@ nsChromeRegistry::GetUserSheets(PRBool aIsChrome, nsISupportsArray **aResult)
|
|||
|
||||
nsresult nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString& aURL)
|
||||
{
|
||||
nsCOMPtr<nsIURL> url;
|
||||
nsresult rv = nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(url));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = url->SetSpec(aURL);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = LoadStyleSheetWithURL(url, aSheet);
|
||||
rv = LoadStyleSheetWithURL(uri, aSheet);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -3131,20 +3099,14 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = chromeFile->InitWithPath(chromeLocation);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIFileURL> chromeFileURL(do_CreateInstance("@mozilla.org/network/standard-url;1", &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = chromeFileURL->SetFile(chromeFile);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
/* xpidl strings aren't unified with strings, so this fu is necessary.
|
||||
* all we want here is the canonical url, found using GetSpec.
|
||||
* all we want here is the canonical url
|
||||
*/
|
||||
nsXPIDLCString chromeURLfoopy;
|
||||
rv = chromeFileURL->GetSpec(getter_Copies(chromeURLfoopy));
|
||||
rv = chromeFile->GetURL(getter_Copies(chromeURLfoopy));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
chromeURL = chromeURLfoopy;
|
||||
|
|
|
@ -875,22 +875,16 @@ nsBindingManager::LoadBindingDocument(nsIDocument* aBoundDoc, const nsAReadableS
|
|||
{
|
||||
nsCAutoString url; url.AssignWithConversion(PromiseFlatString(aURL).get());
|
||||
|
||||
nsCOMPtr<nsIURL> uri;
|
||||
nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(uri));
|
||||
uri->SetSpec(url);
|
||||
|
||||
nsXPIDLCString otherScheme;
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID);
|
||||
if (!ioService) return NS_ERROR_FAILURE;
|
||||
ioService->ExtractScheme(url, 0, 0, getter_Copies(otherScheme));
|
||||
|
||||
nsCOMPtr<nsIURI> docURL;
|
||||
aBoundDoc->GetDocumentURL(getter_AddRefs(docURL));
|
||||
nsXPIDLCString scheme;
|
||||
docURL->GetScheme(getter_Copies(scheme));
|
||||
|
||||
nsXPIDLCString otherScheme;
|
||||
uri->GetScheme(getter_Copies(otherScheme));
|
||||
|
||||
// First we need to load our binding.
|
||||
*aResult = nsnull;
|
||||
nsresult rv;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsXBLService.h"
|
||||
#include "nsIXBLPrototypeHandler.h"
|
||||
#include "nsXBLWindowKeyHandler.h"
|
||||
|
@ -1096,7 +1097,7 @@ nsXBLService::LoadBindingDocumentInfo(nsIContent* aBoundElement, nsIDocument* aB
|
|||
const nsCString& aURLStr, const nsCString& aRef,
|
||||
PRBool aForceSyncLoad, nsIXBLDocumentInfo** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
|
@ -1151,12 +1152,10 @@ nsXBLService::LoadBindingDocumentInfo(nsIContent* aBoundElement, nsIDocument* aB
|
|||
if (!info) {
|
||||
// Finally, if all lines of defense fail, we go and fetch the binding
|
||||
// document.
|
||||
nsCOMPtr<nsIURL> uri;
|
||||
nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(uri));
|
||||
uri->SetSpec(aURLStr);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), aURLStr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a url");
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
FetchBindingDocument(aBoundElement, aBoundDocument, uri, aRef, aForceSyncLoad, getter_AddRefs(document));
|
||||
|
||||
|
|
|
@ -144,7 +144,6 @@ static NS_DEFINE_CID(kCTextServicesDocumentCID, NS_TEXTSERVICESDOCUMENT_CID);
|
|||
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
||||
|
||||
#define APP_DEBUG 0
|
||||
|
||||
|
@ -1710,14 +1709,13 @@ nsEditorShell::CheckOpenWindowForURLMatch(const PRUnichar* inFileURL, nsIDOMWind
|
|||
|
||||
// make a temp URL for testing against
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIFileURL> tempFileURL(do_CreateInstance(kStandardURLCID, &rv));
|
||||
|
||||
nsCOMPtr<nsILocalFile> urlFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = tempFileURL->SetSpec(fileURL.get());
|
||||
rv = urlFile->SetURL(fileURL.get());
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFile> urlFile;
|
||||
rv = tempFileURL->GetFile(getter_AddRefs(urlFile));
|
||||
// We fail if inFileURL isn't a "file:" URL, but that's ok.
|
||||
//TODO: When publishing is done, we should support checking remote URL as well
|
||||
if (NS_FAILED(rv)) return NS_OK;
|
||||
|
@ -2033,16 +2031,8 @@ nsEditorShell::SaveDocument(PRBool aSaveAs, PRBool aSaveCopy, const PRUnichar* a
|
|||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mContentAreaDocShell));
|
||||
if (webShell)
|
||||
{
|
||||
// would like to use nsIFile::GetURL here, but it is not implemented
|
||||
// on all platforms
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_CreateInstance(kStandardURLCID, &res));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = fileURL->SetFile(docFile);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
nsXPIDLCString docURLSpec;
|
||||
res = fileURL->GetSpec(getter_Copies(docURLSpec));
|
||||
res = docFile->GetURL(getter_Copies(docURLSpec));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
nsAutoString fileURLUnicode; fileURLUnicode.AssignWithConversion(docURLSpec);
|
||||
|
|
|
@ -611,18 +611,15 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
|
|||
nsCOMPtr<nsIFile> fileObj ( do_QueryInterface(genericDataObj) );
|
||||
if (fileObj && len > 0)
|
||||
{
|
||||
nsCOMPtr<nsIFileURL> fileURL;
|
||||
rv = nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1", nsnull,
|
||||
NS_GET_IID(nsIURL), getter_AddRefs(fileURL));
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewFileURI(getter_AddRefs(uri), fileObj);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIURL> fileURL(do_QueryInterface(uri));
|
||||
if ( fileURL )
|
||||
{
|
||||
rv = fileURL->SetFile( fileObj );
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRBool insertAsImage = PR_FALSE;
|
||||
char *fileextension = nsnull;
|
||||
rv = fileURL->GetFileExtension( &fileextension );
|
||||
|
|
|
@ -144,7 +144,6 @@ static NS_DEFINE_CID(kCTextServicesDocumentCID, NS_TEXTSERVICESDOCUMENT_CID);
|
|||
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
||||
|
||||
#define APP_DEBUG 0
|
||||
|
||||
|
@ -1710,14 +1709,13 @@ nsEditorShell::CheckOpenWindowForURLMatch(const PRUnichar* inFileURL, nsIDOMWind
|
|||
|
||||
// make a temp URL for testing against
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIFileURL> tempFileURL(do_CreateInstance(kStandardURLCID, &rv));
|
||||
|
||||
nsCOMPtr<nsILocalFile> urlFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = tempFileURL->SetSpec(fileURL.get());
|
||||
rv = urlFile->SetURL(fileURL.get());
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFile> urlFile;
|
||||
rv = tempFileURL->GetFile(getter_AddRefs(urlFile));
|
||||
// We fail if inFileURL isn't a "file:" URL, but that's ok.
|
||||
//TODO: When publishing is done, we should support checking remote URL as well
|
||||
if (NS_FAILED(rv)) return NS_OK;
|
||||
|
@ -2033,16 +2031,8 @@ nsEditorShell::SaveDocument(PRBool aSaveAs, PRBool aSaveCopy, const PRUnichar* a
|
|||
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mContentAreaDocShell));
|
||||
if (webShell)
|
||||
{
|
||||
// would like to use nsIFile::GetURL here, but it is not implemented
|
||||
// on all platforms
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_CreateInstance(kStandardURLCID, &res));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
res = fileURL->SetFile(docFile);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
nsXPIDLCString docURLSpec;
|
||||
res = fileURL->GetSpec(getter_Copies(docURLSpec));
|
||||
res = docFile->GetURL(getter_Copies(docURLSpec));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
nsAutoString fileURLUnicode; fileURLUnicode.AssignWithConversion(docURLSpec);
|
||||
|
|
|
@ -611,18 +611,15 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
|
|||
nsCOMPtr<nsIFile> fileObj ( do_QueryInterface(genericDataObj) );
|
||||
if (fileObj && len > 0)
|
||||
{
|
||||
nsCOMPtr<nsIFileURL> fileURL;
|
||||
rv = nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1", nsnull,
|
||||
NS_GET_IID(nsIURL), getter_AddRefs(fileURL));
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewFileURI(getter_AddRefs(uri), fileObj);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIURL> fileURL(do_QueryInterface(uri));
|
||||
if ( fileURL )
|
||||
{
|
||||
rv = fileURL->SetFile( fileObj );
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRBool insertAsImage = PR_FALSE;
|
||||
char *fileextension = nsnull;
|
||||
rv = fileURL->GetFileExtension( &fileextension );
|
||||
|
|
|
@ -106,12 +106,9 @@ EmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
|
|||
|
||||
// create a new uri object
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
uri = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCAutoString spec(aBaseURI);
|
||||
rv = uri->SetSpec(spec.get());
|
||||
rv = NS_NewURI(getter_AddRefs(uri), spec.get());
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
|
|
@ -435,10 +435,7 @@ nsHelperAppDialog.prototype = {
|
|||
var fileLocator = Components.classes[ "@mozilla.org/file/directory_service;1" ]
|
||||
.getService( Components.interfaces.nsIProperties );
|
||||
var file = fileLocator.get( "UMimTyp", Components.interfaces.nsIFile );
|
||||
var file_url = Components.classes[ "@mozilla.org/network/standard-url;1" ]
|
||||
.createInstance( Components.interfaces.nsIFileURL );
|
||||
file_url.file = file;
|
||||
|
||||
|
||||
// We must try creating a fresh remote DS in order to avoid accidentally
|
||||
// having GetDataSource trigger an asych load.
|
||||
var ds = Components.classes[ "@mozilla.org/rdf/datasource;1?name=xml-datasource" ].createInstance( Components.interfaces.nsIRDFDataSource );
|
||||
|
@ -446,11 +443,11 @@ nsHelperAppDialog.prototype = {
|
|||
// Initialize it. This will fail if the uriloader (or anybody else)
|
||||
// has already loaded/registered this data source.
|
||||
var remoteDS = ds.QueryInterface( Components.interfaces.nsIRDFRemoteDataSource );
|
||||
remoteDS.Init( file_url.spec );
|
||||
remoteDS.Init( file.URL );
|
||||
remoteDS.Refresh( true );
|
||||
} catch ( all ) {
|
||||
// OK then, presume it was already registered; get it.
|
||||
ds = rdf.GetDataSource( file_url.spec );
|
||||
ds = rdf.GetDataSource( file.URL );
|
||||
}
|
||||
|
||||
// Now check if this mimetype is really in there;
|
||||
|
|
|
@ -14,7 +14,6 @@ var pref;
|
|||
//////////// global constants ////////////////////
|
||||
|
||||
const kDirServiceCID = "@mozilla.org/file/directory_service;1"
|
||||
const kStandardURLCID = "@mozilla.org/network/standard-url;1"
|
||||
const kNCURI = "http://home.netscape.com/NC-rdf#";
|
||||
const kSidebarPanelId = "UPnls"; // directory services property to find panels.rdf
|
||||
const kSidebarURNPanelList = "urn:sidebar:current-panel-list";
|
||||
|
@ -103,10 +102,7 @@ SidebarPrefs.prototype =
|
|||
var file = dirService.get(aFileId, Components.interfaces.nsIFile);
|
||||
if (!file.exists())
|
||||
return null;
|
||||
|
||||
var fileURL = XPCU.createInstance(kStandardURLCID, "nsIFileURL");
|
||||
fileURL.file = file;
|
||||
return fileURL.spec;
|
||||
return file.URL;
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -133,13 +133,8 @@ nsP3PDataSchema::PostInit( nsString& aURISpec ) {
|
|||
if (NS_SUCCEEDED( rv )) {
|
||||
|
||||
// Create a URL of the components directory
|
||||
nsCOMPtr<nsIFileURL> compsDirURI(do_CreateInstance("@mozilla.org/network/standard-url;1", &rv));
|
||||
rv = compsDir->GetURL( getter_Copies( xcsPath ) );
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
rv = compsDirURI->SetFile(compsDir);
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
rv = compsDirURI->GetSpec( getter_Copies( xcsPath ) );
|
||||
|
||||
if (NS_SUCCEEDED( rv )) {
|
||||
// Make the local path the URI to be read
|
||||
mUseDOMParser = PR_TRUE;
|
||||
mReadURISpec.AssignWithConversion((const char *)xcsPath );
|
||||
|
@ -156,12 +151,6 @@ nsP3PDataSchema::PostInit( nsString& aURISpec ) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
PR_LOG( gP3PLogModule,
|
||||
PR_LOG_ERROR,
|
||||
("P3PDataSchema: %s PostInit, compsDirURI->SetFile failed - %X, using remote base DataSchema.\n", (const char *)mcsURISpec, rv) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
PR_LOG( gP3PLogModule,
|
||||
PR_LOG_ERROR,
|
||||
("P3PDataSchema: %s PostInit, Creation of nsIFileURL failed - %X, using remote base DataSchema.\n", (const char *)mcsURISpec, rv) );
|
||||
|
|
|
@ -162,12 +162,16 @@ function LoadSignons()
|
|||
|
||||
if (user == "") {
|
||||
/* no username passed in, parse it out of url */
|
||||
var uri =
|
||||
Components.classes["@mozilla.org/network/standard-url;1"]
|
||||
.createInstance(Components.interfaces.nsIURI);
|
||||
uri.spec = host;
|
||||
if (uri.username) {
|
||||
user = uri.username;
|
||||
var unused = { };
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
try {
|
||||
username = ioService.extractUrlPart(host, ioService.url_Username, unused, unused);
|
||||
} catch(e) {
|
||||
username = "";
|
||||
}
|
||||
if (username != "") {
|
||||
user = username;
|
||||
} else {
|
||||
user = "<>";
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "singsign.h"
|
||||
#include "wallet.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include "prpriv.h" /* for NewNamedMonitor */
|
||||
|
@ -2040,20 +2041,12 @@ SINGSIGN_RememberSignonData
|
|||
(nsIPrompt* dialog, const char* passwordRealm, nsVoidArray * signonData,
|
||||
nsIDOMWindowInternal* window)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIURL, uri, "@mozilla.org/network/standard-url;1", &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
rv = uri->SetSpec(passwordRealm);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
char * strippedRealm;
|
||||
rv = uri->GetHost(&strippedRealm);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID);
|
||||
if (!ioService) return;
|
||||
ioService->ExtractUrlPart(passwordRealm, nsIIOService::url_Host, 0, 0, &strippedRealm);
|
||||
|
||||
si_RememberSignonData(dialog, strippedRealm, signonData, window);
|
||||
PR_Free(strippedRealm);
|
||||
}
|
||||
|
@ -2164,20 +2157,11 @@ si_RestoreSignonData(nsIPrompt* dialog, const char* passwordRealm, const PRUnich
|
|||
|
||||
PUBLIC void
|
||||
SINGSIGN_RestoreSignonData(nsIPrompt* dialog, const char* passwordRealm, const PRUnichar* name, PRUnichar** value, PRUint32 elementNumber) {
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIURL, uri, "@mozilla.org/network/standard-url;1", &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
rv = uri->SetSpec(passwordRealm);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
char * strippedRealm;
|
||||
rv = uri->GetHost(&strippedRealm);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID);
|
||||
if (!ioService) return;
|
||||
ioService->ExtractUrlPart(passwordRealm, nsIIOService::url_Host, 0, 0, &strippedRealm);
|
||||
|
||||
si_RestoreSignonData(dialog, strippedRealm, name, value, elementNumber);
|
||||
PR_Free(strippedRealm);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
|
@ -79,7 +80,6 @@
|
|||
#endif
|
||||
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID);
|
||||
static NS_DEFINE_CID(kSmtpServiceCID, NS_SMTPSERVICE_CID);
|
||||
static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kAB4xUpgraderServiceCID, NS_AB4xUPGRADER_CID);
|
||||
|
@ -903,22 +903,19 @@ nsMessengerMigrator::Convert4XUri(const char *old_uri, PRBool for_news, const ch
|
|||
#endif /* DEBUG_MIGRATOR */
|
||||
|
||||
if (PL_strncasecmp(IMAP_SCHEMA,old_uri,IMAP_SCHEMA_LENGTH) == 0) {
|
||||
nsCOMPtr <nsIURL> url;
|
||||
nsXPIDLCString hostname;
|
||||
nsXPIDLCString username;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, NS_GET_IID(nsIURL), getter_AddRefs(url));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID);
|
||||
if (!ioService) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = ioService->ExtractUrlPart(old_uri, nsIIOService::url_Host, 0, 0, getter_Copies(hostname));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->SetSpec(old_uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = ioService->ExtractUrlPart(old_uri, nsIIOService::url_Username, 0, 0, getter_Copies(username));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->GetHost(getter_Copies(hostname));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = url->GetPreHost(getter_Copies(username));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// in 4.x, mac and windows stored the URI as IMAP://<hostname>
|
||||
// in 4.x, mac and windows stored the URI as IMAP://<hostname>
|
||||
// if the URI was the default folder on the server.
|
||||
// If it wasn't the default folder, they would have stored it as
|
||||
if (!username || (PL_strlen((const char *)username) == 0)) {
|
||||
|
|
|
@ -104,19 +104,14 @@ nsMsgServiceProviderService::Init()
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFile> dirEntry;
|
||||
nsCOMPtr<nsIFileURL> dirEntryURL(do_CreateInstance("@mozilla.org/network/standard-url;1"));
|
||||
|
||||
while ((rv = dirIterator->HasMoreElements(&hasMore)) == NS_OK && hasMore) {
|
||||
rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry));
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
rv = dirEntryURL->SetFile(dirEntry);
|
||||
if (NS_FAILED(rv))
|
||||
continue;
|
||||
|
||||
nsXPIDLCString urlSpec;
|
||||
rv = dirEntryURL->GetSpec(getter_Copies(urlSpec));
|
||||
rv = dirEntry->GetURL(getter_Copies(urlSpec));
|
||||
rv = LoadDataSource(urlSpec);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed reading in the datasource\n");
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "nsIPref.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
|
||||
|
@ -100,6 +101,7 @@ nsresult nsStatusBarBiffManager::PerformStatusBarBiff(PRUint32 newBiffFlag)
|
|||
{
|
||||
// See nsMsgStatusFeedback
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
|
||||
// if we got new mail, attempt to play a sound.
|
||||
// if we fail along the way, don't return.
|
||||
|
@ -112,8 +114,6 @@ nsresult nsStatusBarBiffManager::PerformStatusBarBiff(PRUint32 newBiffFlag)
|
|||
if (NS_SUCCEEDED(rv) && playSoundOnBiff) {
|
||||
nsCOMPtr<nsISound> sound = do_CreateInstance("@mozilla.org/sound;1");
|
||||
if (sound) {
|
||||
nsCOMPtr<nsIFileURL> soundURL = do_CreateInstance("@mozilla.org/network/standard-url;1");
|
||||
if (soundURL) {
|
||||
PRBool playDefaultSound = PR_TRUE;
|
||||
rv = pref->GetBoolPref(PREF_PLAY_DEFAULT_SOUND, &playDefaultSound);
|
||||
if (NS_SUCCEEDED(rv) && !playDefaultSound) {
|
||||
|
@ -122,7 +122,9 @@ nsresult nsStatusBarBiffManager::PerformStatusBarBiff(PRUint32 newBiffFlag)
|
|||
if (NS_SUCCEEDED(rv) && soundFile) {
|
||||
nsCOMPtr <nsIFile> file = do_QueryInterface(soundFile);
|
||||
if (file) {
|
||||
rv = soundURL->SetFile(file);
|
||||
rv = NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
@ -131,17 +133,18 @@ nsresult nsStatusBarBiffManager::PerformStatusBarBiff(PRUint32 newBiffFlag)
|
|||
}
|
||||
|
||||
if ((NS_FAILED(rv) || playDefaultSound) && nsCRT::strlen(mDefaultSoundURL.get())) {
|
||||
rv = soundURL->SetSpec(mDefaultSoundURL.get());
|
||||
rv = NS_NewURI(getter_AddRefs(uri), mDefaultSoundURL.get());
|
||||
}
|
||||
}
|
||||
|
||||
nsXPIDLCString soundURLSpec;
|
||||
if (soundURL)
|
||||
rv = soundURL->GetSpec(getter_Copies(soundURLSpec));
|
||||
if (uri)
|
||||
rv = uri->GetSpec(getter_Copies(soundURLSpec));
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
if (NS_SUCCEEDED(rv) && nsCRT::strlen(soundURLSpec.get())) {
|
||||
nsCOMPtr<nsIURL> soundURL(do_QueryInterface(uri));
|
||||
if (NS_SUCCEEDED(rv) && soundURL && nsCRT::strlen(soundURLSpec.get())) {
|
||||
sound->Play(soundURL);
|
||||
}
|
||||
else {
|
||||
|
@ -150,8 +153,7 @@ nsresult nsStatusBarBiffManager::PerformStatusBarBiff(PRUint32 newBiffFlag)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_WITH_SERVICE(nsIWindowMediator, windowMediator, kWindowMediatorCID, &rv);
|
||||
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
||||
|
||||
|
|
|
@ -1979,11 +1979,7 @@ var attachmentBucketObserver = {
|
|||
}
|
||||
break;
|
||||
case "application/x-moz-file":
|
||||
const FileContractID = "@mozilla.org/network/standard-url;1";
|
||||
const FileURLIID = Components.interfaces.nsIFileURL;
|
||||
var fileURL = Components.classes[FileContractID].createInstance(FileURLIID);
|
||||
fileURL.file = aData.data;
|
||||
rawData = fileURL.spec;
|
||||
rawData = aData.data.URL;
|
||||
break;
|
||||
}
|
||||
if (!(DuplicateFileCheck(rawData)))
|
||||
|
|
|
@ -127,28 +127,20 @@ nsresult nsMsgCompFields::CleanUpTempFiles()
|
|||
// Only deal with temp files (ie, starting with "file://")
|
||||
if (!url.IsEmpty() && url.CompareWithConversion(kFileURLPrefix, PR_TRUE, 7) == 0)
|
||||
{
|
||||
nsCOMPtr<nsIFileURL> tempFileURL(do_CreateInstance("@mozilla.org/network/standard-url;1", &rv));
|
||||
if (NS_FAILED(rv))
|
||||
nsCOMPtr<nsILocalFile> urlFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_ASSERTION(0, "Can't creat nsIFileURL interface");
|
||||
continue;
|
||||
}
|
||||
|
||||
rv = tempFileURL->SetSpec(url);
|
||||
|
||||
rv = urlFile->SetURL(url);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_ASSERTION(0, "Can't set file spec in nsIFileURL interface");
|
||||
NS_ASSERTION(0, "Can't set file spec in nsILocalFile interface");
|
||||
continue;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> urlFile;
|
||||
rv = tempFileURL->GetFile(getter_AddRefs(urlFile));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_ASSERTION(0, "Can't get nsIFile interface from nsIFileURL interface");
|
||||
continue;
|
||||
}
|
||||
|
||||
PRBool isDir;
|
||||
rv = urlFile->IsDirectory(&isDir);
|
||||
if (NS_FAILED(rv))
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "prtypes.h"
|
||||
#include "prprf.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIImgManager.h"
|
||||
|
@ -1749,8 +1750,10 @@ PRBool il_PermitLoad(const char * image_url, nsIImageRequestObserver * aObserver
|
|||
|
||||
/* convert image_url to an nsIURL so we can extract host and scheme */
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIURL, uri, "@mozilla.org/network/standard-url;1", &rv);
|
||||
if (NS_FAILED(rv) || NS_FAILED(uri->SetSpec(image_url))) {
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), image_url);
|
||||
if (NS_FAILED(rv)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kStandardURICID, NS_STANDARDURL_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsIconProtocolHandler::nsIconProtocolHandler()
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
interface nsIProtocolHandler;
|
||||
interface nsIChannel;
|
||||
interface nsIURI;
|
||||
interface nsIURLParser;
|
||||
interface nsIFile;
|
||||
|
||||
[scriptable, uuid(ab7c3a84-d488-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIIOService : nsISupports
|
||||
|
@ -49,6 +51,14 @@ interface nsIIOService : nsISupports
|
|||
*/
|
||||
nsIURI newURI(in string aSpec, in nsIURI aBaseURI);
|
||||
|
||||
/**
|
||||
* This method constructs a new file URI
|
||||
*
|
||||
* @param aSpec nsIFile
|
||||
* @return reference to a new nsIURI object
|
||||
*/
|
||||
nsIURI newFileURI(in nsIFile aSpec);
|
||||
|
||||
/**
|
||||
* Creates a channel for a given URI. The notificationCallbacks argument
|
||||
* is used to obtain the appropriate callbacks for the URI's protocol from the
|
||||
|
@ -119,10 +129,18 @@ interface nsIIOService : nsISupports
|
|||
* @return NS_OK - if successful
|
||||
* @return NS_ERROR_MALFORMED_URI - if the urlString is not of the right form
|
||||
*/
|
||||
void extractScheme(in string urlString,
|
||||
out unsigned long schemeStartPos,
|
||||
out unsigned long schemeEndPos,
|
||||
out string scheme);
|
||||
string extractScheme(in string urlString,
|
||||
out unsigned long schemeStartPos,
|
||||
out unsigned long schemeEndPos);
|
||||
|
||||
|
||||
nsIURLParser getParserForScheme(in string scheme);
|
||||
|
||||
string extractUrlPart(in string urlString,
|
||||
in short flag,
|
||||
out unsigned long startPos,
|
||||
out unsigned long endPos);
|
||||
|
||||
|
||||
/**
|
||||
* Constants for the mask in the call to Escape
|
||||
|
|
|
@ -98,6 +98,7 @@ interface nsIURLParser : nsISupports
|
|||
|
||||
%{C++
|
||||
|
||||
#define NS_STANDARDURLPARSER_CONTRACT_ID "@mozilla.org/network/standard-urlparser;1"
|
||||
#define NS_STANDARDURLPARSER_CID \
|
||||
{ /* dbf72351-4fd8-46f0-9dbc-fa5ba60a30c5 */ \
|
||||
0xdbf72351, \
|
||||
|
@ -106,6 +107,7 @@ interface nsIURLParser : nsISupports
|
|||
{0x9d, 0xbc, 0xfa, 0x5b, 0xa6, 0x0a, 0x30, 0x5c} \
|
||||
}
|
||||
|
||||
#define NS_AUTHORITYURLPARSER_CONTRACT_ID "@mozilla.org/network/authority-urlparser;1"
|
||||
#define NS_AUTHORITYURLPARSER_CID \
|
||||
{ /* 90012125-1616-4fa1-ae14-4e7fa5766eb6 */ \
|
||||
0x90012125, \
|
||||
|
@ -114,6 +116,7 @@ interface nsIURLParser : nsISupports
|
|||
{0xae, 0x14, 0x4e, 0x7f, 0xa5, 0x76, 0x6e, 0xb6} \
|
||||
}
|
||||
|
||||
#define NS_NOAUTHORITYURLPARSER_CONTRACT_ID "@mozilla.org/network/authority-urlparser;1"
|
||||
#define NS_NOAUTHORITYURLPARSER_CID \
|
||||
{ /* 9eeb1b89-c87e-4404-9de6-dbd41aeaf3d7 */ \
|
||||
0x9eeb1b89, \
|
||||
|
@ -122,4 +125,6 @@ interface nsIURLParser : nsISupports
|
|||
{0x9d, 0xe6, 0xdb, 0xd4, 0x1a, 0xea, 0xf3, 0xd7} \
|
||||
}
|
||||
|
||||
#define NS_IURLPARSER_KEY "@mozilla.org/urlparser;1"
|
||||
|
||||
%}
|
||||
|
|
|
@ -94,6 +94,24 @@ NS_NewURI(nsIURI* *result,
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
inline nsresult
|
||||
NS_NewFileURI(nsIURI* *result,
|
||||
nsIFile* spec,
|
||||
nsIIOService* ioService = nsnull) // pass in nsIIOService to optimize callers
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIIOService> serv;
|
||||
if (ioService == nsnull) {
|
||||
serv = do_GetIOService(&rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
ioService = serv.get();
|
||||
}
|
||||
|
||||
return ioService->NewFileURI(spec, result);
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_OpenURI(nsIChannel* *result,
|
||||
nsIURI* uri,
|
||||
|
|
|
@ -37,6 +37,9 @@
|
|||
#include "nsIObserverService.h"
|
||||
#include "nsIHttpProtocolHandler.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsIURLParser.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
||||
static NS_DEFINE_CID(kFileTransportService, NS_FILETRANSPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
|
||||
|
@ -45,6 +48,8 @@ static NS_DEFINE_CID(kDNSServiceCID, NS_DNSSERVICE_CID);
|
|||
static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID);
|
||||
static NS_DEFINE_CID(kProtocolProxyServiceCID, NS_PROTOCOLPROXYSERVICE_CID);
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kStdURLParserCID, NS_STANDARDURLPARSER_CID);
|
||||
|
||||
// A general port blacklist. Connections to these ports will not be avoided unless
|
||||
// the protocol overrides.
|
||||
//
|
||||
|
@ -331,6 +336,31 @@ nsIOService::GetCachedProtocolHandler(const char *scheme, nsIProtocolHandler **r
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::CacheURLParser(const char *scheme, nsIURLParser *parser)
|
||||
{
|
||||
for (unsigned int i=0; i<NS_N(gScheme); i++)
|
||||
{
|
||||
if (!nsCRT::strcasecmp(scheme, gScheme[i]))
|
||||
{
|
||||
mURLParsers.SetElementAt(i, parser);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetCachedURLParser(const char *scheme, nsIURLParser **result)
|
||||
{
|
||||
for (unsigned int i=0; i<NS_N(gScheme); i++)
|
||||
{
|
||||
if (!nsCRT::strcasecmp(scheme, gScheme[i]))
|
||||
return mURLParsers.GetElementAt(i, (nsISupports **)result);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result)
|
||||
|
@ -378,6 +408,198 @@ nsIOService::ExtractScheme(const char* inURI, PRUint32 *startPos,
|
|||
return ExtractURLScheme(inURI, startPos, endPos, scheme);
|
||||
}
|
||||
|
||||
/* nsIURLParser getParserForScheme (in string scheme); */
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetParserForScheme(const char *scheme, nsIURLParser **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = GetCachedURLParser(scheme, _retval);
|
||||
if (NS_SUCCEEDED(rv) && *_retval) return NS_OK;
|
||||
|
||||
|
||||
if (!scheme) {
|
||||
if (!mDefaultURLParser) {
|
||||
rv = nsServiceManager::GetService(kStdURLParserCID,
|
||||
NS_GET_IID(nsIURLParser),
|
||||
getter_AddRefs(mDefaultURLParser));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
*_retval = mDefaultURLParser;
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> parserList;
|
||||
rv = catmgr->EnumerateCategory(NS_IURLPARSER_KEY, getter_AddRefs(parserList));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISupportsString> entry;
|
||||
|
||||
// Walk the list of parsers...
|
||||
while (1) {
|
||||
rv = parserList->GetNext(getter_AddRefs(entry));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// get the entry string
|
||||
nsXPIDLCString entryString;
|
||||
rv = entry->GetData(getter_Copies(entryString));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (nsCRT::strcmp(entryString, scheme) == 0) {
|
||||
nsXPIDLCString contractID;
|
||||
rv = catmgr->GetCategoryEntry(NS_IURLPARSER_KEY,(const char *)entryString, getter_Copies(contractID));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
CacheURLParser(scheme, *_retval);
|
||||
return nsServiceManager::GetService(contractID, NS_GET_IID(nsIURLParser), (nsISupports **)_retval);
|
||||
}
|
||||
}
|
||||
|
||||
// no registered url parser. Just use the default...
|
||||
if (!mDefaultURLParser) {
|
||||
rv = nsServiceManager::GetService(kStdURLParserCID,
|
||||
NS_GET_IID(nsIURLParser),
|
||||
getter_AddRefs(mDefaultURLParser));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
*_retval = mDefaultURLParser;
|
||||
NS_ADDREF(*_retval);
|
||||
CacheURLParser(scheme, *_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void CalculateStartEndPos(const char*string, const char* substring, PRUint32 *startPos, PRUint32 *endPos)
|
||||
{
|
||||
// we will only get the first appearance of a substring...
|
||||
char* inst = PL_strstr(string, substring);
|
||||
|
||||
if (startPos)
|
||||
*startPos = (PRUint32)(inst - string);
|
||||
if (endPos)
|
||||
*endPos = (PRUint32)(inst) + PL_strlen(substring);
|
||||
}
|
||||
|
||||
// Crap. How do I ensure that startPos and endPos are correct.
|
||||
NS_IMETHODIMP
|
||||
nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *startPos, PRUint32 *endPos, char **urlPart)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString scheme;
|
||||
|
||||
ExtractScheme(urlString, startPos, endPos, getter_Copies(scheme));
|
||||
|
||||
if (flag == url_Scheme) {
|
||||
CalculateStartEndPos(urlString, scheme, startPos, endPos);
|
||||
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(scheme.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURLParser> parser;
|
||||
rv = GetParserForScheme(scheme, getter_AddRefs(parser));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 port;
|
||||
nsXPIDLCString dummyScheme, username, password, host, path;
|
||||
|
||||
rv = parser->ParseAtScheme(urlString,
|
||||
getter_Copies(dummyScheme),
|
||||
getter_Copies(username),
|
||||
getter_Copies(password),
|
||||
getter_Copies(host),
|
||||
&port,
|
||||
getter_Copies(path));
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (flag == url_Username) {
|
||||
CalculateStartEndPos(urlString, username, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(username.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Password) {
|
||||
CalculateStartEndPos(urlString, password, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(password.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Host) {
|
||||
CalculateStartEndPos(urlString, host, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(host.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Directory) {
|
||||
CalculateStartEndPos(urlString, path, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(path.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLCString fileBaseName, fileExtension, param, query, ref;
|
||||
|
||||
rv = parser->ParseAtDirectory(path,
|
||||
getter_Copies(path),
|
||||
getter_Copies(fileBaseName),
|
||||
getter_Copies(fileExtension),
|
||||
getter_Copies(param),
|
||||
getter_Copies(query),
|
||||
getter_Copies(ref));
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
if (flag == url_FileBaseName) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(fileBaseName.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_FileExtension) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(fileExtension.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Param) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(param.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Query) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(query.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Ref) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(ref.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI, nsIURI* *result)
|
||||
{
|
||||
|
@ -408,6 +630,21 @@ nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI, nsIURI* *result)
|
|||
return handler->NewURI(aSpec, base, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::NewFileURI(nsIFile *aSpec, nsIURI **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ENSURE_ARG_POINTER(aSpec);
|
||||
|
||||
nsXPIDLCString urlString;
|
||||
rv = aSpec->GetURL(getter_Copies(urlString));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NewURI(urlString, nsnull, _retval);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::NewChannelFromURI(nsIURI *aURI, nsIChannel **result)
|
||||
{
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include "nsURLHelper.h"
|
||||
#include "nsWeakPtr.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIURLParser.h"
|
||||
#include "nsSupportsArray.h"
|
||||
|
||||
#define NS_N(x) (sizeof(x)/sizeof(*x))
|
||||
|
||||
|
@ -64,6 +66,12 @@ protected:
|
|||
NS_METHOD CacheProtocolHandler(const char *scheme,
|
||||
nsIProtocolHandler* hdlr);
|
||||
|
||||
NS_METHOD GetCachedURLParser(const char *scheme,
|
||||
nsIURLParser* *hdlrResult);
|
||||
|
||||
NS_METHOD CacheURLParser(const char *scheme,
|
||||
nsIURLParser* hdlr);
|
||||
|
||||
protected:
|
||||
PRBool mOffline;
|
||||
nsCOMPtr<nsISocketTransportService> mSocketTransportService;
|
||||
|
@ -75,6 +83,9 @@ protected:
|
|||
// Cached protocol handlers
|
||||
nsWeakPtr mWeakHandler[NS_N(gScheme)];
|
||||
|
||||
// Cached url handlers
|
||||
nsCOMPtr<nsIURLParser> mDefaultURLParser;
|
||||
nsSupportsArray mURLParsers;
|
||||
nsVoidArray mRestrictedPortList;
|
||||
};
|
||||
|
||||
|
|
|
@ -896,6 +896,9 @@ nsStdURL::SetSpec(const char* i_Spec)
|
|||
CRTFREEIF(mRef);
|
||||
rv = Parse(fwdPtr);
|
||||
CRTFREEIF(eSpec);
|
||||
|
||||
NS_ASSERTION(mScheme, "no scheme? You shouldn't be calling this function without scheme!");
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -352,7 +352,9 @@ NS_NET nsresult ExtractURLScheme(const char* inURI, PRUint32 *startPos,
|
|||
{
|
||||
// search for something up to a colon, and call it the scheme
|
||||
NS_ENSURE_ARG_POINTER(inURI);
|
||||
|
||||
if (scheme)
|
||||
*scheme = nsnull;
|
||||
|
||||
const char* uri = inURI;
|
||||
|
||||
// skip leading white space
|
||||
|
|
|
@ -65,6 +65,8 @@
|
|||
{0x8c, 0xd0, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
// DO NOT USE THIS INTERFACE DIRECTLY UNLESS YOU KNOW
|
||||
// WHAT YOU ARE DOING! - dougt@netscape.com
|
||||
#define NS_STANDARDURL_CLASSNAME \
|
||||
"Standard URL"
|
||||
#define NS_STANDARDURL_CONTRACTID \
|
||||
|
|
|
@ -115,6 +115,63 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpBasicAuth)
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
static NS_METHOD
|
||||
RegisterBuiltInURLParsers(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *registryLocation,
|
||||
const char *componentType,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString previous;
|
||||
|
||||
catman->AddCategoryEntry(NS_IURLPARSER_KEY,
|
||||
"file",
|
||||
NS_NOAUTHORITYURLPARSER_CONTRACT_ID,
|
||||
PR_TRUE,
|
||||
PR_TRUE,
|
||||
getter_Copies(previous));
|
||||
|
||||
catman->AddCategoryEntry(NS_IURLPARSER_KEY,
|
||||
"ftp",
|
||||
NS_AUTHORITYURLPARSER_CONTRACT_ID,
|
||||
PR_TRUE,
|
||||
PR_TRUE,
|
||||
getter_Copies(previous));
|
||||
|
||||
catman->AddCategoryEntry(NS_IURLPARSER_KEY,
|
||||
"http",
|
||||
NS_AUTHORITYURLPARSER_CONTRACT_ID,
|
||||
PR_TRUE,
|
||||
PR_TRUE,
|
||||
getter_Copies(previous));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static NS_METHOD
|
||||
UnregisterBuiltInURLParsers(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *registryLocation,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
catman->DeleteCategoryEntry(NS_IURLPARSER_KEY, "file", PR_TRUE);
|
||||
catman->DeleteCategoryEntry(NS_IURLPARSER_KEY, "ftp", PR_TRUE);
|
||||
catman->DeleteCategoryEntry(NS_IURLPARSER_KEY, "http", PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
#include "nsIHTTPProtocolHandler.h"
|
||||
#include "nsHTTPHandler.h"
|
||||
|
@ -628,18 +685,25 @@ static nsModuleComponentInfo gNetModuleInfo[] = {
|
|||
NS_LOCALFILEOUTPUTSTREAM_CID,
|
||||
NS_LOCALFILEOUTPUTSTREAM_CONTRACTID,
|
||||
nsFileOutputStream::Create },
|
||||
|
||||
// The register functions for the build in
|
||||
// parsers just need to be called once.
|
||||
{ "StdURLParser",
|
||||
NS_STANDARDURLPARSER_CID,
|
||||
"@mozilla.org/network/standard-urlparser;1",
|
||||
nsStdURLParser::Create },
|
||||
NS_STANDARDURLPARSER_CONTRACT_ID,
|
||||
nsStdURLParser::Create,
|
||||
RegisterBuiltInURLParsers,
|
||||
UnregisterBuiltInURLParsers
|
||||
},
|
||||
{ "AuthURLParser",
|
||||
NS_AUTHORITYURLPARSER_CID,
|
||||
"@mozilla.org/network/authority-urlparser;1",
|
||||
NS_AUTHORITYURLPARSER_CONTRACT_ID,
|
||||
nsAuthURLParser::Create },
|
||||
{ "NoAuthURLParser",
|
||||
NS_NOAUTHORITYURLPARSER_CID,
|
||||
"@mozilla.org/network/no-authority-urlparser;1",
|
||||
NS_NOAUTHORITYURLPARSER_CONTRACT_ID,
|
||||
nsNoAuthURLParser::Create },
|
||||
|
||||
{ NS_BUFFEREDINPUTSTREAM_CLASSNAME,
|
||||
NS_BUFFEREDINPUTSTREAM_CID,
|
||||
NS_BUFFEREDINPUTSTREAM_CONTRACTID,
|
||||
|
|
|
@ -208,20 +208,13 @@ NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIURL> url;
|
||||
|
||||
rv = nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(url));
|
||||
nsCOMPtr<nsIURI> url;
|
||||
nsCAutoString str; str.AssignWithConversion(valueStr);
|
||||
rv = NS_NewURI(getter_AddRefs(url), str);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return NS_OK;
|
||||
|
||||
nsCAutoString str; str.AssignWithConversion(valueStr);
|
||||
rv = url->SetSpec(str);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISupports> sup;
|
||||
sup = do_QueryInterface(url, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
|
@ -1317,21 +1310,13 @@ NS_IMETHODIMP nsChromeRegistry::WriteInfoToDataSource(const char *aDocURI,
|
|||
PRBool aRemove)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURL> url;
|
||||
|
||||
rv = nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(url));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsCAutoString str(aDocURI);
|
||||
rv = url->SetSpec(str);
|
||||
rv = NS_NewURI(getter_AddRefs(uri), str);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFDataSource> dataSource;
|
||||
rv = GetDynamicDataSource(url, aIsOverlay, aUseProfile, getter_AddRefs(dataSource));
|
||||
rv = GetDynamicDataSource(uri, aIsOverlay, aUseProfile, getter_AddRefs(dataSource));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!dataSource)
|
||||
|
@ -2511,14 +2496,8 @@ nsChromeRegistry::GetProfileRoot(nsCString& aFileURL)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsXPIDLCString urlSpec;
|
||||
nsCOMPtr<nsIFileURL> url = do_CreateInstance("@mozilla.org/network/standard-url;1", &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = url->SetFile(userChromeDir);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = url->GetSpec(getter_Copies(urlSpec));
|
||||
nsXPIDLCString urlSpec;
|
||||
rv = userChromeDir->GetURL(getter_Copies(urlSpec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
aFileURL = urlSpec;
|
||||
|
@ -2538,14 +2517,8 @@ nsChromeRegistry::GetInstallRoot(nsCString& aFileURL)
|
|||
if (NS_FAILED(rv) || !appChromeDir)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLCString urlSpec;
|
||||
nsCOMPtr<nsIFileURL> url = do_CreateInstance("@mozilla.org/network/standard-url;1", &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = url->SetFile(appChromeDir);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = url->GetSpec(getter_Copies(urlSpec));
|
||||
nsXPIDLCString urlSpec;
|
||||
rv = appChromeDir->GetURL(getter_Copies(urlSpec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
aFileURL = urlSpec;
|
||||
|
@ -2835,16 +2808,11 @@ nsChromeRegistry::GetUserSheets(PRBool aIsChrome, nsISupportsArray **aResult)
|
|||
|
||||
nsresult nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString& aURL)
|
||||
{
|
||||
nsCOMPtr<nsIURL> url;
|
||||
nsresult rv = nsComponentManager::CreateInstance("@mozilla.org/network/standard-url;1",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIURL),
|
||||
getter_AddRefs(url));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = url->SetSpec(aURL);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = LoadStyleSheetWithURL(url, aSheet);
|
||||
rv = LoadStyleSheetWithURL(uri, aSheet);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -3131,20 +3099,14 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength)
|
|||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = chromeFile->InitWithPath(chromeLocation);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIFileURL> chromeFileURL(do_CreateInstance("@mozilla.org/network/standard-url;1", &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = chromeFileURL->SetFile(chromeFile);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
/* xpidl strings aren't unified with strings, so this fu is necessary.
|
||||
* all we want here is the canonical url, found using GetSpec.
|
||||
* all we want here is the canonical url
|
||||
*/
|
||||
nsXPIDLCString chromeURLfoopy;
|
||||
rv = chromeFileURL->GetSpec(getter_Copies(chromeURLfoopy));
|
||||
rv = chromeFile->GetURL(getter_Copies(chromeURLfoopy));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
chromeURL = chromeURLfoopy;
|
||||
|
|
|
@ -172,17 +172,9 @@ nsresult nsExternalHelperAppService::InitDataSource()
|
|||
rv = NS_GetSpecialDirectory(NS_APP_USER_MIMETYPES_50_FILE, getter_AddRefs(mimeTypesFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Now construct a standard (file) url.
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_CreateInstance( "@mozilla.org/network/standard-url;1", &rv );
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Set to point at same file as the 'special directory."
|
||||
rv = fileURL->SetFile( mimeTypesFile );
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Get file url spec to be used to initialize the DS.
|
||||
nsXPIDLCString urlSpec;
|
||||
rv = fileURL->GetSpec(getter_Copies(urlSpec));
|
||||
rv = mimeTypesFile->GetURL(getter_Copies(urlSpec));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = remoteDS->Init(urlSpec);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#define NS_IMPL_IDS
|
||||
#include "nsIPlatformCharset.h"
|
||||
|
@ -233,10 +234,11 @@ NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
|||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
file->InitWithPath(mFile);
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_CreateInstance("@mozilla.org/network/standard-url;1"));
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
|
||||
fileURL->SetFile(file);
|
||||
|
||||
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsFilePicker.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsILocalFileMac.h"
|
||||
|
@ -624,9 +625,11 @@ NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
|||
{
|
||||
NS_ENSURE_TRUE(mFile, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIFileURL> file(do_CreateInstance("@mozilla.org/network/standard-url;1"));
|
||||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
file->SetFile(mFile);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), mFile);
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
|
||||
|
||||
NS_ADDREF(*aFileURL = file);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#endif
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#define NS_IMPL_IDS
|
||||
#include "nsIPlatformCharset.h"
|
||||
|
@ -226,10 +227,11 @@ NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
|||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
file->InitWithPath(mFile);
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_CreateInstance("@mozilla.org/network/standard-url;1"));
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
|
||||
fileURL->SetFile(file);
|
||||
|
||||
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -657,24 +657,18 @@ nsClipboard :: FindURLFromLocalFile ( IDataObject* inDataObject, UINT inIndex, v
|
|||
else {
|
||||
// we have a normal file, use some Necko objects to get our file path
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, PR_FALSE, getter_AddRefs(file))) ) {
|
||||
nsCOMPtr<nsIFileURL> url ( do_CreateInstance("@mozilla.org/network/standard-url;1") );
|
||||
if ( url ) {
|
||||
// get the file:// url from our native path
|
||||
url->SetFile ( file );
|
||||
char* urlSpec = nsnull;
|
||||
url->GetSpec ( &urlSpec );
|
||||
if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, PR_FALSE, getter_AddRefs(file))) ) {
|
||||
nsXPIDLCString urlSpec;
|
||||
file->GetURL( getter_Copies(urlSpec) );
|
||||
|
||||
// convert it to unicode and pass it out
|
||||
nsMemory::Free(*outData);
|
||||
nsAutoString urlSpecUnicode;
|
||||
urlSpecUnicode.AssignWithConversion( urlSpec );
|
||||
*outData = urlSpecUnicode.ToNewUnicode();
|
||||
*outDataLen = strlen(urlSpec) * sizeof(PRUnichar);
|
||||
nsMemory::Free(urlSpec);
|
||||
|
||||
*outDataLen = strlen(urlSpec.get()) * sizeof(PRUnichar);
|
||||
dataFound = PR_TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
} // else regular file
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#endif
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#define NS_IMPL_IDS
|
||||
#include "nsIPlatformCharset.h"
|
||||
|
@ -271,9 +272,10 @@ NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL)
|
|||
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
||||
file->InitWithPath(mFile);
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_CreateInstance("@mozilla.org/network/standard-url;1"));
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewFileURI(getter_AddRefs(uri), file);
|
||||
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
|
||||
NS_ENSURE_TRUE(fileURL, NS_ERROR_FAILURE);
|
||||
fileURL->SetFile(file);
|
||||
|
||||
NS_ADDREF(*aFileURL = fileURL);
|
||||
|
||||
|
|
|
@ -271,4 +271,167 @@ nsEscapeHTML2(const PRUnichar *aSourceBuffer, PRInt32 aSourceBufferLen)
|
|||
return resultBuffer;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
const int EscapeChars[256] =
|
||||
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
|
||||
0,1023, 0, 512,1023, 0,1023, 0,1023,1023,1023,1023,1023,1023, 959, 912, /* 2x !"#$%&'()*+,-./ */
|
||||
1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 912, 896, 0,1008, 0, 768, /* 3x 0123456789:;<=>? */
|
||||
992,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, /* 4x @ABCDEFGHIJKLMNO */
|
||||
1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 896, 896, 896, 896,1023, /* 5x PQRSTUVWXYZ[\]^_ */
|
||||
0,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, /* 6x `abcdefghijklmno */
|
||||
1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 896,1012, 896,1008, 0, /* 7x pqrstuvwxyz{|}~ */
|
||||
0 /* 8x DEL */
|
||||
};
|
||||
|
||||
#define NO_NEED_ESC(C) (EscapeChars[((unsigned int) (C))] & (mask))
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
/* returns an escaped string */
|
||||
|
||||
/* use the following masks to specify which
|
||||
part of an URL you want to escape:
|
||||
|
||||
esc_Scheme = 1
|
||||
esc_Username = 2
|
||||
esc_Password = 4
|
||||
esc_Host = 8
|
||||
esc_Directory = 16
|
||||
esc_FileBaseName = 32
|
||||
esc_FileExtension = 64
|
||||
esc_Param = 128
|
||||
esc_Query = 256
|
||||
esc_Ref = 512
|
||||
*/
|
||||
|
||||
/* by default this function will not escape parts of a string
|
||||
that already look escaped, which means it already includes
|
||||
a valid hexcode. This is done to avoid multiple escapes of
|
||||
a string. Use the following mask to force escaping of a
|
||||
string:
|
||||
|
||||
esc_Forced = 1024
|
||||
*/
|
||||
|
||||
NS_COM nsresult nsStdEscape(const char* str, PRInt16 mask, nsCString &result)
|
||||
{
|
||||
result.Truncate(0);
|
||||
if (!str)
|
||||
return NS_OK;
|
||||
|
||||
int i = 0;
|
||||
char* hexChars = "0123456789ABCDEF";
|
||||
static const char CheckHexChars[] = "0123456789ABCDEFabcdef";
|
||||
int len = PL_strlen(str);
|
||||
PRBool forced = PR_FALSE;
|
||||
|
||||
if (mask & esc_Forced)
|
||||
forced = PR_TRUE;
|
||||
|
||||
register const unsigned char* src = (const unsigned char *) str;
|
||||
|
||||
src = (const unsigned char *) str;
|
||||
|
||||
char tempBuffer[100];
|
||||
unsigned int tempBufferPos = 0;
|
||||
|
||||
char c1[] = " ";
|
||||
char c2[] = " ";
|
||||
char* const pc1 = c1;
|
||||
char* const pc2 = c2;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
c1[0] = *(src+1);
|
||||
if (*(src+1) == '\0')
|
||||
c2[0] = '\0';
|
||||
else
|
||||
c2[0] = *(src+2);
|
||||
unsigned char c = *src++;
|
||||
|
||||
/* if the char has not to be escaped or whatever follows % is
|
||||
a valid escaped string, just copy the char */
|
||||
if (NO_NEED_ESC(c) || (c == HEX_ESCAPE && !(forced) && (pc1) && (pc2) &&
|
||||
PL_strpbrk(pc1, CheckHexChars) != 0 &&
|
||||
PL_strpbrk(pc2, CheckHexChars) != 0)) {
|
||||
tempBuffer[tempBufferPos++]=c;
|
||||
}
|
||||
else
|
||||
/* do the escape magic */
|
||||
{
|
||||
tempBuffer[tempBufferPos++] = HEX_ESCAPE;
|
||||
tempBuffer[tempBufferPos++] = hexChars[c >> 4]; /* high nibble */
|
||||
tempBuffer[tempBufferPos++] = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
|
||||
if(tempBufferPos >= sizeof(tempBuffer) - 4)
|
||||
{
|
||||
tempBuffer[tempBufferPos] = '\0';
|
||||
result += tempBuffer;
|
||||
tempBufferPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
tempBuffer[tempBufferPos] = '\0';
|
||||
result += tempBuffer;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_COM nsresult nsStdUnescape(char* str, char **result)
|
||||
{
|
||||
if (!str) {
|
||||
*result = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
register char *src = str;
|
||||
static const char hexChars[] = "0123456789ABCDEFabcdef";
|
||||
int len = PL_strlen(str);
|
||||
|
||||
*result = (char *)nsMemory::Alloc(len + 1);
|
||||
if (!*result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
register unsigned char* dst = (unsigned char *) *result;
|
||||
|
||||
char c1[] = " ";
|
||||
char c2[] = " ";
|
||||
char* const pc1 = c1;
|
||||
char* const pc2 = c2;
|
||||
|
||||
while (*src) {
|
||||
|
||||
c1[0] = *(src+1);
|
||||
if (*(src+1) == '\0')
|
||||
c2[0] = '\0';
|
||||
else
|
||||
c2[0] = *(src+2);
|
||||
|
||||
/* check for valid escaped sequence */
|
||||
if (*src != HEX_ESCAPE || PL_strpbrk(pc1, hexChars) == 0 ||
|
||||
PL_strpbrk(pc2, hexChars) == 0 )
|
||||
*dst++ = *src++;
|
||||
else
|
||||
{
|
||||
src++; /* walk over escape */
|
||||
if (*src)
|
||||
{
|
||||
*dst = UNHEX(*src) << 4;
|
||||
src++;
|
||||
}
|
||||
if (*src)
|
||||
{
|
||||
*dst = (*dst + UNHEX(*src));
|
||||
src++;
|
||||
}
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
*dst = '\0';
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include "nsError.h"
|
||||
#include "nsString.h"
|
||||
|
||||
/* valid mask values for NET_Escape() and NET_EscapedSize(). */
|
||||
typedef enum {
|
||||
|
@ -67,6 +69,29 @@ nsEscapeHTML2(const PRUnichar *aSourceBuffer,
|
|||
* Escape problem char's for HTML display
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Constants for the mask in the call to nsStdEscape
|
||||
*/
|
||||
|
||||
enum EscapeMask {
|
||||
esc_Scheme = 1,
|
||||
esc_Username = 2,
|
||||
esc_Password = 4,
|
||||
esc_Host = 8,
|
||||
esc_Directory = 16,
|
||||
esc_FileBaseName = 32,
|
||||
esc_FileExtension = 64,
|
||||
esc_Param = 128,
|
||||
esc_Query = 256,
|
||||
esc_Ref = 512,
|
||||
esc_Forced = 1024
|
||||
};
|
||||
|
||||
NS_COM nsresult nsStdEscape(const char* str, PRInt16 mask, nsCString &result);
|
||||
NS_COM nsresult nsStdUnescape(char* str, char **result);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIURLParser.h"
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
|
||||
#include "nsFileSpec.h" // evil ftang hack
|
||||
|
@ -35,6 +36,12 @@
|
|||
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
#ifndef XPCOM_STANDALONE
|
||||
static NS_DEFINE_CID(kStdURLParserCID, NS_STANDARDURLPARSER_CID);
|
||||
#endif
|
||||
|
||||
|
||||
class nsFSStringConversion {
|
||||
public:
|
||||
|
@ -379,15 +386,87 @@ nsLocalFile::CreateUnique(const char* suggestedName, PRUint32 type, PRUint32 att
|
|||
return NS_ERROR_FILE_TOO_BIG;
|
||||
}
|
||||
|
||||
nsresult nsLocalFile::ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||
char **outFileBaseName, char **outFileExtension)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
#ifndef XPCOM_STANDALONE
|
||||
NS_ENSURE_ARG(inURL);
|
||||
NS_ENSURE_ARG_POINTER(outHost);
|
||||
*outHost = nsnull;
|
||||
NS_ENSURE_ARG_POINTER(outDirectory);
|
||||
*outDirectory = nsnull;
|
||||
NS_ENSURE_ARG_POINTER(outFileBaseName);
|
||||
*outFileBaseName = nsnull;
|
||||
NS_ENSURE_ARG_POINTER(outFileExtension);
|
||||
*outFileExtension = nsnull;
|
||||
|
||||
rv = NS_OK;
|
||||
char* eSpec = nsnull;
|
||||
eSpec = nsCRT::strdup(inURL);
|
||||
if (!eSpec)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// Skip leading spaces and control-characters
|
||||
char* fwdPtr= (char*) eSpec;
|
||||
while (fwdPtr && (*fwdPtr > '\0') && (*fwdPtr <= ' '))
|
||||
fwdPtr++;
|
||||
// Remove trailing spaces and control-characters
|
||||
if (fwdPtr) {
|
||||
char* bckPtr= (char*)fwdPtr + PL_strlen(fwdPtr) -1;
|
||||
if (*bckPtr > '\0' && *bckPtr <= ' ') {
|
||||
while ((bckPtr-fwdPtr) >= 0 && (*bckPtr <= ' ')) {
|
||||
bckPtr--;
|
||||
}
|
||||
*(bckPtr+1) = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE(nsIURLParser, parser, kStdURLParserCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString ePath;
|
||||
nsXPIDLCString scheme, username, password, host;
|
||||
PRInt32 mPort;
|
||||
|
||||
// Parse the spec
|
||||
rv = parser->ParseAtScheme(eSpec, getter_Copies(scheme), getter_Copies(username),
|
||||
getter_Copies(password), outHost, &mPort,
|
||||
getter_Copies(ePath));
|
||||
|
||||
// if this isn't a file: URL, then we can't deal
|
||||
if (NS_FAILED(rv) || nsCRT::strcasecmp(scheme, "file") != 0) {
|
||||
CRTFREEIF(*outHost);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsXPIDLCString param, query, ref;
|
||||
|
||||
// Now parse the path
|
||||
rv = parser->ParseAtDirectory(ePath, outDirectory, outFileBaseName, outFileExtension,
|
||||
getter_Copies(param), getter_Copies(query), getter_Copies(ref));
|
||||
if (NS_FAILED(rv)) {
|
||||
CRTFREEIF(*outDirectory);
|
||||
CRTFREEIF(*outFileBaseName);
|
||||
CRTFREEIF(*outFileExtension);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// If any of the components are non-NULL but empty, free them
|
||||
if (*outHost && !nsCRT::strlen(*outHost))
|
||||
CRTFREEIF(*outHost);
|
||||
if (*outDirectory && !nsCRT::strlen(*outDirectory))
|
||||
CRTFREEIF(*outDirectory);
|
||||
if (*outFileBaseName && !nsCRT::strlen(*outFileBaseName))
|
||||
CRTFREEIF(*outFileBaseName);
|
||||
if (*outFileExtension && !nsCRT::strlen(*outFileExtension))
|
||||
CRTFREEIF(*outFileExtension);
|
||||
#endif /* XPCOM_STANDALONE */
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// E_V_I_L Below! E_V_I_L Below! E_V_I_L Below! E_V_I_L Below!
|
||||
|
||||
|
|
|
@ -36,7 +36,11 @@
|
|||
#include "nsIMIMEInfo.h"
|
||||
#include "prtypes.h"
|
||||
#include "prerror.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
#ifdef MACOSX
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
#include "private/pprio.h"
|
||||
#else
|
||||
#include "pprio.h" // Include this rather than prio.h so we get def of PR_ImportFile
|
||||
|
@ -419,6 +423,19 @@ static nsresult ConvertMillisecondsToMacTime(PRInt64 aTime, PRUint32 *aOutMacTim
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static void SwapSlashColon(char * s)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
if (*s == '/')
|
||||
*s++ = ':';
|
||||
else if (*s == ':')
|
||||
*s++ = '/';
|
||||
else
|
||||
*s++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
|
@ -2182,12 +2199,93 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
|
|||
|
||||
NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
SwapSlashColon(ePath);
|
||||
|
||||
// Escape the path with the directory mask
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
escPath.Insert("file:///", 0);
|
||||
|
||||
PRBool dir;
|
||||
rv = IsDirectory(&dir);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Cannot tell if this is a directory");
|
||||
if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') {
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
*aURL = nsCRT::strdup((const char *)escPath);
|
||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseURL(aURL, getter_Copies(host), getter_Copies(directory),
|
||||
getter_Copies(fileBaseName), getter_Copies(fileExtension));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
||||
nsCAutoString component;
|
||||
|
||||
if (host)
|
||||
{
|
||||
// We can end up with a host when given: file:// instead of file:///
|
||||
// Check to see if the host is a volume name - If so prepend it
|
||||
Str255 volName;
|
||||
FSSpec volSpec;
|
||||
|
||||
myPLstrcpy(volName, host);
|
||||
volName[++volName[0]] = ':';
|
||||
if (::FSMakeFSSpec(0, 0, volName, &volSpec) == noErr)
|
||||
path += host;
|
||||
}
|
||||
if (directory)
|
||||
{
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
path += component;
|
||||
SwapSlashColon((char*)path.get());
|
||||
}
|
||||
if (fileBaseName)
|
||||
{
|
||||
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileExtension)
|
||||
{
|
||||
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||
path += '.';
|
||||
path += component;
|
||||
}
|
||||
|
||||
nsUnescape((char*)path.get());
|
||||
|
||||
// wack off leading :'s
|
||||
if (path.CharAt(0) == ':')
|
||||
path.Cut(0, 1);
|
||||
|
||||
rv = InitWithPath(path);
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -78,6 +78,9 @@ public:
|
|||
|
||||
NS_IMETHOD LaunchAppWithDoc(nsILocalFile* aDocToLoad, PRBool aLaunchInBackground);
|
||||
NS_IMETHOD OpenDocWithApp(nsILocalFile* aAppToOpenWith, PRBool aLaunchInBackground);
|
||||
static nsresult ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||
char **outFileBaseName, char **outFileExtension);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@
|
|||
#include "nsMemory.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsString.h"
|
||||
#include "nsLocalFileUnix.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
@ -1299,12 +1301,73 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator **entries)
|
|||
|
||||
NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
// Escape the path with the directory mask
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
escPath.Insert("file://", 0);
|
||||
|
||||
PRBool dir;
|
||||
rv = IsDirectory(&dir);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Cannot tell if this is a directory");
|
||||
if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') {
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
*aURL = nsCRT::strdup((const char *)escPath);
|
||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseURL(aURL, getter_Copies(host), getter_Copies(directory),
|
||||
getter_Copies(fileBaseName), getter_Copies(fileExtension));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
||||
nsCAutoString component;
|
||||
|
||||
if (directory)
|
||||
{
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileBaseName)
|
||||
{
|
||||
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileExtension)
|
||||
{
|
||||
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||
path += '.';
|
||||
path += component;
|
||||
}
|
||||
|
||||
nsUnescape((char*)path.get());
|
||||
|
||||
rv = InitWithPath(path);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -103,6 +103,8 @@ protected:
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||
char **outFileBaseName, char **outFileExtension);
|
||||
};
|
||||
|
||||
#endif /* _nsLocalFileUNIX_H_ */
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
#include "prtypes.h"
|
||||
#include "prio.h"
|
||||
|
||||
#include "nsEscape.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
@ -1864,51 +1867,107 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries)
|
|||
|
||||
NS_IMETHODIMP nsLocalFile::GetURL(char * *aURL)
|
||||
{
|
||||
nsresult rv;
|
||||
char* ePath = (char*) nsMemory::Clone(mWorkingPath, strlen(mWorkingPath)+1);
|
||||
if (ePath == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
#if defined (XP_WIN)
|
||||
// Replace \ with / to convert to an url
|
||||
char* s = ePath;
|
||||
while (*s)
|
||||
{
|
||||
// We need to call IsDBCSLeadByte because
|
||||
// Japanese windows can have 0x5C in the sencond byte
|
||||
// of a Japanese character, for example 0x8F 0x5C is
|
||||
// one Japanese character
|
||||
if(::IsDBCSLeadByte(*s) && *(s+1) != nsnull) {
|
||||
s++;
|
||||
} else
|
||||
if (*s == '\\')
|
||||
*s = '/';
|
||||
s++;
|
||||
}
|
||||
#endif
|
||||
// Escape the path with the directory mask
|
||||
nsCAutoString tmp(ePath);
|
||||
tmp.ReplaceChar(":", '|');
|
||||
nsCAutoString escPath("file://");
|
||||
escPath += tmp;
|
||||
// rv = nsURLEscape(ePath,nsIIOService::url_Directory + nsIIOService::url_Forced, escPath);
|
||||
// if (NS_SUCCEEDED(rv)) {
|
||||
PRBool dir;
|
||||
rv = IsDirectory(&dir);
|
||||
if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') {
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
*aURL = escPath.ToNewCString();
|
||||
if (*aURL == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
// }
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
// Replace \ with / to convert to an url
|
||||
char* s = ePath;
|
||||
while (*s)
|
||||
{
|
||||
// We need to call IsDBCSLeadByte because
|
||||
// Japanese windows can have 0x5C in the sencond byte
|
||||
// of a Japanese character, for example 0x8F 0x5C is
|
||||
// one Japanese character
|
||||
if(::IsDBCSLeadByte(*s) && *(s+1) != nsnull) {
|
||||
s++;
|
||||
}
|
||||
else if (*s == '\\')
|
||||
*s = '/';
|
||||
|
||||
s++;
|
||||
}
|
||||
|
||||
// Escape the path with the directory mask
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
escPath.Insert("file:///", 0);
|
||||
|
||||
PRBool dir;
|
||||
rv = IsDirectory(&dir);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Cannot tell if this is a directory");
|
||||
if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') {
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
*aURL = nsCRT::strdup((const char *)escPath);
|
||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalFile::SetURL(const char * aURL)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||
|
||||
rv = ParseURL(aURL, getter_Copies(host), getter_Copies(directory),
|
||||
getter_Copies(fileBaseName), getter_Copies(fileExtension));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
||||
nsCAutoString component;
|
||||
|
||||
if (host)
|
||||
{
|
||||
// We can end up with a host when given: file://C|/ instead of file:///
|
||||
if (strlen((const char *)host) == 2 && ((const char *)host)[1] == '|')
|
||||
{
|
||||
path += host;
|
||||
path.SetCharAt(':', 1);
|
||||
}
|
||||
}
|
||||
if (directory)
|
||||
{
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
if (!host && component.Length() > 2 && component.CharAt(2) == '|')
|
||||
component.SetCharAt(':', 2);
|
||||
component.ReplaceChar('/', '\\');
|
||||
path += component;
|
||||
}
|
||||
if (fileBaseName)
|
||||
{
|
||||
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileExtension)
|
||||
{
|
||||
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||
path += '.';
|
||||
path += component;
|
||||
}
|
||||
|
||||
nsUnescape((char*)path.get());
|
||||
|
||||
// remove leading '\'
|
||||
if (path.CharAt(0) == '\\')
|
||||
path.Cut(0, 1);
|
||||
|
||||
rv = InitWithPath(path);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -92,6 +92,9 @@ private:
|
|||
nsresult CopySingleFile(nsIFile *source, nsIFile* dest, const char * newName, PRBool followSymlinks, PRBool move);
|
||||
|
||||
nsresult SetModDate(PRInt64 aLastModificationDate, PRBool resolveTerminal);
|
||||
|
||||
static nsresult ParseURL(const char* inURL, char **outHost, char **outDirectory,
|
||||
char **outFileBaseName, char **outFileExtension);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -395,8 +395,6 @@ function getAbsoluteURL(url, node)
|
|||
if (!url || !node)
|
||||
return "";
|
||||
|
||||
var URL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces["nsIURL"]);
|
||||
|
||||
var urlArr = new Array(url);
|
||||
var doc = node.ownerDocument;
|
||||
|
||||
|
@ -417,7 +415,9 @@ function getAbsoluteURL(url, node)
|
|||
}
|
||||
|
||||
// resolve everything from bottom up, starting with document location
|
||||
URL.spec = doc.location.href;
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var URL = ioService.newURI(doc.location.href, null);
|
||||
for (var i=0; i<urlArr.length; i++) {
|
||||
URL.spec = URL.resolve(urlArr[i]);
|
||||
}
|
||||
|
|
|
@ -129,18 +129,33 @@ function addToUrlbarHistory()
|
|||
return;
|
||||
var index = 0;
|
||||
// create the nsIURI objects for comparing the 2 urls
|
||||
var uriToAdd = Components.classes["@mozilla.org/network/standard-url;1"]
|
||||
.createInstance(Components.interfaces.nsIURI);
|
||||
uriToAdd.spec = urlToAdd;
|
||||
var rdfUri = Components.classes["@mozilla.org/network/standard-url;1"]
|
||||
.createInstance(Components.interfaces.nsIURI);
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
|
||||
try {
|
||||
var unused = { };
|
||||
scheme = ioService.extractScheme(urlToAdd, unused, unused);
|
||||
} catch(e) {
|
||||
urlToAdd = "http://" + urlToAdd;
|
||||
}
|
||||
var uriToAdd = ioService.newURI(urlToAdd, null);
|
||||
|
||||
while(elements.hasMoreElements()) {
|
||||
entry = elements.getNext();
|
||||
if (entry) {
|
||||
index ++;
|
||||
entry= entry.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
var rdfValue = entry.Value;
|
||||
rdfUri.spec = rdfValue;
|
||||
|
||||
try {
|
||||
var unused = { };
|
||||
scheme = ioService.extractScheme(rdfValue, unused, unused);
|
||||
} catch(e) {
|
||||
rdfValue = "http://" + rdfValue;
|
||||
}
|
||||
|
||||
var rdfUri = ioService.newURI(rdfValue, null);
|
||||
|
||||
if (rdfUri.equals(uriToAdd)) {
|
||||
// URI already present in the database
|
||||
// Remove it from its current position.
|
||||
|
|
|
@ -278,11 +278,7 @@ function retrieveURLFromData (aData, flavour)
|
|||
data = data.substr(0, separator);
|
||||
return data;
|
||||
case "application/x-moz-file":
|
||||
const kURLContractID = "@mozilla.org/network/standard-url;1";
|
||||
const kFileURLIID = Components.interfaces.nsIFileURL;
|
||||
var fileURL = Components.classes[kURLContractID].createInstance(kFileURLIID);
|
||||
fileURL.file = aData;
|
||||
return fileURL.spec;
|
||||
return aData.URL;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -674,9 +674,9 @@ nsContextMenu.prototype = {
|
|||
// Convert relative URL to absolute, using document's <base>.
|
||||
makeURLAbsolute : function ( base, url ) {
|
||||
// Construct nsIURL.
|
||||
var baseURL = this.createInstance( "@mozilla.org/network/standard-url;1", "nsIURL" );
|
||||
// Initialize from base url.
|
||||
baseURL.spec = base;
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var uriToAdd = ioService.newURI(base, null);
|
||||
// Resolve
|
||||
var result = baseURL.resolve( url );
|
||||
return result;
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
const nsIDirectoryServiceProvider = Components.interfaces.nsIDirectoryServiceProvider;
|
||||
const nsIDirectoryServiceProvider_CONTRACTID = "@mozilla.org/file/directory_service;1";
|
||||
const nsStdURL_CONTRACTID = "@mozilla.org/network/standard-url;1";
|
||||
const nsIFileURL = Components.interfaces.nsIFileURL;
|
||||
const nsIOutlinerBoxObject = Components.interfaces.nsIOutlinerBoxObject;
|
||||
|
||||
var sfile = Components.classes[nsLocalFile_CONTRACTID].createInstance(nsILocalFile);
|
||||
|
|
|
@ -87,8 +87,9 @@ nsFilePicker.prototype = {
|
|||
set fileURL(a) { throw "readonly property"; },
|
||||
get fileURL() {
|
||||
if (this.mFile) {
|
||||
var url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(nsIFileURL);
|
||||
url.file = this.mFile;
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var url = ioService.newFileURI(this.mFile);
|
||||
return url;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -87,8 +87,9 @@ nsFilePicker.prototype = {
|
|||
set fileURL(a) { throw "readonly property"; },
|
||||
get fileURL() {
|
||||
if (this.mFile) {
|
||||
var url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(nsIFileURL);
|
||||
url.file = this.mFile;
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var url = ioService.newFileURI(this.mFile);
|
||||
return url;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
1) Hook up Assert() etc. so that we can delete stuff.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsGlobalHistory.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsCRT.h"
|
||||
|
@ -55,6 +55,7 @@
|
|||
#include "prtime.h"
|
||||
#include "rdf.h"
|
||||
#include "nsQuickSort.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetCID.h"
|
||||
|
@ -102,7 +103,6 @@ nsIRDFResource* nsGlobalHistory::kNC_HistoryByDate;
|
|||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID);
|
||||
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
||||
// closure structures for RemoveMatchingRows
|
||||
|
@ -115,7 +115,7 @@ struct matchHost_t {
|
|||
const char *host;
|
||||
PRBool entireDomain; // should we delete the entire domain?
|
||||
nsGlobalHistory *history;
|
||||
nsIURL* cachedUrl;
|
||||
nsIURI* cachedUrl;
|
||||
};
|
||||
|
||||
struct matchSearchTerm_t {
|
||||
|
@ -652,7 +652,6 @@ nsGlobalHistory::AddNewPageToDatabase(const char *aURL,
|
|||
PRInt64 aDate,
|
||||
nsIMdbRow **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
mdb_err err;
|
||||
|
||||
// Create a new row
|
||||
|
@ -675,15 +674,10 @@ nsGlobalHistory::AddNewPageToDatabase(const char *aURL,
|
|||
SetRowValue(row, kToken_LastVisitDateColumn, aDate);
|
||||
SetRowValue(row, kToken_FirstVisitDateColumn, aDate);
|
||||
|
||||
nsCOMPtr<nsIURL> urlObj(do_CreateInstance(kStandardUrlCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = urlObj->SetSpec(aURL);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString hostname;
|
||||
rv = urlObj->GetHost(getter_Copies(hostname));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID);
|
||||
if (!ioService) return NS_ERROR_FAILURE;
|
||||
ioService->ExtractUrlPart(aURL, nsIIOService::url_Host, 0, 0, getter_Copies(hostname));
|
||||
|
||||
SetRowValue(row, kToken_HostnameColumn, hostname);
|
||||
|
||||
|
@ -934,18 +928,12 @@ nsGlobalHistory::RemovePage(const char *aURL)
|
|||
NS_IMETHODIMP
|
||||
nsGlobalHistory::RemovePagesFromHost(const char *aHost, PRBool aEntireDomain)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIURL> url =
|
||||
do_CreateInstance(kStandardUrlCID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
matchHost_t hostInfo;
|
||||
hostInfo.history = this;
|
||||
hostInfo.entireDomain = aEntireDomain;
|
||||
hostInfo.host = aHost;
|
||||
|
||||
hostInfo.cachedUrl = url;
|
||||
hostInfo.cachedUrl = nsnull; // todo: leak?
|
||||
return RemoveMatchingRows(matchHostCallback, (void *)&hostInfo, PR_TRUE);
|
||||
}
|
||||
|
||||
|
@ -962,7 +950,7 @@ nsGlobalHistory::MatchHost(nsIMdbRow *aRow,
|
|||
|
||||
// do smart zero-termination
|
||||
nsDependentCString url((const char *)yarn.mYarn_Buf, yarn.mYarn_Fill);
|
||||
rv = hostInfo->cachedUrl->SetSpec(nsCAutoString(url).get());
|
||||
rv = NS_NewURI(&hostInfo->cachedUrl, nsCAutoString(url).get());
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
nsXPIDLCString urlHost;
|
||||
|
@ -1492,11 +1480,12 @@ nsGlobalHistory::GetTarget(nsIRDFResource* aSource,
|
|||
rv = GetRowValue(row, kToken_NameColumn, title);
|
||||
if (NS_FAILED(rv) || title.IsEmpty()) {
|
||||
// yank out the filename from the url, use that
|
||||
nsCOMPtr<nsIURL> urlObj(do_CreateInstance(kStandardUrlCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = urlObj->SetSpec(uri);
|
||||
nsCOMPtr<nsIURI> aUri;
|
||||
rv = NS_NewURI(getter_AddRefs(aUri), uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIURL> urlObj(do_QueryInterface(aUri));
|
||||
if (!urlObj)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLCString filename;
|
||||
rv = urlObj->GetFileName(getter_Copies(filename));
|
||||
|
@ -2357,20 +2346,17 @@ nsGlobalHistory::CheckHostnameEntries()
|
|||
// cached variables used in the loop
|
||||
nsCAutoString url;
|
||||
nsXPIDLCString hostname;
|
||||
nsCOMPtr<nsIURL> urlObj(do_CreateInstance(kStandardUrlCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID);
|
||||
if (!ioService) return NS_ERROR_FAILURE;
|
||||
|
||||
|
||||
while (row) {
|
||||
#if 0
|
||||
rv = GetRowValue(row, kToken_URLColumn, url);
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
rv = urlObj->SetSpec(url.get());
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
rv = urlObj->GetHost(getter_Copies(hostname));
|
||||
if (NS_FAILED(rv)) break;
|
||||
ioService->ExtractUrlPart(url, nsIIOService::url_Host, 0, 0, getter_Copies(hostname));
|
||||
|
||||
SetRowValue(row, kToken_HostnameColumn, hostname);
|
||||
|
||||
|
|
|
@ -167,10 +167,7 @@
|
|||
if (fileLocator)
|
||||
fileLocator = fileLocator.QueryInterface(Components.interfaces.nsIProperties);
|
||||
var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
|
||||
var file_url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
|
||||
if (file_url)
|
||||
file_url.file = file;
|
||||
gDS = gRDF.GetDataSource(file_url.spec);
|
||||
gDS = gRDF.GetDataSource(file.URL);
|
||||
if (gDS)
|
||||
gDS = gDS.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
}
|
||||
|
|
|
@ -72,10 +72,7 @@ function onOK()
|
|||
if (fileLocator)
|
||||
fileLocator = fileLocator.QueryInterface(Components.interfaces.nsIProperties);
|
||||
var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
|
||||
var file_url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
|
||||
if (file_url)
|
||||
file_url.file = file;
|
||||
gDS = gRDF.GetDataSource(file_url.spec);
|
||||
gDS = gRDF.GetDataSource(file.URL);
|
||||
if (gDS)
|
||||
gDS = gDS.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
|
||||
|
|
|
@ -69,10 +69,7 @@ function Startup()
|
|||
if (fileLocator)
|
||||
fileLocator = fileLocator.QueryInterface(Components.interfaces.nsIProperties);
|
||||
var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
|
||||
var file_url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
|
||||
if (file_url)
|
||||
file_url.file = file;
|
||||
gDS = gRDF.GetDataSource(file_url.spec);
|
||||
gDS = gRDF.GetDataSource(file.URL);
|
||||
if (gDS)
|
||||
gDS = gDS.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
|
||||
|
|
|
@ -1216,11 +1216,7 @@ InternetSearchDataSource::GetCategoryList()
|
|||
|
||||
rv = NS_GetSpecialDirectory(NS_APP_SEARCH_50_FILE, getter_AddRefs(searchFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIFileURL> searchFileURL(do_CreateInstance("@mozilla.org/network/standard-url;1", &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = searchFileURL->SetFile(searchFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = searchFileURL->GetSpec(getter_Copies(searchFileURLSpec));
|
||||
searchFile->GetURL(getter_Copies(searchFileURLSpec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = remoteCategoryDataSource->Init(searchFileURLSpec);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
|
|
@ -651,9 +651,7 @@ function sidebar_revert_to_default_panels() {
|
|||
function get_sidebar_datasource_uri() {
|
||||
try {
|
||||
var sidebar_file = sidebar_get_panels_file();
|
||||
var file_url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
|
||||
file_url.file = sidebar_file;
|
||||
return file_url.spec;
|
||||
return sidebar_file.URL;
|
||||
} catch (ex) {
|
||||
// This should not happen
|
||||
debug("Error: Unable to load panels file.\n");
|
||||
|
|
|
@ -41,7 +41,6 @@ const SIDEBAR_CONTRACTID = "@mozilla.org/sidebar;1";
|
|||
const SIDEBAR_CID = Components.ID("{22117140-9c6e-11d3-aaf1-00805f8a4905}");
|
||||
const CONTAINER_CONTRACTID = "@mozilla.org/rdf/container;1";
|
||||
const DIR_SERV_CONTRACTID = "@mozilla.org/file/directory_service;1"
|
||||
const STD_URL_CONTRACTID = "@mozilla.org/network/standard-url;1"
|
||||
const NETSEARCH_CONTRACTID = "@mozilla.org/rdf/datasource;1?name=internetsearch"
|
||||
const nsISupports = Components.interfaces.nsISupports;
|
||||
const nsIFactory = Components.interfaces.nsIFactory;
|
||||
|
@ -382,11 +381,8 @@ function getSidebarDatasourceURI(panels_file_id)
|
|||
return null;
|
||||
}
|
||||
|
||||
var file_url = Components.classes[STD_URL_CONTRACTID].createInstance(Components.interfaces.nsIFileURL);
|
||||
file_url.file = sidebar_file;
|
||||
|
||||
debug("sidebar uri is " + file_url.spec);
|
||||
return file_url.spec;
|
||||
debug("sidebar uri is " + sidebar_file.URL);
|
||||
return sidebar_file.URL;
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
|
|
|
@ -38,12 +38,11 @@
|
|||
#include "nsIRDFContainerUtils.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kRDFCUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
||||
|
||||
static char * ignoreArray[] = {
|
||||
"http://",
|
||||
|
@ -548,10 +547,14 @@ nsUrlbarHistory::GetHostIndex(const PRUnichar * aPath, PRInt32 * aReturn)
|
|||
|
||||
PRInt32 slashIndex=-1;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
|
||||
nsCOMPtr<nsIURL> pathURL=do_CreateInstance(kStandardURLCID, &rv);
|
||||
rv = NS_NewURI(getter_AddRefs(uri), NS_ConvertUCS2toUTF8(aPath).get());
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIURL> pathURL(do_QueryInterface(uri));
|
||||
|
||||
if (pathURL) {
|
||||
pathURL->SetSpec(NS_ConvertUCS2toUTF8(aPath).get());
|
||||
char * host=nsnull, *preHost = nsnull, * filePath = nsnull;
|
||||
pathURL->GetHost(&host);
|
||||
pathURL->GetFilePath(&filePath);
|
||||
|
@ -632,23 +635,20 @@ nsUrlbarHistory::VerifyAndCreateEntry(const PRUnichar * aSearchItem, PRUnichar *
|
|||
if (aSearchItem)
|
||||
searchStrLen = nsCRT::strlen(aSearchItem);
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURL> searchURL = do_CreateInstance(kStandardURLCID, &rv);
|
||||
if (searchURL) {
|
||||
searchURL->SetSpec(NS_ConvertUCS2toUTF8(aSearchItem).get());
|
||||
nsXPIDLCString filePath;
|
||||
searchURL->GetFilePath(getter_Copies(filePath));
|
||||
|
||||
nsXPIDLCString filePath;
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID);
|
||||
if (!ioService) return NS_ERROR_FAILURE;
|
||||
ioService->ExtractUrlPart(NS_ConvertUCS2toUTF8(aSearchItem).get(), nsIIOService::url_Directory, 0, 0, getter_Copies(filePath));
|
||||
|
||||
// Don't bother checking for hostname if the search string
|
||||
// already has a filepath;
|
||||
if (filePath && (nsCRT::strlen(filePath) > 1)) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURL> matchURL = do_CreateInstance(kStandardURLCID, &rv);
|
||||
if (matchURL) {
|
||||
matchURL->SetSpec(NS_ConvertUCS2toUTF8(aMatchStr).get());
|
||||
nsXPIDLCString filePath;
|
||||
matchURL->GetFilePath(getter_Copies(filePath));
|
||||
ioService->ExtractUrlPart(NS_ConvertUCS2toUTF8(aMatchStr).get(), nsIIOService::url_Directory, 0, 0, getter_Copies(filePath));
|
||||
|
||||
// If the match string doesn't have a filepath
|
||||
// we need to do nothing here, return.
|
||||
if (!filePath || (filePath && (nsCRT::strlen(filePath) <=1)))
|
||||
|
@ -678,7 +678,6 @@ nsUrlbarHistory::VerifyAndCreateEntry(const PRUnichar * aSearchItem, PRUnichar *
|
|||
array->InsertElementAt(newItem, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,8 +129,6 @@ nsInstallInfo::~nsInstallInfo()
|
|||
MOZ_COUNT_DTOR(nsInstallInfo);
|
||||
}
|
||||
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
||||
|
||||
static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID);
|
||||
static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID);
|
||||
|
||||
|
@ -1168,7 +1166,6 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur
|
|||
}
|
||||
nsresult ret;
|
||||
nsCOMPtr<nsIFile> resFile;
|
||||
nsCOMPtr<nsIFileURL> resFileURL = nsnull;
|
||||
nsIURI *url = nsnull;
|
||||
nsIStringBundleService* service = nsnull;
|
||||
nsIEventQueueService* pEventQueueService = nsnull;
|
||||
|
@ -1208,33 +1205,17 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur
|
|||
if (NS_FAILED(ret))
|
||||
goto cleanup;
|
||||
|
||||
// construct properties file URL as required by StringBundle interface
|
||||
|
||||
//nsCOMPtr<nsIFileURL> url;
|
||||
ret = nsComponentManager::CreateInstance(kStandardURLCID, nsnull,
|
||||
NS_GET_IID(nsIFileURL),
|
||||
getter_AddRefs(resFileURL));
|
||||
|
||||
if (NS_FAILED(ret)) goto cleanup;
|
||||
|
||||
ret = resFileURL->SetFile(resFile);
|
||||
|
||||
if (NS_FAILED(ret)) goto cleanup;
|
||||
|
||||
|
||||
// get the string bundle using the extracted properties file
|
||||
#if 1
|
||||
{
|
||||
char* spec = nsnull;
|
||||
ret = resFileURL->GetSpec(&spec);
|
||||
nsXPIDLCString spec;
|
||||
ret = resFile->GetURL(getter_Copies(spec));
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot get url spec\n");
|
||||
nsServiceManager::ReleaseService(kStringBundleServiceCID, service);
|
||||
nsCRT::free(spec);
|
||||
return ret;
|
||||
}
|
||||
ret = service->CreateBundle(spec, &bundle);
|
||||
nsCRT::free(spec);
|
||||
}
|
||||
#else
|
||||
ret = service->CreateBundle(url, &bundle);
|
||||
|
|
Загрузка…
Ссылка в новой задаче