2010-06-11 13:13:26 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Firefox
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* the Mozilla Foundation <http://www.mozilla.org/>.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2011-08-10 13:24:57 -07:00
|
|
|
* Philipp Kewisch <mozilla@kewis.ch>
|
2010-06-11 13:13:26 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
#include "ManifestParser.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "prio.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include <windows.h>
|
2010-04-27 05:57:34 -07:00
|
|
|
#elif defined(MOZ_WIDGET_COCOA)
|
2010-06-11 13:13:26 -07:00
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#elif defined(MOZ_WIDGET_GTK2)
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#endif
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2011-05-05 13:50:19 -07:00
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#endif
|
|
|
|
|
2010-06-21 10:49:38 -07:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
|
2010-06-28 10:55:57 -07:00
|
|
|
#include "nsConsoleMessage.h"
|
2010-06-11 13:13:26 -07:00
|
|
|
#include "nsTextFormatter.h"
|
|
|
|
#include "nsVersionComparator.h"
|
|
|
|
#include "nsXPCOMCIDInternal.h"
|
|
|
|
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
#include "nsIXULRuntime.h"
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
struct ManifestDirective
|
|
|
|
{
|
|
|
|
const char* directive;
|
|
|
|
int argc;
|
|
|
|
|
|
|
|
// Some directives should only be delivered for NS_COMPONENT_LOCATION
|
|
|
|
// manifests.
|
|
|
|
bool componentonly;
|
|
|
|
|
|
|
|
bool ischrome;
|
|
|
|
|
2011-07-29 02:20:47 -07:00
|
|
|
bool allowbootstrap;
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
// 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.
|
|
|
|
void (nsComponentManagerImpl::*mgrfunc)
|
|
|
|
(nsComponentManagerImpl::ManifestProcessingContext& cx,
|
|
|
|
int lineno, char *const * argv);
|
|
|
|
void (nsChromeRegistry::*regfunc)
|
|
|
|
(nsChromeRegistry::ManifestProcessingContext& cx,
|
|
|
|
int lineno, char *const *argv,
|
|
|
|
bool platform, bool contentaccessible);
|
2010-06-25 05:19:48 -07:00
|
|
|
|
|
|
|
bool isContract;
|
2010-06-11 13:13:26 -07:00
|
|
|
};
|
|
|
|
static const ManifestDirective kParsingTable[] = {
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "manifest", 1, false, true, true, false,
|
2010-07-22 07:31:29 -07:00
|
|
|
&nsComponentManagerImpl::ManifestManifest, NULL },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "binary-component", 1, true, false, false, false,
|
2010-06-11 13:13:26 -07:00
|
|
|
&nsComponentManagerImpl::ManifestBinaryComponent, NULL },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "interfaces", 1, true, false, false, false,
|
2010-06-25 10:55:46 -07:00
|
|
|
&nsComponentManagerImpl::ManifestXPT, NULL },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "component", 2, true, false, false, false,
|
2010-06-11 13:13:26 -07:00
|
|
|
&nsComponentManagerImpl::ManifestComponent, NULL },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "contract", 2, true, false, false, false,
|
2010-06-25 05:19:48 -07:00
|
|
|
&nsComponentManagerImpl::ManifestContract, NULL, true},
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "category", 3, true, false, false, false,
|
2010-06-11 13:13:26 -07:00
|
|
|
&nsComponentManagerImpl::ManifestCategory, NULL },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "content", 2, true, true, true, true,
|
2010-06-11 13:13:26 -07:00
|
|
|
NULL, &nsChromeRegistry::ManifestContent },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "locale", 3, true, true, true, false,
|
2010-06-11 13:13:26 -07:00
|
|
|
NULL, &nsChromeRegistry::ManifestLocale },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "skin", 3, false, true, true, false,
|
2010-06-11 13:13:26 -07:00
|
|
|
NULL, &nsChromeRegistry::ManifestSkin },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "overlay", 2, true, true, false, false,
|
2010-06-11 13:13:26 -07:00
|
|
|
NULL, &nsChromeRegistry::ManifestOverlay },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "style", 2, false, true, false, false,
|
2010-06-11 13:13:26 -07:00
|
|
|
NULL, &nsChromeRegistry::ManifestStyle },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "override", 2, true, true, true, false,
|
2010-06-11 13:13:26 -07:00
|
|
|
NULL, &nsChromeRegistry::ManifestOverride },
|
2011-07-29 02:20:47 -07:00
|
|
|
{ "resource", 2, true, true, false, false,
|
2010-06-11 13:13:26 -07:00
|
|
|
NULL, &nsChromeRegistry::ManifestResource }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char kWhitespace[] = "\t ";
|
2010-06-29 10:16:43 -07:00
|
|
|
|
|
|
|
static bool IsNewline(char c)
|
|
|
|
{
|
|
|
|
return c == '\n' || c == '\r';
|
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
|
2010-06-28 10:55:57 -07:00
|
|
|
namespace {
|
|
|
|
struct AutoPR_smprintf_free
|
|
|
|
{
|
|
|
|
AutoPR_smprintf_free(char* buf)
|
|
|
|
: mBuf(buf)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoPR_smprintf_free()
|
|
|
|
{
|
|
|
|
if (mBuf)
|
|
|
|
PR_smprintf_free(mBuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
operator char*() const {
|
|
|
|
return mBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* mBuf;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void LogMessage(const char* aMsg, ...)
|
2010-06-11 13:13:26 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIConsoleService> console =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
2010-06-28 10:55:57 -07:00
|
|
|
if (!console)
|
2010-06-11 13:13:26 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, aMsg);
|
2010-06-28 10:55:57 -07:00
|
|
|
AutoPR_smprintf_free formatted(PR_vsmprintf(aMsg, args));
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleMessage> error =
|
|
|
|
new nsConsoleMessage(NS_ConvertUTF8toUTF16(formatted).get());
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
2011-11-08 09:10:51 -08:00
|
|
|
void LogMessageWithContext(FileLocation &aFile,
|
2010-07-02 06:53:19 -07:00
|
|
|
PRUint32 aLineNumber, const char* aMsg, ...)
|
2010-06-28 10:55:57 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, aMsg);
|
|
|
|
AutoPR_smprintf_free formatted(PR_vsmprintf(aMsg, args));
|
2010-06-11 13:13:26 -07:00
|
|
|
va_end(args);
|
|
|
|
if (!formatted)
|
|
|
|
return;
|
|
|
|
|
2011-11-08 09:10:51 -08:00
|
|
|
nsCString file;
|
|
|
|
aFile.GetURIString(file);
|
2010-06-11 13:13:26 -07:00
|
|
|
|
2010-06-28 10:55:57 -07:00
|
|
|
nsCOMPtr<nsIScriptError> error =
|
|
|
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
|
|
|
|
if (!error) {
|
|
|
|
// This can happen early in component registration. Fall back to a
|
|
|
|
// generic console message.
|
2011-11-08 09:10:51 -08:00
|
|
|
LogMessage("Warning: in '%s', line %i: %s", file.get(),
|
2010-06-28 10:55:57 -07:00
|
|
|
aLineNumber, (char*) formatted);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService> console =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
if (!console)
|
|
|
|
return;
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
nsresult rv = error->Init(NS_ConvertUTF8toUTF16(formatted).get(),
|
2011-11-08 09:10:51 -08:00
|
|
|
NS_ConvertUTF8toUTF16(file).get(), NULL,
|
2010-06-11 13:13:26 -07:00
|
|
|
aLineNumber, 0, nsIScriptError::warningFlag,
|
|
|
|
"chrome registration");
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (!StringBeginsWith(aData, aFlag))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
case '1':
|
|
|
|
case 't': //true
|
|
|
|
case 'y': //yes
|
|
|
|
aResult = true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case '0':
|
|
|
|
case 'f': //false
|
|
|
|
case 'n': //no
|
|
|
|
aResult = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
CheckStringFlag(const nsSubstring& aFlag, const nsSubstring& aData,
|
|
|
|
const nsSubstring& aValue, TriState& aResult)
|
|
|
|
{
|
|
|
|
if (aData.Length() < aFlag.Length() + 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!StringBeginsWith(aData, aFlag))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool comparison = true;
|
|
|
|
if (aData[aFlag.Length()] != '=') {
|
|
|
|
if (aData[aFlag.Length()] == '!' &&
|
|
|
|
aData.Length() >= aFlag.Length() + 2 &&
|
|
|
|
aData[aFlag.Length() + 1] == '=')
|
|
|
|
comparison = false;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aResult != eOK) {
|
|
|
|
nsDependentSubstring testdata = Substring(aData, aFlag.Length() + (comparison ? 1 : 2));
|
|
|
|
if (testdata.Equals(aValue))
|
|
|
|
aResult = comparison ? eOK : eBad;
|
|
|
|
else
|
|
|
|
aResult = comparison ? eBad : eOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (aData.Length() < aFlag.Length() + 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!StringBeginsWith(aData, aFlag))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (aValue.Length() == 0) {
|
|
|
|
if (aResult != eOK)
|
|
|
|
aResult = eBad;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 comparison;
|
|
|
|
nsAutoString testdata;
|
|
|
|
|
|
|
|
switch (aData[aFlag.Length()]) {
|
|
|
|
case '=':
|
|
|
|
comparison = COMPARE_EQ;
|
|
|
|
testdata = Substring(aData, aFlag.Length() + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (testdata.Length() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (aResult != eOK) {
|
2010-06-21 08:41:42 -07:00
|
|
|
PRInt32 c = NS_CompareVersions(NS_ConvertUTF16toUTF8(aValue).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(testdata).get());
|
2010-06-11 13:13:26 -07:00
|
|
|
if ((c == 0 && comparison & COMPARE_EQ) ||
|
|
|
|
(c < 0 && comparison & COMPARE_LT) ||
|
|
|
|
(c > 0 && comparison & COMPARE_GT))
|
|
|
|
aResult = eOK;
|
|
|
|
else
|
|
|
|
aResult = eBad;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-02 11:23:41 -07:00
|
|
|
// In-place conversion of ascii characters to lower case
|
|
|
|
static void
|
|
|
|
ToLowerCase(char* token)
|
|
|
|
{
|
|
|
|
for (; *token; ++token)
|
|
|
|
*token = NS_ToLower(*token);
|
|
|
|
}
|
|
|
|
|
2010-06-25 05:19:48 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct CachedDirective
|
|
|
|
{
|
|
|
|
int lineno;
|
|
|
|
char* argv[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2011-11-08 09:10:51 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
ParseManifest(NSLocationType type, FileLocation &file, char* buf, bool aChromeOnly)
|
2010-06-11 13:13:26 -07:00
|
|
|
{
|
2011-11-08 09:10:51 -08:00
|
|
|
nsComponentManagerImpl::ManifestProcessingContext mgrcx(type, file, aChromeOnly);
|
|
|
|
nsChromeRegistry::ManifestProcessingContext chromecx(type, file);
|
2010-06-11 13:13:26 -07: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");
|
2011-08-10 13:24:57 -07:00
|
|
|
NS_NAMED_LITERAL_STRING(kGeckoVersion, "platformversion");
|
2010-06-11 13:13:26 -07:00
|
|
|
NS_NAMED_LITERAL_STRING(kOs, "os");
|
|
|
|
NS_NAMED_LITERAL_STRING(kOsVersion, "osversion");
|
2010-06-27 12:13:04 -07:00
|
|
|
NS_NAMED_LITERAL_STRING(kABI, "abi");
|
2011-12-14 13:53:38 -08:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
NS_NAMED_LITERAL_STRING(kTablet, "tablet");
|
|
|
|
#endif
|
2010-06-11 13:13:26 -07:00
|
|
|
|
2010-07-04 18:54:35 -07:00
|
|
|
// Obsolete
|
|
|
|
NS_NAMED_LITERAL_STRING(kXPCNativeWrappers, "xpcnativewrappers");
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
nsAutoString appID;
|
|
|
|
nsAutoString appVersion;
|
2011-08-10 13:24:57 -07:00
|
|
|
nsAutoString geckoVersion;
|
2010-06-11 13:13:26 -07:00
|
|
|
nsAutoString osTarget;
|
2010-06-27 12:13:04 -07:00
|
|
|
nsAutoString abi;
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
nsCOMPtr<nsIXULAppInfo> xapp (do_GetService(XULAPPINFO_SERVICE_CONTRACTID));
|
|
|
|
if (xapp) {
|
|
|
|
nsCAutoString s;
|
|
|
|
rv = xapp->GetID(s);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
CopyUTF8toUTF16(s, appID);
|
|
|
|
|
|
|
|
rv = xapp->GetVersion(s);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
CopyUTF8toUTF16(s, appVersion);
|
2011-07-29 02:20:47 -07:00
|
|
|
|
2011-08-10 13:24:57 -07:00
|
|
|
rv = xapp->GetPlatformVersion(s);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
CopyUTF8toUTF16(s, geckoVersion);
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
nsCOMPtr<nsIXULRuntime> xruntime (do_QueryInterface(xapp));
|
|
|
|
if (xruntime) {
|
|
|
|
rv = xruntime->GetOS(s);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2010-07-02 11:23:41 -07:00
|
|
|
ToLowerCase(s);
|
2010-06-11 13:13:26 -07:00
|
|
|
CopyUTF8toUTF16(s, osTarget);
|
|
|
|
}
|
2010-06-27 12:13:04 -07:00
|
|
|
|
|
|
|
rv = xruntime->GetXPCOMABI(s);
|
|
|
|
if (NS_SUCCEEDED(rv) && osTarget.Length()) {
|
2010-07-02 11:23:41 -07:00
|
|
|
ToLowerCase(s);
|
2010-06-27 12:13:04 -07:00
|
|
|
CopyUTF8toUTF16(s, abi);
|
|
|
|
abi.Insert(PRUnichar('_'), 0);
|
|
|
|
abi.Insert(osTarget, 0);
|
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString osVersion;
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
OSVERSIONINFO info = { sizeof(OSVERSIONINFO) };
|
|
|
|
if (GetVersionEx(&info)) {
|
|
|
|
nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
|
|
|
|
info.dwMajorVersion,
|
|
|
|
info.dwMinorVersion);
|
|
|
|
}
|
2010-04-27 05:57:34 -07:00
|
|
|
#elif defined(MOZ_WIDGET_COCOA)
|
2010-06-11 13:13:26 -07:00
|
|
|
SInt32 majorVersion, minorVersion;
|
|
|
|
if ((Gestalt(gestaltSystemVersionMajor, &majorVersion) == noErr) &&
|
|
|
|
(Gestalt(gestaltSystemVersionMinor, &minorVersion) == noErr)) {
|
|
|
|
nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
|
|
|
|
majorVersion,
|
|
|
|
minorVersion);
|
|
|
|
}
|
|
|
|
#elif defined(MOZ_WIDGET_GTK2)
|
|
|
|
nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
|
|
|
|
gtk_major_version,
|
|
|
|
gtk_minor_version);
|
2011-11-10 16:17:46 -08:00
|
|
|
#elif defined(MOZ_WIDGET_ANDROID)
|
2011-12-14 13:53:38 -08:00
|
|
|
bool isTablet = false;
|
2011-05-05 13:50:19 -07:00
|
|
|
if (mozilla::AndroidBridge::Bridge()) {
|
|
|
|
mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build$VERSION", "RELEASE", osVersion);
|
2011-12-14 13:53:38 -08:00
|
|
|
isTablet = mozilla::AndroidBridge::Bridge()->IsTablet();
|
2011-05-05 13:50:19 -07:00
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
#endif
|
|
|
|
|
2010-06-25 05:19:48 -07:00
|
|
|
// Because contracts must be registered after CIDs, we save and process them
|
|
|
|
// at the end.
|
|
|
|
nsTArray<CachedDirective> contracts;
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
char *token;
|
|
|
|
char *newline = buf;
|
|
|
|
PRUint32 line = 0;
|
|
|
|
|
|
|
|
// outer loop tokenizes by newline
|
2010-06-28 10:55:57 -07:00
|
|
|
while (*newline) {
|
2010-06-29 10:16:43 -07:00
|
|
|
while (*newline && IsNewline(*newline)) {
|
2010-06-28 10:55:57 -07:00
|
|
|
++newline;
|
|
|
|
++line;
|
|
|
|
}
|
|
|
|
if (!*newline)
|
|
|
|
break;
|
|
|
|
|
|
|
|
token = newline;
|
2010-06-29 10:16:43 -07:00
|
|
|
while (*newline && !IsNewline(*newline))
|
2010-06-28 10:55:57 -07:00
|
|
|
++newline;
|
|
|
|
|
|
|
|
if (*newline) {
|
|
|
|
*newline = '\0';
|
|
|
|
++newline;
|
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
++line;
|
|
|
|
|
|
|
|
if (*token == '#') // ignore lines that begin with # as comments
|
|
|
|
continue;
|
|
|
|
|
|
|
|
char *whitespace = token;
|
|
|
|
token = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
|
|
|
|
if (!token) continue;
|
|
|
|
|
|
|
|
const ManifestDirective* directive = NULL;
|
|
|
|
for (const ManifestDirective* d = kParsingTable;
|
2011-10-10 22:50:08 -07:00
|
|
|
d < ArrayEnd(kParsingTable);
|
2010-06-11 13:13:26 -07:00
|
|
|
++d) {
|
|
|
|
if (!strcmp(d->directive, token)) {
|
|
|
|
directive = d;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-07-29 02:20:47 -07:00
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
if (!directive) {
|
2011-11-08 09:10:51 -08:00
|
|
|
LogMessageWithContext(file, line,
|
2010-07-02 06:53:19 -07:00
|
|
|
"Ignoring unrecognized chrome manifest directive '%s'.",
|
|
|
|
token);
|
2010-06-11 13:13:26 -07:00
|
|
|
continue;
|
|
|
|
}
|
2011-07-29 02:20:47 -07:00
|
|
|
|
2011-11-08 09:10:51 -08:00
|
|
|
if (!directive->allowbootstrap && NS_BOOTSTRAPPED_LOCATION == type) {
|
|
|
|
LogMessageWithContext(file, line,
|
2011-07-29 02:20:47 -07:00
|
|
|
"Bootstrapped manifest not allowed to use '%s' directive.",
|
|
|
|
token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-11-08 09:10:51 -08:00
|
|
|
if (directive->componentonly && NS_SKIN_LOCATION == type) {
|
|
|
|
LogMessageWithContext(file, line,
|
2010-07-02 06:53:19 -07:00
|
|
|
"Skin manifest not allowed to use '%s' directive.",
|
|
|
|
token);
|
2010-06-11 13:13:26 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(directive->argc < 4, "Need to reset argv array length");
|
|
|
|
char* argv[4];
|
|
|
|
for (int i = 0; i < directive->argc; ++i)
|
|
|
|
argv[i] = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
|
|
|
|
|
|
|
|
if (!argv[directive->argc - 1]) {
|
2011-11-08 09:10:51 -08:00
|
|
|
LogMessageWithContext(file, line,
|
2010-07-02 06:53:19 -07:00
|
|
|
"Not enough arguments for chrome manifest directive '%s', expected %i.",
|
|
|
|
token, directive->argc);
|
2010-06-11 13:13:26 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
TriState stAppVersion = eUnspecified;
|
2011-08-10 13:24:57 -07:00
|
|
|
TriState stGeckoVersion = eUnspecified;
|
2010-06-11 13:13:26 -07:00
|
|
|
TriState stApp = eUnspecified;
|
|
|
|
TriState stOsVersion = eUnspecified;
|
|
|
|
TriState stOs = eUnspecified;
|
2010-06-27 12:13:04 -07:00
|
|
|
TriState stABI = eUnspecified;
|
2011-12-14 13:53:38 -08:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
TriState stTablet = eUnspecified;
|
|
|
|
#endif
|
2010-06-11 13:13:26 -07:00
|
|
|
bool platform = false;
|
|
|
|
bool contentAccessible = false;
|
|
|
|
|
|
|
|
while (NULL != (token = nsCRT::strtok(whitespace, kWhitespace, &whitespace)) && ok) {
|
2010-07-02 11:23:41 -07:00
|
|
|
ToLowerCase(token);
|
2010-06-11 13:13:26 -07:00
|
|
|
NS_ConvertASCIItoUTF16 wtoken(token);
|
|
|
|
|
|
|
|
if (CheckStringFlag(kApplication, wtoken, appID, stApp) ||
|
2010-07-04 18:54:35 -07:00
|
|
|
CheckStringFlag(kOs, wtoken, osTarget, stOs) ||
|
2010-06-27 12:13:04 -07:00
|
|
|
CheckStringFlag(kABI, wtoken, abi, stABI) ||
|
2010-07-04 18:54:35 -07:00
|
|
|
CheckVersionFlag(kOsVersion, wtoken, osVersion, stOsVersion) ||
|
2011-08-10 13:24:57 -07:00
|
|
|
CheckVersionFlag(kAppVersion, wtoken, appVersion, stAppVersion) ||
|
|
|
|
CheckVersionFlag(kGeckoVersion, wtoken, geckoVersion, stGeckoVersion))
|
2010-07-04 18:54:35 -07:00
|
|
|
continue;
|
2010-06-11 13:13:26 -07:00
|
|
|
|
2011-12-14 13:53:38 -08:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
bool tablet = false;
|
|
|
|
if (CheckFlag(kTablet, wtoken, tablet)) {
|
|
|
|
stTablet = (tablet == isTablet) ? eOK : eBad;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
if (directive->contentflags &&
|
2010-07-04 18:54:35 -07:00
|
|
|
(CheckFlag(kPlatform, wtoken, platform) ||
|
|
|
|
CheckFlag(kContentAccessible, wtoken, contentAccessible)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool xpcNativeWrappers = true; // Dummy for CheckFlag.
|
|
|
|
if (CheckFlag(kXPCNativeWrappers, wtoken, xpcNativeWrappers)) {
|
2011-11-08 09:10:51 -08:00
|
|
|
LogMessageWithContext(file, line,
|
2010-07-04 18:54:35 -07:00
|
|
|
"Warning: Ignoring obsolete chrome registration modifier '%s'.",
|
|
|
|
token);
|
|
|
|
continue;
|
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
|
2011-11-08 09:10:51 -08:00
|
|
|
LogMessageWithContext(file, line,
|
2010-07-02 06:53:19 -07:00
|
|
|
"Unrecognized chrome manifest modifier '%s'.",
|
|
|
|
token);
|
2010-06-11 13:13:26 -07:00
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
2010-06-27 12:13:04 -07:00
|
|
|
if (!ok ||
|
|
|
|
stApp == eBad ||
|
|
|
|
stAppVersion == eBad ||
|
2011-08-10 13:24:57 -07:00
|
|
|
stGeckoVersion == eBad ||
|
2010-06-27 12:13:04 -07:00
|
|
|
stOs == eBad ||
|
|
|
|
stOsVersion == eBad ||
|
2011-12-14 13:53:38 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
stTablet == eBad ||
|
|
|
|
#endif
|
2010-06-27 12:13:04 -07:00
|
|
|
stABI == eBad)
|
2010-06-11 13:13:26 -07:00
|
|
|
continue;
|
|
|
|
|
2010-07-22 07:31:29 -07:00
|
|
|
if (directive->regfunc) {
|
2010-07-01 08:55:57 -07:00
|
|
|
if (GeckoProcessType_Default != XRE_GetProcessType())
|
|
|
|
continue;
|
|
|
|
|
2010-06-21 10:49:38 -07:00
|
|
|
if (!nsChromeRegistry::gChromeRegistry) {
|
|
|
|
nsCOMPtr<nsIChromeRegistry> cr =
|
|
|
|
mozilla::services::GetChromeRegistryService();
|
|
|
|
if (!nsChromeRegistry::gChromeRegistry) {
|
2011-11-08 09:10:51 -08:00
|
|
|
LogMessageWithContext(file, line,
|
2010-07-02 06:53:19 -07:00
|
|
|
"Chrome registry isn't available yet.");
|
2010-06-21 10:49:38 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
(nsChromeRegistry::gChromeRegistry->*(directive->regfunc))
|
|
|
|
(chromecx, line, argv, platform, contentAccessible);
|
2010-06-21 10:49:38 -07:00
|
|
|
}
|
2010-07-22 07:31:29 -07:00
|
|
|
else if (directive->ischrome || !aChromeOnly) {
|
2010-06-25 05:19:48 -07:00
|
|
|
if (directive->isContract) {
|
|
|
|
CachedDirective* cd = contracts.AppendElement();
|
|
|
|
cd->lineno = line;
|
|
|
|
cd->argv[0] = argv[0];
|
|
|
|
cd->argv[1] = argv[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
(nsComponentManagerImpl::gComponentManager->*(directive->mgrfunc))
|
|
|
|
(mgrcx, line, argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-27 12:13:04 -07:00
|
|
|
for (PRUint32 i = 0; i < contracts.Length(); ++i) {
|
2010-06-25 05:19:48 -07:00
|
|
|
CachedDirective& d = contracts[i];
|
|
|
|
nsComponentManagerImpl::gComponentManager->ManifestContract
|
|
|
|
(mgrcx, d.lineno, d.argv);
|
2010-06-11 13:13:26 -07:00
|
|
|
}
|
|
|
|
}
|