Bug 1481176 - P2. Move nsContentTypeParser to its own file. r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D2800
This commit is contained in:
Jean-Yves Avenard 2018-08-07 17:24:07 +02:00
parent 35a7076534
commit e4e8c5f1a8
3 changed files with 41 additions and 33 deletions

View File

@ -299,6 +299,7 @@ UNIFIED_SOURCES += [
'nsContentPermissionHelper.cpp',
'nsContentPolicy.cpp',
'nsContentSink.cpp',
'nsContentTypeParser.cpp',
'nsCopySupport.cpp',
'nsDataDocumentContentPolicy.cpp',
'nsDocument.cpp',

View File

@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "nsContentTypeParser.h"
#include "nsContentUtils.h"
nsContentTypeParser::nsContentTypeParser(const nsAString& aString)
: mString(aString)
, mService(nullptr)
{
CallGetService("@mozilla.org/network/mime-hdrparam;1", &mService);
}
nsContentTypeParser::~nsContentTypeParser()
{
NS_IF_RELEASE(mService);
}
nsresult
nsContentTypeParser::GetParameter(const char* aParameterName,
nsAString& aResult) const
{
NS_ENSURE_TRUE(mService, NS_ERROR_FAILURE);
return mService->GetParameterHTTP(
mString, aParameterName, EmptyCString(), false, nullptr, aResult);
}
nsresult
nsContentTypeParser::GetType(nsAString& aResult) const
{
nsresult rv = GetParameter(nullptr, aResult);
if (NS_FAILED(rv)) {
return rv;
}
nsContentUtils::ASCIIToLower(aResult);
return NS_OK;
}

View File

@ -6424,40 +6424,7 @@ nsContentUtils::CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel, boo
return NS_SUCCEEDED(aPrincipal->CheckMayLoad(channelURI, false, aAllowIfInheritsPrincipal));
}
nsContentTypeParser::nsContentTypeParser(const nsAString& aString)
: mString(aString), mService(nullptr)
{
CallGetService("@mozilla.org/network/mime-hdrparam;1", &mService);
}
nsContentTypeParser::~nsContentTypeParser()
{
NS_IF_RELEASE(mService);
}
nsresult
nsContentTypeParser::GetParameter(const char* aParameterName,
nsAString& aResult) const
{
NS_ENSURE_TRUE(mService, NS_ERROR_FAILURE);
return mService->GetParameterHTTP(mString, aParameterName,
EmptyCString(), false, nullptr,
aResult);
}
nsresult
nsContentTypeParser::GetType(nsAString& aResult) const
{
nsresult rv = GetParameter(nullptr, aResult);
if (NS_FAILED(rv)) {
return rv;
}
nsContentUtils::ASCIIToLower(aResult);
return NS_OK;
}
/* static */
bool
nsContentUtils::CanAccessNativeAnon()
{