2012-03-05 07:22:28 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 07:22:28 -08:00
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
#include "ManifestParser.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "prio.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
#elif defined(MOZ_WIDGET_COCOA)
|
|
|
|
#include <CoreServices/CoreServices.h>
|
2013-12-19 08:42:19 -08:00
|
|
|
#include "nsCocoaFeatures.h"
|
2012-06-15 23:05:00 -07:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2012-03-05 07:22:28 -08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
|
2012-03-12 15:53:18 -07:00
|
|
|
#include "nsCRT.h"
|
2012-03-05 07:22:28 -08: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"
|
2014-07-25 17:52:00 -07:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
|
|
|
#include "mozilla/XPTInterfaceInfoManager.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_B2G_LOADER
|
|
|
|
#define XPTONLY_MANIFEST &nsComponentManagerImpl::XPTOnlyManifestManifest
|
|
|
|
#define XPTONLY_XPT &nsComponentManagerImpl::XPTOnlyManifestXPT
|
|
|
|
#else
|
|
|
|
#define XPTONLY_MANIFEST nullptr
|
|
|
|
#define XPTONLY_XPT nullptr
|
|
|
|
#endif
|
|
|
|
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
struct ManifestDirective
|
|
|
|
{
|
|
|
|
const char* directive;
|
|
|
|
int argc;
|
|
|
|
|
|
|
|
// Some directives should only be delivered for NS_COMPONENT_LOCATION
|
|
|
|
// manifests.
|
|
|
|
bool componentonly;
|
|
|
|
|
|
|
|
bool ischrome;
|
|
|
|
|
|
|
|
bool allowbootstrap;
|
|
|
|
|
|
|
|
// The platform/contentaccessible flags only apply to content directives.
|
|
|
|
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-02 13:44:06 -07:00
|
|
|
void (nsComponentManagerImpl::*mgrfunc)(
|
|
|
|
nsComponentManagerImpl::ManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv);
|
|
|
|
void (nsChromeRegistry::*regfunc)(
|
|
|
|
nsChromeRegistry::ManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv,
|
|
|
|
bool aPlatform, bool aContentAccessible);
|
2014-07-25 17:52:00 -07:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
|
|
|
// The function to handle the directive for XPT Only parsing.
|
2014-08-02 13:44:06 -07:00
|
|
|
void (*xptonlyfunc)(
|
|
|
|
nsComponentManagerImpl::XPTOnlyManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv);
|
2014-07-25 17:52:00 -07:00
|
|
|
#else
|
2014-08-02 13:44:06 -07:00
|
|
|
void* xptonlyfunc;
|
2014-07-25 17:52:00 -07:00
|
|
|
#endif
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
bool isContract;
|
|
|
|
};
|
|
|
|
static const ManifestDirective kParsingTable[] = {
|
2014-08-02 13:44:06 -07:00
|
|
|
{
|
|
|
|
"manifest", 1, false, true, true, false,
|
|
|
|
&nsComponentManagerImpl::ManifestManifest, nullptr, XPTONLY_MANIFEST
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"binary-component", 1, true, false, false, false,
|
|
|
|
&nsComponentManagerImpl::ManifestBinaryComponent, nullptr, nullptr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"interfaces", 1, true, false, false, false,
|
|
|
|
&nsComponentManagerImpl::ManifestXPT, nullptr, XPTONLY_XPT
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"component", 2, true, false, false, false,
|
|
|
|
&nsComponentManagerImpl::ManifestComponent, nullptr, nullptr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"contract", 2, true, false, false, false,
|
|
|
|
&nsComponentManagerImpl::ManifestContract, nullptr, nullptr, true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"category", 3, true, false, false, false,
|
|
|
|
&nsComponentManagerImpl::ManifestCategory, nullptr, nullptr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"content", 2, true, true, true, true,
|
|
|
|
nullptr, &nsChromeRegistry::ManifestContent, nullptr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"locale", 3, true, true, true, false,
|
|
|
|
nullptr, &nsChromeRegistry::ManifestLocale, nullptr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"skin", 3, false, true, true, false,
|
|
|
|
nullptr, &nsChromeRegistry::ManifestSkin, nullptr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"overlay", 2, true, true, false, false,
|
|
|
|
nullptr, &nsChromeRegistry::ManifestOverlay, nullptr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"style", 2, false, true, false, false,
|
|
|
|
nullptr, &nsChromeRegistry::ManifestStyle, nullptr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"override", 2, true, true, true, false,
|
|
|
|
nullptr, &nsChromeRegistry::ManifestOverride, nullptr
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"resource", 2, true, true, false, false,
|
|
|
|
nullptr, &nsChromeRegistry::ManifestResource, nullptr
|
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char kWhitespace[] = "\t ";
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
static bool
|
|
|
|
IsNewline(char aChar)
|
2012-03-05 07:22:28 -08:00
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
return aChar == '\n' || aChar == '\r';
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct AutoPR_smprintf_free
|
|
|
|
{
|
2014-08-05 06:21:27 -07:00
|
|
|
explicit AutoPR_smprintf_free(char* aBuf) : mBuf(aBuf) {}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
~AutoPR_smprintf_free()
|
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
if (mBuf) {
|
2012-03-05 07:22:28 -08:00
|
|
|
PR_smprintf_free(mBuf);
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
operator char*() const { return mBuf; }
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
char* mBuf;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2014-07-25 17:52:00 -07:00
|
|
|
/**
|
|
|
|
* If we are pre-loading XPTs, this method may do nothing because the
|
|
|
|
* console service is not initialized.
|
|
|
|
*/
|
2014-08-02 13:44:06 -07:00
|
|
|
void
|
|
|
|
LogMessage(const char* aMsg, ...)
|
2012-03-05 07:22:28 -08:00
|
|
|
{
|
2014-07-25 17:52:00 -07:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-05 07:22:28 -08:00
|
|
|
nsCOMPtr<nsIConsoleService> console =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
2014-08-02 13:44:06 -07:00
|
|
|
if (!console) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, aMsg);
|
|
|
|
AutoPR_smprintf_free formatted(PR_vsmprintf(aMsg, args));
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleMessage> error =
|
|
|
|
new nsConsoleMessage(NS_ConvertUTF8toUTF16(formatted).get());
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
2014-07-25 17:52:00 -07:00
|
|
|
/**
|
|
|
|
* If we are pre-loading XPTs, this method may do nothing because the
|
|
|
|
* console service is not initialized.
|
|
|
|
*/
|
2014-08-02 13:44:06 -07:00
|
|
|
void
|
|
|
|
LogMessageWithContext(FileLocation& aFile,
|
|
|
|
uint32_t aLineNumber, const char* aMsg, ...)
|
2012-03-05 07:22:28 -08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, aMsg);
|
|
|
|
AutoPR_smprintf_free formatted(PR_vsmprintf(aMsg, args));
|
|
|
|
va_end(args);
|
2014-08-02 13:44:06 -07:00
|
|
|
if (!formatted) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
2014-07-25 17:52:00 -07:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-05 07:22:28 -08: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(),
|
2014-08-25 12:17:15 -07:00
|
|
|
aLineNumber, (char*)formatted);
|
2012-03-05 07:22:28 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService> console =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
2014-08-02 13:44:06 -07:00
|
|
|
if (!console) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
2012-09-09 16:29:12 -07:00
|
|
|
nsresult rv = error->Init(NS_ConvertUTF8toUTF16(formatted),
|
2014-08-02 13:44:06 -07:00
|
|
|
NS_ConvertUTF8toUTF16(file), EmptyString(),
|
|
|
|
aLineNumber, 0, nsIScriptError::warningFlag,
|
|
|
|
"chrome registration");
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08: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.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
CheckFlag(const nsSubstring& aFlag, const nsSubstring& aData, bool& aResult)
|
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
if (!StringBeginsWith(aData, aFlag)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return false;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08: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-02 13:44:06 -07: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 07:22:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
enum TriState
|
|
|
|
{
|
2012-03-05 07:22:28 -08:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
CheckStringFlag(const nsSubstring& aFlag, const nsSubstring& aData,
|
|
|
|
const nsSubstring& aValue, TriState& aResult)
|
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
if (aData.Length() < aFlag.Length() + 1) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return false;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
if (!StringBeginsWith(aData, aFlag)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return false;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
bool comparison = true;
|
|
|
|
if (aData[aFlag.Length()] != '=') {
|
|
|
|
if (aData[aFlag.Length()] == '!' &&
|
|
|
|
aData.Length() >= aFlag.Length() + 2 &&
|
2014-08-02 13:44:06 -07:00
|
|
|
aData[aFlag.Length() + 1] == '=') {
|
2012-03-05 07:22:28 -08:00
|
|
|
comparison = false;
|
2014-08-02 13:44:06 -07:00
|
|
|
} else {
|
2012-03-05 07:22:28 -08:00
|
|
|
return false;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aResult != eOK) {
|
2014-08-02 13:44:06 -07:00
|
|
|
nsDependentSubstring testdata =
|
|
|
|
Substring(aData, aFlag.Length() + (comparison ? 1 : 2));
|
|
|
|
if (testdata.Equals(aValue)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
aResult = comparison ? eOK : eBad;
|
2014-08-02 13:44:06 -07:00
|
|
|
} else {
|
2012-03-05 07:22:28 -08:00
|
|
|
aResult = comparison ? eBad : eOK;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-02 13:44:06 -07:00
|
|
|
if (aData.Length() < aFlag.Length() + 2) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return false;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
if (!StringBeginsWith(aData, aFlag)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return false;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
if (aValue.Length() == 0) {
|
2014-08-02 13:44:06 -07:00
|
|
|
if (aResult != eOK) {
|
2012-03-05 07:22:28 -08:00
|
|
|
aResult = eBad;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t comparison;
|
2012-03-05 07:22:28 -08:00
|
|
|
nsAutoString testdata;
|
|
|
|
|
|
|
|
switch (aData[aFlag.Length()]) {
|
2014-08-02 13:44:06 -07:00
|
|
|
case '=':
|
|
|
|
comparison = COMPARE_EQ;
|
2012-03-05 07:22:28 -08:00
|
|
|
testdata = Substring(aData, aFlag.Length() + 1);
|
2014-08-02 13:44:06 -07:00
|
|
|
break;
|
2012-03-05 07:22:28 -08:00
|
|
|
|
2014-08-02 13:44:06 -07: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 07:22:28 -08:00
|
|
|
|
2014-08-02 13:44:06 -07: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 07:22:28 -08:00
|
|
|
}
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
if (testdata.Length() == 0) {
|
2012-03-05 07:22:28 -08:00
|
|
|
return false;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
if (aResult != eOK) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t c = mozilla::CompareVersions(NS_ConvertUTF16toUTF8(aValue).get(),
|
2012-04-18 20:22:29 -07:00
|
|
|
NS_ConvertUTF16toUTF8(testdata).get());
|
2012-03-05 07:22:28 -08:00
|
|
|
if ((c == 0 && comparison & COMPARE_EQ) ||
|
2014-08-02 13:44:06 -07:00
|
|
|
(c < 0 && comparison & COMPARE_LT) ||
|
|
|
|
(c > 0 && comparison & COMPARE_GT)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
aResult = eOK;
|
2014-08-02 13:44:06 -07:00
|
|
|
} else {
|
2012-03-05 07:22:28 -08:00
|
|
|
aResult = eBad;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In-place conversion of ascii characters to lower case
|
|
|
|
static void
|
2014-08-02 13:44:06 -07:00
|
|
|
ToLowerCase(char* aToken)
|
2012-03-05 07:22:28 -08:00
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
for (; *aToken; ++aToken) {
|
|
|
|
*aToken = NS_ToLower(*aToken);
|
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct CachedDirective
|
|
|
|
{
|
|
|
|
int lineno;
|
|
|
|
char* argv[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
2014-07-25 17:52:00 -07:00
|
|
|
/**
|
|
|
|
* For XPT-Only mode, the parser handles only directives of "manifest"
|
|
|
|
* and "interfaces", and always call the function given by |xptonlyfunc|
|
|
|
|
* variable of struct |ManifestDirective|.
|
|
|
|
*
|
|
|
|
* This function is safe to be called before the component manager is
|
|
|
|
* ready if aXPTOnly is true for it don't invoke any component during
|
|
|
|
* parsing.
|
|
|
|
*/
|
2012-03-05 07:22:28 -08:00
|
|
|
void
|
2014-08-02 13:44:06 -07:00
|
|
|
ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf,
|
|
|
|
bool aChromeOnly, bool aXPTOnly)
|
2012-03-05 07:22:28 -08:00
|
|
|
{
|
2014-08-02 13:44:06 -07:00
|
|
|
nsComponentManagerImpl::ManifestProcessingContext mgrcx(aType, aFile,
|
|
|
|
aChromeOnly);
|
|
|
|
nsChromeRegistry::ManifestProcessingContext chromecx(aType, aFile);
|
2014-07-25 17:52:00 -07:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
2014-08-02 13:44:06 -07:00
|
|
|
nsComponentManagerImpl::XPTOnlyManifestProcessingContext xptonlycx(aFile);
|
2014-07-25 17:52:00 -07:00
|
|
|
#endif
|
2012-03-05 07:22:28 -08:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(kPlatform, "platform");
|
|
|
|
NS_NAMED_LITERAL_STRING(kContentAccessible, "contentaccessible");
|
|
|
|
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");
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
NS_NAMED_LITERAL_STRING(kTablet, "tablet");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Obsolete
|
|
|
|
NS_NAMED_LITERAL_STRING(kXPCNativeWrappers, "xpcnativewrappers");
|
|
|
|
|
|
|
|
nsAutoString appID;
|
|
|
|
nsAutoString appVersion;
|
|
|
|
nsAutoString geckoVersion;
|
|
|
|
nsAutoString osTarget;
|
|
|
|
nsAutoString abi;
|
|
|
|
|
2014-07-25 17:52:00 -07:00
|
|
|
nsCOMPtr<nsIXULAppInfo> xapp;
|
|
|
|
if (!aXPTOnly) {
|
|
|
|
// Avoid to create any component for XPT only mode.
|
|
|
|
// No xapp means no ID, version, ..., modifiers checking.
|
|
|
|
xapp = do_GetService(XULAPPINFO_SERVICE_CONTRACTID);
|
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
if (xapp) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString s;
|
2012-03-05 07:22:28 -08:00
|
|
|
rv = xapp->GetID(s);
|
2014-08-02 13:44:06 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
CopyUTF8toUTF16(s, appID);
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
rv = xapp->GetVersion(s);
|
2014-08-02 13:44:06 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
CopyUTF8toUTF16(s, appVersion);
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
rv = xapp->GetPlatformVersion(s);
|
2014-08-02 13:44:06 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
CopyUTF8toUTF16(s, geckoVersion);
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
nsCOMPtr<nsIXULRuntime> xruntime(do_QueryInterface(xapp));
|
2012-03-05 07:22:28 -08: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 07:02:17 -08:00
|
|
|
abi.Insert(char16_t('_'), 0);
|
2012-03-05 07:22:28 -08:00
|
|
|
abi.Insert(osTarget, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString osVersion;
|
|
|
|
#if defined(XP_WIN)
|
2014-01-28 15:37:47 -08:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4996) // VC12+ deprecates GetVersionEx
|
2012-03-05 07:22:28 -08:00
|
|
|
OSVERSIONINFO info = { sizeof(OSVERSIONINFO) };
|
|
|
|
if (GetVersionEx(&info)) {
|
2013-12-12 17:50:01 -08:00
|
|
|
nsTextFormatter::ssprintf(osVersion, MOZ_UTF16("%ld.%ld"),
|
2014-08-02 13:44:06 -07:00
|
|
|
info.dwMajorVersion,
|
|
|
|
info.dwMinorVersion);
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
2014-01-28 15:37:47 -08:00
|
|
|
#pragma warning(pop)
|
2012-03-05 07:22:28 -08:00
|
|
|
#elif defined(MOZ_WIDGET_COCOA)
|
2013-12-19 08:42:19 -08:00
|
|
|
SInt32 majorVersion = nsCocoaFeatures::OSXVersionMajor();
|
|
|
|
SInt32 minorVersion = nsCocoaFeatures::OSXVersionMinor();
|
|
|
|
nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
|
2014-08-02 13:44:06 -07:00
|
|
|
majorVersion,
|
|
|
|
minorVersion);
|
2013-06-10 05:36:26 -07:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2013-12-12 17:50:01 -08:00
|
|
|
nsTextFormatter::ssprintf(osVersion, MOZ_UTF16("%ld.%ld"),
|
2014-08-02 13:44:06 -07:00
|
|
|
gtk_major_version,
|
|
|
|
gtk_minor_version);
|
2012-03-05 07:22:28 -08:00
|
|
|
#elif defined(MOZ_WIDGET_ANDROID)
|
|
|
|
bool isTablet = false;
|
|
|
|
if (mozilla::AndroidBridge::Bridge()) {
|
2014-08-02 13:44:06 -07:00
|
|
|
mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build$VERSION",
|
|
|
|
"RELEASE",
|
|
|
|
osVersion);
|
2013-11-12 10:41:01 -08:00
|
|
|
isTablet = mozilla::widget::android::GeckoAppShell::IsTablet();
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Because contracts must be registered after CIDs, we save and process them
|
|
|
|
// at the end.
|
|
|
|
nsTArray<CachedDirective> contracts;
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
char* token;
|
|
|
|
char* newline = aBuf;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t line = 0;
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
// outer loop tokenizes by newline
|
|
|
|
while (*newline) {
|
|
|
|
while (*newline && IsNewline(*newline)) {
|
|
|
|
++newline;
|
|
|
|
++line;
|
|
|
|
}
|
2014-08-02 13:44:06 -07:00
|
|
|
if (!*newline) {
|
2012-03-05 07:22:28 -08:00
|
|
|
break;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
token = newline;
|
2014-08-02 13:44:06 -07:00
|
|
|
while (*newline && !IsNewline(*newline)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
++newline;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
if (*newline) {
|
|
|
|
*newline = '\0';
|
|
|
|
++newline;
|
|
|
|
}
|
|
|
|
++line;
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
if (*token == '#') { // ignore lines that begin with # as comments
|
2012-03-05 07:22:28 -08:00
|
|
|
continue;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
char* whitespace = token;
|
2012-03-05 07:22:28 -08:00
|
|
|
token = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
|
2014-08-02 13:44:06 -07:00
|
|
|
if (!token) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
2013-10-10 13:41:00 -07:00
|
|
|
const ManifestDirective* directive = nullptr;
|
2012-03-05 07:22:28 -08:00
|
|
|
for (const ManifestDirective* d = kParsingTable;
|
2014-08-02 13:44:06 -07:00
|
|
|
d < ArrayEnd(kParsingTable);
|
|
|
|
++d) {
|
2014-07-25 17:52:00 -07:00
|
|
|
if (!strcmp(d->directive, token) &&
|
|
|
|
(!aXPTOnly || d->xptonlyfunc)) {
|
|
|
|
directive = d;
|
|
|
|
break;
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!directive) {
|
2014-08-02 13:44:06 -07:00
|
|
|
LogMessageWithContext(aFile, line,
|
2012-03-05 07:22:28 -08:00
|
|
|
"Ignoring unrecognized chrome manifest directive '%s'.",
|
|
|
|
token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
if (!directive->allowbootstrap && NS_BOOTSTRAPPED_LOCATION == aType) {
|
|
|
|
LogMessageWithContext(aFile, line,
|
2012-03-05 07:22:28 -08:00
|
|
|
"Bootstrapped manifest not allowed to use '%s' directive.",
|
|
|
|
token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
if (directive->componentonly && NS_SKIN_LOCATION == aType) {
|
|
|
|
LogMessageWithContext(aFile, line,
|
2012-03-05 07:22:28 -08:00
|
|
|
"Skin 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-02 13:44:06 -07:00
|
|
|
for (int i = 0; i < directive->argc; ++i) {
|
2012-03-05 07:22:28 -08:00
|
|
|
argv[i] = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
if (!argv[directive->argc - 1]) {
|
2014-08-02 13:44:06 -07:00
|
|
|
LogMessageWithContext(aFile, line,
|
2012-03-05 07:22:28 -08: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;
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
TriState stTablet = eUnspecified;
|
|
|
|
#endif
|
|
|
|
bool platform = false;
|
|
|
|
bool contentAccessible = false;
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
while ((token = nsCRT::strtok(whitespace, kWhitespace, &whitespace)) &&
|
|
|
|
ok) {
|
2012-03-05 07:22:28 -08:00
|
|
|
ToLowerCase(token);
|
|
|
|
NS_ConvertASCIItoUTF16 wtoken(token);
|
|
|
|
|
|
|
|
if (CheckStringFlag(kApplication, wtoken, appID, stApp) ||
|
|
|
|
CheckStringFlag(kOs, wtoken, osTarget, stOs) ||
|
|
|
|
CheckStringFlag(kABI, wtoken, abi, stABI) ||
|
|
|
|
CheckVersionFlag(kOsVersion, wtoken, osVersion, stOsVersion) ||
|
|
|
|
CheckVersionFlag(kAppVersion, wtoken, appVersion, stAppVersion) ||
|
2014-07-25 17:52:00 -07:00
|
|
|
CheckVersionFlag(kGeckoVersion, wtoken, geckoVersion, stGeckoVersion)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
continue;
|
2014-07-25 17:52:00 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
bool tablet = false;
|
|
|
|
if (CheckFlag(kTablet, wtoken, tablet)) {
|
|
|
|
stTablet = (tablet == isTablet) ? eOK : eBad;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (directive->contentflags &&
|
|
|
|
(CheckFlag(kPlatform, wtoken, platform) ||
|
2014-08-02 13:44:06 -07:00
|
|
|
CheckFlag(kContentAccessible, wtoken, contentAccessible))) {
|
2012-03-05 07:22:28 -08:00
|
|
|
continue;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
bool xpcNativeWrappers = true; // Dummy for CheckFlag.
|
|
|
|
if (CheckFlag(kXPCNativeWrappers, wtoken, xpcNativeWrappers)) {
|
2014-08-02 13:44:06 -07:00
|
|
|
LogMessageWithContext(aFile, line,
|
2012-03-05 07:22:28 -08:00
|
|
|
"Ignoring obsolete chrome registration modifier '%s'.",
|
|
|
|
token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
LogMessageWithContext(aFile, line,
|
2012-03-05 07:22:28 -08:00
|
|
|
"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-08-02 13:44:06 -07:00
|
|
|
stABI == eBad) {
|
2012-03-05 07:22:28 -08:00
|
|
|
continue;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
2014-07-25 17:52:00 -07:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
|
|
|
if (aXPTOnly) {
|
|
|
|
directive->xptonlyfunc(xptonlycx, line, argv);
|
|
|
|
} else
|
|
|
|
#endif /* MOZ_B2G_LOADER */
|
2012-03-05 07:22:28 -08:00
|
|
|
if (directive->regfunc) {
|
2014-08-02 13:44:06 -07:00
|
|
|
if (GeckoProcessType_Default != XRE_GetProcessType()) {
|
2012-03-05 07:22:28 -08:00
|
|
|
continue;
|
2014-08-02 13:44:06 -07:00
|
|
|
}
|
2012-03-05 07:22:28 -08:00
|
|
|
|
|
|
|
if (!nsChromeRegistry::gChromeRegistry) {
|
|
|
|
nsCOMPtr<nsIChromeRegistry> cr =
|
|
|
|
mozilla::services::GetChromeRegistryService();
|
|
|
|
if (!nsChromeRegistry::gChromeRegistry) {
|
2014-08-02 13:44:06 -07:00
|
|
|
LogMessageWithContext(aFile, line,
|
2012-03-05 07:22:28 -08:00
|
|
|
"Chrome registry isn't available yet.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-02 13:44:06 -07:00
|
|
|
(nsChromeRegistry::gChromeRegistry->*(directive->regfunc))(
|
|
|
|
chromecx, line, argv, platform, contentAccessible);
|
|
|
|
} else if (directive->mgrfunc && (directive->ischrome || !aChromeOnly)) {
|
2012-03-05 07:22:28 -08:00
|
|
|
if (directive->isContract) {
|
|
|
|
CachedDirective* cd = contracts.AppendElement();
|
|
|
|
cd->lineno = line;
|
|
|
|
cd->argv[0] = argv[0];
|
|
|
|
cd->argv[1] = argv[1];
|
2014-08-02 13:44:06 -07:00
|
|
|
} else {
|
|
|
|
(nsComponentManagerImpl::gComponentManager->*(directive->mgrfunc))(
|
|
|
|
mgrcx, line, argv);
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
2014-07-25 17:52:00 -07:00
|
|
|
} else {
|
2014-08-02 13:44:06 -07:00
|
|
|
LogMessageWithContext(aFile, line, "No valid manifest directive.");
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < contracts.Length(); ++i) {
|
2012-03-05 07:22:28 -08:00
|
|
|
CachedDirective& d = contracts[i];
|
2014-08-02 13:44:06 -07:00
|
|
|
nsComponentManagerImpl::gComponentManager->ManifestContract(mgrcx,
|
|
|
|
d.lineno,
|
|
|
|
d.argv);
|
2012-03-05 07:22:28 -08:00
|
|
|
}
|
|
|
|
}
|