gecko-dev/netwerk/protocol/file/nsFileProtocolHandler.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

279 строки
8.0 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// vim:ts=4 sw=2 sts=2 et cin:
2012-05-21 15:12:37 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
1999-06-11 05:37:24 +04:00
Bug 1238290 - fix bad necko deps on unified_sources r=valentin.gosu --- netwerk/base/ARefBase.h | 2 ++ netwerk/base/CaptivePortalService.cpp | 1 + netwerk/base/CaptivePortalService.h | 1 + netwerk/base/EventTokenBucket.cpp | 4 +++- netwerk/base/LoadContextInfo.cpp | 3 +++ netwerk/base/LoadInfo.cpp | 3 +++ netwerk/base/MemoryDownloader.cpp | 1 + netwerk/base/Predictor.cpp | 1 + netwerk/base/RedirectChannelRegistrar.h | 1 + netwerk/base/nsBaseChannel.cpp | 1 + netwerk/base/nsChannelClassifier.cpp | 1 + netwerk/base/nsDirectoryIndexStream.cpp | 3 ++- netwerk/base/nsDownloader.cpp | 1 + netwerk/base/nsIOService.cpp | 1 + netwerk/base/nsIncrementalDownload.cpp | 3 +++ netwerk/base/nsNetUtil.cpp | 4 ++++ netwerk/base/nsNetUtil.h | 1 + netwerk/base/nsProtocolProxyService.cpp | 1 + netwerk/base/nsSecCheckWrapChannel.cpp | 2 ++ netwerk/base/nsUDPSocket.cpp | 4 +++- netwerk/cache/nsDiskCacheBinding.cpp | 2 +- netwerk/cache/nsDiskCacheDeviceSQL.cpp | 2 ++ netwerk/cache/nsMemoryCacheDevice.cpp | 2 +- netwerk/cache2/CacheFileUtils.cpp | 2 ++ netwerk/cache2/CacheStorageService.h | 1 + netwerk/ipc/NeckoParent.cpp | 1 + netwerk/ipc/RemoteOpenFileChild.cpp | 1 + netwerk/protocol/about/nsAboutBloat.cpp | 1 + netwerk/protocol/about/nsAboutCacheEntry.cpp | 1 + netwerk/protocol/about/nsAboutProtocolHandler.cpp | 1 + netwerk/protocol/data/DataChannelParent.cpp | 1 + netwerk/protocol/file/nsFileProtocolHandler.cpp | 1 + netwerk/protocol/ftp/FTPChannelParent.cpp | 2 ++ netwerk/protocol/ftp/FTPChannelParent.h | 1 + netwerk/protocol/ftp/nsFtpConnectionThread.cpp | 1 + netwerk/protocol/ftp/nsFtpProtocolHandler.h | 1 + netwerk/protocol/http/Http2Compression.cpp | 1 + netwerk/protocol/http/Http2Session.cpp | 1 + netwerk/protocol/http/Http2Stream.h | 2 ++ netwerk/protocol/http/HttpBaseChannel.cpp | 4 ++++ netwerk/protocol/http/HttpBaseChannel.h | 1 + netwerk/protocol/http/HttpChannelChild.cpp | 25 ++-------------------- netwerk/protocol/http/HttpChannelChild.h | 24 +++++++++++++++++++++ netwerk/protocol/http/HttpChannelParent.cpp | 1 + netwerk/protocol/http/HttpChannelParent.h | 1 + .../protocol/http/HttpChannelParentListener.cpp | 1 + netwerk/protocol/http/HttpChannelParentListener.h | 1 + netwerk/protocol/http/InterceptedChannel.cpp | 1 + netwerk/protocol/http/NullHttpChannel.cpp | 1 + netwerk/protocol/http/NullHttpTransaction.cpp | 1 + netwerk/protocol/http/PackagedAppService.cpp | 14 ++++++++++-- netwerk/protocol/http/PackagedAppService.h | 4 +++- netwerk/protocol/http/PackagedAppVerifier.cpp | 1 + netwerk/protocol/http/nsCORSListenerProxy.cpp | 2 +- netwerk/protocol/http/nsHttpBasicAuth.cpp | 1 + netwerk/protocol/http/nsHttpChannel.cpp | 2 ++ netwerk/protocol/http/nsHttpChunkedDecoder.cpp | 1 + netwerk/protocol/http/nsHttpConnectionInfo.cpp | 2 ++ netwerk/protocol/http/nsHttpConnectionMgr.cpp | 1 + netwerk/protocol/http/nsHttpDigestAuth.cpp | 1 + netwerk/protocol/viewsource/nsViewSourceHandler.h | 4 ++++ .../protocol/websocket/BaseWebSocketChannel.cpp | 1 + .../websocket/WebSocketEventListenerParent.cpp | 1 + .../protocol/websocket/WebSocketEventService.cpp | 3 +++ netwerk/protocol/websocket/WebSocketFrame.cpp | 2 ++ netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp | 1 + .../protocol/wyciwyg/nsWyciwygProtocolHandler.cpp | 1 + netwerk/streamconv/converters/mozTXTToHTMLConv.cpp | 1 + .../streamconv/converters/nsFTPDirListingConv.cpp | 1 + .../streamconv/converters/nsHTTPCompressConv.cpp | 2 ++ netwerk/streamconv/converters/nsHTTPCompressConv.h | 1 + netwerk/streamconv/converters/nsIndexedToHTML.cpp | 1 + netwerk/streamconv/converters/nsMultiMixedConv.cpp | 2 ++ netwerk/streamconv/converters/nsTXTToHTMLConv.cpp | 2 ++ netwerk/streamconv/converters/nsUnknownDecoder.cpp | 2 ++ 75 files changed, 147 insertions(+), 32 deletions(-)
2016-01-09 04:20:50 +03:00
#include "nsIFile.h"
1999-06-11 05:37:24 +04:00
#include "nsFileProtocolHandler.h"
#include "nsFileChannel.h"
#include "nsStandardURL.h"
#include "nsURLHelper.h"
#include "nsIURIMutator.h"
#include "nsNetUtil.h"
#include "FileChannelChild.h"
#include "mozilla/ResultExtensions.h"
// URL file handling, copied and modified from
// xpfe/components/bookmarks/src/nsBookmarksService.cpp
#ifdef XP_WIN
# include <shlobj.h>
# include <intshcut.h>
# include "nsIFileURL.h"
# ifdef CompareString
# undef CompareString
# endif
#endif
1999-06-11 05:37:24 +04:00
// URL file handling for freedesktop.org
#ifdef XP_UNIX
# include "nsINIParser.h"
# define DESKTOP_ENTRY_SECTION "Desktop Entry"
#endif
//-----------------------------------------------------------------------------
1999-06-11 05:37:24 +04:00
nsresult nsFileProtocolHandler::Init() { return NS_OK; }
NS_IMPL_ISUPPORTS(nsFileProtocolHandler, nsIFileProtocolHandler,
nsIProtocolHandler, nsISupportsWeakReference)
1999-06-11 05:37:24 +04:00
//-----------------------------------------------------------------------------
1999-06-11 05:37:24 +04:00
// nsIProtocolHandler methods:
#if defined(XP_WIN)
NS_IMETHODIMP
nsFileProtocolHandler::ReadURLFile(nsIFile* aFile, nsIURI** aURI) {
nsAutoString path;
2004-07-16 01:10:06 +04:00
nsresult rv = aFile->GetPath(path);
if (NS_FAILED(rv)) return rv;
if (path.Length() < 4) return NS_ERROR_NOT_AVAILABLE;
if (!StringTail(path, 4).LowerCaseEqualsLiteral(".url"))
return NS_ERROR_NOT_AVAILABLE;
HRESULT result;
rv = NS_ERROR_NOT_AVAILABLE;
IUniformResourceLocatorW* urlLink = nullptr;
result =
::CoCreateInstance(CLSID_InternetShortcut, nullptr, CLSCTX_INPROC_SERVER,
IID_IUniformResourceLocatorW, (void**)&urlLink);
if (SUCCEEDED(result) && urlLink) {
IPersistFile* urlFile = nullptr;
result = urlLink->QueryInterface(IID_IPersistFile, (void**)&urlFile);
if (SUCCEEDED(result) && urlFile) {
result = urlFile->Load(path.get(), STGM_READ);
if (SUCCEEDED(result)) {
LPWSTR lpTemp = nullptr;
// The URL this method will give us back seems to be already
// escaped. Hence, do not do escaping of our own.
result = urlLink->GetURL(&lpTemp);
if (SUCCEEDED(result) && lpTemp) {
rv = NS_NewURI(aURI, nsDependentString(lpTemp));
// free the string that GetURL alloc'd
CoTaskMemFree(lpTemp);
}
}
urlFile->Release();
}
urlLink->Release();
}
return rv;
}
#elif defined(XP_UNIX)
NS_IMETHODIMP
nsFileProtocolHandler::ReadURLFile(nsIFile* aFile, nsIURI** aURI) {
// We only support desktop files that end in ".desktop" like the spec says:
// http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s02.html
nsAutoCString leafName;
nsresult rv = aFile->GetNativeLeafName(leafName);
if (NS_FAILED(rv) || !StringEndsWith(leafName, ".desktop"_ns)) {
return NS_ERROR_NOT_AVAILABLE;
}
bool isFile = false;
rv = aFile->IsFile(&isFile);
if (NS_FAILED(rv) || !isFile) {
return NS_ERROR_NOT_AVAILABLE;
}
nsINIParser parser;
rv = parser.Init(aFile);
if (NS_FAILED(rv)) return rv;
nsAutoCString type;
parser.GetString(DESKTOP_ENTRY_SECTION, "Type", type);
if (!type.EqualsLiteral("Link")) return NS_ERROR_NOT_AVAILABLE;
nsAutoCString url;
rv = parser.GetString(DESKTOP_ENTRY_SECTION, "URL", url);
if (NS_FAILED(rv) || url.IsEmpty()) return NS_ERROR_NOT_AVAILABLE;
return NS_NewURI(aURI, url);
}
#else // other platforms
NS_IMETHODIMP
nsFileProtocolHandler::ReadURLFile(nsIFile* aFile, nsIURI** aURI) {
return NS_ERROR_NOT_AVAILABLE;
}
#endif // ReadURLFile()
NS_IMETHODIMP
nsFileProtocolHandler::ReadShellLink(nsIFile* aFile, nsIURI** aURI) {
#if defined(XP_WIN)
nsAutoString path;
MOZ_TRY(aFile->GetPath(path));
if (path.Length() < 4 ||
!StringTail(path, 4).LowerCaseEqualsLiteral(".lnk")) {
return NS_ERROR_NOT_AVAILABLE;
}
RefPtr<IPersistFile> persistFile;
RefPtr<IShellLinkW> shellLink;
WCHAR lpTemp[MAX_PATH];
// Get a pointer to the IPersistFile interface.
if (FAILED(CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER,
IID_IShellLinkW, getter_AddRefs(shellLink))) ||
FAILED(shellLink->QueryInterface(IID_IPersistFile,
getter_AddRefs(persistFile))) ||
FAILED(persistFile->Load(path.get(), STGM_READ)) ||
FAILED(shellLink->Resolve(nullptr, SLR_NO_UI)) ||
FAILED(shellLink->GetPath(lpTemp, MAX_PATH, nullptr, SLGP_UNCPRIORITY))) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIFile> linkedFile;
MOZ_TRY(NS_NewLocalFile(nsDependentString(lpTemp), false,
getter_AddRefs(linkedFile)));
return NS_NewFileURI(aURI, linkedFile);
#else
return NS_ERROR_NOT_AVAILABLE;
#endif
}
1999-06-11 05:37:24 +04:00
NS_IMETHODIMP
nsFileProtocolHandler::GetScheme(nsACString& result) {
result.AssignLiteral("file");
1999-06-11 05:37:24 +04:00
return NS_OK;
}
NS_IMETHODIMP
nsFileProtocolHandler::GetDefaultPort(int32_t* result) {
1999-06-17 07:38:23 +04:00
*result = -1; // no port for file: URLs
1999-06-11 05:37:24 +04:00
return NS_OK;
}
NS_IMETHODIMP
nsFileProtocolHandler::GetProtocolFlags(uint32_t* result) {
*result = URI_NOAUTH | URI_IS_LOCAL_FILE | URI_IS_LOCAL_RESOURCE |
URI_IS_POTENTIALLY_TRUSTWORTHY;
return NS_OK;
}
1999-06-11 05:37:24 +04:00
NS_IMETHODIMP
nsFileProtocolHandler::NewChannel(nsIURI* uri, nsILoadInfo* aLoadInfo,
nsIChannel** result) {
nsresult rv;
RefPtr<nsFileChannel> chan;
if (IsNeckoChild()) {
chan = new mozilla::net::FileChannelChild(uri);
} else {
chan = new nsFileChannel(uri);
}
// set the loadInfo on the new channel ; must do this
// before calling Init() on it, since it needs the load
// info be already set.
rv = chan->SetLoadInfo(aLoadInfo);
1999-06-11 05:37:24 +04:00
if (NS_FAILED(rv)) {
return rv;
}
rv = chan->Init();
if (NS_FAILED(rv)) {
return rv;
}
chan.forget(result);
1999-06-11 05:37:24 +04:00
return NS_OK;
}
NS_IMETHODIMP
nsFileProtocolHandler::AllowPort(int32_t port, const char* scheme,
bool* result) {
// don't override anything.
*result = false;
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsIFileProtocolHandler methods:
NS_IMETHODIMP
nsFileProtocolHandler::NewFileURI(nsIFile* aFile, nsIURI** aResult) {
NS_ENSURE_ARG_POINTER(aFile);
RefPtr<nsIFile> file(aFile);
// NOTE: the origin charset is assigned the value of the platform
// charset by the SetFile method.
return NS_MutateURI(new nsStandardURL::Mutator())
.Apply(&nsIFileURLMutator::SetFile, file)
.Finalize(aResult);
}
NS_IMETHODIMP
nsFileProtocolHandler::NewFileURIMutator(nsIFile* aFile,
nsIURIMutator** aResult) {
NS_ENSURE_ARG_POINTER(aFile);
nsresult rv;
nsCOMPtr<nsIURIMutator> mutator = new nsStandardURL::Mutator();
nsCOMPtr<nsIFileURLMutator> fileMutator = do_QueryInterface(mutator, &rv);
if (NS_FAILED(rv)) {
return rv;
}
// NOTE: the origin charset is assigned the value of the platform
// charset by the SetFile method.
rv = fileMutator->SetFile(aFile);
if (NS_FAILED(rv)) {
return rv;
}
mutator.forget(aResult);
return NS_OK;
}
NS_IMETHODIMP
nsFileProtocolHandler::GetURLSpecFromFile(nsIFile* file, nsACString& result) {
NS_ENSURE_ARG_POINTER(file);
return net_GetURLSpecFromFile(file, result);
}
NS_IMETHODIMP
nsFileProtocolHandler::GetURLSpecFromActualFile(nsIFile* file,
nsACString& result) {
NS_ENSURE_ARG_POINTER(file);
return net_GetURLSpecFromActualFile(file, result);
}
NS_IMETHODIMP
nsFileProtocolHandler::GetURLSpecFromDir(nsIFile* file, nsACString& result) {
NS_ENSURE_ARG_POINTER(file);
return net_GetURLSpecFromDir(file, result);
}
NS_IMETHODIMP
nsFileProtocolHandler::GetFileFromURLSpec(const nsACString& spec,
nsIFile** result) {
return net_GetFileFromURLSpec(spec, result);
}