2012-03-05 19:22:28 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-04-09 20:25:05 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2016-12-16 06:13:08 +03:00
|
|
|
#include "mozilla/Printf.h"
|
|
|
|
#include "mozilla/UniquePtr.h"
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
#include "ManifestParser.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "prio.h"
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
# include <windows.h>
|
|
|
|
#elif defined(MOZ_WIDGET_COCOA)
|
|
|
|
# include <CoreServices/CoreServices.h>
|
2013-12-19 20:42:19 +04:00
|
|
|
# include "nsCocoaFeatures.h"
|
2012-06-16 10:05:00 +04:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2012-03-05 19:22:28 +04:00
|
|
|
# include <gtk/gtk.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
# include "AndroidBridge.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
|
2012-03-13 02:53:18 +04:00
|
|
|
#include "nsCRT.h"
|
2012-03-05 19:22:28 +04:00
|
|
|
#include "nsConsoleMessage.h"
|
|
|
|
#include "nsTextFormatter.h"
|
|
|
|
#include "nsVersionComparator.h"
|
|
|
|
#include "nsXPCOMCIDInternal.h"
|
|
|
|
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
#include "nsIXULRuntime.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
struct ManifestDirective {
|
|
|
|
const char* directive;
|
|
|
|
int argc;
|
|
|
|
|
|
|
|
bool ischrome;
|
|
|
|
|
2017-06-08 12:44:09 +03:00
|
|
|
// The contentaccessible flags only apply to content/resource directives.
|
2012-03-05 19:22:28 +04:00
|
|
|
bool contentflags;
|
|
|
|
|
|
|
|
// Function to handle this directive. This isn't a union because C++ still
|
|
|
|
// hasn't learned how to initialize unions in a sane way.
|
2014-08-03 00:44:06 +04:00
|
|
|
void (nsComponentManagerImpl::*mgrfunc)(
|
|
|
|
nsComponentManagerImpl::ManifestProcessingContext& aCx, int aLineNo,
|
|
|
|
char* const* aArgv);
|
|
|
|
void (nsChromeRegistry::*regfunc)(
|
|
|
|
nsChromeRegistry::ManifestProcessingContext& aCx, int aLineNo,
|
2015-02-05 19:09:15 +03:00
|
|
|
char* const* aArgv, int aFlags);
|
2012-03-05 19:22:28 +04:00
|
|
|
};
|
|
|
|
static const ManifestDirective kParsingTable[] = {
|
2018-10-12 23:48:24 +03:00
|
|
|
// clang-format off
|
2014-08-03 00:44:06 +04:00
|
|
|
{
|
2018-08-01 02:44:52 +03:00
|
|
|
"manifest", 1, true, false,
|
2018-03-09 00:58:29 +03:00
|
|
|
&nsComponentManagerImpl::ManifestManifest, nullptr,
|
2014-08-03 00:44:06 +04:00
|
|
|
},
|
2018-08-07 17:30:52 +03:00
|
|
|
{
|
2018-08-01 02:44:52 +03:00
|
|
|
"component", 2, false, false,
|
2018-03-09 00:58:29 +03:00
|
|
|
&nsComponentManagerImpl::ManifestComponent, nullptr,
|
2014-08-03 00:44:06 +04:00
|
|
|
},
|
|
|
|
{
|
2018-08-01 02:44:52 +03:00
|
|
|
"contract", 2, false, false,
|
2018-03-09 00:58:29 +03:00
|
|
|
&nsComponentManagerImpl::ManifestContract, nullptr,
|
2014-08-03 00:44:06 +04:00
|
|
|
},
|
|
|
|
{
|
2018-08-01 02:44:52 +03:00
|
|
|
"category", 3, false, false,
|
2018-03-09 00:58:29 +03:00
|
|
|
&nsComponentManagerImpl::ManifestCategory, nullptr,
|
2014-08-03 00:44:06 +04:00
|
|
|
},
|
|
|
|
{
|
2018-08-01 02:44:52 +03:00
|
|
|
"content", 2, true, true,
|
2018-03-09 00:58:29 +03:00
|
|
|
nullptr, &nsChromeRegistry::ManifestContent,
|
2014-08-03 00:44:06 +04:00
|
|
|
},
|
|
|
|
{
|
2018-08-01 02:44:52 +03:00
|
|
|
"locale", 3, true, false,
|
2018-03-09 00:58:29 +03:00
|
|
|
nullptr, &nsChromeRegistry::ManifestLocale,
|
2014-08-03 00:44:06 +04:00
|
|
|
},
|
|
|
|
{
|
2018-08-01 02:44:52 +03:00
|
|
|
"skin", 3, true, false,
|
2018-03-09 00:58:29 +03:00
|
|
|
nullptr, &nsChromeRegistry::ManifestSkin,
|
2014-08-03 00:44:06 +04:00
|
|
|
},
|
|
|
|
{
|
2015-06-01 19:05:39 +03:00
|
|
|
// NB: note that while skin manifests can use this, they are only allowed
|
|
|
|
// to use it for chrome://../skin/ URLs
|
2018-08-01 02:44:52 +03:00
|
|
|
"override", 2, true, false,
|
2018-03-09 00:58:29 +03:00
|
|
|
nullptr, &nsChromeRegistry::ManifestOverride,
|
2014-08-03 00:44:06 +04:00
|
|
|
},
|
|
|
|
{
|
2018-08-01 02:44:52 +03:00
|
|
|
"resource", 2, false, true,
|
2018-03-09 00:58:29 +03:00
|
|
|
nullptr, &nsChromeRegistry::ManifestResource,
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2018-10-12 23:48:24 +03:00
|
|
|
// clang-format on
|
2012-03-05 19:22:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char kWhitespace[] = "\t ";
|
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
static bool IsNewline(char aChar) { return aChar == '\n' || aChar == '\r'; }
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
void LogMessage(const char* aMsg, ...) {
|
2018-03-09 00:58:29 +03:00
|
|
|
MOZ_ASSERT(nsComponentManagerImpl::gComponentManager);
|
2014-07-26 04:52:00 +04:00
|
|
|
|
2012-03-05 19:22:28 +04:00
|
|
|
nsCOMPtr<nsIConsoleService> console =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
2014-08-03 00:44:06 +04:00
|
|
|
if (!console) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, aMsg);
|
2016-12-16 06:13:08 +03:00
|
|
|
SmprintfPointer formatted(mozilla::Vsmprintf(aMsg, args));
|
2012-03-05 19:22:28 +04:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleMessage> error =
|
2016-12-16 06:13:08 +03:00
|
|
|
new nsConsoleMessage(NS_ConvertUTF8toUTF16(formatted.get()).get());
|
2012-03-05 19:22:28 +04:00
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
void LogMessageWithContext(FileLocation& aFile, uint32_t aLineNumber,
|
|
|
|
const char* aMsg, ...) {
|
2012-03-05 19:22:28 +04:00
|
|
|
va_list args;
|
|
|
|
va_start(args, aMsg);
|
2016-12-16 06:13:08 +03:00
|
|
|
SmprintfPointer formatted(mozilla::Vsmprintf(aMsg, args));
|
2012-03-05 19:22:28 +04:00
|
|
|
va_end(args);
|
2014-08-03 00:44:06 +04:00
|
|
|
if (!formatted) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2018-03-09 00:58:29 +03:00
|
|
|
MOZ_ASSERT(nsComponentManagerImpl::gComponentManager);
|
2014-07-26 04:52:00 +04:00
|
|
|
|
2012-03-05 19:22:28 +04:00
|
|
|
nsCString file;
|
|
|
|
aFile.GetURIString(file);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptError> error = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
|
|
|
|
if (!error) {
|
|
|
|
// This can happen early in component registration. Fall back to a
|
|
|
|
// generic console message.
|
|
|
|
LogMessage("Warning: in '%s', line %i: %s", file.get(), aLineNumber,
|
2016-12-16 06:13:08 +03:00
|
|
|
formatted.get());
|
2012-03-05 19:22:28 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService> console =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
2014-08-03 00:44:06 +04:00
|
|
|
if (!console) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2016-12-16 06:13:08 +03:00
|
|
|
nsresult rv = error->Init(
|
|
|
|
NS_ConvertUTF8toUTF16(formatted.get()), NS_ConvertUTF8toUTF16(file),
|
2014-08-03 00:44:06 +04:00
|
|
|
EmptyString(), aLineNumber, 0, nsIScriptError::warningFlag,
|
2019-04-02 01:42:34 +03:00
|
|
|
"chrome registration", false /* from private window */,
|
|
|
|
true /* from chrome context */);
|
2014-08-03 00:44:06 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for a modifier flag of the following forms:
|
|
|
|
* "flag" (same as "true")
|
|
|
|
* "flag=yes|true|1"
|
|
|
|
* "flag="no|false|0"
|
|
|
|
* @param aFlag The flag to compare.
|
|
|
|
* @param aData The tokenized data to check; this is lowercased
|
|
|
|
* before being passed in.
|
|
|
|
* @param aResult If the flag is found, the value is assigned here.
|
|
|
|
* @return Whether the flag was handled.
|
|
|
|
*/
|
2017-06-20 12:19:52 +03:00
|
|
|
static bool CheckFlag(const nsAString& aFlag, const nsAString& aData,
|
|
|
|
bool& aResult) {
|
2014-08-03 00:44:06 +04:00
|
|
|
if (!StringBeginsWith(aData, aFlag)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return false;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
if (aFlag.Length() == aData.Length()) {
|
|
|
|
// the data is simply "flag", which is the same as "flag=yes"
|
|
|
|
aResult = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.CharAt(aFlag.Length()) != '=') {
|
|
|
|
// the data is "flag2=", which is not anything we care about
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData.Length() == aFlag.Length() + 1) {
|
|
|
|
aResult = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aData.CharAt(aFlag.Length() + 1)) {
|
2014-08-03 00:44:06 +04:00
|
|
|
case '1':
|
|
|
|
case 't': // true
|
|
|
|
case 'y': // yes
|
|
|
|
aResult = true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case '0':
|
|
|
|
case 'f': // false
|
|
|
|
case 'n': // no
|
|
|
|
aResult = false;
|
|
|
|
return true;
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum TriState { eUnspecified, eBad, eOK };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for a modifier flag of the following form:
|
|
|
|
* "flag=string"
|
|
|
|
* "flag!=string"
|
|
|
|
* @param aFlag The flag to compare.
|
|
|
|
* @param aData The tokenized data to check; this is lowercased
|
|
|
|
* before being passed in.
|
|
|
|
* @param aValue The value that is expected.
|
|
|
|
* @param aResult If this is "ok" when passed in, this is left alone.
|
|
|
|
* Otherwise if the flag is found it is set to eBad or eOK.
|
|
|
|
* @return Whether the flag was handled.
|
|
|
|
*/
|
2017-06-20 12:19:52 +03:00
|
|
|
static bool CheckStringFlag(const nsAString& aFlag, const nsAString& aData,
|
|
|
|
const nsAString& aValue, TriState& aResult) {
|
2014-08-03 00:44:06 +04:00
|
|
|
if (aData.Length() < aFlag.Length() + 1) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return false;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
if (!StringBeginsWith(aData, aFlag)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return false;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
bool comparison = true;
|
|
|
|
if (aData[aFlag.Length()] != '=') {
|
|
|
|
if (aData[aFlag.Length()] == '!' && aData.Length() >= aFlag.Length() + 2 &&
|
2014-08-03 00:44:06 +04:00
|
|
|
aData[aFlag.Length() + 1] == '=') {
|
2012-03-05 19:22:28 +04:00
|
|
|
comparison = false;
|
2014-08-03 00:44:06 +04:00
|
|
|
} else {
|
2012-03-05 19:22:28 +04:00
|
|
|
return false;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aResult != eOK) {
|
2014-08-03 00:44:06 +04:00
|
|
|
nsDependentSubstring testdata =
|
|
|
|
Substring(aData, aFlag.Length() + (comparison ? 1 : 2));
|
|
|
|
if (testdata.Equals(aValue)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
aResult = comparison ? eOK : eBad;
|
2014-08-03 00:44:06 +04:00
|
|
|
} else {
|
2012-03-05 19:22:28 +04:00
|
|
|
aResult = comparison ? eBad : eOK;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:19:52 +03:00
|
|
|
static bool CheckOsFlag(const nsAString& aFlag, const nsAString& aData,
|
|
|
|
const nsAString& aValue, TriState& aResult) {
|
Bug 1365419 - Allow to apply manifest entries for all non-(Darwin,Windows,Android) OSes. r=bsmedberg
Manifest entries can contain flags, one of which allows to match on the
os running Gecko. The match is performed against the value returned by
nsIXULRuntime.getOS, which itself comes from the build-system's
OS_TARGET.
In practice, this means that things like os=WINNT, os=Darwin,
os=Android, os=Linux are valid filters, but the latter is too specific,
and most of the time, one would want something that is "any OS but
WINNT, Darwin, Android", which can't be expressed with manifest entry
flags (there is no "and" for them, only "or").
For convenience, we add the keyword "LikeUnix", which has that meaning.
--HG--
extra : rebase_source : faf3986d2a4361d12a512752e15e81270be224ef
2017-05-26 02:56:18 +03:00
|
|
|
bool result = CheckStringFlag(aFlag, aData, aValue, aResult);
|
|
|
|
#if defined(XP_UNIX) && !defined(XP_DARWIN) && !defined(ANDROID)
|
|
|
|
if (result && aResult == eBad) {
|
|
|
|
result =
|
|
|
|
CheckStringFlag(aFlag, aData, NS_LITERAL_STRING("likeunix"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:22:28 +04:00
|
|
|
/**
|
|
|
|
* Check for a modifier flag of the following form:
|
|
|
|
* "flag=version"
|
|
|
|
* "flag<=version"
|
|
|
|
* "flag<version"
|
|
|
|
* "flag>=version"
|
|
|
|
* "flag>version"
|
|
|
|
* @param aFlag The flag to compare.
|
|
|
|
* @param aData The tokenized data to check; this is lowercased
|
|
|
|
* before being passed in.
|
|
|
|
* @param aValue The value that is expected. If this is empty then no
|
|
|
|
* comparison will match.
|
|
|
|
* @param aResult If this is eOK when passed in, this is left alone.
|
|
|
|
* Otherwise if the flag is found it is set to eBad or eOK.
|
|
|
|
* @return Whether the flag was handled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COMPARE_EQ 1 << 0
|
|
|
|
#define COMPARE_LT 1 << 1
|
|
|
|
#define COMPARE_GT 1 << 2
|
|
|
|
|
|
|
|
static bool CheckVersionFlag(const nsString& aFlag, const nsString& aData,
|
|
|
|
const nsString& aValue, TriState& aResult) {
|
2014-08-03 00:44:06 +04:00
|
|
|
if (aData.Length() < aFlag.Length() + 2) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return false;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
if (!StringBeginsWith(aData, aFlag)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return false;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
if (aValue.Length() == 0) {
|
2014-08-03 00:44:06 +04:00
|
|
|
if (aResult != eOK) {
|
2012-03-05 19:22:28 +04:00
|
|
|
aResult = eBad;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t comparison;
|
2012-03-05 19:22:28 +04:00
|
|
|
nsAutoString testdata;
|
|
|
|
|
|
|
|
switch (aData[aFlag.Length()]) {
|
2014-08-03 00:44:06 +04:00
|
|
|
case '=':
|
|
|
|
comparison = COMPARE_EQ;
|
2012-03-05 19:22:28 +04:00
|
|
|
testdata = Substring(aData, aFlag.Length() + 1);
|
2014-08-03 00:44:06 +04:00
|
|
|
break;
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
case '<':
|
|
|
|
if (aData[aFlag.Length() + 1] == '=') {
|
|
|
|
comparison = COMPARE_EQ | COMPARE_LT;
|
|
|
|
testdata = Substring(aData, aFlag.Length() + 2);
|
|
|
|
} else {
|
|
|
|
comparison = COMPARE_LT;
|
|
|
|
testdata = Substring(aData, aFlag.Length() + 1);
|
|
|
|
}
|
|
|
|
break;
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
case '>':
|
|
|
|
if (aData[aFlag.Length() + 1] == '=') {
|
|
|
|
comparison = COMPARE_EQ | COMPARE_GT;
|
|
|
|
testdata = Substring(aData, aFlag.Length() + 2);
|
|
|
|
} else {
|
|
|
|
comparison = COMPARE_GT;
|
|
|
|
testdata = Substring(aData, aFlag.Length() + 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
if (testdata.Length() == 0) {
|
2012-03-05 19:22:28 +04:00
|
|
|
return false;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
if (aResult != eOK) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t c = mozilla::CompareVersions(NS_ConvertUTF16toUTF8(aValue).get(),
|
2012-04-19 07:22:29 +04:00
|
|
|
NS_ConvertUTF16toUTF8(testdata).get());
|
2012-03-05 19:22:28 +04:00
|
|
|
if ((c == 0 && comparison & COMPARE_EQ) ||
|
2014-08-03 00:44:06 +04:00
|
|
|
(c < 0 && comparison & COMPARE_LT) ||
|
|
|
|
(c > 0 && comparison & COMPARE_GT)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
aResult = eOK;
|
2014-08-03 00:44:06 +04:00
|
|
|
} else {
|
2012-03-05 19:22:28 +04:00
|
|
|
aResult = eBad;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In-place conversion of ascii characters to lower case
|
2014-08-03 00:44:06 +04:00
|
|
|
static void ToLowerCase(char* aToken) {
|
|
|
|
for (; *aToken; ++aToken) {
|
|
|
|
*aToken = NS_ToLower(*aToken);
|
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct CachedDirective {
|
|
|
|
int lineno;
|
|
|
|
char* argv[4];
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
void ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
|
2018-03-09 00:58:29 +03:00
|
|
|
bool aChromeOnly) {
|
2014-08-03 00:44:06 +04:00
|
|
|
nsComponentManagerImpl::ManifestProcessingContext mgrcx(aType, aFile,
|
|
|
|
aChromeOnly);
|
|
|
|
nsChromeRegistry::ManifestProcessingContext chromecx(aType, aFile);
|
2012-03-05 19:22:28 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(kContentAccessible, "contentaccessible");
|
2015-02-05 19:09:15 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(kRemoteEnabled, "remoteenabled");
|
|
|
|
NS_NAMED_LITERAL_STRING(kRemoteRequired, "remoterequired");
|
2012-03-05 19:22:28 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(kApplication, "application");
|
|
|
|
NS_NAMED_LITERAL_STRING(kAppVersion, "appversion");
|
|
|
|
NS_NAMED_LITERAL_STRING(kGeckoVersion, "platformversion");
|
|
|
|
NS_NAMED_LITERAL_STRING(kOs, "os");
|
|
|
|
NS_NAMED_LITERAL_STRING(kOsVersion, "osversion");
|
|
|
|
NS_NAMED_LITERAL_STRING(kABI, "abi");
|
2014-10-07 22:46:24 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(kProcess, "process");
|
2012-03-05 19:22:28 +04:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
NS_NAMED_LITERAL_STRING(kTablet, "tablet");
|
|
|
|
#endif
|
|
|
|
|
2014-10-07 22:46:24 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(kMain, "main");
|
|
|
|
NS_NAMED_LITERAL_STRING(kContent, "content");
|
|
|
|
|
2012-03-05 19:22:28 +04:00
|
|
|
// Obsolete
|
|
|
|
NS_NAMED_LITERAL_STRING(kXPCNativeWrappers, "xpcnativewrappers");
|
|
|
|
|
|
|
|
nsAutoString appID;
|
|
|
|
nsAutoString appVersion;
|
|
|
|
nsAutoString geckoVersion;
|
|
|
|
nsAutoString osTarget;
|
|
|
|
nsAutoString abi;
|
2014-10-07 22:46:24 +04:00
|
|
|
nsAutoString process;
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2018-03-09 00:58:29 +03:00
|
|
|
nsCOMPtr<nsIXULAppInfo> xapp(do_GetService(XULAPPINFO_SERVICE_CONTRACTID));
|
2012-03-05 19:22:28 +04:00
|
|
|
if (xapp) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString s;
|
2012-03-05 19:22:28 +04:00
|
|
|
rv = xapp->GetID(s);
|
2014-08-03 00:44:06 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
CopyUTF8toUTF16(s, appID);
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
rv = xapp->GetVersion(s);
|
2014-08-03 00:44:06 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
CopyUTF8toUTF16(s, appVersion);
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
rv = xapp->GetPlatformVersion(s);
|
2014-08-03 00:44:06 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
CopyUTF8toUTF16(s, geckoVersion);
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
nsCOMPtr<nsIXULRuntime> xruntime(do_QueryInterface(xapp));
|
2012-03-05 19:22:28 +04:00
|
|
|
if (xruntime) {
|
|
|
|
rv = xruntime->GetOS(s);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
ToLowerCase(s);
|
|
|
|
CopyUTF8toUTF16(s, osTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = xruntime->GetXPCOMABI(s);
|
|
|
|
if (NS_SUCCEEDED(rv) && osTarget.Length()) {
|
|
|
|
ToLowerCase(s);
|
|
|
|
CopyUTF8toUTF16(s, abi);
|
2014-01-04 19:02:17 +04:00
|
|
|
abi.Insert(char16_t('_'), 0);
|
2012-03-05 19:22:28 +04:00
|
|
|
abi.Insert(osTarget, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString osVersion;
|
|
|
|
#if defined(XP_WIN)
|
2014-01-29 03:37:47 +04:00
|
|
|
# pragma warning(push)
|
|
|
|
# pragma warning(disable : 4996) // VC12+ deprecates GetVersionEx
|
2012-03-05 19:22:28 +04:00
|
|
|
OSVERSIONINFO info = {sizeof(OSVERSIONINFO)};
|
|
|
|
if (GetVersionEx(&info)) {
|
2016-07-21 08:03:25 +03:00
|
|
|
nsTextFormatter::ssprintf(osVersion, u"%ld.%ld", info.dwMajorVersion,
|
2014-08-03 00:44:06 +04:00
|
|
|
info.dwMinorVersion);
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
2014-01-29 03:37:47 +04:00
|
|
|
# pragma warning(pop)
|
2012-03-05 19:22:28 +04:00
|
|
|
#elif defined(MOZ_WIDGET_COCOA)
|
2013-12-19 20:42:19 +04:00
|
|
|
SInt32 majorVersion = nsCocoaFeatures::OSXVersionMajor();
|
|
|
|
SInt32 minorVersion = nsCocoaFeatures::OSXVersionMinor();
|
2016-07-21 08:03:25 +03:00
|
|
|
nsTextFormatter::ssprintf(osVersion, u"%ld.%ld", majorVersion, minorVersion);
|
2013-06-10 16:36:26 +04:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2016-07-21 08:03:25 +03:00
|
|
|
nsTextFormatter::ssprintf(osVersion, u"%ld.%ld", gtk_major_version,
|
2014-08-03 00:44:06 +04:00
|
|
|
gtk_minor_version);
|
2012-03-05 19:22:28 +04:00
|
|
|
#elif defined(MOZ_WIDGET_ANDROID)
|
|
|
|
bool isTablet = false;
|
|
|
|
if (mozilla::AndroidBridge::Bridge()) {
|
2014-08-03 00:44:06 +04:00
|
|
|
mozilla::AndroidBridge::Bridge()->GetStaticStringField(
|
|
|
|
"android/os/Build$VERSION", "RELEASE", osVersion);
|
2016-07-21 20:49:04 +03:00
|
|
|
isTablet = java::GeckoAppShell::IsTablet();
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2014-10-07 22:46:24 +04:00
|
|
|
process = kContent;
|
|
|
|
} else {
|
|
|
|
process = kMain;
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:22:28 +04:00
|
|
|
// Because contracts must be registered after CIDs, we save and process them
|
|
|
|
// at the end.
|
|
|
|
nsTArray<CachedDirective> contracts;
|
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
char* token;
|
|
|
|
char* newline = aBuf;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t line = 0;
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
// outer loop tokenizes by newline
|
|
|
|
while (*newline) {
|
|
|
|
while (*newline && IsNewline(*newline)) {
|
|
|
|
++newline;
|
|
|
|
++line;
|
|
|
|
}
|
2014-08-03 00:44:06 +04:00
|
|
|
if (!*newline) {
|
2012-03-05 19:22:28 +04:00
|
|
|
break;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
token = newline;
|
2014-08-03 00:44:06 +04:00
|
|
|
while (*newline && !IsNewline(*newline)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
++newline;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
if (*newline) {
|
|
|
|
*newline = '\0';
|
|
|
|
++newline;
|
|
|
|
}
|
|
|
|
++line;
|
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
if (*token == '#') { // ignore lines that begin with # as comments
|
2012-03-05 19:22:28 +04:00
|
|
|
continue;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
char* whitespace = token;
|
2012-03-05 19:22:28 +04:00
|
|
|
token = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
|
2014-08-03 00:44:06 +04:00
|
|
|
if (!token) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2013-10-11 00:41:00 +04:00
|
|
|
const ManifestDirective* directive = nullptr;
|
2012-03-05 19:22:28 +04:00
|
|
|
for (const ManifestDirective* d = kParsingTable;
|
2014-08-03 00:44:06 +04:00
|
|
|
d < ArrayEnd(kParsingTable); ++d) {
|
2018-03-09 00:58:29 +03:00
|
|
|
if (!strcmp(d->directive, token)) {
|
2014-07-26 04:52:00 +04:00
|
|
|
directive = d;
|
|
|
|
break;
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!directive) {
|
2014-08-03 00:44:06 +04:00
|
|
|
LogMessageWithContext(
|
2012-03-05 19:22:28 +04:00
|
|
|
aFile, line, "Ignoring unrecognized chrome manifest directive '%s'.",
|
|
|
|
token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-01 02:44:52 +03:00
|
|
|
if (!directive->ischrome && NS_BOOTSTRAPPED_LOCATION == aType) {
|
2014-08-03 00:44:06 +04:00
|
|
|
LogMessageWithContext(
|
|
|
|
aFile, line,
|
2012-03-05 19:22:28 +04:00
|
|
|
"Bootstrapped manifest not allowed to use '%s' directive.", token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(directive->argc < 4, "Need to reset argv array length");
|
|
|
|
char* argv[4];
|
2014-08-03 00:44:06 +04:00
|
|
|
for (int i = 0; i < directive->argc; ++i) {
|
2012-03-05 19:22:28 +04:00
|
|
|
argv[i] = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
if (!argv[directive->argc - 1]) {
|
2014-08-03 00:44:06 +04:00
|
|
|
LogMessageWithContext(aFile, line,
|
2012-03-05 19:22:28 +04:00
|
|
|
"Not enough arguments for chrome manifest "
|
|
|
|
"directive '%s', expected %i.",
|
|
|
|
token, directive->argc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
TriState stAppVersion = eUnspecified;
|
|
|
|
TriState stGeckoVersion = eUnspecified;
|
|
|
|
TriState stApp = eUnspecified;
|
|
|
|
TriState stOsVersion = eUnspecified;
|
|
|
|
TriState stOs = eUnspecified;
|
|
|
|
TriState stABI = eUnspecified;
|
2014-10-07 22:46:24 +04:00
|
|
|
TriState stProcess = eUnspecified;
|
2012-03-05 19:22:28 +04:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
TriState stTablet = eUnspecified;
|
|
|
|
#endif
|
2015-02-05 19:09:15 +03:00
|
|
|
int flags = 0;
|
2012-03-05 19:22:28 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
while ((token = nsCRT::strtok(whitespace, kWhitespace, &whitespace)) &&
|
|
|
|
ok) {
|
2012-03-05 19:22:28 +04:00
|
|
|
ToLowerCase(token);
|
|
|
|
NS_ConvertASCIItoUTF16 wtoken(token);
|
|
|
|
|
|
|
|
if (CheckStringFlag(kApplication, wtoken, appID, stApp) ||
|
Bug 1365419 - Allow to apply manifest entries for all non-(Darwin,Windows,Android) OSes. r=bsmedberg
Manifest entries can contain flags, one of which allows to match on the
os running Gecko. The match is performed against the value returned by
nsIXULRuntime.getOS, which itself comes from the build-system's
OS_TARGET.
In practice, this means that things like os=WINNT, os=Darwin,
os=Android, os=Linux are valid filters, but the latter is too specific,
and most of the time, one would want something that is "any OS but
WINNT, Darwin, Android", which can't be expressed with manifest entry
flags (there is no "and" for them, only "or").
For convenience, we add the keyword "LikeUnix", which has that meaning.
--HG--
extra : rebase_source : faf3986d2a4361d12a512752e15e81270be224ef
2017-05-26 02:56:18 +03:00
|
|
|
CheckOsFlag(kOs, wtoken, osTarget, stOs) ||
|
2012-03-05 19:22:28 +04:00
|
|
|
CheckStringFlag(kABI, wtoken, abi, stABI) ||
|
2014-10-07 22:46:24 +04:00
|
|
|
CheckStringFlag(kProcess, wtoken, process, stProcess) ||
|
2012-03-05 19:22:28 +04:00
|
|
|
CheckVersionFlag(kOsVersion, wtoken, osVersion, stOsVersion) ||
|
|
|
|
CheckVersionFlag(kAppVersion, wtoken, appVersion, stAppVersion) ||
|
2014-07-26 04:52:00 +04:00
|
|
|
CheckVersionFlag(kGeckoVersion, wtoken, geckoVersion,
|
|
|
|
stGeckoVersion)) {
|
2012-03-05 19:22:28 +04:00
|
|
|
continue;
|
2014-07-26 04:52:00 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
bool tablet = false;
|
|
|
|
if (CheckFlag(kTablet, wtoken, tablet)) {
|
|
|
|
stTablet = (tablet == isTablet) ? eOK : eBad;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-05 19:09:15 +03:00
|
|
|
if (directive->contentflags) {
|
|
|
|
bool flag;
|
|
|
|
if (CheckFlag(kContentAccessible, wtoken, flag)) {
|
|
|
|
if (flag) flags |= nsChromeRegistry::CONTENT_ACCESSIBLE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (CheckFlag(kRemoteEnabled, wtoken, flag)) {
|
|
|
|
if (flag) flags |= nsChromeRegistry::REMOTE_ALLOWED;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (CheckFlag(kRemoteRequired, wtoken, flag)) {
|
|
|
|
if (flag) flags |= nsChromeRegistry::REMOTE_REQUIRED;
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
bool xpcNativeWrappers = true; // Dummy for CheckFlag.
|
|
|
|
if (CheckFlag(kXPCNativeWrappers, wtoken, xpcNativeWrappers)) {
|
2014-08-03 00:44:06 +04:00
|
|
|
LogMessageWithContext(
|
2012-03-05 19:22:28 +04:00
|
|
|
aFile, line, "Ignoring obsolete chrome registration modifier '%s'.",
|
|
|
|
token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
LogMessageWithContext(
|
2012-03-05 19:22:28 +04:00
|
|
|
aFile, line, "Unrecognized chrome manifest modifier '%s'.", token);
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok || stApp == eBad || stAppVersion == eBad ||
|
|
|
|
stGeckoVersion == eBad || stOs == eBad || stOsVersion == eBad ||
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
stTablet == eBad ||
|
|
|
|
#endif
|
2014-10-07 22:46:24 +04:00
|
|
|
stABI == eBad || stProcess == eBad) {
|
2012-03-05 19:22:28 +04:00
|
|
|
continue;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
if (directive->regfunc) {
|
2014-08-03 00:44:06 +04:00
|
|
|
if (GeckoProcessType_Default != XRE_GetProcessType()) {
|
2012-03-05 19:22:28 +04:00
|
|
|
continue;
|
2014-08-03 00:44:06 +04:00
|
|
|
}
|
2012-03-05 19:22:28 +04:00
|
|
|
|
|
|
|
if (!nsChromeRegistry::gChromeRegistry) {
|
|
|
|
nsCOMPtr<nsIChromeRegistry> cr =
|
|
|
|
mozilla::services::GetChromeRegistryService();
|
|
|
|
if (!nsChromeRegistry::gChromeRegistry) {
|
2014-08-03 00:44:06 +04:00
|
|
|
LogMessageWithContext(aFile, line,
|
2012-03-05 19:22:28 +04:00
|
|
|
"Chrome registry isn't available yet.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
(nsChromeRegistry::gChromeRegistry->*(directive->regfunc))(chromecx, line,
|
2015-02-05 19:09:15 +03:00
|
|
|
argv, flags);
|
2014-10-16 02:02:42 +04:00
|
|
|
} else if (directive->ischrome || !aChromeOnly) {
|
2018-08-01 02:38:49 +03:00
|
|
|
(nsComponentManagerImpl::gComponentManager->*(directive->mgrfunc))(
|
|
|
|
mgrcx, line, argv);
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < contracts.Length(); ++i) {
|
2012-03-05 19:22:28 +04:00
|
|
|
CachedDirective& d = contracts[i];
|
2014-08-03 00:44:06 +04:00
|
|
|
nsComponentManagerImpl::gComponentManager->ManifestContract(mgrcx, d.lineno,
|
|
|
|
d.argv);
|
2012-03-05 19:22:28 +04:00
|
|
|
}
|
|
|
|
}
|