mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Merge inbound to central, a=merge
This commit is contained in:
commit
68fb4b9d24
@ -1,3 +1,3 @@
|
||||
This is the pdf.js project output, https://github.com/mozilla/pdf.js
|
||||
|
||||
Current extension version is: 1.6.329
|
||||
Current extension version is: 1.6.355
|
||||
|
@ -23,8 +23,8 @@
|
||||
}
|
||||
}(this, function (exports) {
|
||||
'use strict';
|
||||
var pdfjsVersion = '1.6.329';
|
||||
var pdfjsBuild = '9c3419d';
|
||||
var pdfjsVersion = '1.6.355';
|
||||
var pdfjsBuild = '451956c';
|
||||
var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null;
|
||||
var pdfjsLibs = {};
|
||||
(function pdfjsWrapper() {
|
||||
@ -4753,7 +4753,7 @@
|
||||
return;
|
||||
}
|
||||
var name = fontObj.loadedName || 'sans-serif';
|
||||
var bold = fontObj.black ? fontObj.bold ? '900' : 'bold' : fontObj.bold ? 'bold' : 'normal';
|
||||
var bold = fontObj.black ? '900' : fontObj.bold ? 'bold' : 'normal';
|
||||
var italic = fontObj.italic ? 'italic' : 'normal';
|
||||
var typeface = '"' + name + '", ' + fontObj.fallbackName;
|
||||
var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
|
||||
@ -5843,6 +5843,9 @@
|
||||
get ref() {
|
||||
return this.pageInfo.ref;
|
||||
},
|
||||
get userUnit() {
|
||||
return this.pageInfo.userUnit;
|
||||
},
|
||||
get view() {
|
||||
return this.pageInfo.view;
|
||||
},
|
||||
|
1529
browser/extensions/pdfjs/content/build/pdf.worker.js
vendored
1529
browser/extensions/pdfjs/content/build/pdf.worker.js
vendored
File diff suppressed because it is too large
Load Diff
@ -931,11 +931,6 @@ html[dir='rtl'] .toolbarButton:first-child {
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
.toolbarButtonFlexibleSpacer {
|
||||
-moz-box-flex: 1;
|
||||
min-width: 30px;
|
||||
}
|
||||
|
||||
html[dir='ltr'] #findPrevious {
|
||||
margin-left: 3px;
|
||||
}
|
||||
|
@ -507,13 +507,13 @@ var pdfjsWebLibs;
|
||||
_writeToStorage: function ViewHistory_writeToStorage() {
|
||||
return new Promise(function (resolve) {
|
||||
var databaseStr = JSON.stringify(this.database);
|
||||
sessionStorage.setItem('pdfjsHistory', databaseStr);
|
||||
sessionStorage.setItem('pdfjs.history', databaseStr);
|
||||
resolve();
|
||||
}.bind(this));
|
||||
},
|
||||
_readFromStorage: function ViewHistory_readFromStorage() {
|
||||
return new Promise(function (resolve) {
|
||||
resolve(sessionStorage.getItem('pdfjsHistory'));
|
||||
resolve(sessionStorage.getItem('pdfjs.history'));
|
||||
});
|
||||
},
|
||||
set: function ViewHistory_set(name, val) {
|
||||
@ -4263,7 +4263,13 @@ var pdfjsWebLibs;
|
||||
return result;
|
||||
},
|
||||
paintOnSvg: function PDFPageView_paintOnSvg(wrapper) {
|
||||
return Promise.resolve('SVG rendering is not supported.');
|
||||
return {
|
||||
promise: Promise.reject(new Error('SVG rendering is not supported.')),
|
||||
onRenderContinue: function (cont) {
|
||||
},
|
||||
cancel: function () {
|
||||
}
|
||||
};
|
||||
},
|
||||
setPageLabel: function PDFView_setPageLabel(label) {
|
||||
this.pageLabel = typeof label === 'string' ? label : null;
|
||||
|
@ -161,11 +161,11 @@ ReadPrincipalInfo(JSStructuredCloneReader* aReader,
|
||||
aInfo = SystemPrincipalInfo();
|
||||
} else if (aTag == SCTAG_DOM_NULL_PRINCIPAL) {
|
||||
PrincipalOriginAttributes attrs;
|
||||
nsAutoCString dummy;
|
||||
if (!ReadSuffixAndSpec(aReader, attrs, dummy)) {
|
||||
nsAutoCString spec;
|
||||
if (!ReadSuffixAndSpec(aReader, attrs, spec)) {
|
||||
return false;
|
||||
}
|
||||
aInfo = NullPrincipalInfo(attrs);
|
||||
aInfo = NullPrincipalInfo(attrs, spec);
|
||||
} else if (aTag == SCTAG_DOM_EXPANDED_PRINCIPAL) {
|
||||
uint32_t length, unused;
|
||||
if (!JS_ReadUint32Pair(aReader, &length, &unused)) {
|
||||
@ -254,7 +254,7 @@ WritePrincipalInfo(JSStructuredCloneWriter* aWriter, const PrincipalInfo& aInfo)
|
||||
if (aInfo.type() == PrincipalInfo::TNullPrincipalInfo) {
|
||||
const NullPrincipalInfo& nullInfo = aInfo;
|
||||
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_NULL_PRINCIPAL, 0) &&
|
||||
WriteSuffixAndSpec(aWriter, nullInfo.attrs(), EmptyCString());
|
||||
WriteSuffixAndSpec(aWriter, nullInfo.attrs(), nullInfo.spec());
|
||||
}
|
||||
if (aInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
|
||||
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_SYSTEM_PRINCIPAL, 0);
|
||||
|
@ -58,22 +58,35 @@ nsNullPrincipal::CreateWithInheritedAttributes(nsIDocShell* aDocShell)
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsNullPrincipal>
|
||||
nsNullPrincipal::Create(const PrincipalOriginAttributes& aOriginAttributes)
|
||||
nsNullPrincipal::Create(const PrincipalOriginAttributes& aOriginAttributes,
|
||||
nsIURI* aURI)
|
||||
{
|
||||
RefPtr<nsNullPrincipal> nullPrin = new nsNullPrincipal();
|
||||
nsresult rv = nullPrin->Init(aOriginAttributes);
|
||||
nsresult rv = nullPrin->Init(aOriginAttributes, aURI);
|
||||
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
return nullPrin.forget();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsNullPrincipal::Init(const PrincipalOriginAttributes& aOriginAttributes)
|
||||
nsNullPrincipal::Init(const PrincipalOriginAttributes& aOriginAttributes,
|
||||
nsIURI* aURI)
|
||||
{
|
||||
mOriginAttributes = aOriginAttributes;
|
||||
|
||||
mURI = nsNullPrincipalURI::Create();
|
||||
NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_AVAILABLE);
|
||||
if (aURI) {
|
||||
nsAutoCString scheme;
|
||||
nsresult rv = aURI->GetScheme(scheme);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_ENSURE_TRUE(scheme.EqualsLiteral(NS_NULLPRINCIPAL_SCHEME),
|
||||
NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
mURI = aURI;
|
||||
} else {
|
||||
mURI = nsNullPrincipalURI::Create();
|
||||
NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_AVAILABLE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -53,9 +53,11 @@ public:
|
||||
static already_AddRefed<nsNullPrincipal> CreateWithInheritedAttributes(nsIDocShell* aDocShell);
|
||||
|
||||
static already_AddRefed<nsNullPrincipal>
|
||||
Create(const mozilla::PrincipalOriginAttributes& aOriginAttributes = mozilla::PrincipalOriginAttributes());
|
||||
Create(const mozilla::PrincipalOriginAttributes& aOriginAttributes = mozilla::PrincipalOriginAttributes(),
|
||||
nsIURI* aURI = nullptr);
|
||||
|
||||
nsresult Init(const mozilla::PrincipalOriginAttributes& aOriginAttributes = mozilla::PrincipalOriginAttributes());
|
||||
nsresult Init(const mozilla::PrincipalOriginAttributes& aOriginAttributes = mozilla::PrincipalOriginAttributes(),
|
||||
nsIURI* aURI = nullptr);
|
||||
|
||||
virtual nsresult GetScriptLocation(nsACString &aStr) override;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/******************************************************************************
|
||||
** This file is an amalgamation of many separate C source files from SQLite
|
||||
** version 3.15.1. By combining all the individual C code files into this
|
||||
** version 3.15.2. By combining all the individual C code files into this
|
||||
** single large file, the entire code can be compiled as a single translation
|
||||
** unit. This allows many compilers to do optimizations that would not be
|
||||
** possible if the files were compiled separately. Performance improvements
|
||||
@ -381,9 +381,9 @@ extern "C" {
|
||||
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
|
||||
** [sqlite_version()] and [sqlite_source_id()].
|
||||
*/
|
||||
#define SQLITE_VERSION "3.15.1"
|
||||
#define SQLITE_VERSION_NUMBER 3015001
|
||||
#define SQLITE_SOURCE_ID "2016-11-04 12:08:49 1136863c76576110e710dd5d69ab6bf347c65e36"
|
||||
#define SQLITE_VERSION "3.15.2"
|
||||
#define SQLITE_VERSION_NUMBER 3015002
|
||||
#define SQLITE_SOURCE_ID "2016-11-28 19:13:37 bbd85d235f7037c6a033a9690534391ffeacecc8"
|
||||
|
||||
/*
|
||||
** CAPI3REF: Run-Time Library Version Numbers
|
||||
@ -15583,15 +15583,15 @@ struct Parse {
|
||||
} aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
|
||||
int aTempReg[8]; /* Holding area for temporary registers */
|
||||
Token sNameToken; /* Token with unqualified schema object name */
|
||||
Token sLastToken; /* The last token parsed */
|
||||
|
||||
/************************************************************************
|
||||
** Above is constant between recursions. Below is reset before and after
|
||||
** each recursion. The boundary between these two regions is determined
|
||||
** using offsetof(Parse,nVar) so the nVar field must be the first field
|
||||
** in the recursive region.
|
||||
** using offsetof(Parse,sLastToken) so the sLastToken field must be the
|
||||
** first field in the recursive region.
|
||||
************************************************************************/
|
||||
|
||||
Token sLastToken; /* The last token parsed */
|
||||
ynVar nVar; /* Number of '?' variables seen in the SQL so far */
|
||||
int nzVar; /* Number of available slots in azVar[] */
|
||||
u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
|
||||
@ -15625,7 +15625,7 @@ struct Parse {
|
||||
** Sizes and pointers of various parts of the Parse object.
|
||||
*/
|
||||
#define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/
|
||||
#define PARSE_RECURSE_SZ offsetof(Parse,nVar) /* Recursive part */
|
||||
#define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
|
||||
#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
|
||||
#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
|
||||
|
||||
@ -88585,6 +88585,10 @@ static int lookupName(
|
||||
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
|
||||
return WRC_Abort;
|
||||
}
|
||||
if( sqlite3ExprVectorSize(pOrig)!=1 ){
|
||||
sqlite3ErrorMsg(pParse, "row value misused");
|
||||
return WRC_Abort;
|
||||
}
|
||||
resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
|
||||
cnt = 1;
|
||||
pMatch = 0;
|
||||
@ -88961,6 +88965,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
|
||||
break;
|
||||
}
|
||||
case TK_BETWEEN:
|
||||
case TK_EQ:
|
||||
case TK_NE:
|
||||
case TK_LT:
|
||||
@ -88971,10 +88976,17 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
case TK_ISNOT: {
|
||||
int nLeft, nRight;
|
||||
if( pParse->db->mallocFailed ) break;
|
||||
assert( pExpr->pRight!=0 );
|
||||
assert( pExpr->pLeft!=0 );
|
||||
nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
|
||||
nRight = sqlite3ExprVectorSize(pExpr->pRight);
|
||||
if( pExpr->op==TK_BETWEEN ){
|
||||
nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
|
||||
if( nRight==nLeft ){
|
||||
nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
|
||||
}
|
||||
}else{
|
||||
assert( pExpr->pRight!=0 );
|
||||
nRight = sqlite3ExprVectorSize(pExpr->pRight);
|
||||
}
|
||||
if( nLeft!=nRight ){
|
||||
testcase( pExpr->op==TK_EQ );
|
||||
testcase( pExpr->op==TK_NE );
|
||||
@ -88984,6 +88996,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
testcase( pExpr->op==TK_GE );
|
||||
testcase( pExpr->op==TK_IS );
|
||||
testcase( pExpr->op==TK_ISNOT );
|
||||
testcase( pExpr->op==TK_BETWEEN );
|
||||
sqlite3ErrorMsg(pParse, "row value misused");
|
||||
}
|
||||
break;
|
||||
@ -93012,7 +93025,7 @@ static int exprCodeVector(Parse *pParse, Expr *p, int *piFreeable){
|
||||
iResult = pParse->nMem+1;
|
||||
pParse->nMem += nResult;
|
||||
for(i=0; i<nResult; i++){
|
||||
sqlite3ExprCode(pParse, p->x.pList->a[i].pExpr, i+iResult);
|
||||
sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97764,6 +97777,7 @@ static void codeAttach(
|
||||
sqlite3* db = pParse->db;
|
||||
int regArgs;
|
||||
|
||||
if( pParse->nErr ) goto attach_end;
|
||||
memset(&sName, 0, sizeof(NameContext));
|
||||
sName.pParse = pParse;
|
||||
|
||||
@ -104309,6 +104323,8 @@ static void instrFunc(
|
||||
zHaystack = sqlite3_value_text(argv[0]);
|
||||
zNeedle = sqlite3_value_text(argv[1]);
|
||||
isText = 1;
|
||||
if( zNeedle==0 ) return;
|
||||
assert( zHaystack );
|
||||
}
|
||||
while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
|
||||
N++;
|
||||
@ -124771,6 +124787,7 @@ static int codeEqualityTerm(
|
||||
}else{
|
||||
Select *pSelect = pX->x.pSelect;
|
||||
sqlite3 *db = pParse->db;
|
||||
u16 savedDbOptFlags = db->dbOptFlags;
|
||||
ExprList *pOrigRhs = pSelect->pEList;
|
||||
ExprList *pOrigLhs = pX->pLeft->x.pList;
|
||||
ExprList *pRhs = 0; /* New Select.pEList for RHS */
|
||||
@ -124814,7 +124831,9 @@ static int codeEqualityTerm(
|
||||
testcase( aiMap==0 );
|
||||
}
|
||||
pSelect->pEList = pRhs;
|
||||
db->dbOptFlags |= SQLITE_QueryFlattener;
|
||||
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
|
||||
db->dbOptFlags = savedDbOptFlags;
|
||||
testcase( aiMap!=0 && aiMap[0]!=0 );
|
||||
pSelect->pEList = pOrigRhs;
|
||||
pLeft->x.pList = pOrigLhs;
|
||||
@ -127633,6 +127652,8 @@ static void exprAnalyze(
|
||||
/* Prevent ON clause terms of a LEFT JOIN from being used to drive
|
||||
** an index for tables to the left of the join.
|
||||
*/
|
||||
testcase( pTerm!=&pWC->a[idxTerm] );
|
||||
pTerm = &pWC->a[idxTerm];
|
||||
pTerm->prereqRight |= extraRight;
|
||||
}
|
||||
|
||||
@ -165385,20 +165406,20 @@ SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
|
||||
void *pContext; /* sqlite3_user_data() context */
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
|
||||
} scalars[] = {
|
||||
{"regexp", 2, SQLITE_ANY, 0, icuRegexpFunc},
|
||||
{"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc},
|
||||
|
||||
{"lower", 1, SQLITE_UTF16, 0, icuCaseFunc16},
|
||||
{"lower", 2, SQLITE_UTF16, 0, icuCaseFunc16},
|
||||
{"upper", 1, SQLITE_UTF16, (void*)1, icuCaseFunc16},
|
||||
{"upper", 2, SQLITE_UTF16, (void*)1, icuCaseFunc16},
|
||||
{"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
|
||||
{"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
|
||||
{"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
|
||||
{"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
|
||||
|
||||
{"lower", 1, SQLITE_UTF8, 0, icuCaseFunc16},
|
||||
{"lower", 2, SQLITE_UTF8, 0, icuCaseFunc16},
|
||||
{"upper", 1, SQLITE_UTF8, (void*)1, icuCaseFunc16},
|
||||
{"upper", 2, SQLITE_UTF8, (void*)1, icuCaseFunc16},
|
||||
{"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
|
||||
{"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
|
||||
{"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
|
||||
{"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
|
||||
|
||||
{"like", 2, SQLITE_UTF8, 0, icuLikeFunc},
|
||||
{"like", 3, SQLITE_UTF8, 0, icuLikeFunc},
|
||||
{"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
|
||||
{"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
|
||||
|
||||
{"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
|
||||
};
|
||||
@ -176416,13 +176437,15 @@ SQLITE_EXTENSION_INIT1
|
||||
#ifdef sqlite3Isdigit
|
||||
/* Use the SQLite core versions if this routine is part of the
|
||||
** SQLite amalgamation */
|
||||
# define safe_isdigit(x) sqlite3Isdigit(x)
|
||||
# define safe_isalnum(x) sqlite3Isalnum(x)
|
||||
# define safe_isdigit(x) sqlite3Isdigit(x)
|
||||
# define safe_isalnum(x) sqlite3Isalnum(x)
|
||||
# define safe_isxdigit(x) sqlite3Isxdigit(x)
|
||||
#else
|
||||
/* Use the standard library for separate compilation */
|
||||
#include <ctype.h> /* amalgamator: keep */
|
||||
# define safe_isdigit(x) isdigit((unsigned char)(x))
|
||||
# define safe_isalnum(x) isalnum((unsigned char)(x))
|
||||
# define safe_isdigit(x) isdigit((unsigned char)(x))
|
||||
# define safe_isalnum(x) isalnum((unsigned char)(x))
|
||||
# define safe_isxdigit(x) isxdigit((unsigned char)(x))
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -177069,6 +177092,15 @@ static int jsonParseAddNode(
|
||||
return pParse->nNode++;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return true if z[] begins with 4 (or more) hexadecimal digits
|
||||
*/
|
||||
static int jsonIs4Hex(const char *z){
|
||||
int i;
|
||||
for(i=0; i<4; i++) if( !safe_isxdigit(z[i]) ) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Parse a single JSON value which begins at pParse->zJson[i]. Return the
|
||||
** index of the first character past the end of the value parsed.
|
||||
@ -177143,8 +177175,13 @@ static int jsonParseValue(JsonParse *pParse, u32 i){
|
||||
if( c==0 ) return -1;
|
||||
if( c=='\\' ){
|
||||
c = pParse->zJson[++j];
|
||||
if( c==0 ) return -1;
|
||||
jnFlags = JNODE_ESCAPE;
|
||||
if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
|
||||
|| c=='n' || c=='r' || c=='t'
|
||||
|| (c=='u' && jsonIs4Hex(pParse->zJson+j+1)) ){
|
||||
jnFlags = JNODE_ESCAPE;
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}else if( c=='"' ){
|
||||
break;
|
||||
}
|
||||
@ -178012,7 +178049,7 @@ static void jsonObjectFinal(sqlite3_context *ctx){
|
||||
if( pStr ){
|
||||
jsonAppendChar(pStr, '}');
|
||||
if( pStr->bErr ){
|
||||
if( pStr->bErr==0 ) sqlite3_result_error_nomem(ctx);
|
||||
if( pStr->bErr==1 ) sqlite3_result_error_nomem(ctx);
|
||||
assert( pStr->bStatic );
|
||||
}else{
|
||||
sqlite3_result_text(ctx, pStr->zBuf, pStr->nUsed,
|
||||
@ -178290,9 +178327,9 @@ static int jsonEachColumn(
|
||||
/* For json_each() path and root are the same so fall through
|
||||
** into the root case */
|
||||
}
|
||||
case JEACH_ROOT: {
|
||||
default: {
|
||||
const char *zRoot = p->zRoot;
|
||||
if( zRoot==0 ) zRoot = "$";
|
||||
if( zRoot==0 ) zRoot = "$";
|
||||
sqlite3_result_text(ctx, zRoot, -1, SQLITE_STATIC);
|
||||
break;
|
||||
}
|
||||
@ -184219,7 +184256,7 @@ static int fts5ExprNodeTest_STRING(
|
||||
}
|
||||
}else{
|
||||
Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
|
||||
if( pIter->iRowid==iLast ) continue;
|
||||
if( pIter->iRowid==iLast || pIter->bEof ) continue;
|
||||
bMatch = 0;
|
||||
if( fts5ExprAdvanceto(pIter, bDesc, &iLast, &rc, &pNode->bEof) ){
|
||||
return rc;
|
||||
@ -189359,6 +189396,7 @@ static void fts5MultiIterNext(
|
||||
i64 iFrom /* Advance at least as far as this */
|
||||
){
|
||||
int bUseFrom = bFrom;
|
||||
assert( pIter->base.bEof==0 );
|
||||
while( p->rc==SQLITE_OK ){
|
||||
int iFirst = pIter->aFirst[1].iFirst;
|
||||
int bNewTerm = 0;
|
||||
@ -195623,7 +195661,7 @@ static void fts5SourceIdFunc(
|
||||
){
|
||||
assert( nArg==0 );
|
||||
UNUSED_PARAM2(nArg, apUnused);
|
||||
sqlite3_result_text(pCtx, "fts5: 2016-11-04 12:08:49 1136863c76576110e710dd5d69ab6bf347c65e36", -1, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(pCtx, "fts5: 2016-11-28 19:13:37 bbd85d235f7037c6a033a9690534391ffeacecc8", -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
static int fts5Init(sqlite3 *db){
|
||||
|
@ -121,9 +121,9 @@ extern "C" {
|
||||
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
|
||||
** [sqlite_version()] and [sqlite_source_id()].
|
||||
*/
|
||||
#define SQLITE_VERSION "3.15.1"
|
||||
#define SQLITE_VERSION_NUMBER 3015001
|
||||
#define SQLITE_SOURCE_ID "2016-11-04 12:08:49 1136863c76576110e710dd5d69ab6bf347c65e36"
|
||||
#define SQLITE_VERSION "3.15.2"
|
||||
#define SQLITE_VERSION_NUMBER 3015002
|
||||
#define SQLITE_SOURCE_ID "2016-11-28 19:13:37 bbd85d235f7037c6a033a9690534391ffeacecc8"
|
||||
|
||||
/*
|
||||
** CAPI3REF: Run-Time Library Version Numbers
|
||||
|
@ -93,11 +93,6 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(principal->GetIsNullPrincipal())) {
|
||||
mRv.Throw(NS_ERROR_FAILURE);
|
||||
return true;
|
||||
}
|
||||
|
||||
mRv = PrincipalToPrincipalInfo(principal, &mPrincipalInfo);
|
||||
if (NS_WARN_IF(mRv.Failed())) {
|
||||
return true;
|
||||
@ -323,11 +318,6 @@ BroadcastChannel::Constructor(const GlobalObject& aGlobal,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(principal->GetIsNullPrincipal())) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
aRv = principal->GetOrigin(origin);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
|
@ -22,3 +22,4 @@ support-files =
|
||||
[test_invalidState.html]
|
||||
[test_ordering.html]
|
||||
[test_dataCloning.html]
|
||||
[test_dataURL.html]
|
||||
|
35
dom/broadcastchannel/tests/test_dataURL.html
Normal file
35
dom/broadcastchannel/tests/test_dataURL.html
Normal file
@ -0,0 +1,35 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for BroadcastChannel in data: URL</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="dataURL">
|
||||
var a = new BroadcastChannel('a');
|
||||
var b = new BroadcastChannel('a');
|
||||
a.onmessage = function(e) { parent.postMessage(e.data, "*"); };
|
||||
b.postMessage(42);
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
onmessage= function(e) {
|
||||
ok(e.data, "42", "BroadcastChannel works with data URLs");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
var url = "data:text/html,<script>" + document.getElementById("dataURL").textContent + "</" + "script>";
|
||||
|
||||
var ifr = document.createElement('iframe');
|
||||
document.body.appendChild(ifr);
|
||||
|
||||
ifr.setAttribute('sandbox', 'allow-scripts');
|
||||
ifr.src = url;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -650,7 +650,7 @@ TexUnpackImage::TexOrSubImage(bool isSubImage, bool needsRespec, const char* fun
|
||||
webgl->ErrorOutOfMemory("%s: GetAsSourceSurface or GetDataSurface failed after"
|
||||
" blit failed for TexUnpackImage.",
|
||||
funcName);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
const TexUnpackSurface surfBlob(webgl, target, mWidth, mHeight, mDepth, dataSurf,
|
||||
|
@ -264,6 +264,10 @@ public:
|
||||
{
|
||||
mDecoder->SetSeekThreshold(aTime);
|
||||
}
|
||||
bool SupportDecoderRecycling() const override
|
||||
{
|
||||
return mDecoder->SupportDecoderRecycling();
|
||||
}
|
||||
void Shutdown() override
|
||||
{
|
||||
mDecoder->Shutdown();
|
||||
@ -1302,29 +1306,39 @@ MediaFormatReader::HandleDemuxedSamples(TrackType aTrack,
|
||||
return;
|
||||
}
|
||||
|
||||
bool supportRecycling = MediaPrefs::MediaDecoderCheckRecycling() &&
|
||||
decoder.mDecoder->SupportDecoderRecycling();
|
||||
if (decoder.mNextStreamSourceID.isNothing() ||
|
||||
decoder.mNextStreamSourceID.ref() != info->GetID()) {
|
||||
LOG("%s stream id has changed from:%d to:%d, draining decoder.",
|
||||
if (!supportRecycling) {
|
||||
LOG("%s stream id has changed from:%d to:%d, draining decoder.",
|
||||
TrackTypeToStr(aTrack), decoder.mLastStreamSourceID,
|
||||
info->GetID());
|
||||
decoder.mNeedDraining = true;
|
||||
decoder.mNextStreamSourceID = Some(info->GetID());
|
||||
ScheduleUpdate(aTrack);
|
||||
return;
|
||||
decoder.mNeedDraining = true;
|
||||
decoder.mNextStreamSourceID = Some(info->GetID());
|
||||
ScheduleUpdate(aTrack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LOG("%s stream id has changed from:%d to:%d, recreating decoder.",
|
||||
LOG("%s stream id has changed from:%d to:%d.",
|
||||
TrackTypeToStr(aTrack), decoder.mLastStreamSourceID,
|
||||
info->GetID());
|
||||
decoder.mLastStreamSourceID = info->GetID();
|
||||
decoder.mNextStreamSourceID.reset();
|
||||
// Reset will clear our array of queued samples. So make a copy now.
|
||||
nsTArray<RefPtr<MediaRawData>> samples{decoder.mQueuedSamples};
|
||||
Reset(aTrack);
|
||||
decoder.ShutdownDecoder();
|
||||
if (!supportRecycling) {
|
||||
LOG("Decoder does not support recycling, recreate decoder.");
|
||||
// Reset will clear our array of queued samples. So make a copy now.
|
||||
nsTArray<RefPtr<MediaRawData>> samples{decoder.mQueuedSamples};
|
||||
Reset(aTrack);
|
||||
decoder.ShutdownDecoder();
|
||||
if (sample->mKeyframe) {
|
||||
decoder.mQueuedSamples.AppendElements(Move(samples));
|
||||
}
|
||||
}
|
||||
|
||||
decoder.mInfo = info;
|
||||
if (sample->mKeyframe) {
|
||||
decoder.mQueuedSamples.AppendElements(Move(samples));
|
||||
ScheduleUpdate(aTrack);
|
||||
} else {
|
||||
TimeInterval time =
|
||||
|
@ -130,6 +130,7 @@ private:
|
||||
DECL_MEDIA_PREF("media.decoder.fuzzing.enabled", PDMFuzzingEnabled, bool, false);
|
||||
DECL_MEDIA_PREF("media.decoder.fuzzing.video-output-minimum-interval-ms", PDMFuzzingInterval, uint32_t, 0);
|
||||
DECL_MEDIA_PREF("media.decoder.fuzzing.dont-delay-inputexhausted", PDMFuzzingDelayInputExhausted, bool, true);
|
||||
DECL_MEDIA_PREF("media.decoder.recycle.enabled", MediaDecoderCheckRecycling, bool, false);
|
||||
DECL_MEDIA_PREF("media.gmp.decoder.enabled", PDMGMPEnabled, bool, true);
|
||||
DECL_MEDIA_PREF("media.gmp.decoder.aac", GMPAACPreferred, uint32_t, 0);
|
||||
DECL_MEDIA_PREF("media.gmp.decoder.h264", GMPH264Preferred, uint32_t, 0);
|
||||
|
@ -297,6 +297,12 @@ public:
|
||||
// video decoder implements this API to improve seek performance.
|
||||
// Note: it should be called before Input() or after Flush().
|
||||
virtual void SetSeekThreshold(const media::TimeUnit& aTime) {}
|
||||
|
||||
// When playing adaptive playback, recreating an Android video decoder will
|
||||
// cause the transition not smooth during resolution change.
|
||||
// Reuse the decoder if the decoder support recycling.
|
||||
// Currently, only Android video decoder will return true.
|
||||
virtual bool SupportDecoderRecycling() const { return false; }
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -123,6 +123,8 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool SupportDecoderRecycling() const override { return true; }
|
||||
|
||||
protected:
|
||||
layers::ImageContainer* mImageContainer;
|
||||
const VideoInfo& mConfig;
|
||||
|
@ -245,6 +245,8 @@ public:
|
||||
mInputDurations.Put(aSample->mDuration);
|
||||
}
|
||||
|
||||
bool SupportDecoderRecycling() const override { return true; }
|
||||
|
||||
private:
|
||||
class DurationQueue {
|
||||
public:
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "H264Converter.h"
|
||||
#include "ImageContainer.h"
|
||||
#include "MediaInfo.h"
|
||||
#include "MediaPrefs.h"
|
||||
#include "mp4_demuxer/AnnexB.h"
|
||||
#include "mp4_demuxer/H264.h"
|
||||
|
||||
@ -285,6 +286,14 @@ H264Converter::CheckForSPSChange(MediaRawData* aSample)
|
||||
mCurrentConfig.mExtraData)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (MediaPrefs::MediaDecoderCheckRecycling() &&
|
||||
mDecoder->SupportDecoderRecycling()) {
|
||||
// Do not recreate the decoder, reuse it.
|
||||
UpdateConfigFromExtraData(extra_data);
|
||||
mNeedKeyframe = true;
|
||||
return NS_OK;
|
||||
}
|
||||
// The SPS has changed, signal to flush the current decoder and create a
|
||||
// new one.
|
||||
mDecoder->Flush();
|
||||
|
@ -39,6 +39,13 @@ public:
|
||||
return "H264Converter decoder (pending)";
|
||||
}
|
||||
void SetSeekThreshold(const media::TimeUnit& aTime) override;
|
||||
bool SupportDecoderRecycling() const override
|
||||
{
|
||||
if (mDecoder) {
|
||||
return mDecoder->SupportDecoderRecycling();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
nsresult GetLastError() const { return mLastError; }
|
||||
|
||||
|
@ -195,8 +195,18 @@ public:
|
||||
|
||||
CGContextRef cg;
|
||||
private:
|
||||
#ifdef USE_SKIA
|
||||
static CGContextRef BorrowCGContextFromDrawTarget(DrawTarget *aDT);
|
||||
static void ReturnCGContextToDrawTarget(DrawTarget *aDT, CGContextRef cg);
|
||||
#else
|
||||
static CGContextRef BorrowCGContextFromDrawTarget(DrawTarget *aDT) {
|
||||
MOZ_CRASH("Not supported without Skia");
|
||||
}
|
||||
|
||||
static void ReturnCGContextToDrawTarget(DrawTarget *aDT, CGContextRef cg) {
|
||||
MOZ_CRASH("not supported without Skia");
|
||||
}
|
||||
#endif
|
||||
DrawTarget *mDT;
|
||||
};
|
||||
#endif
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "CompositableHost.h" // for CompositableHost
|
||||
#include "ContainerLayerComposite.h" // for ContainerLayerComposite, etc
|
||||
#include "FPSCounter.h" // for FPSState, FPSCounter
|
||||
#include "PaintCounter.h" // For PaintCounter
|
||||
#include "FrameMetrics.h" // for FrameMetrics
|
||||
#include "GeckoProfiler.h" // for profiler_set_frame_number, etc
|
||||
#include "ImageLayerComposite.h" // for ImageLayerComposite
|
||||
@ -69,6 +68,10 @@
|
||||
#include "mozilla/layers/CompositorBridgeParent.h"
|
||||
#include "TreeTraversal.h" // for ForEachNode
|
||||
|
||||
#ifdef USE_SKIA
|
||||
#include "PaintCounter.h" // For PaintCounter
|
||||
#endif
|
||||
|
||||
class gfxContext;
|
||||
|
||||
namespace mozilla {
|
||||
@ -134,6 +137,10 @@ LayerManagerComposite::LayerManagerComposite(Compositor* aCompositor)
|
||||
{
|
||||
mTextRenderer = new TextRenderer(aCompositor);
|
||||
MOZ_ASSERT(aCompositor);
|
||||
|
||||
#ifdef USE_SKIA
|
||||
mPaintCounter = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
LayerManagerComposite::~LayerManagerComposite()
|
||||
@ -153,8 +160,11 @@ LayerManagerComposite::Destroy()
|
||||
mCompositor->CancelFrame();
|
||||
mRoot = nullptr;
|
||||
mClonedLayerTreeProperties = nullptr;
|
||||
mPaintCounter = nullptr;
|
||||
mDestroyed = true;
|
||||
|
||||
#ifdef USE_SKIA
|
||||
mPaintCounter = nullptr;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -527,7 +537,6 @@ LayerManagerComposite::InvalidateDebugOverlay(nsIntRegion& aInvalidRegion, const
|
||||
bool drawFps = gfxPrefs::LayersDrawFPS();
|
||||
bool drawFrameCounter = gfxPrefs::DrawFrameCounter();
|
||||
bool drawFrameColorBars = gfxPrefs::CompositorDrawColorBars();
|
||||
bool drawPaintTimes = gfxPrefs::AlwaysPaint();
|
||||
|
||||
if (drawFps || drawFrameCounter) {
|
||||
aInvalidRegion.Or(aInvalidRegion, nsIntRect(0, 0, 256, 256));
|
||||
@ -535,11 +544,16 @@ LayerManagerComposite::InvalidateDebugOverlay(nsIntRegion& aInvalidRegion, const
|
||||
if (drawFrameColorBars) {
|
||||
aInvalidRegion.Or(aInvalidRegion, nsIntRect(0, 0, 10, aBounds.height));
|
||||
}
|
||||
|
||||
#ifdef USE_SKIA
|
||||
bool drawPaintTimes = gfxPrefs::AlwaysPaint();
|
||||
if (drawPaintTimes) {
|
||||
aInvalidRegion.Or(aInvalidRegion, nsIntRect(PaintCounter::GetPaintRect()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_SKIA
|
||||
void
|
||||
LayerManagerComposite::DrawPaintTimes(Compositor* aCompositor)
|
||||
{
|
||||
@ -550,6 +564,7 @@ LayerManagerComposite::DrawPaintTimes(Compositor* aCompositor)
|
||||
TimeDuration compositeTime = TimeStamp::Now() - mRenderStartTime;
|
||||
mPaintCounter->Draw(aCompositor, mLastPaintTime, compositeTime);
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint16_t sFrameCount = 0;
|
||||
void
|
||||
@ -558,7 +573,6 @@ LayerManagerComposite::RenderDebugOverlay(const IntRect& aBounds)
|
||||
bool drawFps = gfxPrefs::LayersDrawFPS();
|
||||
bool drawFrameCounter = gfxPrefs::DrawFrameCounter();
|
||||
bool drawFrameColorBars = gfxPrefs::CompositorDrawColorBars();
|
||||
bool drawPaintTimes = gfxPrefs::AlwaysPaint();
|
||||
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
|
||||
@ -699,9 +713,12 @@ LayerManagerComposite::RenderDebugOverlay(const IntRect& aBounds)
|
||||
sFrameCount++;
|
||||
}
|
||||
|
||||
#ifdef USE_SKIA
|
||||
bool drawPaintTimes = gfxPrefs::AlwaysPaint();
|
||||
if (drawPaintTimes) {
|
||||
DrawPaintTimes(mCompositor);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
RefPtr<CompositingRenderTarget>
|
||||
|
@ -172,7 +172,6 @@ protected:
|
||||
mozilla::TimeStamp mWarnTime;
|
||||
|
||||
bool mWindowOverlayChanged;
|
||||
RefPtr<PaintCounter> mPaintCounter;
|
||||
TimeDuration mLastPaintTime;
|
||||
TimeStamp mRenderStartTime;
|
||||
};
|
||||
@ -386,11 +385,6 @@ private:
|
||||
void RenderToPresentationSurface();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Render paint and composite times above the frame.
|
||||
*/
|
||||
void DrawPaintTimes(Compositor* aCompositor);
|
||||
|
||||
/**
|
||||
* We need to know our invalid region before we're ready to render.
|
||||
*/
|
||||
@ -436,6 +430,14 @@ private:
|
||||
RefPtr<CompositingRenderTarget> mTwoPassTmpTarget;
|
||||
RefPtr<TextRenderer> mTextRenderer;
|
||||
bool mGeometryChanged;
|
||||
|
||||
#ifdef USE_SKIA
|
||||
/**
|
||||
* Render paint and composite times above the frame.
|
||||
*/
|
||||
void DrawPaintTimes(Compositor* aCompositor);
|
||||
RefPtr<PaintCounter> mPaintCounter;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -321,7 +321,6 @@ UNIFIED_SOURCES += [
|
||||
'composite/ImageHost.cpp',
|
||||
'composite/ImageLayerComposite.cpp',
|
||||
'composite/LayerManagerComposite.cpp',
|
||||
'composite/PaintCounter.cpp',
|
||||
'composite/PaintedLayerComposite.cpp',
|
||||
'composite/TextRenderer.cpp',
|
||||
'composite/TextureHost.cpp',
|
||||
@ -450,3 +449,8 @@ LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']
|
||||
|
||||
if CONFIG['GNU_CXX']:
|
||||
CXXFLAGS += ['-Wno-error=shadow']
|
||||
|
||||
if CONFIG['MOZ_ENABLE_SKIA']:
|
||||
UNIFIED_SOURCES += [
|
||||
'composite/PaintCounter.cpp',
|
||||
]
|
||||
|
@ -152,6 +152,9 @@
|
||||
|
||||
#define SK_IGNORE_ETC1_SUPPORT
|
||||
|
||||
// Don't use __stdcall with SkiaGLGlue - bug 1320644
|
||||
#define GR_GL_FUNCTION_TYPE
|
||||
|
||||
#define SK_RASTERIZE_EVEN_ROUNDING
|
||||
|
||||
#define SK_DISABLE_SCREENSPACE_TESS_AA_PATH_RENDERER
|
||||
|
@ -521,11 +521,6 @@ public:
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(mPrincipalInfo);
|
||||
|
||||
if (principal->GetIsNullPrincipal()) {
|
||||
mContentParent->KillHard("BroadcastChannel killed: no null principal.");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoCString origin;
|
||||
nsresult rv = principal->GetOrigin(origin);
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -638,7 +633,6 @@ BackgroundParentImpl::RecvPBroadcastChannelConstructor(
|
||||
|
||||
// If the ContentParent is null we are dealing with a same-process actor.
|
||||
if (!parent) {
|
||||
MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::TNullPrincipalInfo);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,14 @@ PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo,
|
||||
case PrincipalInfo::TNullPrincipalInfo: {
|
||||
const NullPrincipalInfo& info =
|
||||
aPrincipalInfo.get_NullPrincipalInfo();
|
||||
principal = nsNullPrincipal::Create(info.attrs());
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), info.spec());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
principal = nsNullPrincipal::Create(info.attrs(), uri);
|
||||
return principal.forget();
|
||||
}
|
||||
|
||||
@ -131,7 +137,25 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
|
||||
MOZ_ASSERT(aPrincipalInfo);
|
||||
|
||||
if (aPrincipal->GetIsNullPrincipal()) {
|
||||
*aPrincipalInfo = NullPrincipalInfo(BasePrincipal::Cast(aPrincipal)->OriginAttributesRef());
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = aPrincipal->GetURI(getter_AddRefs(uri));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(!uri)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsAutoCString spec;
|
||||
rv = uri->GetSpec(spec);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aPrincipalInfo =
|
||||
NullPrincipalInfo(BasePrincipal::Cast(aPrincipal)->OriginAttributesRef(),
|
||||
spec);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -191,7 +215,7 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCString spec;
|
||||
nsAutoCString spec;
|
||||
rv = uri->GetSpec(spec);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
|
@ -20,6 +20,7 @@ struct SystemPrincipalInfo
|
||||
struct NullPrincipalInfo
|
||||
{
|
||||
PrincipalOriginAttributes attrs;
|
||||
nsCString spec;
|
||||
};
|
||||
|
||||
struct ExpandedPrincipalInfo
|
||||
|
@ -2242,7 +2242,7 @@ js::Promise_then(JSContext* cx, unsigned argc, Value* vp)
|
||||
} else {
|
||||
RootedObject unwrappedPromiseObj(cx, CheckedUnwrap(promiseObj));
|
||||
if (!unwrappedPromiseObj) {
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_UNWRAP_DENIED);
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
if (!unwrappedPromiseObj->is<PromiseObject>()) {
|
||||
|
@ -2582,7 +2582,7 @@ SharedAddress(JSContext* cx, unsigned argc, Value* vp)
|
||||
#else
|
||||
RootedObject obj(cx, CheckedUnwrap(&args[0].toObject()));
|
||||
if (!obj) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
if (!obj->is<SharedArrayBufferObject>()) {
|
||||
@ -3579,12 +3579,12 @@ GetLcovInfo(JSContext* cx, unsigned argc, Value* vp)
|
||||
if (args.hasDefined(0)) {
|
||||
global = ToObject(cx, args[0]);
|
||||
if (!global) {
|
||||
JS_ReportErrorASCII(cx, "First argument should be an object");
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access global");
|
||||
return false;
|
||||
}
|
||||
global = CheckedUnwrap(global);
|
||||
if (!global) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access global");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
if (!global->is<GlobalObject>()) {
|
||||
|
@ -790,14 +790,6 @@ class GCRuntime
|
||||
|
||||
void setFullCompartmentChecks(bool enable);
|
||||
|
||||
bool isManipulatingDeadZones() { return manipulatingDeadZones; }
|
||||
void setManipulatingDeadZones(bool value) { manipulatingDeadZones = value; }
|
||||
unsigned objectsMarkedInDeadZonesCount() { return objectsMarkedInDeadZones; }
|
||||
void incObjectsMarkedInDeadZone() {
|
||||
MOZ_ASSERT(manipulatingDeadZones);
|
||||
++objectsMarkedInDeadZones;
|
||||
}
|
||||
|
||||
JS::Zone* getCurrentZoneGroup() { return currentZoneGroup; }
|
||||
void setFoundBlackGrayEdges(TenuredCell& target) {
|
||||
AutoEnterOOMUnsafeRegion oomUnsafe;
|
||||
@ -1287,23 +1279,6 @@ class GCRuntime
|
||||
*/
|
||||
unsigned compactingDisabledCount;
|
||||
|
||||
/*
|
||||
* This is true if we are in the middle of a brain transplant (e.g.,
|
||||
* JS_TransplantObject) or some other operation that can manipulate
|
||||
* dead zones.
|
||||
*/
|
||||
bool manipulatingDeadZones;
|
||||
|
||||
/*
|
||||
* This field is incremented each time we mark an object inside a
|
||||
* zone with no incoming cross-compartment pointers. Typically if
|
||||
* this happens it signals that an incremental GC is marking too much
|
||||
* stuff. At various times we check this counter and, if it has changed, we
|
||||
* run an immediate, non-incremental GC to clean up the dead
|
||||
* zones. This should happen very rarely.
|
||||
*/
|
||||
unsigned objectsMarkedInDeadZones;
|
||||
|
||||
bool poked;
|
||||
|
||||
/*
|
||||
|
@ -551,7 +551,7 @@ SplitCriticalEdgesForBlock(MIRGraph& graph, MBasicBlock* block)
|
||||
|
||||
// Create a simple new block which contains a goto and which split the
|
||||
// edge between block and target.
|
||||
MBasicBlock* split = MBasicBlock::NewSplitEdge(graph, block->info(), block, i, target);
|
||||
MBasicBlock* split = MBasicBlock::NewSplitEdge(graph, block, i, target);
|
||||
if (!split)
|
||||
return false;
|
||||
}
|
||||
|
@ -275,12 +275,12 @@ MBasicBlock::NewPendingLoopHeader(MIRGraph& graph, const CompileInfo& info,
|
||||
}
|
||||
|
||||
MBasicBlock*
|
||||
MBasicBlock::NewSplitEdge(MIRGraph& graph, const CompileInfo& info, MBasicBlock* pred, size_t predEdgeIdx, MBasicBlock* succ)
|
||||
MBasicBlock::NewSplitEdge(MIRGraph& graph, MBasicBlock* pred, size_t predEdgeIdx, MBasicBlock* succ)
|
||||
{
|
||||
MBasicBlock* split = nullptr;
|
||||
if (!pred->pc()) {
|
||||
if (!succ->pc()) {
|
||||
// The predecessor does not have a PC, this is a Wasm compilation.
|
||||
split = MBasicBlock::New(graph, info, pred, SPLIT_EDGE);
|
||||
split = MBasicBlock::New(graph, succ->info(), pred, SPLIT_EDGE);
|
||||
if (!split)
|
||||
return nullptr;
|
||||
} else {
|
||||
@ -288,7 +288,7 @@ MBasicBlock::NewSplitEdge(MIRGraph& graph, const CompileInfo& info, MBasicBlock*
|
||||
MResumePoint* succEntry = succ->entryResumePoint();
|
||||
|
||||
BytecodeSite* site = new(graph.alloc()) BytecodeSite(succ->trackedTree(), succEntry->pc());
|
||||
split = new(graph.alloc()) MBasicBlock(graph, info, site, SPLIT_EDGE);
|
||||
split = new(graph.alloc()) MBasicBlock(graph, succ->info(), site, SPLIT_EDGE);
|
||||
|
||||
if (!split->init())
|
||||
return nullptr;
|
||||
|
@ -117,9 +117,8 @@ class MBasicBlock : public TempObject, public InlineListNode<MBasicBlock>
|
||||
static MBasicBlock* NewPendingLoopHeader(MIRGraph& graph, const CompileInfo& info,
|
||||
MBasicBlock* pred, BytecodeSite* site,
|
||||
unsigned loopStateSlots);
|
||||
static MBasicBlock* NewSplitEdge(MIRGraph& graph, const CompileInfo& info,
|
||||
MBasicBlock* pred, size_t predEdgeIdx,
|
||||
MBasicBlock* succ);
|
||||
static MBasicBlock* NewSplitEdge(MIRGraph& graph, MBasicBlock* pred,
|
||||
size_t predEdgeIdx, MBasicBlock* succ);
|
||||
|
||||
bool dominates(const MBasicBlock* other) const {
|
||||
return other->domIndex() - domIndex() < numDominated();
|
||||
|
@ -155,7 +155,8 @@ MSG_DEF(JSMSG_CSP_BLOCKED_FUNCTION, 0, JSEXN_ERR, "call to Function() blocked
|
||||
// Wrappers
|
||||
MSG_DEF(JSMSG_ACCESSOR_DEF_DENIED, 1, JSEXN_ERR, "Permission denied to define accessor property {0}")
|
||||
MSG_DEF(JSMSG_DEAD_OBJECT, 0, JSEXN_TYPEERR, "can't access dead object")
|
||||
MSG_DEF(JSMSG_UNWRAP_DENIED, 0, JSEXN_ERR, "permission denied to unwrap object")
|
||||
MSG_DEF(JSMSG_OBJECT_ACCESS_DENIED, 0, JSEXN_ERR, "Permission denied to access object")
|
||||
MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 1, JSEXN_ERR, "Permission denied to access property {0}")
|
||||
|
||||
// JSAPI-only (Not thrown as JS exceptions)
|
||||
MSG_DEF(JSMSG_BAD_CLONE_FUNOBJ_SCOPE, 0, JSEXN_TYPEERR, "bad cloned function scope chain")
|
||||
@ -412,8 +413,6 @@ MSG_DEF(JSMSG_CANT_SKIP_NC, 0, JSEXN_TYPEERR, "proxy can't skip a non
|
||||
MSG_DEF(JSMSG_ONWKEYS_STR_SYM, 0, JSEXN_TYPEERR, "proxy [[OwnPropertyKeys]] must return an array with only string and symbol elements")
|
||||
MSG_DEF(JSMSG_MUST_REPORT_SAME_VALUE, 0, JSEXN_TYPEERR, "proxy must report the same value for a non-writable, non-configurable property")
|
||||
MSG_DEF(JSMSG_MUST_REPORT_UNDEFINED, 0, JSEXN_TYPEERR, "proxy must report undefined for a non-configurable accessor property without a getter")
|
||||
MSG_DEF(JSMSG_OBJECT_ACCESS_DENIED, 0, JSEXN_ERR, "Permission denied to access object")
|
||||
MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 1, JSEXN_ERR, "Permission denied to access property {0}")
|
||||
MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object")
|
||||
MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target")
|
||||
MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined")
|
||||
|
@ -906,7 +906,7 @@ js::IsWrappedArrayConstructor(JSContext* cx, const Value& v, bool* result)
|
||||
if (v.toObject().is<WrapperObject>()) {
|
||||
JSObject* obj = CheckedUnwrap(&v.toObject());
|
||||
if (!obj) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -857,8 +857,6 @@ GCRuntime::GCRuntime(JSRuntime* rt) :
|
||||
generationalDisabled(0),
|
||||
compactingEnabled(true),
|
||||
compactingDisabledCount(0),
|
||||
manipulatingDeadZones(false),
|
||||
objectsMarkedInDeadZones(0),
|
||||
poked(false),
|
||||
#ifdef JS_GC_ZEAL
|
||||
zealModeBits(0),
|
||||
|
@ -358,6 +358,9 @@ CheckedUnwrap(JSObject* obj, bool stopAtWindowProxy = true);
|
||||
JS_FRIEND_API(JSObject*)
|
||||
UnwrapOneChecked(JSObject* obj, bool stopAtWindowProxy = true);
|
||||
|
||||
void
|
||||
ReportAccessDenied(JSContext* cx);
|
||||
|
||||
JS_FRIEND_API(bool)
|
||||
IsCrossCompartmentWrapper(JSObject* obj);
|
||||
|
||||
|
@ -34,7 +34,7 @@ js::AutoEnterPolicy::reportErrorIfExceptionIsNotPending(JSContext* cx, jsid id)
|
||||
return;
|
||||
|
||||
if (JSID_IS_VOID(id)) {
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_OBJECT_ACCESS_DENIED);
|
||||
ReportAccessDenied(cx);
|
||||
} else {
|
||||
RootedValue idVal(cx, IdToValue(id));
|
||||
JSString* str = ValueToSource(cx, idVal);
|
||||
|
@ -11,18 +11,12 @@
|
||||
|
||||
using namespace js;
|
||||
|
||||
static void
|
||||
ReportUnwrapDenied(JSContext *cx)
|
||||
{
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_UNWRAP_DENIED);
|
||||
}
|
||||
|
||||
template <class Base>
|
||||
bool
|
||||
SecurityWrapper<Base>::enter(JSContext* cx, HandleObject wrapper, HandleId id,
|
||||
Wrapper::Action act, bool* bp) const
|
||||
{
|
||||
ReportUnwrapDenied(cx);
|
||||
ReportAccessDenied(cx);
|
||||
*bp = false;
|
||||
return false;
|
||||
}
|
||||
@ -32,7 +26,7 @@ bool
|
||||
SecurityWrapper<Base>::nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl,
|
||||
const CallArgs& args) const
|
||||
{
|
||||
ReportUnwrapDenied(cx);
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -41,7 +35,7 @@ bool
|
||||
SecurityWrapper<Base>::setPrototype(JSContext* cx, HandleObject wrapper, HandleObject proto,
|
||||
ObjectOpResult& result) const
|
||||
{
|
||||
ReportUnwrapDenied(cx);
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -50,7 +44,7 @@ bool
|
||||
SecurityWrapper<Base>::setImmutablePrototype(JSContext* cx, HandleObject wrapper,
|
||||
bool* succeeded) const
|
||||
{
|
||||
ReportUnwrapDenied(cx);
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -87,7 +81,7 @@ template <class Base>
|
||||
bool
|
||||
SecurityWrapper<Base>::isArray(JSContext* cx, HandleObject obj, JS::IsArrayAnswer* answer) const
|
||||
{
|
||||
// This should ReportUnwrapDenied(cx), but bug 849730 disagrees. :-(
|
||||
// This should ReportAccessDenied(cx), but bug 849730 disagrees. :-(
|
||||
*answer = JS::IsArrayAnswer::NotArray;
|
||||
return true;
|
||||
}
|
||||
@ -135,7 +129,7 @@ bool
|
||||
SecurityWrapper<Base>::watch(JSContext* cx, HandleObject proxy,
|
||||
HandleId id, HandleObject callable) const
|
||||
{
|
||||
ReportUnwrapDenied(cx);
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -144,7 +138,7 @@ bool
|
||||
SecurityWrapper<Base>::unwatch(JSContext* cx, HandleObject proxy,
|
||||
HandleId id) const
|
||||
{
|
||||
ReportUnwrapDenied(cx);
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -382,6 +382,12 @@ js::UnwrapOneChecked(JSObject* obj, bool stopAtWindowProxy)
|
||||
return handler->hasSecurityPolicy() ? nullptr : Wrapper::wrappedObject(obj);
|
||||
}
|
||||
|
||||
void
|
||||
js::ReportAccessDenied(JSContext* cx)
|
||||
{
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_OBJECT_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
const char Wrapper::family = 0;
|
||||
const Wrapper Wrapper::singleton((unsigned)0);
|
||||
const Wrapper Wrapper::singletonWithPrototype((unsigned)0, true);
|
||||
|
@ -3575,7 +3575,7 @@ Debugger::unwrapDebuggeeArgument(JSContext* cx, const Value& v)
|
||||
/* If we have a cross-compartment wrapper, dereference as far as is secure. */
|
||||
obj = CheckedUnwrap(obj);
|
||||
if (!obj) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -8501,7 +8501,7 @@ DebuggerObject_checkThis(JSContext* cx, const CallArgs& args, const char* fnname
|
||||
THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, fnname, args, obj); \
|
||||
obj = CheckedUnwrap(obj); \
|
||||
if (!obj) { \
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object"); \
|
||||
ReportAccessDenied(cx); \
|
||||
return false; \
|
||||
} \
|
||||
if (!obj->is<PromiseObject>()) { \
|
||||
@ -8515,7 +8515,7 @@ DebuggerObject_checkThis(JSContext* cx, const CallArgs& args, const char* fnname
|
||||
THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, fnname, args, dbg, obj); \
|
||||
obj = CheckedUnwrap(obj); \
|
||||
if (!obj) { \
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object"); \
|
||||
ReportAccessDenied(cx); \
|
||||
return false; \
|
||||
} \
|
||||
if (!obj->is<PromiseObject>()) { \
|
||||
@ -9813,7 +9813,7 @@ DebuggerObject::getErrorReport(JSContext* cx, HandleObject maybeError, JSErrorRe
|
||||
obj = CheckedUnwrap(obj);
|
||||
|
||||
if (!obj) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -10387,7 +10387,7 @@ DebuggerObject::requirePromise(JSContext* cx, HandleDebuggerObject object)
|
||||
if (IsCrossCompartmentWrapper(referent)) {
|
||||
referent = CheckedUnwrap(referent);
|
||||
if (!referent) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ FindErrorInstanceOrPrototype(JSContext* cx, HandleObject obj, MutableHandleObjec
|
||||
|
||||
RootedObject target(cx, CheckedUnwrap(obj));
|
||||
if (!target) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ FindErrorInstanceOrPrototype(JSContext* cx, HandleObject obj, MutableHandleObjec
|
||||
|
||||
target = CheckedUnwrap(proto);
|
||||
if (!target) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -996,7 +996,7 @@ intrinsic_IsWrappedArrayBuffer(JSContext* cx, unsigned argc, Value* vp)
|
||||
|
||||
JSObject* unwrapped = CheckedUnwrap(obj);
|
||||
if (!unwrapped) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1027,7 +1027,7 @@ intrinsic_PossiblyWrappedArrayBufferByteLength(JSContext* cx, unsigned argc, Val
|
||||
|
||||
JSObject* obj = CheckedUnwrap(&args[0].toObject());
|
||||
if (!obj) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1052,7 +1052,7 @@ intrinsic_ArrayBufferCopyData(JSContext* cx, unsigned argc, Value* vp)
|
||||
MOZ_ASSERT(wrapped->is<WrapperObject>());
|
||||
RootedObject toBufferObj(cx, CheckedUnwrap(wrapped));
|
||||
if (!toBufferObj) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
toBuffer = toBufferObj.as<T>();
|
||||
@ -1135,7 +1135,7 @@ intrinsic_IsPossiblyWrappedTypedArray(JSContext* cx, unsigned argc, Value* vp)
|
||||
if (args[0].isObject()) {
|
||||
JSObject* obj = CheckedUnwrap(&args[0].toObject());
|
||||
if (!obj) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1208,7 +1208,7 @@ intrinsic_PossiblyWrappedTypedArrayLength(JSContext* cx, unsigned argc, Value* v
|
||||
|
||||
JSObject* obj = CheckedUnwrap(&args[0].toObject());
|
||||
if (!obj) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1227,7 +1227,7 @@ intrinsic_PossiblyWrappedTypedArrayHasDetachedBuffer(JSContext* cx, unsigned arg
|
||||
|
||||
JSObject* obj = CheckedUnwrap(&args[0].toObject());
|
||||
if (!obj) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -780,7 +780,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject
|
||||
*/
|
||||
JSObject* wrapped = CheckedUnwrap(bufobj);
|
||||
if (!wrapped) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -1166,7 +1166,7 @@ TypedArrayObjectTemplate<T>::fromTypedArray(JSContext* cx, HandleObject other, b
|
||||
} else {
|
||||
RootedObject unwrapped(cx, CheckedUnwrap(other));
|
||||
if (!unwrapped) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -1825,7 +1825,7 @@ DataViewObject::constructWrapped(JSContext* cx, HandleObject bufobj, const CallA
|
||||
|
||||
JSObject* unwrapped = CheckedUnwrap(bufobj);
|
||||
if (!unwrapped) {
|
||||
JS_ReportErrorASCII(cx, "Permission denied to access object");
|
||||
ReportAccessDenied(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -52,12 +52,7 @@ public class AccountsHelper implements NativeEventListener {
|
||||
mContext = context;
|
||||
mProfile = profile;
|
||||
|
||||
EventDispatcher dispatcher = GeckoApp.getEventDispatcher();
|
||||
if (dispatcher == null) {
|
||||
Log.e(LOGTAG, "Gecko event dispatcher must not be null", new RuntimeException());
|
||||
return;
|
||||
}
|
||||
dispatcher.registerGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"Accounts:CreateFirefoxAccountFromJSON",
|
||||
"Accounts:UpdateFirefoxAccountFromJSON",
|
||||
"Accounts:Create",
|
||||
@ -68,12 +63,7 @@ public class AccountsHelper implements NativeEventListener {
|
||||
}
|
||||
|
||||
public synchronized void uninit() {
|
||||
EventDispatcher dispatcher = GeckoApp.getEventDispatcher();
|
||||
if (dispatcher == null) {
|
||||
Log.e(LOGTAG, "Gecko event dispatcher must not be null", new RuntimeException());
|
||||
return;
|
||||
}
|
||||
dispatcher.unregisterGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"Accounts:CreateFirefoxAccountFromJSON",
|
||||
"Accounts:UpdateFirefoxAccountFromJSON",
|
||||
"Accounts:Create",
|
||||
|
@ -67,7 +67,7 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
|
||||
mStatusText = (TextView) content.findViewById(R.id.find_status);
|
||||
|
||||
mInflated = true;
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"FindInPage:MatchesCountResult",
|
||||
"TextSelection:Data");
|
||||
}
|
||||
@ -112,7 +112,7 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
|
||||
if (!mInflated) {
|
||||
return;
|
||||
}
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"FindInPage:MatchesCountResult",
|
||||
"TextSelection:Data");
|
||||
}
|
||||
|
@ -32,13 +32,8 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
|
||||
|
||||
public MediaCastingBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"Casting:Started",
|
||||
"Casting:Paused",
|
||||
"Casting:Playing",
|
||||
@ -77,17 +72,11 @@ public class MediaCastingBar extends RelativeLayout implements View.OnClickListe
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"Casting:Started",
|
||||
"Casting:Paused",
|
||||
"Casting:Playing",
|
||||
"Casting:Stopped");
|
||||
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
// View.OnClickListener implementation
|
||||
|
@ -76,9 +76,10 @@ public class MediaPlayerManager extends Fragment implements NativeEventListener
|
||||
protected final Map<String, GeckoPresentationDisplay> displays = new HashMap<String, GeckoPresentationDisplay>(); // used for Presentation API
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this,
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"MediaPlayer:Load",
|
||||
"MediaPlayer:Start",
|
||||
"MediaPlayer:Stop",
|
||||
@ -93,8 +94,8 @@ public class MediaPlayerManager extends Fragment implements NativeEventListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this,
|
||||
public void onDestroy() {
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"MediaPlayer:Load",
|
||||
"MediaPlayer:Start",
|
||||
"MediaPlayer:Stop",
|
||||
@ -106,7 +107,8 @@ public class MediaPlayerManager extends Fragment implements NativeEventListener
|
||||
"AndroidCastDevice:Start",
|
||||
"AndroidCastDevice:Stop",
|
||||
"AndroidCastDevice:SyncDevice");
|
||||
super.onStop();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
// GeckoEventListener implementation
|
||||
|
@ -64,24 +64,14 @@ public final class SharedPreferencesHelper
|
||||
|
||||
mListeners = new HashMap<String, SharedPreferences.OnSharedPreferenceChangeListener>();
|
||||
|
||||
EventDispatcher dispatcher = GeckoApp.getEventDispatcher();
|
||||
if (dispatcher == null) {
|
||||
Log.e(LOGTAG, "Gecko event dispatcher must not be null", new RuntimeException());
|
||||
return;
|
||||
}
|
||||
dispatcher.registerGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"SharedPreferences:Set",
|
||||
"SharedPreferences:Get",
|
||||
"SharedPreferences:Observe");
|
||||
}
|
||||
|
||||
public synchronized void uninit() {
|
||||
EventDispatcher dispatcher = GeckoApp.getEventDispatcher();
|
||||
if (dispatcher == null) {
|
||||
Log.e(LOGTAG, "Gecko event dispatcher must not be null", new RuntimeException());
|
||||
return;
|
||||
}
|
||||
dispatcher.unregisterGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"SharedPreferences:Set",
|
||||
"SharedPreferences:Get",
|
||||
"SharedPreferences:Observe");
|
||||
|
@ -240,10 +240,15 @@ public class ZoomedView extends FrameLayout implements LayerView.DynamicToolbarL
|
||||
}
|
||||
};
|
||||
touchListener = new ZoomedViewTouchListener();
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this,
|
||||
"Gesture:clusteredLinksClicked", "Window:Resize", "Content:LocationChange",
|
||||
"Gesture:CloseZoomedView", "Browser:ZoomToPageWidth", "Browser:ZoomToRect",
|
||||
"FormAssist:AutoComplete", "FormAssist:Hide");
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"Gesture:clusteredLinksClicked",
|
||||
"Window:Resize",
|
||||
"Content:LocationChange",
|
||||
"Gesture:CloseZoomedView",
|
||||
"Browser:ZoomToPageWidth",
|
||||
"Browser:ZoomToRect",
|
||||
"FormAssist:AutoComplete",
|
||||
"FormAssist:Hide");
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
@ -252,10 +257,15 @@ public class ZoomedView extends FrameLayout implements LayerView.DynamicToolbarL
|
||||
prefObserver = null;
|
||||
}
|
||||
ThreadUtils.removeCallbacksFromUiThread(requestRenderRunnable);
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this,
|
||||
"Gesture:clusteredLinksClicked", "Window:Resize", "Content:LocationChange",
|
||||
"Gesture:CloseZoomedView", "Browser:ZoomToPageWidth", "Browser:ZoomToRect",
|
||||
"FormAssist:AutoComplete", "FormAssist:Hide");
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"Gesture:clusteredLinksClicked",
|
||||
"Window:Resize",
|
||||
"Content:LocationChange",
|
||||
"Gesture:CloseZoomedView",
|
||||
"Browser:ZoomToPageWidth",
|
||||
"Browser:ZoomToRect",
|
||||
"FormAssist:AutoComplete",
|
||||
"FormAssist:Hide");
|
||||
}
|
||||
|
||||
// This method (onFinishInflate) is called only when the zoomed view class is used inside
|
||||
|
@ -21,7 +21,6 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.PrefsHelper;
|
||||
@ -309,7 +308,7 @@ public class BrowserSearch extends HomeFragment
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"SearchEngines:Data");
|
||||
|
||||
mSearchEngineBar.setAdapter(null);
|
||||
@ -409,7 +408,7 @@ public class BrowserSearch extends HomeFragment
|
||||
});
|
||||
|
||||
registerForContextMenu(mList);
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"SearchEngines:Data");
|
||||
|
||||
mSearchEngineBar.setOnSearchBarClickListener(this);
|
||||
|
@ -6,7 +6,7 @@
|
||||
package org.mozilla.gecko.home;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.animation.PropertyAnimator;
|
||||
@ -114,14 +114,14 @@ public class HomeBanner extends LinearLayout
|
||||
}
|
||||
});
|
||||
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this, "HomeBanner:Data");
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this, "HomeBanner:Data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this, "HomeBanner:Data");
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "HomeBanner:Data");
|
||||
}
|
||||
|
||||
public void setScrollingPages(boolean scrollingPages) {
|
||||
|
@ -14,7 +14,6 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.home.HomeConfig.PanelConfig;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
@ -78,7 +77,7 @@ public class PanelInfoManager implements GeckoEventListener {
|
||||
synchronized (sCallbacks) {
|
||||
// If there are no pending callbacks, register the event listener.
|
||||
if (sCallbacks.size() == 0) {
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"HomePanels:Data");
|
||||
}
|
||||
sCallbacks.put(requestId, callback);
|
||||
@ -137,7 +136,7 @@ public class PanelInfoManager implements GeckoEventListener {
|
||||
|
||||
// Unregister the event listener if there are no more pending callbacks.
|
||||
if (sCallbacks.size() == 0) {
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"HomePanels:Data");
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.Telemetry;
|
||||
import org.mozilla.gecko.TelemetryContract;
|
||||
@ -42,7 +41,7 @@ public class SearchPreferenceCategory extends CustomListCategory implements Geck
|
||||
super.onAttachedToActivity();
|
||||
|
||||
// Register for SearchEngines messages and request list of search engines from Gecko.
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this, "SearchEngines:Data");
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this, "SearchEngines:Data");
|
||||
GeckoAppShell.notifyObservers("SearchEngines:GetVisible", null);
|
||||
}
|
||||
|
||||
@ -50,7 +49,7 @@ public class SearchPreferenceCategory extends CustomListCategory implements Geck
|
||||
protected void onPrepareForRemoval() {
|
||||
super.onPrepareForRemoval();
|
||||
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this, "SearchEngines:Data");
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "SearchEngines:Data");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,7 +9,6 @@ import org.json.JSONObject;
|
||||
|
||||
import org.mozilla.gecko.AboutPages;
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoProfile;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
@ -36,12 +35,12 @@ public final class ReadingListHelper implements NativeEventListener {
|
||||
this.context = context;
|
||||
this.db = BrowserDB.from(profile);
|
||||
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener((NativeEventListener) this,
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener) this,
|
||||
"Reader:FaviconRequest", "Reader:AddedToCache");
|
||||
}
|
||||
|
||||
public void uninit() {
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener((NativeEventListener) this,
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener((NativeEventListener) this,
|
||||
"Reader:FaviconRequest", "Reader:AddedToCache");
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
package org.mozilla.gecko.toolbar;
|
||||
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.util.ResourceDrawableUtils;
|
||||
@ -61,14 +61,14 @@ public class PageActionLayout extends LinearLayout implements NativeEventListene
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"PageActions:Add",
|
||||
"PageActions:Remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"PageActions:Add",
|
||||
"PageActions:Remove");
|
||||
|
||||
|
@ -21,7 +21,6 @@ import org.mozilla.gecko.AboutPages;
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.SiteIdentity;
|
||||
import org.mozilla.gecko.SiteIdentity.SecurityMode;
|
||||
@ -101,7 +100,7 @@ public class SiteIdentityPopup extends AnchoredPopup implements GeckoEventListen
|
||||
}
|
||||
|
||||
void registerListeners() {
|
||||
GeckoApp.getEventDispatcher().registerGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"Doorhanger:Logins",
|
||||
"Permissions:CheckResult");
|
||||
}
|
||||
@ -561,7 +560,7 @@ public class SiteIdentityPopup extends AnchoredPopup implements GeckoEventListen
|
||||
}
|
||||
|
||||
void unregisterListeners() {
|
||||
GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this,
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
|
||||
"Doorhanger:Logins",
|
||||
"Permissions:CheckResult");
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
ac_add_options --enable-profiling
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
# Global options
|
||||
ac_add_options --enable-debug
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
# L10n
|
||||
ac_add_options --with-l10n-base=../../l10n-central
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
# L10n
|
||||
ac_add_options --with-l10n-base=..
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
ac_add_options --enable-profiling
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
# Android
|
||||
ac_add_options --with-android-min-sdk=15
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
# Global options
|
||||
ac_add_options --enable-debug
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
# L10n
|
||||
ac_add_options --with-l10n-base=../../l10n-central
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
# L10n
|
||||
ac_add_options --with-l10n-base=..
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
ac_add_options --target=i386-linux-android
|
||||
ac_add_options --with-android-min-sdk=15
|
||||
|
@ -1,4 +1,5 @@
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
# Android
|
||||
ac_add_options --target=i386-linux-android
|
||||
|
@ -1,5 +1,6 @@
|
||||
# currently a copy of mobile/android/config/mozconfigs/android-api-15/nightly
|
||||
. "$topsrcdir/mobile/android/config/mozconfigs/common"
|
||||
. "$topsrcdir/build/mozconfig.rust"
|
||||
|
||||
ac_add_options --enable-profiling
|
||||
|
||||
|
@ -607,6 +607,9 @@ pref("media.video-queue.send-to-compositor-size", 9999);
|
||||
// Whether to disable the video stats to prevent fingerprinting
|
||||
pref("media.video_stats.enabled", true);
|
||||
|
||||
// Whether to check the decoder supports recycling.
|
||||
pref("media.decoder.recycle.enabled", false);
|
||||
|
||||
// Weather we allow AMD switchable graphics
|
||||
pref("layers.amd-switchable-gfx.enabled", true);
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DIRS += ['converters']
|
||||
TEST_DIRS += ['test']
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'mozITXTToHTMLConv.idl',
|
||||
|
@ -1,140 +0,0 @@
|
||||
#include "Converters.h"
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// TestConverter
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
#define NS_TESTCONVERTER_CID \
|
||||
{ /* B8A067B0-4450-11d3-A16E-0050041CAF44 */ \
|
||||
0xb8a067b0, \
|
||||
0x4450, \
|
||||
0x11d3, \
|
||||
{0xa1, 0x6e, 0x00, 0x50, 0x04, 0x1c, 0xaf, 0x44} \
|
||||
}
|
||||
|
||||
NS_DEFINE_CID(kTestConverterCID, NS_TESTCONVERTER_CID);
|
||||
|
||||
NS_IMPL_ISUPPORTS(TestConverter,
|
||||
nsIStreamConverter,
|
||||
nsIStreamListener,
|
||||
nsIRequestObserver)
|
||||
|
||||
TestConverter::TestConverter() {
|
||||
}
|
||||
|
||||
// Convert aFromStream (of type aFromType), to _retval (nsIInputStream of type aToType).
|
||||
// This Convert method simply converts the stream byte-by-byte, to the first character
|
||||
// in the aToType "string".
|
||||
NS_IMETHODIMP
|
||||
TestConverter::Convert(nsIInputStream *aFromStream,
|
||||
const char *aFromType,
|
||||
const char *aToType,
|
||||
nsISupports *ctxt,
|
||||
nsIInputStream **_retval) {
|
||||
char buf[1024+1];
|
||||
uint32_t read;
|
||||
nsresult rv = aFromStream->Read(buf, 1024, &read);
|
||||
if (NS_FAILED(rv) || read == 0) return rv;
|
||||
|
||||
// verify that the data we're converting matches the from type
|
||||
// if it doesn't then we're being handed the wrong data.
|
||||
char fromChar = *aFromType;
|
||||
|
||||
if (fromChar != buf[0]) {
|
||||
printf("We're receiving %c, but are supposed to have %c.\n", buf[0], fromChar);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
// Get the first character
|
||||
char toChar = *aToType;
|
||||
|
||||
for (uint32_t i = 0; i < read; i++)
|
||||
buf[i] = toChar;
|
||||
|
||||
buf[read] = '\0';
|
||||
|
||||
nsCOMPtr<nsIStringInputStream> str
|
||||
(do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = str->SetData(buf, read);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_ADDREF(*_retval = str);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* This method initializes any internal state before the stream converter
|
||||
* begins asynchronous conversion */
|
||||
NS_IMETHODIMP
|
||||
TestConverter::AsyncConvertData(const char *aFromType,
|
||||
const char *aToType,
|
||||
nsIStreamListener *aListener,
|
||||
nsISupports *ctxt) {
|
||||
NS_ASSERTION(aListener, "null listener");
|
||||
|
||||
mListener = aListener;
|
||||
|
||||
// based on these types, setup internal state to handle the appropriate conversion.
|
||||
fromType = aFromType;
|
||||
toType = aToType;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIStreamListener method
|
||||
/* This method handles asyncronous conversion of data. */
|
||||
NS_IMETHODIMP
|
||||
TestConverter::OnDataAvailable(nsIRequest* request,
|
||||
nsISupports *ctxt,
|
||||
nsIInputStream *inStr,
|
||||
uint64_t sourceOffset,
|
||||
uint32_t count) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStream> convertedStream;
|
||||
// just make a syncronous call to the Convert() method.
|
||||
// Anything can happen here, I just happen to be using the sync call to
|
||||
// do the actual conversion.
|
||||
rv = Convert(inStr, fromType.get(), toType.get(), ctxt, getter_AddRefs(convertedStream));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
uint64_t len = 0;
|
||||
convertedStream->Available(&len);
|
||||
|
||||
uint64_t offset = sourceOffset;
|
||||
while (len > 0) {
|
||||
uint32_t count = saturated(len);
|
||||
rv = mListener->OnDataAvailable(request, ctxt, convertedStream, offset, count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
offset += count;
|
||||
len -= count;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIRequestObserver methods
|
||||
/* These methods just pass through directly to the mListener */
|
||||
NS_IMETHODIMP
|
||||
TestConverter::OnStartRequest(nsIRequest* request, nsISupports *ctxt) {
|
||||
return mListener->OnStartRequest(request, ctxt);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TestConverter::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
||||
nsresult aStatus) {
|
||||
return mListener->OnStopRequest(request, ctxt, aStatus);
|
||||
}
|
||||
|
||||
nsresult
|
||||
CreateTestConverter(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
||||
{
|
||||
nsCOMPtr<nsISupports> conv = new TestConverter();
|
||||
return conv->QueryInterface(aIID, aResult);
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
#ifndef Converters_h___
|
||||
#define Converters_h___
|
||||
|
||||
#include "nsIStreamConverter.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsStringAPI.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
/* This file defines stream converter components, and their accompanying factory class.
|
||||
* These converters implement the nsIStreamConverter interface and support both
|
||||
* asynchronous and synchronous stream conversion.
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// TestConverter
|
||||
|
||||
extern const nsCID kTestConverterCID;
|
||||
|
||||
class TestConverter : public nsIStreamConverter {
|
||||
virtual ~TestConverter() {}
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
|
||||
TestConverter();
|
||||
|
||||
// nsIStreamConverter methods
|
||||
NS_IMETHOD Convert(nsIInputStream *aFromStream, const char *aFromType,
|
||||
const char *aToType, nsISupports *ctxt, nsIInputStream **_retval) override;
|
||||
|
||||
|
||||
NS_IMETHOD AsyncConvertData(const char *aFromType, const char *aToType,
|
||||
nsIStreamListener *aListener, nsISupports *ctxt) override;
|
||||
|
||||
// member data
|
||||
nsCOMPtr<nsIStreamListener> mListener;
|
||||
nsCString fromType;
|
||||
nsCString toType;
|
||||
};
|
||||
|
||||
nsresult CreateTestConverter(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
||||
|
||||
static inline uint32_t
|
||||
saturated(uint64_t aValue)
|
||||
{
|
||||
return (uint32_t) std::min(aValue, (uint64_t) UINT32_MAX);
|
||||
}
|
||||
|
||||
#endif /* !Converters_h___ */
|
@ -1,261 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* 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 "nsIServiceManager.h"
|
||||
#include "nsIStreamConverterService.h"
|
||||
#include "nsIStreamConverter.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "mozilla/Module.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#define ASYNC_TEST // undefine this if you want to test sycnronous conversion.
|
||||
|
||||
/////////////////////////////////
|
||||
// Event pump setup
|
||||
/////////////////////////////////
|
||||
#ifdef XP_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static int gKeepRunning = 0;
|
||||
/////////////////////////////////
|
||||
// Event pump END
|
||||
/////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Test converters include
|
||||
/////////////////////////////////
|
||||
#include "Converters.h"
|
||||
|
||||
// CID setup
|
||||
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// EndListener - This listener is the final one in the chain. It
|
||||
// receives the fully converted data, although it doesn't do anything with
|
||||
// the data.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
class EndListener final : public nsIStreamListener {
|
||||
~EndListener() {}
|
||||
public:
|
||||
// nsISupports declaration
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
EndListener() {}
|
||||
|
||||
// nsIStreamListener method
|
||||
NS_IMETHOD OnDataAvailable(nsIRequest* request, nsISupports *ctxt, nsIInputStream *inStr,
|
||||
uint64_t sourceOffset, uint32_t count) override
|
||||
{
|
||||
nsresult rv;
|
||||
uint32_t read;
|
||||
uint64_t len64;
|
||||
rv = inStr->Available(&len64);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
uint32_t len = (uint32_t)std::min(len64, (uint64_t)(UINT32_MAX - 1));
|
||||
|
||||
char *buffer = (char*)moz_xmalloc(len + 1);
|
||||
if (!buffer) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = inStr->Read(buffer, len, &read);
|
||||
buffer[len] = '\0';
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
printf("CONTEXT %p: Received %u bytes and the following data: \n %s\n\n",
|
||||
static_cast<void*>(ctxt), read, buffer);
|
||||
}
|
||||
free(buffer);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIRequestObserver methods
|
||||
NS_IMETHOD OnStartRequest(nsIRequest* request, nsISupports *ctxt) override { return NS_OK; }
|
||||
|
||||
NS_IMETHOD OnStopRequest(nsIRequest* request, nsISupports *ctxt,
|
||||
nsresult aStatus) override { return NS_OK; }
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(EndListener,
|
||||
nsIStreamListener,
|
||||
nsIRequestObserver)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// EndListener END
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult SendData(const char * aData, nsIStreamListener* aListener, nsIRequest* request) {
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIStringInputStream> dataStream
|
||||
(do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = dataStream->SetData(aData, strlen(aData));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
uint64_t avail = 0;
|
||||
dataStream->Available(&avail);
|
||||
|
||||
uint64_t offset = 0;
|
||||
while (avail > 0) {
|
||||
uint32_t count = saturated(avail);
|
||||
rv = aListener->OnDataAvailable(request, nullptr, dataStream,
|
||||
offset, count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
offset += count;
|
||||
avail -= count;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
#define SEND_DATA(x) SendData(x, converterListener, request)
|
||||
|
||||
static const mozilla::Module::CIDEntry kTestCIDs[] = {
|
||||
{ &kTestConverterCID, false, nullptr, CreateTestConverter },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
static const mozilla::Module::ContractIDEntry kTestContracts[] = {
|
||||
{ NS_ISTREAMCONVERTER_KEY "?from=a/foo&to=b/foo", &kTestConverterCID },
|
||||
{ NS_ISTREAMCONVERTER_KEY "?from=b/foo&to=c/foo", &kTestConverterCID },
|
||||
{ NS_ISTREAMCONVERTER_KEY "?from=b/foo&to=d/foo", &kTestConverterCID },
|
||||
{ NS_ISTREAMCONVERTER_KEY "?from=c/foo&to=d/foo", &kTestConverterCID },
|
||||
{ NS_ISTREAMCONVERTER_KEY "?from=d/foo&to=e/foo", &kTestConverterCID },
|
||||
{ NS_ISTREAMCONVERTER_KEY "?from=d/foo&to=f/foo", &kTestConverterCID },
|
||||
{ NS_ISTREAMCONVERTER_KEY "?from=t/foo&to=k/foo", &kTestConverterCID },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
static const mozilla::Module::CategoryEntry kTestCategories[] = {
|
||||
{ NS_ISTREAMCONVERTER_KEY, "?from=a/foo&to=b/foo", "x" },
|
||||
{ NS_ISTREAMCONVERTER_KEY, "?from=b/foo&to=c/foo", "x" },
|
||||
{ NS_ISTREAMCONVERTER_KEY, "?from=b/foo&to=d/foo", "x" },
|
||||
{ NS_ISTREAMCONVERTER_KEY, "?from=c/foo&to=d/foo", "x" },
|
||||
{ NS_ISTREAMCONVERTER_KEY, "?from=d/foo&to=e/foo", "x" },
|
||||
{ NS_ISTREAMCONVERTER_KEY, "?from=d/foo&to=f/foo", "x" },
|
||||
{ NS_ISTREAMCONVERTER_KEY, "?from=t/foo&to=k/foo", "x" },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
static const mozilla::Module kTestModule = {
|
||||
mozilla::Module::kVersion,
|
||||
kTestCIDs,
|
||||
kTestContracts,
|
||||
kTestCategories
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
nsresult rv;
|
||||
{
|
||||
XRE_AddStaticComponent(&kTestModule);
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
|
||||
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
|
||||
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
nsCString previous;
|
||||
|
||||
nsCOMPtr<nsIStreamConverterService> StreamConvService =
|
||||
do_GetService(kStreamConverterServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
// Define the *from* content type and *to* content-type for conversion.
|
||||
static const char fromStr[] = "a/foo";
|
||||
static const char toStr[] = "c/foo";
|
||||
|
||||
#ifdef ASYNC_TEST
|
||||
// ASYNCHRONOUS conversion
|
||||
|
||||
// Build up a channel that represents the content we're
|
||||
// starting the transaction with.
|
||||
//
|
||||
// sample multipart mixed content-type string:
|
||||
// "multipart/x-mixed-replacE;boundary=thisrandomstring"
|
||||
#if 0
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
nsCOMPtr<nsIURI> dummyURI;
|
||||
rv = NS_NewURI(getter_AddRefs(dummyURI), "http://meaningless");
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = NS_NewInputStreamChannel(getter_AddRefs(channel),
|
||||
dummyURI,
|
||||
nullptr, // inStr
|
||||
"text/plain", // content-type
|
||||
-1); // XXX fix contentLength
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
nsCOMPtr<nsIRequest> request(do_QueryInterface(channel));
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIRequest> request;
|
||||
|
||||
// setup a listener to receive the converted data. This guy is the end
|
||||
// listener in the chain, he wants the fully converted (toType) data.
|
||||
// An example of this listener in mozilla would be the DocLoader.
|
||||
nsIStreamListener *dataReceiver = new EndListener();
|
||||
NS_ADDREF(dataReceiver);
|
||||
|
||||
// setup a listener to push the data into. This listener sits inbetween the
|
||||
// unconverted data of fromType, and the final listener in the chain (in this case
|
||||
// the dataReceiver.
|
||||
nsIStreamListener *converterListener = nullptr;
|
||||
rv = StreamConvService->AsyncConvertData(fromStr, toStr,
|
||||
dataReceiver, nullptr, &converterListener);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
NS_RELEASE(dataReceiver);
|
||||
|
||||
// at this point we have a stream listener to push data to, and the one
|
||||
// that will receive the converted data. Let's mimic On*() calls and get the conversion
|
||||
// going. Typically these On*() calls would be made inside their respective wrappers On*()
|
||||
// methods.
|
||||
rv = converterListener->OnStartRequest(request, nullptr);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = SEND_DATA("aaa");
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = SEND_DATA("aaa");
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
// Finish the request.
|
||||
rv = converterListener->OnStopRequest(request, nullptr, rv);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
NS_RELEASE(converterListener);
|
||||
#else
|
||||
// SYNCHRONOUS conversion
|
||||
nsCOMPtr<nsIInputStream> convertedData;
|
||||
rv = StreamConvService->Convert(inputData, fromStr, toStr,
|
||||
nullptr, getter_AddRefs(convertedData));
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
#endif
|
||||
|
||||
// Enter the message pump to allow the URL load to proceed.
|
||||
while ( gKeepRunning ) {
|
||||
if (!NS_ProcessNextEvent(thread))
|
||||
break;
|
||||
}
|
||||
} // this scopes the nsCOMPtrs
|
||||
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
return 0;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
GeckoProgram('TestStreamConv', linkage='dependent')
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'Converters.cpp',
|
||||
'TestStreamConv.cpp',
|
||||
]
|
||||
|
||||
if CONFIG['OS_ARCH'] == 'WINNT':
|
||||
DEFINES['NGPREFS'] = True
|
||||
if CONFIG['GNU_CXX']:
|
||||
LDFLAGS += ['-mconsole']
|
||||
else:
|
||||
LDFLAGS += ['-SUBSYSTEM:CONSOLE']
|
||||
|
||||
if CONFIG['GNU_CXX']:
|
||||
CXXFLAGS += ['-Wno-error=shadow']
|
@ -1,131 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 "TestCommon.h"
|
||||
#include "mozilla/Sprintf.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include <stdio.h>
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsILoadInfo.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#define TEST_URL "resource:/res/test.properties"
|
||||
static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult ret;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
|
||||
nsIInputStream* in = nullptr;
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &ret);
|
||||
if (NS_FAILED(ret)) return 1;
|
||||
nsCOMPtr<nsIPrincipal> systemPrincipal;
|
||||
ret = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
|
||||
if (NS_FAILED(ret)) return 1;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
ret = NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING(TEST_URL));
|
||||
if (NS_FAILED(ret)) return 1;
|
||||
|
||||
nsIChannel *channel = nullptr;
|
||||
ret = NS_NewChannel(&channel,
|
||||
uri,
|
||||
systemPrincipal,
|
||||
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
||||
nsIContentPolicy::TYPE_OTHER);
|
||||
if (NS_FAILED(ret)) return 1;
|
||||
|
||||
ret = channel->Open2(&in);
|
||||
if (NS_FAILED(ret)) return 1;
|
||||
|
||||
nsIPersistentProperties* props;
|
||||
ret = CallCreateInstance(kPersistentPropertiesCID, &props);
|
||||
if (NS_FAILED(ret) || (!props)) {
|
||||
printf("create nsIPersistentProperties failed\n");
|
||||
return 1;
|
||||
}
|
||||
ret = props->Load(in);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot load properties\n");
|
||||
return 1;
|
||||
}
|
||||
int i = 1;
|
||||
while (true) {
|
||||
char name[16];
|
||||
name[0] = 0;
|
||||
SprintfLiteral(name, "%d", i);
|
||||
nsAutoString v;
|
||||
ret = props->GetStringProperty(nsDependentCString(name), v);
|
||||
if (NS_FAILED(ret) || (!v.Length())) {
|
||||
break;
|
||||
}
|
||||
printf("\"%d\"=\"%s\"\n", i, NS_ConvertUTF16toUTF8(v).get());
|
||||
i++;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> propEnum;
|
||||
ret = props->Enumerate(getter_AddRefs(propEnum));
|
||||
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot enumerate properties\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
printf("\nKey\tValue\n");
|
||||
printf( "---\t-----\n");
|
||||
|
||||
bool hasMore;
|
||||
while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) &&
|
||||
hasMore) {
|
||||
nsCOMPtr<nsISupports> sup;
|
||||
ret = propEnum->GetNext(getter_AddRefs(sup));
|
||||
|
||||
nsCOMPtr<nsIPropertyElement> propElem = do_QueryInterface(sup, &ret);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("failed to get current item\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
nsAutoCString key;
|
||||
nsAutoString value;
|
||||
|
||||
ret = propElem->GetKey(key);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("failed to get current element's key\n");
|
||||
return 1;
|
||||
}
|
||||
ret = propElem->GetValue(value);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("failed to get current element's value\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("%s\t%s\n", key.get(), NS_ConvertUTF16toUTF8(value).get());
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,325 +0,0 @@
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
/* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "plbase64.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "prmem.h"
|
||||
|
||||
/*
|
||||
* ReadNTLM : reads NTLM messages.
|
||||
*
|
||||
* based on http://davenport.sourceforge.net/ntlm.html
|
||||
*/
|
||||
|
||||
#define kNegotiateUnicode 0x00000001
|
||||
#define kNegotiateOEM 0x00000002
|
||||
#define kRequestTarget 0x00000004
|
||||
#define kUnknown1 0x00000008
|
||||
#define kNegotiateSign 0x00000010
|
||||
#define kNegotiateSeal 0x00000020
|
||||
#define kNegotiateDatagramStyle 0x00000040
|
||||
#define kNegotiateLanManagerKey 0x00000080
|
||||
#define kNegotiateNetware 0x00000100
|
||||
#define kNegotiateNTLMKey 0x00000200
|
||||
#define kUnknown2 0x00000400
|
||||
#define kUnknown3 0x00000800
|
||||
#define kNegotiateDomainSupplied 0x00001000
|
||||
#define kNegotiateWorkstationSupplied 0x00002000
|
||||
#define kNegotiateLocalCall 0x00004000
|
||||
#define kNegotiateAlwaysSign 0x00008000
|
||||
#define kTargetTypeDomain 0x00010000
|
||||
#define kTargetTypeServer 0x00020000
|
||||
#define kTargetTypeShare 0x00040000
|
||||
#define kNegotiateNTLM2Key 0x00080000
|
||||
#define kRequestInitResponse 0x00100000
|
||||
#define kRequestAcceptResponse 0x00200000
|
||||
#define kRequestNonNTSessionKey 0x00400000
|
||||
#define kNegotiateTargetInfo 0x00800000
|
||||
#define kUnknown4 0x01000000
|
||||
#define kUnknown5 0x02000000
|
||||
#define kUnknown6 0x04000000
|
||||
#define kUnknown7 0x08000000
|
||||
#define kUnknown8 0x10000000
|
||||
#define kNegotiate128 0x20000000
|
||||
#define kNegotiateKeyExchange 0x40000000
|
||||
#define kNegotiate56 0x80000000
|
||||
|
||||
static const char NTLM_SIGNATURE[] = "NTLMSSP";
|
||||
static const char NTLM_TYPE1_MARKER[] = { 0x01, 0x00, 0x00, 0x00 };
|
||||
static const char NTLM_TYPE2_MARKER[] = { 0x02, 0x00, 0x00, 0x00 };
|
||||
static const char NTLM_TYPE3_MARKER[] = { 0x03, 0x00, 0x00, 0x00 };
|
||||
|
||||
#define NTLM_MARKER_LEN 4
|
||||
#define NTLM_TYPE1_HEADER_LEN 32
|
||||
#define NTLM_TYPE2_HEADER_LEN 32
|
||||
#define NTLM_TYPE3_HEADER_LEN 64
|
||||
|
||||
#define LM_HASH_LEN 16
|
||||
#define LM_RESP_LEN 24
|
||||
|
||||
#define NTLM_HASH_LEN 16
|
||||
#define NTLM_RESP_LEN 24
|
||||
|
||||
static void PrintFlags(uint32_t flags)
|
||||
{
|
||||
#define TEST(_flag) \
|
||||
if (flags & k ## _flag) \
|
||||
printf(" 0x%08x (" # _flag ")\n", k ## _flag)
|
||||
|
||||
TEST(NegotiateUnicode);
|
||||
TEST(NegotiateOEM);
|
||||
TEST(RequestTarget);
|
||||
TEST(Unknown1);
|
||||
TEST(NegotiateSign);
|
||||
TEST(NegotiateSeal);
|
||||
TEST(NegotiateDatagramStyle);
|
||||
TEST(NegotiateLanManagerKey);
|
||||
TEST(NegotiateNetware);
|
||||
TEST(NegotiateNTLMKey);
|
||||
TEST(Unknown2);
|
||||
TEST(Unknown3);
|
||||
TEST(NegotiateDomainSupplied);
|
||||
TEST(NegotiateWorkstationSupplied);
|
||||
TEST(NegotiateLocalCall);
|
||||
TEST(NegotiateAlwaysSign);
|
||||
TEST(TargetTypeDomain);
|
||||
TEST(TargetTypeServer);
|
||||
TEST(TargetTypeShare);
|
||||
TEST(NegotiateNTLM2Key);
|
||||
TEST(RequestInitResponse);
|
||||
TEST(RequestAcceptResponse);
|
||||
TEST(RequestNonNTSessionKey);
|
||||
TEST(NegotiateTargetInfo);
|
||||
TEST(Unknown4);
|
||||
TEST(Unknown5);
|
||||
TEST(Unknown6);
|
||||
TEST(Unknown7);
|
||||
TEST(Unknown8);
|
||||
TEST(Negotiate128);
|
||||
TEST(NegotiateKeyExchange);
|
||||
TEST(Negotiate56);
|
||||
|
||||
#undef TEST
|
||||
}
|
||||
|
||||
static void
|
||||
PrintBuf(const char *tag, const uint8_t *buf, uint32_t bufLen)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("%s =\n", tag);
|
||||
while (bufLen > 0)
|
||||
{
|
||||
int count = bufLen;
|
||||
if (count > 8)
|
||||
count = 8;
|
||||
|
||||
printf(" ");
|
||||
for (i=0; i<count; ++i)
|
||||
{
|
||||
printf("0x%02x ", int(buf[i]));
|
||||
}
|
||||
for (; i<8; ++i)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
printf(" ");
|
||||
for (i=0; i<count; ++i)
|
||||
{
|
||||
if (isprint(buf[i]))
|
||||
printf("%c", buf[i]);
|
||||
else
|
||||
printf(".");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
bufLen -= count;
|
||||
buf += count;
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
ReadUint16(const uint8_t *&buf)
|
||||
{
|
||||
uint16_t x;
|
||||
#ifdef IS_BIG_ENDIAN
|
||||
x = ((uint16_t) buf[1]) | ((uint16_t) buf[0] << 8);
|
||||
#else
|
||||
x = ((uint16_t) buf[0]) | ((uint16_t) buf[1] << 8);
|
||||
#endif
|
||||
buf += sizeof(x);
|
||||
return x;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
ReadUint32(const uint8_t *&buf)
|
||||
{
|
||||
uint32_t x;
|
||||
#ifdef IS_BIG_ENDIAN
|
||||
x = ( (uint32_t) buf[3]) |
|
||||
(((uint32_t) buf[2]) << 8) |
|
||||
(((uint32_t) buf[1]) << 16) |
|
||||
(((uint32_t) buf[0]) << 24);
|
||||
#else
|
||||
x = ( (uint32_t) buf[0]) |
|
||||
(((uint32_t) buf[1]) << 8) |
|
||||
(((uint32_t) buf[2]) << 16) |
|
||||
(((uint32_t) buf[3]) << 24);
|
||||
#endif
|
||||
buf += sizeof(x);
|
||||
return x;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint16_t length;
|
||||
uint16_t capacity;
|
||||
uint32_t offset;
|
||||
} SecBuf;
|
||||
|
||||
static void
|
||||
ReadSecBuf(SecBuf *s, const uint8_t *&buf)
|
||||
{
|
||||
s->length = ReadUint16(buf);
|
||||
s->capacity = ReadUint16(buf);
|
||||
s->offset = ReadUint32(buf);
|
||||
}
|
||||
|
||||
static void
|
||||
ReadType1MsgBody(const uint8_t *inBuf, uint32_t start)
|
||||
{
|
||||
const uint8_t *cursor = inBuf + start;
|
||||
uint32_t flags;
|
||||
|
||||
PrintBuf("flags", cursor, 4);
|
||||
// read flags
|
||||
flags = ReadUint32(cursor);
|
||||
PrintFlags(flags);
|
||||
|
||||
// type 1 message may not include trailing security buffers
|
||||
if ((flags & kNegotiateDomainSupplied) |
|
||||
(flags & kNegotiateWorkstationSupplied))
|
||||
{
|
||||
SecBuf secbuf;
|
||||
ReadSecBuf(&secbuf, cursor);
|
||||
PrintBuf("supplied domain", inBuf + secbuf.offset, secbuf.length);
|
||||
|
||||
ReadSecBuf(&secbuf, cursor);
|
||||
PrintBuf("supplied workstation", inBuf + secbuf.offset, secbuf.length);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ReadType2MsgBody(const uint8_t *inBuf, uint32_t start)
|
||||
{
|
||||
uint16_t targetLen, offset;
|
||||
uint32_t flags;
|
||||
const uint8_t *target;
|
||||
const uint8_t *cursor = inBuf + start;
|
||||
|
||||
// read target name security buffer
|
||||
targetLen = ReadUint16(cursor);
|
||||
ReadUint16(cursor); // discard next 16-bit value
|
||||
offset = ReadUint32(cursor); // get offset from inBuf
|
||||
target = inBuf + offset;
|
||||
|
||||
PrintBuf("target", target, targetLen);
|
||||
|
||||
PrintBuf("flags", cursor, 4);
|
||||
// read flags
|
||||
flags = ReadUint32(cursor);
|
||||
PrintFlags(flags);
|
||||
|
||||
// read challenge
|
||||
PrintBuf("challenge", cursor, 8);
|
||||
cursor += 8;
|
||||
|
||||
PrintBuf("context", cursor, 8);
|
||||
cursor += 8;
|
||||
|
||||
SecBuf secbuf;
|
||||
ReadSecBuf(&secbuf, cursor);
|
||||
PrintBuf("target information", inBuf + secbuf.offset, secbuf.length);
|
||||
}
|
||||
|
||||
static void
|
||||
ReadType3MsgBody(const uint8_t *inBuf, uint32_t start)
|
||||
{
|
||||
const uint8_t *cursor = inBuf + start;
|
||||
|
||||
SecBuf secbuf;
|
||||
|
||||
ReadSecBuf(&secbuf, cursor); // LM response
|
||||
PrintBuf("LM response", inBuf + secbuf.offset, secbuf.length);
|
||||
|
||||
ReadSecBuf(&secbuf, cursor); // NTLM response
|
||||
PrintBuf("NTLM response", inBuf + secbuf.offset, secbuf.length);
|
||||
|
||||
ReadSecBuf(&secbuf, cursor); // domain name
|
||||
PrintBuf("domain name", inBuf + secbuf.offset, secbuf.length);
|
||||
|
||||
ReadSecBuf(&secbuf, cursor); // user name
|
||||
PrintBuf("user name", inBuf + secbuf.offset, secbuf.length);
|
||||
|
||||
ReadSecBuf(&secbuf, cursor); // workstation name
|
||||
PrintBuf("workstation name", inBuf + secbuf.offset, secbuf.length);
|
||||
|
||||
ReadSecBuf(&secbuf, cursor); // session key
|
||||
PrintBuf("session key", inBuf + secbuf.offset, secbuf.length);
|
||||
|
||||
uint32_t flags = ReadUint32(cursor);
|
||||
PrintBuf("flags", (const uint8_t *) &flags, sizeof(flags));
|
||||
PrintFlags(flags);
|
||||
}
|
||||
|
||||
static void
|
||||
ReadMsg(const char *base64buf, uint32_t bufLen)
|
||||
{
|
||||
uint8_t *inBuf = (uint8_t *) PL_Base64Decode(base64buf, bufLen, nullptr);
|
||||
if (!inBuf)
|
||||
{
|
||||
printf("PL_Base64Decode failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t *cursor = inBuf;
|
||||
|
||||
PrintBuf("signature", cursor, 8);
|
||||
|
||||
// verify NTLMSSP signature
|
||||
if (memcmp(cursor, NTLM_SIGNATURE, sizeof(NTLM_SIGNATURE)) != 0)
|
||||
{
|
||||
printf("### invalid or corrupt NTLM signature\n");
|
||||
}
|
||||
cursor += sizeof(NTLM_SIGNATURE);
|
||||
|
||||
PrintBuf("message type", cursor, 4);
|
||||
|
||||
if (memcmp(cursor, NTLM_TYPE1_MARKER, sizeof(NTLM_MARKER_LEN)) == 0)
|
||||
ReadType1MsgBody(inBuf, 12);
|
||||
else if (memcmp(cursor, NTLM_TYPE2_MARKER, sizeof(NTLM_MARKER_LEN)) == 0)
|
||||
ReadType2MsgBody(inBuf, 12);
|
||||
else if (memcmp(cursor, NTLM_TYPE3_MARKER, sizeof(NTLM_MARKER_LEN)) == 0)
|
||||
ReadType3MsgBody(inBuf, 12);
|
||||
else
|
||||
printf("### invalid or unknown message type\n");
|
||||
|
||||
PR_Free(inBuf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1)
|
||||
{
|
||||
printf("usage: ntlmread <msg>\n");
|
||||
return -1;
|
||||
}
|
||||
ReadMsg(argv[1], (uint32_t) strlen(argv[1]));
|
||||
return 0;
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "TestCommon.h"
|
||||
#include "TestHarness.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsISocketTransport.h"
|
||||
#include "nsIServerSocket.h"
|
||||
@ -11,6 +11,8 @@
|
||||
#include "nsINetAddr.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
#include "prerror.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
using namespace mozilla::net;
|
||||
using namespace mozilla;
|
||||
@ -21,20 +23,22 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISERVERSOCKETLISTENER
|
||||
|
||||
ServerListener();
|
||||
explicit ServerListener(WaitForCondition* waiter);
|
||||
|
||||
// Port that is got from server side will be store here.
|
||||
uint32_t mClientPort;
|
||||
bool mFailed;
|
||||
RefPtr<WaitForCondition> mWaiter;
|
||||
private:
|
||||
virtual ~ServerListener();
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(ServerListener, nsIServerSocketListener)
|
||||
|
||||
ServerListener::ServerListener()
|
||||
ServerListener::ServerListener(WaitForCondition* waiter)
|
||||
: mClientPort(-1)
|
||||
, mFailed(false)
|
||||
, mWaiter(waiter)
|
||||
{
|
||||
}
|
||||
|
||||
@ -49,13 +53,11 @@ ServerListener::OnSocketAccepted(nsIServerSocket *aServ,
|
||||
nsresult rv = aTransport->GetPeerAddr(&peerAddr);
|
||||
if (NS_FAILED(rv)) {
|
||||
mFailed = true;
|
||||
fail("Server: not able to get peer address.");
|
||||
QuitPumpingEvents();
|
||||
mWaiter->Notify();
|
||||
return NS_OK;
|
||||
}
|
||||
mClientPort = PR_ntohs(peerAddr.inet.port);
|
||||
passed("Server: received connection");
|
||||
QuitPumpingEvents();
|
||||
mWaiter->Notify();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -72,17 +74,19 @@ public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIINPUTSTREAMCALLBACK
|
||||
|
||||
ClientInputCallback();
|
||||
explicit ClientInputCallback(WaitForCondition* waiter);
|
||||
|
||||
bool mFailed;
|
||||
RefPtr<WaitForCondition> mWaiter;
|
||||
private:
|
||||
virtual ~ClientInputCallback();
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(ClientInputCallback, nsIInputStreamCallback)
|
||||
|
||||
ClientInputCallback::ClientInputCallback()
|
||||
ClientInputCallback::ClientInputCallback(WaitForCondition* waiter)
|
||||
: mFailed(false)
|
||||
, mWaiter(waiter)
|
||||
{
|
||||
}
|
||||
|
||||
@ -98,48 +102,31 @@ ClientInputCallback::OnInputStreamReady(nsIAsyncInputStream *aStream)
|
||||
if (NS_FAILED(rv)) {
|
||||
mFailed = true;
|
||||
}
|
||||
QuitPumpingEvents();
|
||||
mWaiter->Notify();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
main(int32_t argc, char *argv[])
|
||||
TEST(TestBind, MainTest)
|
||||
{
|
||||
ScopedXPCOM xpcom("SocketTransport");
|
||||
if (xpcom.failed()) {
|
||||
fail("Unable to initalize XPCOM.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// Server side.
|
||||
//
|
||||
nsCOMPtr<nsIServerSocket> server = do_CreateInstance("@mozilla.org/network/server-socket;1");
|
||||
if (!server) {
|
||||
fail("Failed to create server socket.");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(server);
|
||||
|
||||
nsresult rv = server->Init(-1, true, -1);
|
||||
if (NS_FAILED(rv)) {
|
||||
fail("Failed to initialize server.");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
int32_t serverPort;
|
||||
rv = server->GetPort(&serverPort);
|
||||
if (NS_FAILED(rv)) {
|
||||
fail("Unable to get server port.");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
RefPtr<WaitForCondition> waiter = new WaitForCondition();
|
||||
|
||||
// Listening.
|
||||
RefPtr<ServerListener> serverListener = new ServerListener();
|
||||
RefPtr<ServerListener> serverListener = new ServerListener(waiter);
|
||||
rv = server->AsyncListen(serverListener);
|
||||
if (NS_FAILED(rv)) {
|
||||
fail("Server fail to start listening.");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
//
|
||||
// Client side
|
||||
@ -147,19 +134,16 @@ main(int32_t argc, char *argv[])
|
||||
uint32_t bindingPort = 20000;
|
||||
nsCOMPtr<nsISocketTransportService> sts =
|
||||
do_GetService("@mozilla.org/network/socket-transport-service;1", &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
fail("Unable to get socket transport service.");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
RefPtr<ClientInputCallback> clientCallback;
|
||||
|
||||
for (int32_t tried = 0; tried < 100; tried++) {
|
||||
nsCOMPtr<nsISocketTransport> client;
|
||||
rv = sts->CreateTransport(nullptr, 0, NS_LITERAL_CSTRING("127.0.0.1"),
|
||||
serverPort, nullptr, getter_AddRefs(client));
|
||||
if (NS_FAILED(rv)) {
|
||||
fail("Unable to create transport.");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
// Bind to a port. It's possible that we are binding to a port that is
|
||||
// currently in use. If we failed to bind, we try next port.
|
||||
@ -168,25 +152,19 @@ main(int32_t argc, char *argv[])
|
||||
bindingAddr.inet.ip = 0;
|
||||
bindingAddr.inet.port = PR_htons(bindingPort);
|
||||
rv = client->Bind(&bindingAddr);
|
||||
if (NS_FAILED(rv)) {
|
||||
fail("Unable to bind a port.");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
// Open IO streams, to make client SocketTransport connect to server.
|
||||
RefPtr<ClientInputCallback> clientCallback = new ClientInputCallback();
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
clientCallback = new ClientInputCallback(waiter);
|
||||
rv = client->OpenInputStream(nsITransport::OPEN_UNBUFFERED,
|
||||
0, 0, getter_AddRefs(inputStream));
|
||||
if (NS_FAILED(rv)) {
|
||||
fail("Failed to open an input stream.");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
nsCOMPtr<nsIAsyncInputStream> asyncInputStream = do_QueryInterface(inputStream);
|
||||
rv = asyncInputStream->AsyncWait(clientCallback, 0, 0, nullptr);
|
||||
|
||||
// Wait for server's response or callback of input stream.
|
||||
PumpEvents();
|
||||
waiter->Wait(1);
|
||||
if (clientCallback->mFailed) {
|
||||
// if client received error, we likely have bound a port that is in use.
|
||||
// we can try another port.
|
||||
@ -197,14 +175,12 @@ main(int32_t argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (serverListener->mFailed) {
|
||||
fail("Server failure.");
|
||||
return -1;
|
||||
}
|
||||
if (serverListener->mClientPort != bindingPort) {
|
||||
fail("Port that server got doesn't match what we are expecting.");
|
||||
return -1;
|
||||
}
|
||||
passed("Port matched");
|
||||
return 0;
|
||||
ASSERT_FALSE(serverListener->mFailed);
|
||||
ASSERT_EQ(serverListener->mClientPort, bindingPort);
|
||||
|
||||
inputStream->Close();
|
||||
waiter->Wait(1);
|
||||
ASSERT_TRUE(clientCallback->mFailed);
|
||||
|
||||
server->Close();
|
||||
}
|
||||
|
@ -1,127 +0,0 @@
|
||||
/* 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 "TestCommon.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsISocketTransport.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "NetwerkTestLogging.h"
|
||||
#include "prenv.h"
|
||||
#include "prthread.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// set NSPR_LOG_MODULES=Test:5
|
||||
//
|
||||
static PRLogModuleInfo *gTestLog = nullptr;
|
||||
#define LOG(args) MOZ_LOG(gTestLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static nsresult
|
||||
RunBlockingTest(const nsACString &host, int32_t port, nsIFile *file)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
LOG(("RunBlockingTest\n"));
|
||||
|
||||
nsCOMPtr<nsISocketTransportService> sts =
|
||||
do_GetService(kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIInputStream> input;
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(input), file);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISocketTransport> trans;
|
||||
rv = sts->CreateTransport(nullptr, 0, host, port, nullptr, getter_AddRefs(trans));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> output;
|
||||
rv = trans->OpenOutputStream(nsITransport::OPEN_BLOCKING, 100, 10, getter_AddRefs(output));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char buf[120];
|
||||
uint32_t nr, nw;
|
||||
for (;;) {
|
||||
rv = input->Read(buf, sizeof(buf), &nr);
|
||||
if (NS_FAILED(rv) || (nr == 0)) return rv;
|
||||
|
||||
/*
|
||||
const char *p = buf;
|
||||
while (nr) {
|
||||
rv = output->Write(p, nr, &nw);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nr -= nw;
|
||||
p += nw;
|
||||
}
|
||||
*/
|
||||
|
||||
rv = output->Write(buf, nr, &nw);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ASSERTION(nr == nw, "not all written");
|
||||
}
|
||||
|
||||
LOG((" done copying data.\n"));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (argc < 4) {
|
||||
printf("usage: %s <host> <port> <file-to-read>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
char* hostName = argv[1];
|
||||
int32_t port = atoi(argv[2]);
|
||||
char* fileName = argv[3];
|
||||
{
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
|
||||
gTestLog = PR_NewLogModule("Test");
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = NS_NewNativeLocalFile(nsDependentCString(fileName), false, getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
rv = RunBlockingTest(nsDependentCString(hostName), port, file);
|
||||
if (NS_FAILED(rv))
|
||||
LOG(("RunBlockingTest failed [rv=%x]\n", rv));
|
||||
|
||||
// give background threads a chance to finish whatever work they may
|
||||
// be doing.
|
||||
LOG(("sleeping for 5 seconds...\n"));
|
||||
PR_Sleep(PR_SecondsToInterval(5));
|
||||
} // this scopes the nsCOMPtrs
|
||||
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
||||
rv = NS_ShutdownXPCOM(nullptr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
||||
return 0;
|
||||
}
|
@ -9,43 +9,42 @@
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
inline int test_common_init(int *argc, char ***argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static bool gKeepPumpingEvents = false;
|
||||
|
||||
class nsQuitPumpingEvent final : public nsIRunnable {
|
||||
~nsQuitPumpingEvent() {}
|
||||
class WaitForCondition : public nsIRunnable
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
void Wait(int pending)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mPending == 0);
|
||||
|
||||
mPending = pending;
|
||||
while (mPending) {
|
||||
NS_ProcessNextEvent();
|
||||
}
|
||||
NS_ProcessPendingEvents(nullptr);
|
||||
}
|
||||
|
||||
void Notify() {
|
||||
NS_DispatchToMainThread(this);
|
||||
}
|
||||
|
||||
private:
|
||||
virtual ~WaitForCondition() { }
|
||||
|
||||
NS_IMETHOD Run() override {
|
||||
gKeepPumpingEvents = false;
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mPending);
|
||||
|
||||
--mPending;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t mPending = 0;
|
||||
};
|
||||
NS_IMPL_ISUPPORTS(nsQuitPumpingEvent, nsIRunnable)
|
||||
|
||||
static inline void PumpEvents()
|
||||
{
|
||||
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
|
||||
|
||||
gKeepPumpingEvents = true;
|
||||
while (gKeepPumpingEvents)
|
||||
NS_ProcessNextEvent(thread);
|
||||
|
||||
NS_ProcessPendingEvents(thread);
|
||||
}
|
||||
|
||||
static inline void QuitPumpingEvents()
|
||||
{
|
||||
// Dispatch a task that toggles gKeepPumpingEvents so that we flush all
|
||||
// of the pending tasks before exiting from PumpEvents.
|
||||
nsCOMPtr<nsIRunnable> event = new nsQuitPumpingEvent();
|
||||
NS_DispatchToMainThread(event);
|
||||
}
|
||||
NS_IMPL_ISUPPORTS(WaitForCondition, nsIRunnable)
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,130 +0,0 @@
|
||||
/* 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 "TestCommon.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsPIDNSService.h"
|
||||
#include "nsIDNSListener.h"
|
||||
#include "nsIDNSRecord.h"
|
||||
#include "nsICancelable.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "prinrval.h"
|
||||
#include "prthread.h"
|
||||
#include "prnetdb.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
class myDNSListener : public nsIDNSListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
myDNSListener(const char *host, int32_t index)
|
||||
: mHost(host)
|
||||
, mIndex(index) {}
|
||||
|
||||
NS_IMETHOD OnLookupComplete(nsICancelable *request,
|
||||
nsIDNSRecord *rec,
|
||||
nsresult status) override
|
||||
{
|
||||
printf("%d: OnLookupComplete called [host=%s status=%x rec=%p]\n",
|
||||
mIndex, mHost.get(), static_cast<uint32_t>(status), (void*)rec);
|
||||
|
||||
if (NS_SUCCEEDED(status)) {
|
||||
nsAutoCString buf;
|
||||
|
||||
rec->GetCanonicalName(buf);
|
||||
printf("%d: canonname=%s\n", mIndex, buf.get());
|
||||
|
||||
bool hasMore;
|
||||
while (NS_SUCCEEDED(rec->HasMore(&hasMore)) && hasMore) {
|
||||
rec->GetNextAddrAsString(buf);
|
||||
printf("%d: => %s\n", mIndex, buf.get());
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual ~myDNSListener() = default;
|
||||
|
||||
nsCString mHost;
|
||||
int32_t mIndex;
|
||||
};
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(myDNSListener, nsIDNSListener)
|
||||
|
||||
static bool IsAscii(const char *s)
|
||||
{
|
||||
for (; *s; ++s) {
|
||||
if (*s & 0x80)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
int sleepLen = 10; // default: 10 seconds
|
||||
|
||||
if (argc == 1) {
|
||||
printf("usage: TestDNS [-N] hostname1 [hostname2 ...]\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
{
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
|
||||
nsCOMPtr<nsPIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
|
||||
if (!dns)
|
||||
return -1;
|
||||
|
||||
if (argv[1][0] == '-') {
|
||||
sleepLen = atoi(argv[1]+1);
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
|
||||
for (int j=0; j<2; ++j) {
|
||||
for (int i=1; i<argc; ++i) {
|
||||
// assume non-ASCII input is given in the native charset
|
||||
nsAutoCString hostBuf;
|
||||
if (IsAscii(argv[i]))
|
||||
hostBuf.Assign(argv[i]);
|
||||
else
|
||||
hostBuf = NS_ConvertUTF16toUTF8(NS_ConvertASCIItoUTF16(argv[i]));
|
||||
|
||||
nsCOMPtr<nsIDNSListener> listener = new myDNSListener(argv[i], i);
|
||||
|
||||
nsCOMPtr<nsICancelable> req;
|
||||
nsresult rv = dns->AsyncResolve(hostBuf,
|
||||
nsIDNSService::RESOLVE_CANONICAL_NAME,
|
||||
listener, nullptr, getter_AddRefs(req));
|
||||
if (NS_FAILED(rv))
|
||||
printf("### AsyncResolve failed [rv=%x]\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
}
|
||||
|
||||
printf("main thread sleeping for %d seconds...\n", sleepLen);
|
||||
PR_Sleep(PR_SecondsToInterval(sleepLen));
|
||||
}
|
||||
|
||||
printf("shutting down main thread...\n");
|
||||
dns->Shutdown();
|
||||
}
|
||||
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
return 0;
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/* 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 "TestCommon.h"
|
||||
#include <stdio.h>
|
||||
#include "nsIIDNService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsStringAPI.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
// Test case from RFC 3492 (7.1 - Simplified Chinese)
|
||||
const char plain[] =
|
||||
"\xE4\xBB\x96\xE4\xBB\xAC\xE4\xB8\xBA\xE4\xBB\x80\xE4\xB9\x88\xE4\xB8\x8D\xE8\xAF\xB4\xE4\xB8\xAD\xE6\x96\x87";
|
||||
const char encoded[] = "xn--ihqwcrb4cv8a8dqg056pqjye";
|
||||
|
||||
nsCOMPtr<nsIIDNService> converter = do_GetService(NS_IDNSERVICE_CONTRACTID);
|
||||
NS_ASSERTION(converter, "idnSDK not installed!");
|
||||
if (converter) {
|
||||
nsAutoCString buf;
|
||||
nsresult rv = converter->ConvertUTF8toACE(NS_LITERAL_CSTRING(plain), buf);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error ConvertUTF8toACE");
|
||||
NS_ASSERTION(buf.Equals(NS_LITERAL_CSTRING(encoded)),
|
||||
"encode result incorrect");
|
||||
printf("encoded = %s\n", buf.get());
|
||||
|
||||
buf.Truncate();
|
||||
rv = converter->ConvertACEtoUTF8(NS_LITERAL_CSTRING(encoded), buf);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error ConvertACEtoUTF8");
|
||||
NS_ASSERTION(buf.Equals(NS_LITERAL_CSTRING(plain)),
|
||||
"decode result incorrect");
|
||||
printf("decoded = ");
|
||||
NS_ConvertUTF8toUTF16 utf(buf);
|
||||
const char16_t *u = utf.get();
|
||||
for (int i = 0; u[i]; i++) {
|
||||
printf("U+%.4X ", u[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
bool isAce;
|
||||
rv = converter->IsACE(NS_LITERAL_CSTRING("www.xn--ihqwcrb4cv8a8dqg056pqjye.com"), &isAce);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error IsACE");
|
||||
NS_ASSERTION(isAce, "IsACE incorrect result");
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/* 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 "TestCommon.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "mozilla/Logging.h"
|
||||
|
||||
//
|
||||
// set NSPR_LOG_MODULES=Test:5
|
||||
//
|
||||
static PRLogModuleInfo *gTestLog = nullptr;
|
||||
#define LOG(args) MOZ_LOG(gTestLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
class nsIOEvent : public nsIRunnable {
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
nsIOEvent(int i) : mIndex(i) {}
|
||||
|
||||
NS_IMETHOD Run() override {
|
||||
LOG(("Run [%d]\n", mIndex));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
int mIndex;
|
||||
};
|
||||
NS_IMPL_ISUPPORTS(nsIOEvent, nsIRunnable)
|
||||
|
||||
static nsresult RunTest()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIEventTarget> target =
|
||||
do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
for (int i=0; i<10; ++i) {
|
||||
nsCOMPtr<nsIRunnable> event = new nsIOEvent(i);
|
||||
LOG(("Dispatch %d\n", i));
|
||||
target->Dispatch(event, NS_DISPATCH_NORMAL);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
gTestLog = PR_NewLogModule("Test");
|
||||
|
||||
rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = RunTest();
|
||||
if (NS_FAILED(rv))
|
||||
LOG(("RunTest failed [rv=%x]\n", rv));
|
||||
|
||||
LOG(("sleeping main thread for 2 seconds...\n"));
|
||||
PR_Sleep(PR_SecondsToInterval(2));
|
||||
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
return 0;
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 cin et: */
|
||||
/* 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 <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include "TestCommon.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIIncrementalDownload.h"
|
||||
#include "nsIRequestObserver.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "prprf.h"
|
||||
#include "prenv.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class FetchObserver final : public nsIRequestObserver
|
||||
, public nsIProgressEventSink
|
||||
{
|
||||
~FetchObserver() = default;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSIPROGRESSEVENTSINK
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(FetchObserver, nsIRequestObserver,
|
||||
nsIProgressEventSink)
|
||||
|
||||
NS_IMETHODIMP
|
||||
FetchObserver::OnStartRequest(nsIRequest *request, nsISupports *context)
|
||||
{
|
||||
printf("FetchObserver::OnStartRequest\n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
FetchObserver::OnProgress(nsIRequest *request, nsISupports *context,
|
||||
int64_t progress, int64_t progressMax)
|
||||
{
|
||||
printf("FetchObserver::OnProgress [%" PRId64 "/%" PRId64 "]\n",
|
||||
progress, progressMax);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
FetchObserver::OnStatus(nsIRequest *request, nsISupports *context,
|
||||
nsresult status, const char16_t *statusText)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
FetchObserver::OnStopRequest(nsIRequest *request, nsISupports *context,
|
||||
nsresult status)
|
||||
{
|
||||
printf("FetchObserver::OnStopRequest [status=%x]\n",
|
||||
static_cast<uint32_t>(status));
|
||||
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static nsresult
|
||||
DoIncrementalFetch(const char *uriSpec, const char *resultPath, int32_t chunkSize,
|
||||
int32_t interval)
|
||||
{
|
||||
nsCOMPtr<nsIFile> resultFile;
|
||||
nsresult rv = NS_NewNativeLocalFile(nsDependentCString(resultPath),
|
||||
false, getter_AddRefs(resultFile));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), uriSpec);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRequestObserver> observer = new FetchObserver();
|
||||
if (!observer)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsIIncrementalDownload> download =
|
||||
do_CreateInstance(NS_INCREMENTALDOWNLOAD_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = download->Init(uri, resultFile, chunkSize, interval);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = download->Start(observer, nullptr);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PumpEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (PR_GetEnv("MOZ_BREAK_ON_MAIN"))
|
||||
NS_BREAK();
|
||||
|
||||
if (argc < 5) {
|
||||
fprintf(stderr, "USAGE: TestIncrementalDownload <url> <file> <chunksize> <interval-in-seconds>\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
||||
if (NS_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
int32_t chunkSize = atoi(argv[3]);
|
||||
int32_t interval = atoi(argv[4]);
|
||||
|
||||
rv = DoIncrementalFetch(argv[1], argv[2], chunkSize, interval);
|
||||
if (NS_FAILED(rv))
|
||||
fprintf(stderr, "ERROR: DoIncrementalFetch failed [%x]\n",
|
||||
static_cast<uint32_t>(rv));
|
||||
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
return 0;
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "TestCommon.h"
|
||||
#include "TestHarness.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
@ -63,17 +63,17 @@ nsNamedPipeDataObserver::Read(void* aBuffer, uint32_t aSize)
|
||||
mMonitor.Wait();
|
||||
}
|
||||
if (!GetOverlappedResult(mPipe, &mOverlapped, &bytesRead, FALSE)) {
|
||||
fail("GetOverlappedResult failed");
|
||||
ADD_FAILURE() << "GetOverlappedResult failed";
|
||||
return -1;
|
||||
}
|
||||
if (mBytesTransferred != bytesRead) {
|
||||
fail("GetOverlappedResult mismatch");
|
||||
ADD_FAILURE() << "GetOverlappedResult mismatch";
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
fail("ReadFile error %d", GetLastError());
|
||||
ADD_FAILURE() << "ReadFile error " << GetLastError();
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
@ -81,13 +81,12 @@ nsNamedPipeDataObserver::Read(void* aBuffer, uint32_t aSize)
|
||||
mMonitor.Wait();
|
||||
|
||||
if (mBytesTransferred != bytesRead) {
|
||||
fail("GetOverlappedResult mismatch");
|
||||
ADD_FAILURE() << "GetOverlappedResult mismatch";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
mBytesTransferred = 0;
|
||||
passed("[read] match");
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
@ -103,17 +102,17 @@ nsNamedPipeDataObserver::Write(const void* aBuffer, uint32_t aSize)
|
||||
mMonitor.Wait();
|
||||
}
|
||||
if (!GetOverlappedResult(mPipe, &mOverlapped, &bytesWritten, FALSE)) {
|
||||
fail("GetOverlappedResult failed");
|
||||
ADD_FAILURE() << "GetOverlappedResult failed";
|
||||
return -1;
|
||||
}
|
||||
if (mBytesTransferred != bytesWritten) {
|
||||
fail("GetOverlappedResult mismatch");
|
||||
ADD_FAILURE() << "GetOverlappedResult mismatch";
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
fail("WriteFile error %d", GetLastError());
|
||||
ADD_FAILURE() << "WriteFile error " << GetLastError();
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
@ -121,13 +120,12 @@ nsNamedPipeDataObserver::Write(const void* aBuffer, uint32_t aSize)
|
||||
mMonitor.Wait();
|
||||
|
||||
if (mBytesTransferred != bytesWritten) {
|
||||
fail("GetOverlappedResult mismatch");
|
||||
ADD_FAILURE() << "GetOverlappedResult mismatch";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
mBytesTransferred = 0;
|
||||
passed("[write] match");
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
@ -136,7 +134,7 @@ nsNamedPipeDataObserver::OnDataAvailable(uint32_t aBytesTransferred,
|
||||
void *aOverlapped)
|
||||
{
|
||||
if (aOverlapped != &mOverlapped) {
|
||||
fail("invalid overlapped object");
|
||||
ADD_FAILURE() << "invalid overlapped object";
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -147,12 +145,12 @@ nsNamedPipeDataObserver::OnDataAvailable(uint32_t aBytesTransferred,
|
||||
FALSE);
|
||||
|
||||
if (!ret) {
|
||||
fail("GetOverlappedResult failed");
|
||||
ADD_FAILURE() << "GetOverlappedResult failed";
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (bytesTransferred != aBytesTransferred) {
|
||||
fail("GetOverlappedResult mismatch");
|
||||
ADD_FAILURE() << "GetOverlappedResult mismatch";
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -174,11 +172,6 @@ BOOL ConnectToNewClient(HANDLE aPipe, LPOVERLAPPED aOverlapped);
|
||||
|
||||
BOOL CreateAndConnectInstance(LPOVERLAPPED aOverlapped, LPHANDLE aPipe)
|
||||
{
|
||||
if (!aPipe) {
|
||||
fail("Parameter aPipe is NULL\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// FIXME: adjust parameters
|
||||
*aPipe = CreateNamedPipeA(
|
||||
PIPE_NAME,
|
||||
@ -194,7 +187,7 @@ BOOL CreateAndConnectInstance(LPOVERLAPPED aOverlapped, LPHANDLE aPipe)
|
||||
NULL);
|
||||
|
||||
if (*aPipe == INVALID_HANDLE_VALUE) {
|
||||
fail("CreateNamedPipe failed [%d]\n", GetLastError());
|
||||
ADD_FAILURE() << "CreateNamedPipe failed " << GetLastError();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -204,7 +197,7 @@ BOOL CreateAndConnectInstance(LPOVERLAPPED aOverlapped, LPHANDLE aPipe)
|
||||
BOOL ConnectToNewClient(HANDLE aPipe, LPOVERLAPPED aOverlapped)
|
||||
{
|
||||
if (ConnectNamedPipe(aPipe, aOverlapped)) {
|
||||
fail("Unexpected, overlapped ConnectNamedPipe() always returns 0.\n");
|
||||
ADD_FAILURE() << "Unexpected, overlapped ConnectNamedPipe() always returns 0.";
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -218,7 +211,7 @@ BOOL ConnectToNewClient(HANDLE aPipe, LPOVERLAPPED aOverlapped)
|
||||
break;
|
||||
|
||||
default: // error
|
||||
fail("ConnectNamedPipe failed [%d]\n", GetLastError());
|
||||
ADD_FAILURE() << "ConnectNamedPipe failed " << GetLastError();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -234,7 +227,7 @@ CreateNamedPipe(LPHANDLE aServer, LPHANDLE aClient)
|
||||
|
||||
ret = CreateAndConnectInstance(&overlapped, aServer);
|
||||
if (!ret) {
|
||||
fail("pipe server should be pending");
|
||||
ADD_FAILURE() << "pipe server should be pending";
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -247,14 +240,14 @@ CreateNamedPipe(LPHANDLE aServer, LPHANDLE aClient)
|
||||
nullptr);
|
||||
|
||||
if (*aClient == INVALID_HANDLE_VALUE) {
|
||||
fail("Unable to create pipe client");
|
||||
ADD_FAILURE() << "Unable to create pipe client";
|
||||
CloseHandle(*aServer);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
DWORD pipeMode = PIPE_READMODE_MESSAGE;
|
||||
if (!SetNamedPipeHandleState(*aClient, &pipeMode, nullptr, nullptr)) {
|
||||
fail("SetNamedPipeHandleState error (%d)", GetLastError());
|
||||
ADD_FAILURE() << "SetNamedPipeHandleState error " << GetLastError();
|
||||
CloseHandle(*aServer);
|
||||
CloseHandle(*aClient);
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -265,70 +258,30 @@ CreateNamedPipe(LPHANDLE aServer, LPHANDLE aClient)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
main(int32_t argc, char* argv[])
|
||||
TEST(TestNamedPipeService,Test)
|
||||
{
|
||||
ScopedXPCOM xpcom("NamedPipeService");
|
||||
if (xpcom.failed()) {
|
||||
fail("Unable to initalize XPCOM.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsINamedPipeService> svc =
|
||||
do_GetService(NS_NAMEDPIPESERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
fail("Unable to create named pipe service");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
HANDLE readPipe, writePipe;
|
||||
if (NS_FAILED(rv = CreateNamedPipe(&readPipe, &writePipe))) {
|
||||
fail("Unable to create pipes %d", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
rv = CreateNamedPipe(&readPipe, &writePipe);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
RefPtr<nsNamedPipeDataObserver> readObserver =
|
||||
new nsNamedPipeDataObserver(readPipe);
|
||||
RefPtr<nsNamedPipeDataObserver> writeObserver =
|
||||
new nsNamedPipeDataObserver(writePipe);
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(svc->AddDataObserver(readPipe, readObserver)))) {
|
||||
fail("Unable to add read data observer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(svc->AddDataObserver(writePipe, writeObserver)))) {
|
||||
fail("Unable to add read data observer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (writeObserver->Write(TEST_STR, sizeof(TEST_STR)) != sizeof(TEST_STR)) {
|
||||
fail("write error");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(svc->AddDataObserver(readPipe, readObserver)));
|
||||
ASSERT_TRUE(NS_SUCCEEDED(svc->AddDataObserver(writePipe, writeObserver)));
|
||||
ASSERT_EQ(writeObserver->Write(TEST_STR, sizeof(TEST_STR)), sizeof(TEST_STR));
|
||||
|
||||
char buffer[sizeof(TEST_STR)];
|
||||
if (readObserver->Read(buffer, sizeof(buffer)) != sizeof(TEST_STR)) {
|
||||
fail("read error");
|
||||
return -1;
|
||||
}
|
||||
ASSERT_EQ(readObserver->Read(buffer, sizeof(buffer)), sizeof(TEST_STR));
|
||||
ASSERT_STREQ(buffer, TEST_STR) << "I/O mismatch";
|
||||
|
||||
if (strcmp(buffer, TEST_STR) != 0) {
|
||||
fail("I/O mismatch");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(svc->RemoveDataObserver(readPipe, readObserver)))) {
|
||||
fail("Unable to remove read data observer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(svc->RemoveDataObserver(writePipe, writeObserver)))) {
|
||||
fail("Unable to remove read data observer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
passed("Finish");
|
||||
return 0;
|
||||
ASSERT_TRUE(NS_SUCCEEDED(svc->RemoveDataObserver(readPipe, readObserver)));
|
||||
ASSERT_TRUE(NS_SUCCEEDED(svc->RemoveDataObserver(writePipe, writeObserver)));
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 "TestCommon.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
/*
|
||||
* Test synchronous Open.
|
||||
*/
|
||||
|
||||
#define RETURN_IF_FAILED(rv, what) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (NS_FAILED(rv)) { \
|
||||
printf(what ": failed - %08x\n", static_cast<uint32_t>(rv)); \
|
||||
return -1; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
char buf[256];
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Usage: TestOpen url filename\nLoads a URL using ::Open, writing it to a file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
|
||||
rv = NS_NewURI(getter_AddRefs(uri), argv[1]);
|
||||
RETURN_IF_FAILED(rv, "NS_NewURI");
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
||||
RETURN_IF_FAILED(rv, "Couldn't get script security manager!");
|
||||
nsCOMPtr<nsIPrincipal> systemPrincipal;
|
||||
rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
|
||||
RETURN_IF_FAILED(rv, "Couldn't get system principal!");
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = NS_NewChannel(getter_AddRefs(channel),
|
||||
uri,
|
||||
systemPrincipal,
|
||||
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
||||
nsIContentPolicy::TYPE_OTHER);
|
||||
RETURN_IF_FAILED(rv, "NS_NewChannel");
|
||||
|
||||
rv = channel->Open2(getter_AddRefs(stream));
|
||||
RETURN_IF_FAILED(rv, "channel->Open2()");
|
||||
|
||||
FILE* outfile = fopen(argv[2], "wb");
|
||||
if (!outfile) {
|
||||
printf("error opening %s\n", argv[2]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t read;
|
||||
while (NS_SUCCEEDED(stream->Read(buf, sizeof(buf), &read)) && read) {
|
||||
Unused << fwrite(buf, 1, read, outfile);
|
||||
}
|
||||
printf("Done\n");
|
||||
|
||||
fclose(outfile);
|
||||
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
return 0;
|
||||
}
|
@ -1,890 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 sw=2 et cindent: */
|
||||
/* 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/. */
|
||||
|
||||
/*
|
||||
The TestProtocols tests the basic protocols architecture and can
|
||||
be used to test individual protocols as well. If this grows too
|
||||
big then we should split it to individual protocols.
|
||||
|
||||
-Gagan Saksena 04/29/99
|
||||
*/
|
||||
|
||||
#include "TestCommon.h"
|
||||
#include <algorithm>
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifdef XP_UNIX
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "nspr.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIResumableChannel.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIHttpChannelInternal.h"
|
||||
#include "nsIHttpHeaderVisitor.h"
|
||||
#include "nsIChannelEventSink.h"
|
||||
#include "nsIAsyncVerifyRedirectCallback.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIDNSService.h"
|
||||
#include "nsIAuthPrompt.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPropertyBag2.h"
|
||||
#include "nsIWritablePropertyBag2.h"
|
||||
#include "nsITimedChannel.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "NetwerkTestLogging.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
namespace TestProtocols {
|
||||
|
||||
//
|
||||
// set NSPR_LOG_MODULES=Test:5
|
||||
//
|
||||
static PRLogModuleInfo *gTestLog = nullptr;
|
||||
#define LOG(args) MOZ_LOG(gTestLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
//static PRTime gElapsedTime; // enable when we time it...
|
||||
static int gKeepRunning = 0;
|
||||
static bool gVerbose = false;
|
||||
static bool gAskUserForInput = false;
|
||||
static bool gResume = false;
|
||||
static uint64_t gStartAt = 0;
|
||||
|
||||
static const char* gEntityID;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set proxy preferences for testing
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static nsresult
|
||||
SetHttpProxy(const char *proxy)
|
||||
{
|
||||
const char *colon = strchr(proxy, ':');
|
||||
if (!colon)
|
||||
{
|
||||
NS_WARNING("invalid proxy token; use host:port");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
int port = atoi(colon + 1);
|
||||
if (port == 0)
|
||||
{
|
||||
NS_WARNING("invalid proxy port; must be an integer");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
nsAutoCString proxyHost;
|
||||
proxyHost = Substring(proxy, colon);
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs)
|
||||
{
|
||||
prefs->SetCharPref("network.proxy.http", proxyHost.get());
|
||||
prefs->SetIntPref("network.proxy.http_port", port);
|
||||
prefs->SetIntPref("network.proxy.type", 1); // manual proxy config
|
||||
}
|
||||
LOG(("connecting via proxy=%s:%d\n", proxyHost.get(), port));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
SetPACFile(const char* pacURL)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs)
|
||||
{
|
||||
prefs->SetCharPref("network.proxy.autoconfig_url", pacURL);
|
||||
prefs->SetIntPref("network.proxy.type", 2); // PAC file
|
||||
}
|
||||
LOG(("connecting using PAC file %s\n", pacURL));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Timing information
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void PrintTimingInformation(nsITimedChannel* channel) {
|
||||
#define PRINT_VALUE(property) \
|
||||
{ \
|
||||
PRTime value; \
|
||||
channel->Get##property(&value); \
|
||||
if (value) { \
|
||||
PRExplodedTime exploded; \
|
||||
PR_ExplodeTime(value, PR_LocalTimeParameters, &exploded); \
|
||||
char buf[256]; \
|
||||
PR_FormatTime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &exploded); \
|
||||
LOG((" " #property ":\t%s (%i usec)", buf, exploded.tm_usec)); \
|
||||
} else { \
|
||||
LOG((" " #property ":\t0")); \
|
||||
} \
|
||||
}
|
||||
LOG(("Timing data:"));
|
||||
PRINT_VALUE(ChannelCreationTime)
|
||||
PRINT_VALUE(AsyncOpenTime)
|
||||
PRINT_VALUE(DomainLookupStartTime)
|
||||
PRINT_VALUE(DomainLookupEndTime)
|
||||
PRINT_VALUE(ConnectStartTime)
|
||||
PRINT_VALUE(ConnectEndTime)
|
||||
PRINT_VALUE(RequestStartTime)
|
||||
PRINT_VALUE(ResponseStartTime)
|
||||
PRINT_VALUE(ResponseEndTime)
|
||||
PRINT_VALUE(CacheReadStartTime)
|
||||
PRINT_VALUE(CacheReadEndTime)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HeaderVisitor
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class HeaderVisitor : public nsIHttpHeaderVisitor
|
||||
{
|
||||
virtual ~HeaderVisitor() = default;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIHTTPHEADERVISITOR
|
||||
|
||||
HeaderVisitor() { }
|
||||
};
|
||||
NS_IMPL_ISUPPORTS(HeaderVisitor, nsIHttpHeaderVisitor)
|
||||
|
||||
NS_IMETHODIMP
|
||||
HeaderVisitor::VisitHeader(const nsACString &header, const nsACString &value)
|
||||
{
|
||||
LOG((" %s: %s\n",
|
||||
PromiseFlatCString(header).get(),
|
||||
PromiseFlatCString(value).get()));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// URLLoadInfo
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class URLLoadInfo : public nsISupports
|
||||
{
|
||||
virtual ~URLLoadInfo();
|
||||
|
||||
public:
|
||||
|
||||
explicit URLLoadInfo(const char* aUrl);
|
||||
|
||||
// ISupports interface...
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
const char* Name() { return mURLString.get(); }
|
||||
int64_t mBytesRead;
|
||||
PRTime mTotalTime;
|
||||
PRTime mConnectTime;
|
||||
nsCString mURLString;
|
||||
};
|
||||
|
||||
URLLoadInfo::URLLoadInfo(const char *aUrl) : mURLString(aUrl)
|
||||
{
|
||||
mBytesRead = 0;
|
||||
mConnectTime = mTotalTime = PR_Now();
|
||||
}
|
||||
|
||||
URLLoadInfo::~URLLoadInfo() = default;
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS0(URLLoadInfo)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// TestChannelEventSink
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TestChannelEventSink : public nsIChannelEventSink
|
||||
{
|
||||
virtual ~TestChannelEventSink();
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICHANNELEVENTSINK
|
||||
|
||||
TestChannelEventSink();
|
||||
};
|
||||
|
||||
TestChannelEventSink::TestChannelEventSink()
|
||||
{
|
||||
}
|
||||
|
||||
TestChannelEventSink::~TestChannelEventSink() = default;
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(TestChannelEventSink, nsIChannelEventSink)
|
||||
|
||||
NS_IMETHODIMP
|
||||
TestChannelEventSink::AsyncOnChannelRedirect(nsIChannel *channel,
|
||||
nsIChannel *newChannel,
|
||||
uint32_t flags,
|
||||
nsIAsyncVerifyRedirectCallback *callback)
|
||||
{
|
||||
LOG(("\n+++ TestChannelEventSink::OnChannelRedirect (with flags %x) +++\n",
|
||||
flags));
|
||||
callback->OnRedirectVerifyCallback(NS_OK);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// TestAuthPrompt
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TestAuthPrompt : public nsIAuthPrompt
|
||||
{
|
||||
virtual ~TestAuthPrompt();
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIAUTHPROMPT
|
||||
|
||||
TestAuthPrompt();
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(TestAuthPrompt, nsIAuthPrompt)
|
||||
|
||||
TestAuthPrompt::TestAuthPrompt()
|
||||
{
|
||||
}
|
||||
|
||||
TestAuthPrompt::~TestAuthPrompt() = default;
|
||||
|
||||
NS_IMETHODIMP
|
||||
TestAuthPrompt::Prompt(const char16_t *dialogTitle,
|
||||
const char16_t *text,
|
||||
const char16_t *passwordRealm,
|
||||
uint32_t savePassword,
|
||||
const char16_t *defaultText,
|
||||
char16_t **result,
|
||||
bool *_retval)
|
||||
{
|
||||
*_retval = false;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TestAuthPrompt::PromptUsernameAndPassword(const char16_t *dialogTitle,
|
||||
const char16_t *dialogText,
|
||||
const char16_t *passwordRealm,
|
||||
uint32_t savePassword,
|
||||
char16_t **user,
|
||||
char16_t **pwd,
|
||||
bool *_retval)
|
||||
{
|
||||
NS_ConvertUTF16toUTF8 text(passwordRealm);
|
||||
printf("* --------------------------------------------------------------------------- *\n");
|
||||
printf("* Authentication Required [%s]\n", text.get());
|
||||
printf("* --------------------------------------------------------------------------- *\n");
|
||||
|
||||
char buf[256];
|
||||
int n;
|
||||
|
||||
printf("Enter username: ");
|
||||
Unused << fgets(buf, sizeof(buf), stdin);
|
||||
n = strlen(buf);
|
||||
buf[n-1] = '\0'; // trim trailing newline
|
||||
*user = NS_StringCloneData(NS_ConvertUTF8toUTF16(buf));
|
||||
|
||||
const char *p;
|
||||
#if defined(XP_UNIX) && !defined(ANDROID)
|
||||
p = getpass("Enter password: ");
|
||||
#else
|
||||
printf("Enter password: ");
|
||||
fgets(buf, sizeof(buf), stdin);
|
||||
n = strlen(buf);
|
||||
buf[n-1] = '\0'; // trim trailing newline
|
||||
p = buf;
|
||||
#endif
|
||||
*pwd = NS_StringCloneData(NS_ConvertUTF8toUTF16(p));
|
||||
|
||||
// zap buf
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
*_retval = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TestAuthPrompt::PromptPassword(const char16_t *dialogTitle,
|
||||
const char16_t *text,
|
||||
const char16_t *passwordRealm,
|
||||
uint32_t savePassword,
|
||||
char16_t **pwd,
|
||||
bool *_retval)
|
||||
{
|
||||
*_retval = false;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// InputTestConsumer
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class InputTestConsumer : public nsIStreamListener
|
||||
{
|
||||
virtual ~InputTestConsumer();
|
||||
|
||||
public:
|
||||
|
||||
explicit InputTestConsumer(URLLoadInfo* aURLLoadInfo);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
private:
|
||||
URLLoadInfo* mURLLoadInfo;
|
||||
};
|
||||
|
||||
InputTestConsumer::InputTestConsumer(URLLoadInfo* aURLLoadInfo)
|
||||
: mURLLoadInfo(aURLLoadInfo)
|
||||
{
|
||||
NS_IF_ADDREF(mURLLoadInfo);
|
||||
}
|
||||
|
||||
InputTestConsumer::~InputTestConsumer()
|
||||
{
|
||||
NS_RELEASE(mURLLoadInfo);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(InputTestConsumer, nsIStreamListener, nsIRequestObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
|
||||
{
|
||||
LOG(("InputTestConsumer::OnStartRequest\n"));
|
||||
|
||||
NS_ASSERTION(!context, "context needs to be null when calling asyncOpen2");
|
||||
|
||||
if (mURLLoadInfo)
|
||||
mURLLoadInfo->mConnectTime = PR_Now() - mURLLoadInfo->mConnectTime;
|
||||
|
||||
if (gVerbose) {
|
||||
LOG(("\nStarted loading: %s\n", mURLLoadInfo ? mURLLoadInfo->Name() : "UNKNOWN URL"));
|
||||
}
|
||||
|
||||
nsAutoCString value;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
||||
if (channel) {
|
||||
nsresult status;
|
||||
channel->GetStatus(&status);
|
||||
LOG(("Channel Status: %08x\n", status));
|
||||
if (NS_SUCCEEDED(status)) {
|
||||
LOG(("Channel Info:\n"));
|
||||
|
||||
channel->GetName(value);
|
||||
LOG(("\tName: %s\n", value.get()));
|
||||
|
||||
channel->GetContentType(value);
|
||||
LOG(("\tContent-Type: %s\n", value.get()));
|
||||
|
||||
channel->GetContentCharset(value);
|
||||
LOG(("\tContent-Charset: %s\n", value.get()));
|
||||
|
||||
int64_t length = -1;
|
||||
if (NS_SUCCEEDED(channel->GetContentLength(&length))) {
|
||||
LOG(("\tContent-Length: %lld\n", length));
|
||||
} else {
|
||||
LOG(("\tContent-Length: Unknown\n"));
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> owner;
|
||||
channel->GetOwner(getter_AddRefs(owner));
|
||||
LOG(("\tChannel Owner: %x\n", owner.get()));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPropertyBag2> props = do_QueryInterface(request);
|
||||
if (props) {
|
||||
nsCOMPtr<nsIURI> foo;
|
||||
props->GetPropertyAsInterface(NS_LITERAL_STRING("test.foo"),
|
||||
NS_GET_IID(nsIURI),
|
||||
getter_AddRefs(foo));
|
||||
if (foo) {
|
||||
LOG(("\ttest.foo: %s\n", foo->GetSpecOrDefault().get()));
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIHttpChannelInternal> httpChannelInt(do_QueryInterface(request));
|
||||
if (httpChannelInt) {
|
||||
uint32_t majorVer, minorVer;
|
||||
nsresult rv = httpChannelInt->GetResponseVersion(&majorVer, &minorVer);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
LOG(("HTTP Response version: %u.%u\n", majorVer, minorVer));
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(request));
|
||||
if (httpChannel) {
|
||||
auto *visitor = new HeaderVisitor();
|
||||
if (!visitor)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(visitor);
|
||||
|
||||
LOG(("HTTP request headers:\n"));
|
||||
httpChannel->VisitRequestHeaders(visitor);
|
||||
|
||||
LOG(("HTTP response headers:\n"));
|
||||
httpChannel->VisitResponseHeaders(visitor);
|
||||
|
||||
NS_RELEASE(visitor);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIResumableChannel> resChannel = do_QueryInterface(request);
|
||||
if (resChannel) {
|
||||
LOG(("Resumable entity identification:\n"));
|
||||
nsAutoCString entityID;
|
||||
nsresult rv = resChannel->GetEntityID(entityID);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
LOG(("\t|%s|\n", entityID.get()));
|
||||
}
|
||||
else {
|
||||
LOG(("\t<none>\n"));
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnDataAvailable(nsIRequest *request,
|
||||
nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
uint64_t aSourceOffset,
|
||||
uint32_t aLength)
|
||||
{
|
||||
NS_ASSERTION(!context, "context needs to be null when calling asyncOpen2");
|
||||
|
||||
char buf[1025];
|
||||
uint32_t amt, size;
|
||||
nsresult rv;
|
||||
|
||||
while (aLength) {
|
||||
size = std::min<uint32_t>(aLength, sizeof(buf));
|
||||
|
||||
rv = aIStream->Read(buf, size, &amt);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ASSERTION((NS_BASE_STREAM_WOULD_BLOCK != rv),
|
||||
"The stream should never block.");
|
||||
return rv;
|
||||
}
|
||||
if (gVerbose) {
|
||||
buf[amt] = '\0';
|
||||
puts(buf);
|
||||
}
|
||||
if (mURLLoadInfo) {
|
||||
mURLLoadInfo->mBytesRead += amt;
|
||||
}
|
||||
|
||||
aLength -= amt;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context,
|
||||
nsresult aStatus)
|
||||
{
|
||||
LOG(("InputTestConsumer::OnStopRequest [status=%x]\n", aStatus));
|
||||
|
||||
if (mURLLoadInfo) {
|
||||
uint32_t httpStatus;
|
||||
bool bHTTPURL = false;
|
||||
|
||||
mURLLoadInfo->mTotalTime = PR_Now() - mURLLoadInfo->mTotalTime;
|
||||
|
||||
double readTime = ((mURLLoadInfo->mTotalTime-mURLLoadInfo->mConnectTime)/1000.0)/1000.0;
|
||||
|
||||
nsCOMPtr<nsIHttpChannel> pHTTPCon(do_QueryInterface(request));
|
||||
if (pHTTPCon) {
|
||||
pHTTPCon->GetResponseStatus(&httpStatus);
|
||||
bHTTPURL = true;
|
||||
}
|
||||
|
||||
LOG(("\nFinished loading: %s Status Code: %x\n", mURLLoadInfo->Name(), aStatus));
|
||||
if (bHTTPURL) {
|
||||
LOG(("\tHTTP Status: %u\n", httpStatus));
|
||||
}
|
||||
if (NS_ERROR_UNKNOWN_HOST == aStatus ||
|
||||
NS_ERROR_UNKNOWN_PROXY_HOST == aStatus) {
|
||||
LOG(("\tDNS lookup failed.\n"));
|
||||
}
|
||||
LOG(("\tTime to connect: %.3f seconds\n", (mURLLoadInfo->mConnectTime/1000.0)/1000.0));
|
||||
LOG(("\tTime to read: %.3f seconds.\n", readTime));
|
||||
LOG(("\tRead: %lld bytes.\n", mURLLoadInfo->mBytesRead));
|
||||
if (mURLLoadInfo->mBytesRead == int64_t(0)) {
|
||||
} else if (readTime > 0.0) {
|
||||
LOG(("\tThroughput: %.0f bps.\n", (double)(mURLLoadInfo->mBytesRead*int64_t(8))/readTime));
|
||||
} else {
|
||||
LOG(("\tThroughput: REAL FAST!!\n"));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITimedChannel> timed(do_QueryInterface(request));
|
||||
if (timed)
|
||||
PrintTimingInformation(timed);
|
||||
} else {
|
||||
LOG(("\nFinished loading: UNKNOWN URL. Status Code: %x\n", aStatus));
|
||||
}
|
||||
|
||||
if (--gKeepRunning == 0)
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// NotificationCallbacks
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class NotificationCallbacks final : public nsIInterfaceRequestor {
|
||||
|
||||
~NotificationCallbacks() = default;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NotificationCallbacks() {
|
||||
}
|
||||
|
||||
NS_IMETHOD GetInterface(const nsIID& iid, void* *result) override {
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
if (iid.Equals(NS_GET_IID(nsIChannelEventSink))) {
|
||||
TestChannelEventSink *sink;
|
||||
|
||||
sink = new TestChannelEventSink();
|
||||
if (sink == nullptr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(sink);
|
||||
rv = sink->QueryInterface(iid, result);
|
||||
NS_RELEASE(sink);
|
||||
}
|
||||
|
||||
if (iid.Equals(NS_GET_IID(nsIAuthPrompt))) {
|
||||
TestAuthPrompt *prompt;
|
||||
|
||||
prompt = new TestAuthPrompt();
|
||||
if (prompt == nullptr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(prompt);
|
||||
rv = prompt->QueryInterface(iid, result);
|
||||
NS_RELEASE(prompt);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(NotificationCallbacks, nsIInterfaceRequestor)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// helpers...
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
nsresult StartLoadingURL(const char* aUrlString)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIIOService> pService(do_GetService(kIOServiceCID, &rv));
|
||||
if (pService) {
|
||||
nsCOMPtr<nsIURI> pURL;
|
||||
|
||||
rv = pService->NewURI(nsDependentCString(aUrlString), nullptr, nullptr, getter_AddRefs(pURL));
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG(("ERROR: NewURI failed for %s [rv=%x]\n", aUrlString));
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsIChannel> pChannel;
|
||||
|
||||
auto* callbacks = new NotificationCallbacks();
|
||||
if (!callbacks) {
|
||||
LOG(("Failed to create a new consumer!"));
|
||||
return NS_ERROR_OUT_OF_MEMORY;;
|
||||
}
|
||||
NS_ADDREF(callbacks);
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIPrincipal> systemPrincipal;
|
||||
rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Async reading thru the calls of the event sink interface
|
||||
rv = NS_NewChannel(getter_AddRefs(pChannel),
|
||||
pURL,
|
||||
systemPrincipal,
|
||||
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
||||
nsIContentPolicy::TYPE_OTHER,
|
||||
nullptr, // loadGroup
|
||||
callbacks,
|
||||
nsIRequest::LOAD_NORMAL,
|
||||
pService);
|
||||
|
||||
NS_RELEASE(callbacks);
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG(("ERROR: NS_NewChannel failed for %s [rv=%x]\n", aUrlString, rv));
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITimedChannel> timed(do_QueryInterface(pChannel));
|
||||
if (timed)
|
||||
timed->SetTimingEnabled(true);
|
||||
|
||||
nsCOMPtr<nsIWritablePropertyBag2> props = do_QueryInterface(pChannel);
|
||||
if (props) {
|
||||
rv = props->SetPropertyAsInterface(NS_LITERAL_STRING("test.foo"),
|
||||
pURL);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
LOG(("set prop 'test.foo'\n"));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
You may optionally add/set other headers on this
|
||||
request object. This is done by QI for the specific
|
||||
protocolConnection.
|
||||
*/
|
||||
nsCOMPtr<nsIHttpChannel> pHTTPCon(do_QueryInterface(pChannel));
|
||||
|
||||
if (pHTTPCon) {
|
||||
// Setting a sample header.
|
||||
rv = pHTTPCon->SetRequestHeader(NS_LITERAL_CSTRING("sample-header"),
|
||||
NS_LITERAL_CSTRING("Sample-Value"),
|
||||
false);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
auto* info = new URLLoadInfo(aUrlString);
|
||||
if (!info) {
|
||||
NS_ERROR("Failed to create a load info!");
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
auto* listener = new InputTestConsumer(info);
|
||||
NS_IF_ADDREF(listener);
|
||||
if (!listener) {
|
||||
NS_ERROR("Failed to create a new stream listener!");
|
||||
return NS_ERROR_OUT_OF_MEMORY;;
|
||||
}
|
||||
|
||||
|
||||
if (gResume) {
|
||||
nsCOMPtr<nsIResumableChannel> res = do_QueryInterface(pChannel);
|
||||
if (!res) {
|
||||
NS_ERROR("Channel is not resumable!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
nsAutoCString id;
|
||||
if (gEntityID)
|
||||
id = gEntityID;
|
||||
LOG(("* resuming at %llu bytes, with entity id |%s|\n", gStartAt, id.get()));
|
||||
res->ResumeAt(gStartAt, id);
|
||||
}
|
||||
rv = pChannel->AsyncOpen2(listener);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
gKeepRunning++;
|
||||
}
|
||||
else {
|
||||
LOG(("ERROR: AsyncOpen failed [rv=%x]\n", rv));
|
||||
}
|
||||
NS_RELEASE(listener);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
FindChar(nsCString& buffer, char c)
|
||||
{
|
||||
const char *b;
|
||||
int32_t len = NS_CStringGetData(buffer, &b);
|
||||
|
||||
for (int32_t offset = 0; offset < len; ++offset) {
|
||||
if (b[offset] == c)
|
||||
return offset;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
StripChar(nsCString& buffer, char c)
|
||||
{
|
||||
const char *b;
|
||||
uint32_t len = NS_CStringGetData(buffer, &b) - 1;
|
||||
|
||||
for (; len > 0; --len) {
|
||||
if (b[len] == c) {
|
||||
buffer.Cut(len, 1);
|
||||
NS_CStringGetData(buffer, &b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult LoadURLsFromFile(char *aFileName)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
int32_t len, offset;
|
||||
PRFileDesc* fd;
|
||||
char buffer[1024];
|
||||
nsCString fileBuffer;
|
||||
nsCString urlString;
|
||||
|
||||
fd = PR_Open(aFileName, PR_RDONLY, 777);
|
||||
if (!fd) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Keep reading the file until EOF (or an error) is reached...
|
||||
do {
|
||||
len = PR_Read(fd, buffer, sizeof(buffer));
|
||||
if (len>0) {
|
||||
fileBuffer.Append(buffer, len);
|
||||
// Treat each line as a URL...
|
||||
while ((offset = FindChar(fileBuffer, '\n')) != -1) {
|
||||
urlString = StringHead(fileBuffer, offset);
|
||||
fileBuffer.Cut(0, offset+1);
|
||||
|
||||
StripChar(urlString, '\r');
|
||||
if (urlString.Length()) {
|
||||
LOG(("\t%s\n", urlString.get()));
|
||||
rv = StartLoadingURL(urlString.get());
|
||||
if (NS_FAILED(rv)) {
|
||||
// No need to log an error -- StartLoadingURL already
|
||||
// did that for us, probably.
|
||||
PR_Close(fd);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (len>0);
|
||||
|
||||
// If anything is left in the fileBuffer, treat it as a URL...
|
||||
StripChar(fileBuffer, '\r');
|
||||
if (fileBuffer.Length()) {
|
||||
LOG(("\t%s\n", fileBuffer.get()));
|
||||
StartLoadingURL(fileBuffer.get());
|
||||
}
|
||||
|
||||
PR_Close(fd);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult LoadURLFromConsole()
|
||||
{
|
||||
char buffer[1024];
|
||||
printf(R"(Enter URL ("q" to start): )");
|
||||
Unused << scanf("%s", buffer);
|
||||
if (buffer[0]=='q')
|
||||
gAskUserForInput = false;
|
||||
else
|
||||
StartLoadingURL(buffer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace TestProtocols
|
||||
|
||||
using namespace TestProtocols;
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv= (nsresult)-1;
|
||||
if (argc < 2) {
|
||||
printf("usage: %s [-verbose] [-file <name>] [-resume <startoffset>"
|
||||
"[-entityid <entityid>]] [-proxy <proxy>] [-pac <pacURL>]"
|
||||
"[-console] <url> <url> ... \n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
gTestLog = PR_NewLogModule("Test");
|
||||
|
||||
/*
|
||||
The following code only deals with XPCOM registration stuff. and setting
|
||||
up the event queues. Copied from TestSocketIO.cpp
|
||||
*/
|
||||
|
||||
rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
{
|
||||
int i;
|
||||
LOG(("Trying to load:\n"));
|
||||
for (i=1; i<argc; i++) {
|
||||
// Turn on verbose printing...
|
||||
if (PL_strcasecmp(argv[i], "-verbose") == 0) {
|
||||
gVerbose = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Turn on netlib tracing...
|
||||
if (PL_strcasecmp(argv[i], "-file") == 0) {
|
||||
LoadURLsFromFile(argv[++i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PL_strcasecmp(argv[i], "-console") == 0) {
|
||||
gAskUserForInput = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PL_strcasecmp(argv[i], "-resume") == 0) {
|
||||
gResume = true;
|
||||
PR_sscanf(argv[++i], "%llu", &gStartAt);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PL_strcasecmp(argv[i], "-entityid") == 0) {
|
||||
gEntityID = argv[++i];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PL_strcasecmp(argv[i], "-proxy") == 0) {
|
||||
SetHttpProxy(argv[++i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PL_strcasecmp(argv[i], "-pac") == 0) {
|
||||
SetPACFile(argv[++i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG(("\t%s\n", argv[i]));
|
||||
rv = StartLoadingURL(argv[i]);
|
||||
}
|
||||
// Enter the message pump to allow the URL load to proceed.
|
||||
PumpEvents();
|
||||
} // this scopes the nsCOMPtrs
|
||||
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
return NS_FAILED(rv) ? -1 : 0;
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
/* vim:set ts=4 sw=4 et cindent: */
|
||||
/* 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 "TestCommon.h"
|
||||
#include <stdlib.h>
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIServerSocket.h"
|
||||
#include "nsISocketTransport.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "NetwerkTestLogging.h"
|
||||
|
||||
//
|
||||
// set NSPR_LOG_MODULES=Test:5
|
||||
//
|
||||
static PRLogModuleInfo *gTestLog = nullptr;
|
||||
#define LOG(args) MOZ_LOG(gTestLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
class MySocketListener : public nsIServerSocketListener
|
||||
{
|
||||
protected:
|
||||
virtual ~MySocketListener() = default;
|
||||
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSISERVERSOCKETLISTENER
|
||||
|
||||
MySocketListener() {}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(MySocketListener, nsIServerSocketListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
MySocketListener::OnSocketAccepted(nsIServerSocket *serv,
|
||||
nsISocketTransport *trans)
|
||||
{
|
||||
LOG(("MySocketListener::OnSocketAccepted [serv=%p trans=%p]\n", serv, trans));
|
||||
|
||||
nsAutoCString host;
|
||||
int32_t port;
|
||||
|
||||
trans->GetHost(host);
|
||||
trans->GetPort(&port);
|
||||
|
||||
LOG((" -> %s:%d\n", host.get(), port));
|
||||
|
||||
nsCOMPtr<nsIInputStream> input;
|
||||
nsCOMPtr<nsIOutputStream> output;
|
||||
nsresult rv;
|
||||
|
||||
rv = trans->OpenInputStream(nsITransport::OPEN_BLOCKING, 0, 0, getter_AddRefs(input));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = trans->OpenOutputStream(nsITransport::OPEN_BLOCKING, 0, 0, getter_AddRefs(output));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
char buf[256];
|
||||
uint32_t n;
|
||||
|
||||
rv = input->Read(buf, sizeof(buf), &n);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
const char response[] = "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\nFooooopy!!\r\n";
|
||||
rv = output->Write(response, sizeof(response) - 1, &n);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
input->Close();
|
||||
output->Close();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MySocketListener::OnStopListening(nsIServerSocket *serv, nsresult status)
|
||||
{
|
||||
LOG(("MySocketListener::OnStopListening [serv=%p status=%x]\n", serv, status));
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
MakeServer(int32_t port)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIServerSocket> serv = do_CreateInstance(NS_SERVERSOCKET_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = serv->Init(port, true, 5);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = serv->GetPort(&port);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
LOG((" listening on port %d\n", port));
|
||||
|
||||
rv = serv->AsyncListen(new MySocketListener());
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv= (nsresult)-1;
|
||||
if (argc < 2) {
|
||||
printf("usage: %s <port>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
gTestLog = PR_NewLogModule("Test");
|
||||
|
||||
/*
|
||||
* The following code only deals with XPCOM registration stuff. and setting
|
||||
* up the event queues. Copied from TestSocketIO.cpp
|
||||
*/
|
||||
|
||||
rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
{
|
||||
rv = MakeServer(atoi(argv[1]));
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG(("MakeServer failed [rv=%x]\n", rv));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Enter the message pump to allow the URL load to proceed.
|
||||
PumpEvents();
|
||||
} // this scopes the nsCOMPtrs
|
||||
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
return 0;
|
||||
}
|
@ -1,307 +0,0 @@
|
||||
/* 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 "TestCommon.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsPISocketTransportService.h"
|
||||
#include "nsISocketTransport.h"
|
||||
#include "nsIAsyncInputStream.h"
|
||||
#include "nsIAsyncOutputStream.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsIDNSService.h"
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "mozilla/Logging.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// set NSPR_LOG_MODULES=Test:5
|
||||
//
|
||||
static PRLogModuleInfo *gTestLog = nullptr;
|
||||
#define LOG(args) MOZ_LOG(gTestLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class MyHandler : public nsIOutputStreamCallback
|
||||
, public nsIInputStreamCallback
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
MyHandler(const char *path,
|
||||
nsIAsyncInputStream *in,
|
||||
nsIAsyncOutputStream *out)
|
||||
: mInput(in)
|
||||
, mOutput(out)
|
||||
, mWriteOffset(0)
|
||||
{
|
||||
mBuf.AssignLiteral("GET ");
|
||||
mBuf.Append(path);
|
||||
mBuf.AppendLiteral(" HTTP/1.0\r\n\r\n");
|
||||
}
|
||||
virtual ~MyHandler() {}
|
||||
|
||||
// called on any thread
|
||||
NS_IMETHOD OnOutputStreamReady(nsIAsyncOutputStream *out)
|
||||
{
|
||||
LOG(("OnOutputStreamReady\n"));
|
||||
|
||||
nsresult rv;
|
||||
uint32_t n, count = mBuf.Length() - mWriteOffset;
|
||||
|
||||
rv = out->Write(mBuf.get() + mWriteOffset, count, &n);
|
||||
|
||||
LOG((" write returned [rv=%x count=%u]\n", rv, n));
|
||||
|
||||
if (NS_FAILED(rv) || (n == 0)) {
|
||||
if (rv != NS_BASE_STREAM_WOULD_BLOCK) {
|
||||
LOG((" done writing; starting to read\n"));
|
||||
mInput->AsyncWait(this, 0, 0, nullptr);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
mWriteOffset += n;
|
||||
|
||||
return out->AsyncWait(this, 0, 0, nullptr);
|
||||
}
|
||||
|
||||
// called on any thread
|
||||
NS_IMETHOD OnInputStreamReady(nsIAsyncInputStream *in)
|
||||
{
|
||||
LOG(("OnInputStreamReady\n"));
|
||||
|
||||
nsresult rv;
|
||||
uint32_t n;
|
||||
char buf[500];
|
||||
|
||||
rv = in->Read(buf, sizeof(buf), &n);
|
||||
|
||||
LOG((" read returned [rv=%x count=%u]\n", rv, n));
|
||||
|
||||
if (NS_FAILED(rv) || (n == 0)) {
|
||||
if (rv != NS_BASE_STREAM_WOULD_BLOCK) {
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return in->AsyncWait(this, 0, 0, nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIAsyncInputStream> mInput;
|
||||
nsCOMPtr<nsIAsyncOutputStream> mOutput;
|
||||
nsCString mBuf;
|
||||
uint32_t mWriteOffset;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(MyHandler,
|
||||
nsIOutputStreamCallback,
|
||||
nsIInputStreamCallback)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* create transport, open streams, and close
|
||||
*/
|
||||
static nsresult
|
||||
RunCloseTest(nsISocketTransportService *sts,
|
||||
const char *host, int port,
|
||||
uint32_t inFlags, uint32_t outFlags)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
LOG(("RunCloseTest\n"));
|
||||
|
||||
nsCOMPtr<nsISocketTransport> transport;
|
||||
rv = sts->CreateTransport(nullptr, 0,
|
||||
nsDependentCString(host), port, nullptr,
|
||||
getter_AddRefs(transport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
rv = transport->OpenInputStream(inFlags, 0, 0, getter_AddRefs(in));
|
||||
nsCOMPtr<nsIAsyncInputStream> asyncIn = do_QueryInterface(in, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> out;
|
||||
rv = transport->OpenOutputStream(outFlags, 0, 0, getter_AddRefs(out));
|
||||
nsCOMPtr<nsIAsyncOutputStream> asyncOut = do_QueryInterface(out, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
LOG(("waiting 1 second before closing transport and streams...\n"));
|
||||
PR_Sleep(PR_SecondsToInterval(1));
|
||||
|
||||
// let nsCOMPtr destructors close everything...
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* asynchronously read socket stream
|
||||
*/
|
||||
static nsresult
|
||||
RunTest(nsISocketTransportService *sts,
|
||||
const char *host, int port, const char *path,
|
||||
uint32_t inFlags, uint32_t outFlags)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
LOG(("RunTest\n"));
|
||||
|
||||
nsCOMPtr<nsISocketTransport> transport;
|
||||
rv = sts->CreateTransport(nullptr, 0,
|
||||
nsDependentCString(host), port, nullptr,
|
||||
getter_AddRefs(transport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
rv = transport->OpenInputStream(inFlags, 0, 0, getter_AddRefs(in));
|
||||
nsCOMPtr<nsIAsyncInputStream> asyncIn = do_QueryInterface(in, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> out;
|
||||
rv = transport->OpenOutputStream(outFlags, 0, 0, getter_AddRefs(out));
|
||||
nsCOMPtr<nsIAsyncOutputStream> asyncOut = do_QueryInterface(out, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
MyHandler *handler = new MyHandler(path, asyncIn, asyncOut);
|
||||
if (handler == nullptr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(handler);
|
||||
|
||||
rv = asyncOut->AsyncWait(handler, 0, 0, nullptr);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
PumpEvents();
|
||||
|
||||
NS_RELEASE(handler);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (argc < 4) {
|
||||
printf("usage: TestSocketTransport <host> <port> <path>\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
{
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
||||
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
||||
if (registrar)
|
||||
registrar->AutoRegister(nullptr);
|
||||
|
||||
gTestLog = PR_NewLogModule("Test");
|
||||
|
||||
// Make sure the DNS service is initialized on the main thread
|
||||
nsCOMPtr<nsIDNSService> dns =
|
||||
do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsPISocketTransportService> sts =
|
||||
do_GetService(kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
LOG(("phase 1 tests...\n"));
|
||||
|
||||
LOG(("flags = { OPEN_UNBUFFERED, OPEN_UNBUFFERED }\n"));
|
||||
rv = RunCloseTest(sts, argv[1], atoi(argv[2]),
|
||||
nsITransport::OPEN_UNBUFFERED,
|
||||
nsITransport::OPEN_UNBUFFERED);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunCloseTest failed");
|
||||
|
||||
LOG(("flags = { OPEN_BUFFERED, OPEN_UNBUFFERED }\n"));
|
||||
rv = RunCloseTest(sts, argv[1], atoi(argv[2]),
|
||||
0 /* nsITransport::OPEN_BUFFERED */,
|
||||
nsITransport::OPEN_UNBUFFERED);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunCloseTest failed");
|
||||
|
||||
LOG(("flags = { OPEN_UNBUFFERED, OPEN_BUFFERED }\n"));
|
||||
rv = RunCloseTest(sts, argv[1], atoi(argv[2]),
|
||||
nsITransport::OPEN_UNBUFFERED,
|
||||
0 /*nsITransport::OPEN_BUFFERED */);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunCloseTest failed");
|
||||
|
||||
LOG(("flags = { OPEN_BUFFERED, OPEN_BUFFERED }\n"));
|
||||
rv = RunCloseTest(sts, argv[1], atoi(argv[2]),
|
||||
0 /*nsITransport::OPEN_BUFFERED */,
|
||||
0 /*nsITransport::OPEN_BUFFERED */);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunCloseTest failed");
|
||||
|
||||
LOG(("calling Shutdown on socket transport service:\n"));
|
||||
sts->Shutdown();
|
||||
|
||||
LOG(("calling Init on socket transport service:\n"));
|
||||
sts->Init();
|
||||
|
||||
LOG(("phase 2 tests...\n"));
|
||||
|
||||
LOG(("flags = { OPEN_UNBUFFERED, OPEN_UNBUFFERED }\n"));
|
||||
rv = RunTest(sts, argv[1], atoi(argv[2]), argv[3],
|
||||
nsITransport::OPEN_UNBUFFERED,
|
||||
nsITransport::OPEN_UNBUFFERED);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");
|
||||
|
||||
LOG(("flags = { OPEN_BUFFERED, OPEN_UNBUFFERED }\n"));
|
||||
rv = RunTest(sts, argv[1], atoi(argv[2]), argv[3],
|
||||
0 /* nsITransport::OPEN_BUFFERED */,
|
||||
nsITransport::OPEN_UNBUFFERED);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");
|
||||
|
||||
LOG(("flags = { OPEN_UNBUFFERED, OPEN_BUFFERED }\n"));
|
||||
rv = RunTest(sts, argv[1], atoi(argv[2]), argv[3],
|
||||
nsITransport::OPEN_UNBUFFERED,
|
||||
0 /*nsITransport::OPEN_BUFFERED */);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");
|
||||
|
||||
LOG(("flags = { OPEN_BUFFERED, OPEN_BUFFERED }\n"));
|
||||
rv = RunTest(sts, argv[1], atoi(argv[2]), argv[3],
|
||||
0 /*nsITransport::OPEN_BUFFERED */,
|
||||
0 /*nsITransport::OPEN_BUFFERED */);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");
|
||||
|
||||
LOG(("waiting 1 second before calling Shutdown...\n"));
|
||||
PR_Sleep(PR_SecondsToInterval(1));
|
||||
|
||||
LOG(("calling Shutdown on socket transport service:\n"));
|
||||
sts->Shutdown();
|
||||
|
||||
// give background threads a chance to finish whatever work they may
|
||||
// be doing.
|
||||
LOG(("waiting 1 second before exiting...\n"));
|
||||
PR_Sleep(PR_SecondsToInterval(1));
|
||||
} // this scopes the nsCOMPtrs
|
||||
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
||||
rv = NS_ShutdownXPCOM(nullptr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
||||
return 0;
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include "TestCommon.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "NetwerkTestLogging.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
//
|
||||
// set NSPR_LOG_MODULES=Test:5
|
||||
//
|
||||
static PRLogModuleInfo *gTestLog = nullptr;
|
||||
#define LOG(args) MOZ_LOG(gTestLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
class MyStreamLoaderObserver final : public nsIStreamLoaderObserver
|
||||
{
|
||||
~MyStreamLoaderObserver() = default;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(MyStreamLoaderObserver, nsIStreamLoaderObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
MyStreamLoaderObserver::OnStreamComplete(nsIStreamLoader *loader,
|
||||
nsISupports *ctxt,
|
||||
nsresult status,
|
||||
uint32_t resultLen,
|
||||
const uint8_t *result)
|
||||
{
|
||||
LOG(("OnStreamComplete [status=%x resultLen=%u]\n", status, resultLen));
|
||||
|
||||
nsCOMPtr<nsIRequest> request;
|
||||
loader->GetRequest(getter_AddRefs(request));
|
||||
LOG((" request=%p\n", request.get()));
|
||||
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: %s <url>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
gTestLog = PR_NewLogModule("Test");
|
||||
|
||||
nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
||||
if (NS_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(argv[1]));
|
||||
if (NS_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
nsCOMPtr<nsIPrincipal> systemPrincipal;
|
||||
rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
|
||||
nsCOMPtr<nsIChannel> chan;
|
||||
rv = NS_NewChannel(getter_AddRefs(chan),
|
||||
uri,
|
||||
systemPrincipal,
|
||||
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS,
|
||||
nsIContentPolicy::TYPE_OTHER);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
nsCOMPtr<nsIStreamLoaderObserver> observer = new MyStreamLoaderObserver();
|
||||
if (!observer)
|
||||
return -1;
|
||||
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), observer);
|
||||
if (NS_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
rv = chan->AsyncOpen2(loader);
|
||||
if (NS_FAILED(rv))
|
||||
return -1;
|
||||
|
||||
PumpEvents();
|
||||
} // this scopes the nsCOMPtrs
|
||||
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
||||
NS_ShutdownXPCOM(nullptr);
|
||||
return 0;
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
/* 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 "TestCommon.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsIStreamTransportService.h"
|
||||
#include "nsIAsyncInputStream.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsISeekableStream.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "prprf.h"
|
||||
#include <algorithm>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// set NSPR_LOG_MODULES=Test:5
|
||||
//
|
||||
static PRLogModuleInfo *gTestLog = nullptr;
|
||||
#define LOG(args) MOZ_LOG(gTestLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class MyListener : public nsIStreamListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
MyListener() {}
|
||||
virtual ~MyListener() {}
|
||||
|
||||
NS_IMETHOD OnStartRequest(nsIRequest *req, nsISupports *ctx)
|
||||
{
|
||||
LOG(("MyListener::OnStartRequest\n"));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD OnDataAvailable(nsIRequest *req, nsISupports *ctx,
|
||||
nsIInputStream *stream,
|
||||
uint64_t offset, uint32_t count)
|
||||
{
|
||||
LOG(("MyListener::OnDataAvailable [offset=%llu count=%u]\n", offset, count));
|
||||
|
||||
char buf[500];
|
||||
nsresult rv;
|
||||
|
||||
while (count) {
|
||||
uint32_t n, amt = std::min<uint32_t>(count, sizeof(buf));
|
||||
|
||||
rv = stream->Read(buf, amt, &n);
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG((" read returned 0x%08x\n", rv));
|
||||
return rv;
|
||||
}
|
||||
|
||||
fwrite(buf, n, 1, stdout);
|
||||
printf("\n");
|
||||
|
||||
LOG((" read %u bytes\n", n));
|
||||
count -= n;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD OnStopRequest(nsIRequest *req, nsISupports *ctx, nsresult status)
|
||||
{
|
||||
LOG(("MyListener::OnStopRequest [status=%x]\n", status));
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(MyListener,
|
||||
nsIRequestObserver,
|
||||
nsIStreamListener)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* asynchronously copy file.
|
||||
*/
|
||||
static nsresult
|
||||
RunTest(nsIFile *file, int64_t offset, int64_t length)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
LOG(("RunTest\n"));
|
||||
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIInputStreamPump> pump;
|
||||
rv = NS_NewInputStreamPump(getter_AddRefs(pump), stream, offset, length);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = pump->AsyncRead(new MyListener(), nullptr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PumpEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (argc < 4) {
|
||||
printf("usage: %s <file-to-read> <start-offset> <read-length>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
char* fileName = argv[1];
|
||||
int64_t offset, length;
|
||||
int err = PR_sscanf(argv[2], "%lld", &offset);
|
||||
if (err == -1) {
|
||||
printf("Start offset must be an integer!\n");
|
||||
return 1;
|
||||
}
|
||||
err = PR_sscanf(argv[3], "%lld", &length);
|
||||
if (err == -1) {
|
||||
printf("Length must be an integer!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
{
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
||||
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
||||
if (registrar)
|
||||
registrar->AutoRegister(nullptr);
|
||||
|
||||
gTestLog = PR_NewLogModule("Test");
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = NS_NewNativeLocalFile(nsDependentCString(fileName), false, getter_AddRefs(file));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = RunTest(file, offset, length);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");
|
||||
|
||||
// give background threads a chance to finish whatever work they may
|
||||
// be doing.
|
||||
PR_Sleep(PR_SecondsToInterval(1));
|
||||
} // this scopes the nsCOMPtrs
|
||||
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
||||
rv = NS_ShutdownXPCOM(nullptr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
||||
return NS_OK;
|
||||
}
|
@ -1,319 +0,0 @@
|
||||
/* 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 "TestCommon.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsIStreamTransportService.h"
|
||||
#include "nsIAsyncInputStream.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "prenv.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// set NSPR_LOG_MODULES=Test:5
|
||||
//
|
||||
static PRLogModuleInfo *gTestLog = nullptr;
|
||||
#define LOG(args) MOZ_LOG(gTestLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define CHUNK_SIZE 500
|
||||
|
||||
class MyCopier : public nsIInputStreamCallback
|
||||
, public nsIOutputStreamCallback
|
||||
{
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
MyCopier()
|
||||
: mLock(nullptr)
|
||||
, mInputCondition(NS_OK)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~MyCopier()
|
||||
{
|
||||
if (mLock)
|
||||
nsAutoLock::DestroyLock(mLock);
|
||||
if (mInput)
|
||||
mInput->Close();
|
||||
if (mOutput)
|
||||
mOutput->Close();
|
||||
}
|
||||
|
||||
// called on any thread
|
||||
NS_IMETHOD OnInputStreamReady(nsIAsyncInputStream *inStr)
|
||||
{
|
||||
LOG(("OnInputStreamReady\n"));
|
||||
nsAutoLock lock(mLock);
|
||||
NS_ASSERTION(inStr == mInput, "unexpected stream");
|
||||
Process_Locked();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// called on any thread
|
||||
NS_IMETHOD OnOutputStreamReady(nsIAsyncOutputStream *outStr)
|
||||
{
|
||||
LOG(("OnOutputStreamReady\n"));
|
||||
nsAutoLock lock(mLock);
|
||||
NS_ASSERTION(outStr == mOutput, "unexpected stream");
|
||||
Process_Locked();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void Close_Locked()
|
||||
{
|
||||
LOG(("Close_Locked\n"));
|
||||
|
||||
mOutput->Close();
|
||||
mOutput = 0;
|
||||
mInput->Close();
|
||||
mInput = 0;
|
||||
|
||||
// post done copying event
|
||||
QuitPumpingEvents();
|
||||
}
|
||||
|
||||
void Process_Locked()
|
||||
{
|
||||
while (1) {
|
||||
mInputCondition = NS_OK; // reset
|
||||
|
||||
uint32_t n;
|
||||
nsresult rv = mOutput->WriteSegments(FillOutputBuffer, this, CHUNK_SIZE, &n);
|
||||
if (NS_FAILED(rv) || (n == 0)) {
|
||||
if (rv == NS_BASE_STREAM_WOULD_BLOCK)
|
||||
mOutput->AsyncWait(this, 0, 0, nullptr);
|
||||
else if (mInputCondition == NS_BASE_STREAM_WOULD_BLOCK)
|
||||
mInput->AsyncWait(this, 0, 0, nullptr);
|
||||
else
|
||||
Close_Locked();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult AsyncCopy(nsITransport *srcTrans, nsITransport *destTrans)
|
||||
{
|
||||
mLock = nsAutoLock::NewLock("MyCopier::mLock");
|
||||
if (!mLock)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIInputStream> inStr;
|
||||
rv = srcTrans->OpenInputStream(0, 0, 0, getter_AddRefs(inStr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> outStr;
|
||||
rv = destTrans->OpenOutputStream(0, 0, 0, getter_AddRefs(outStr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mInput = do_QueryInterface(inStr);
|
||||
mOutput = do_QueryInterface(outStr);
|
||||
|
||||
return mInput->AsyncWait(this, 0, 0, nullptr);
|
||||
}
|
||||
|
||||
static nsresult FillOutputBuffer(nsIOutputStream *outStr,
|
||||
void *closure,
|
||||
char *buffer,
|
||||
uint32_t offset,
|
||||
uint32_t count,
|
||||
uint32_t *countRead)
|
||||
{
|
||||
MyCopier *self = (MyCopier *) closure;
|
||||
|
||||
nsresult rv = self->mInput->Read(buffer, count, countRead);
|
||||
if (NS_FAILED(rv))
|
||||
self->mInputCondition = rv;
|
||||
else if (*countRead == 0)
|
||||
self->mInputCondition = NS_BASE_STREAM_CLOSED;
|
||||
|
||||
return self->mInputCondition;
|
||||
}
|
||||
|
||||
protected:
|
||||
PRLock *mLock;
|
||||
nsCOMPtr<nsIAsyncInputStream> mInput;
|
||||
nsCOMPtr<nsIAsyncOutputStream> mOutput;
|
||||
nsresult mInputCondition;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(MyCopier,
|
||||
nsIInputStreamCallback,
|
||||
nsIOutputStreamCallback)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* asynchronously copy file.
|
||||
*/
|
||||
static nsresult
|
||||
RunTest(nsIFile *srcFile, nsIFile *destFile)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
LOG(("RunTest\n"));
|
||||
|
||||
nsCOMPtr<nsIStreamTransportService> sts =
|
||||
do_GetService(kStreamTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIInputStream> srcStr;
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(srcStr), srcFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> destStr;
|
||||
rv = NS_NewLocalFileOutputStream(getter_AddRefs(destStr), destFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsITransport> srcTransport;
|
||||
rv = sts->CreateInputTransport(srcStr, int64_t(-1), int64_t(-1), true,
|
||||
getter_AddRefs(srcTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsITransport> destTransport;
|
||||
rv = sts->CreateOutputTransport(destStr, int64_t(-1), int64_t(-1), true,
|
||||
getter_AddRefs(destTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
MyCopier *copier = new MyCopier();
|
||||
if (copier == nullptr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(copier);
|
||||
|
||||
rv = copier->AsyncCopy(srcTransport, destTransport);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PumpEvents();
|
||||
|
||||
NS_RELEASE(copier);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static nsresult
|
||||
RunBlockingTest(nsIFile *srcFile, nsIFile *destFile)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
LOG(("RunBlockingTest\n"));
|
||||
|
||||
nsCOMPtr<nsIStreamTransportService> sts =
|
||||
do_GetService(kStreamTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIInputStream> srcIn;
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(srcIn), srcFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> fileOut;
|
||||
rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOut), destFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsITransport> destTransport;
|
||||
rv = sts->CreateOutputTransport(fileOut, int64_t(-1), int64_t(-1),
|
||||
true, getter_AddRefs(destTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> destOut;
|
||||
rv = destTransport->OpenOutputStream(nsITransport::OPEN_BLOCKING, 100, 10, getter_AddRefs(destOut));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char buf[120];
|
||||
uint32_t n;
|
||||
for (;;) {
|
||||
rv = srcIn->Read(buf, sizeof(buf), &n);
|
||||
if (NS_FAILED(rv) || (n == 0)) return rv;
|
||||
|
||||
rv = destOut->Write(buf, n, &n);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: %s <file-to-read>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
char* fileName = argv[1];
|
||||
{
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
||||
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
||||
if (registrar)
|
||||
registrar->AutoRegister(nullptr);
|
||||
|
||||
gTestLog = PR_NewLogModule("Test");
|
||||
|
||||
nsCOMPtr<nsIFile> srcFile;
|
||||
rv = NS_NewNativeLocalFile(nsDependentCString(fileName), false, getter_AddRefs(srcFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFile> destFile;
|
||||
rv = srcFile->Clone(getter_AddRefs(destFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoCString leafName;
|
||||
rv = destFile->GetNativeLeafName(leafName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoCString newName(leafName);
|
||||
newName.AppendLiteral(".1");
|
||||
rv = destFile->SetNativeLeafName(newName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = RunTest(srcFile, destFile);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunTest failed");
|
||||
|
||||
newName = leafName;
|
||||
newName.AppendLiteral(".2");
|
||||
rv = destFile->SetNativeLeafName(newName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = RunBlockingTest(srcFile, destFile);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RunBlockingTest failed");
|
||||
|
||||
// give background threads a chance to finish whatever work they may
|
||||
// be doing.
|
||||
PR_Sleep(PR_SecondsToInterval(1));
|
||||
} // this scopes the nsCOMPtrs
|
||||
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
||||
rv = NS_ShutdownXPCOM(nullptr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
||||
return NS_OK;
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "TestCommon.h"
|
||||
#include "TestHarness.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "nsIUDPSocket.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsISocketTransport.h"
|
||||
@ -22,31 +22,6 @@
|
||||
#define RESPONSE 0x6f6c6568
|
||||
#define MULTICAST_TIMEOUT 2000
|
||||
|
||||
#define EXPECT_SUCCESS(rv, ...) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (NS_FAILED(rv)) { \
|
||||
fail(__VA_ARGS__); \
|
||||
return false; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
|
||||
#define EXPECT_FAILURE(rv, ...) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (NS_SUCCEEDED(rv)) { \
|
||||
fail(__VA_ARGS__); \
|
||||
return false; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#define REQUIRE_EQUAL(a, b, ...) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (a != b) { \
|
||||
fail(__VA_ARGS__); \
|
||||
return false; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
enum TestPhase {
|
||||
TEST_OUTPUT_STREAM,
|
||||
TEST_SEND_API,
|
||||
@ -68,13 +43,13 @@ static bool CheckMessageContent(nsIUDPMessage *aMessage, uint32_t aExpectedConte
|
||||
uint32_t rawLen = rawData.Length();
|
||||
|
||||
if (len != rawLen) {
|
||||
fail("Raw data length(%d) do not matches String data length(%d).", rawLen, len);
|
||||
ADD_FAILURE() << "Raw data length " << rawLen << " does not match String data length " << len;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
if (buffer[i] != rawData[i]) {
|
||||
fail("Raw data(%s) do not matches String data(%s)", rawData.Elements() ,buffer);
|
||||
ADD_FAILURE();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -84,14 +59,18 @@ static bool CheckMessageContent(nsIUDPMessage *aMessage, uint32_t aExpectedConte
|
||||
input += buffer[i] << (8 * i);
|
||||
}
|
||||
|
||||
if (len != sizeof(uint32_t) || input != aExpectedContent)
|
||||
{
|
||||
fail("Request 0x%x received, expected 0x%x", input, aExpectedContent);
|
||||
if (len != sizeof(uint32_t)) {
|
||||
ADD_FAILURE() << "Message length mismatch, expected " << sizeof(uint32_t) <<
|
||||
" got " << len;
|
||||
return false;
|
||||
} else {
|
||||
passed("Request 0x%x received as expected", input);
|
||||
return true;
|
||||
}
|
||||
if (input != aExpectedContent) {
|
||||
ADD_FAILURE() << "Message content mismatch, expected 0x" <<
|
||||
std::hex << aExpectedContent << " got 0x" << input;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -103,9 +82,14 @@ protected:
|
||||
virtual ~UDPClientListener();
|
||||
|
||||
public:
|
||||
explicit UDPClientListener(WaitForCondition* waiter)
|
||||
: mWaiter(waiter)
|
||||
{ }
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIUDPSOCKETLISTENER
|
||||
nsresult mResult;
|
||||
nsresult mResult = NS_ERROR_FAILURE;
|
||||
RefPtr<WaitForCondition> mWaiter;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(UDPClientListener, nsIUDPSocketListener)
|
||||
@ -123,18 +107,16 @@ UDPClientListener::OnPacketReceived(nsIUDPSocket* socket, nsIUDPMessage* message
|
||||
message->GetFromAddr(getter_AddRefs(fromAddr));
|
||||
fromAddr->GetPort(&port);
|
||||
fromAddr->GetAddress(ip);
|
||||
passed("Packet received on client from %s:%d", ip.get(), port);
|
||||
|
||||
if (TEST_SEND_API == phase && CheckMessageContent(message, REQUEST)) {
|
||||
uint32_t count;
|
||||
const uint32_t data = RESPONSE;
|
||||
printf("*** Attempting to write response 0x%x to server by SendWithAddr...\n", RESPONSE);
|
||||
mResult = socket->SendWithAddr(fromAddr, (const uint8_t*)&data,
|
||||
sizeof(uint32_t), &count);
|
||||
if (mResult == NS_OK && count == sizeof(uint32_t)) {
|
||||
passed("Response written");
|
||||
SUCCEED();
|
||||
} else {
|
||||
fail("Response written");
|
||||
ADD_FAILURE();
|
||||
}
|
||||
return NS_OK;
|
||||
} else if (TEST_OUTPUT_STREAM != phase || !CheckMessageContent(message, RESPONSE)) {
|
||||
@ -142,14 +124,14 @@ UDPClientListener::OnPacketReceived(nsIUDPSocket* socket, nsIUDPMessage* message
|
||||
}
|
||||
|
||||
// Notify thread
|
||||
QuitPumpingEvents();
|
||||
mWaiter->Notify();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPClientListener::OnStopListening(nsIUDPSocket*, nsresult)
|
||||
{
|
||||
QuitPumpingEvents();
|
||||
mWaiter->Notify();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -162,10 +144,15 @@ protected:
|
||||
virtual ~UDPServerListener();
|
||||
|
||||
public:
|
||||
explicit UDPServerListener(WaitForCondition* waiter)
|
||||
: mWaiter(waiter)
|
||||
{ }
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIUDPSOCKETLISTENER
|
||||
|
||||
nsresult mResult;
|
||||
nsresult mResult = NS_ERROR_FAILURE;
|
||||
RefPtr<WaitForCondition> mWaiter;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(UDPServerListener, nsIUDPSocketListener)
|
||||
@ -183,7 +170,7 @@ UDPServerListener::OnPacketReceived(nsIUDPSocket* socket, nsIUDPMessage* message
|
||||
message->GetFromAddr(getter_AddRefs(fromAddr));
|
||||
fromAddr->GetPort(&port);
|
||||
fromAddr->GetAddress(ip);
|
||||
passed("Packet received on server from %s:%d", ip.get(), port);
|
||||
SUCCEED();
|
||||
|
||||
if (TEST_OUTPUT_STREAM == phase && CheckMessageContent(message, REQUEST))
|
||||
{
|
||||
@ -192,13 +179,12 @@ UDPServerListener::OnPacketReceived(nsIUDPSocket* socket, nsIUDPMessage* message
|
||||
|
||||
uint32_t count;
|
||||
const uint32_t data = RESPONSE;
|
||||
printf("*** Attempting to write response 0x%x to client by OutputStream...\n", RESPONSE);
|
||||
mResult = outstream->Write((const char*)&data, sizeof(uint32_t), &count);
|
||||
|
||||
if (mResult == NS_OK && count == sizeof(uint32_t)) {
|
||||
passed("Response written");
|
||||
SUCCEED();
|
||||
} else {
|
||||
fail("Response written");
|
||||
ADD_FAILURE();
|
||||
}
|
||||
return NS_OK;
|
||||
} else if (TEST_MULTICAST == phase && CheckMessageContent(message, REQUEST)) {
|
||||
@ -208,14 +194,14 @@ UDPServerListener::OnPacketReceived(nsIUDPSocket* socket, nsIUDPMessage* message
|
||||
}
|
||||
|
||||
// Notify thread
|
||||
QuitPumpingEvents();
|
||||
mWaiter->Notify();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
UDPServerListener::OnStopListening(nsIUDPSocket*, nsresult)
|
||||
{
|
||||
QuitPumpingEvents();
|
||||
mWaiter->Notify();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -228,10 +214,15 @@ protected:
|
||||
virtual ~MulticastTimerCallback();
|
||||
|
||||
public:
|
||||
explicit MulticastTimerCallback(WaitForCondition* waiter)
|
||||
: mWaiter(waiter)
|
||||
{ }
|
||||
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSITIMERCALLBACK
|
||||
|
||||
nsresult mResult;
|
||||
RefPtr<WaitForCondition> mWaiter;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(MulticastTimerCallback, nsITimerCallback)
|
||||
@ -247,46 +238,46 @@ MulticastTimerCallback::Notify(nsITimer* timer)
|
||||
// Multicast ping failed
|
||||
printf("Multicast ping timeout expired\n");
|
||||
mResult = NS_ERROR_FAILURE;
|
||||
QuitPumpingEvents();
|
||||
mWaiter->Notify();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**** Main ****/
|
||||
int
|
||||
main(int32_t argc, char *argv[])
|
||||
|
||||
TEST(TestUDPSocket, TestUDPSocketMain)
|
||||
{
|
||||
nsresult rv;
|
||||
ScopedXPCOM xpcom("UDP ServerSocket");
|
||||
if (xpcom.failed())
|
||||
return -1;
|
||||
|
||||
// Create UDPSocket
|
||||
nsCOMPtr<nsIUDPSocket> server, client;
|
||||
server = do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
client = do_CreateInstance("@mozilla.org/network/udp-socket;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
RefPtr<WaitForCondition> waiter = new WaitForCondition();
|
||||
|
||||
// Create UDPServerListener to process UDP packets
|
||||
RefPtr<UDPServerListener> serverListener = new UDPServerListener();
|
||||
RefPtr<UDPServerListener> serverListener = new UDPServerListener(waiter);
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
nsCOMPtr<nsIPrincipal> systemPrincipal;
|
||||
rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
// Bind server socket to 0.0.0.0
|
||||
rv = server->Init(0, false, systemPrincipal, true, 0);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
int32_t serverPort;
|
||||
server->GetPort(&serverPort);
|
||||
server->AsyncListen(serverListener);
|
||||
|
||||
// Bind clinet on arbitrary port
|
||||
RefPtr<UDPClientListener> clientListener = new UDPClientListener();
|
||||
RefPtr<UDPClientListener> clientListener = new UDPClientListener(waiter);
|
||||
client->Init(0, false, systemPrincipal, true, 0);
|
||||
client->AsyncListen(clientListener);
|
||||
|
||||
@ -296,43 +287,39 @@ main(int32_t argc, char *argv[])
|
||||
|
||||
phase = TEST_OUTPUT_STREAM;
|
||||
rv = client->Send(NS_LITERAL_CSTRING("127.0.0.1"), serverPort, (uint8_t*)&data, sizeof(uint32_t), &count);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
REQUIRE_EQUAL(count, sizeof(uint32_t), "Error");
|
||||
passed("Request written by Send");
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
EXPECT_EQ(count, sizeof(uint32_t));
|
||||
|
||||
// Wait for server
|
||||
PumpEvents();
|
||||
NS_ENSURE_SUCCESS(serverListener->mResult, -1);
|
||||
waiter->Wait(1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(serverListener->mResult));
|
||||
|
||||
// Read response from server
|
||||
NS_ENSURE_SUCCESS(clientListener->mResult, -1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(clientListener->mResult));
|
||||
|
||||
mozilla::net::NetAddr clientAddr;
|
||||
rv = client->GetAddress(&clientAddr);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
// The client address is 0.0.0.0, but Windows won't receive packets there, so
|
||||
// use 127.0.0.1 explicitly
|
||||
clientAddr.inet.ip = PR_htonl(127 << 24 | 1);
|
||||
|
||||
phase = TEST_SEND_API;
|
||||
rv = server->SendWithAddress(&clientAddr, (uint8_t*)&data, sizeof(uint32_t), &count);
|
||||
NS_ENSURE_SUCCESS(rv, -1);
|
||||
REQUIRE_EQUAL(count, sizeof(uint32_t), "Error");
|
||||
passed("Request written by SendWithAddress");
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
EXPECT_EQ(count, sizeof(uint32_t));
|
||||
|
||||
// Wait for server
|
||||
PumpEvents();
|
||||
NS_ENSURE_SUCCESS(serverListener->mResult, -1);
|
||||
waiter->Wait(1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(serverListener->mResult));
|
||||
|
||||
// Read response from server
|
||||
NS_ENSURE_SUCCESS(clientListener->mResult, -1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(clientListener->mResult));
|
||||
|
||||
// Setup timer to detect multicast failure
|
||||
nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
if (NS_WARN_IF(!timer)) {
|
||||
return -1;
|
||||
}
|
||||
RefPtr<MulticastTimerCallback> timerCb = new MulticastTimerCallback();
|
||||
ASSERT_TRUE(timer);
|
||||
RefPtr<MulticastTimerCallback> timerCb = new MulticastTimerCallback(waiter);
|
||||
|
||||
// The following multicast tests using multiple sockets require a firewall
|
||||
// exception on Windows XP (the earliest version of Windows we now support)
|
||||
@ -352,30 +339,20 @@ main(int32_t argc, char *argv[])
|
||||
multicastAddr.inet.ip = PR_htonl(224 << 24 | 255);
|
||||
multicastAddr.inet.port = PR_htons(serverPort);
|
||||
rv = server->JoinMulticastAddr(multicastAddr, nullptr);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
// Send multicast ping
|
||||
timerCb->mResult = NS_OK;
|
||||
timer->InitWithCallback(timerCb, MULTICAST_TIMEOUT, nsITimer::TYPE_ONE_SHOT);
|
||||
rv = client->SendWithAddress(&multicastAddr, (uint8_t*)&data, sizeof(uint32_t), &count);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return -1;
|
||||
}
|
||||
REQUIRE_EQUAL(count, sizeof(uint32_t), "Error");
|
||||
passed("Multicast ping written by SendWithAddress");
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
EXPECT_EQ(count, sizeof(uint32_t));
|
||||
|
||||
// Wait for server to receive successfully
|
||||
PumpEvents();
|
||||
if (NS_WARN_IF(NS_FAILED(serverListener->mResult))) {
|
||||
return -1;
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(timerCb->mResult))) {
|
||||
return -1;
|
||||
}
|
||||
waiter->Wait(1);
|
||||
ASSERT_TRUE(NS_SUCCEEDED(serverListener->mResult));
|
||||
ASSERT_TRUE(NS_SUCCEEDED(timerCb->mResult));
|
||||
timer->Cancel();
|
||||
passed("Server received ping successfully");
|
||||
|
||||
// Disable multicast loopback
|
||||
printf("Disable multicast loopback\n");
|
||||
@ -386,26 +363,19 @@ main(int32_t argc, char *argv[])
|
||||
timerCb->mResult = NS_OK;
|
||||
timer->InitWithCallback(timerCb, MULTICAST_TIMEOUT, nsITimer::TYPE_ONE_SHOT);
|
||||
rv = client->SendWithAddress(&multicastAddr, (uint8_t*)&data, sizeof(uint32_t), &count);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return -1;
|
||||
}
|
||||
REQUIRE_EQUAL(count, sizeof(uint32_t), "Error");
|
||||
passed("Multicast ping written by SendWithAddress");
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
EXPECT_EQ(count, sizeof(uint32_t));
|
||||
|
||||
// Wait for server to fail to receive
|
||||
PumpEvents();
|
||||
if (NS_WARN_IF(NS_SUCCEEDED(timerCb->mResult))) {
|
||||
return -1;
|
||||
}
|
||||
waiter->Wait(1);
|
||||
ASSERT_FALSE(NS_SUCCEEDED(timerCb->mResult));
|
||||
timer->Cancel();
|
||||
passed("Server failed to receive ping correctly");
|
||||
|
||||
// Reset state
|
||||
client->SetMulticastLoopback(true);
|
||||
server->SetMulticastLoopback(true);
|
||||
|
||||
// Change multicast interface
|
||||
printf("Changing multicast interface\n");
|
||||
mozilla::net::NetAddr loopbackAddr;
|
||||
loopbackAddr.inet.family = AF_INET;
|
||||
loopbackAddr.inet.ip = PR_htonl(INADDR_LOOPBACK);
|
||||
@ -415,19 +385,13 @@ main(int32_t argc, char *argv[])
|
||||
timerCb->mResult = NS_OK;
|
||||
timer->InitWithCallback(timerCb, MULTICAST_TIMEOUT, nsITimer::TYPE_ONE_SHOT);
|
||||
rv = client->SendWithAddress(&multicastAddr, (uint8_t*)&data, sizeof(uint32_t), &count);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return -1;
|
||||
}
|
||||
REQUIRE_EQUAL(count, sizeof(uint32_t), "Error");
|
||||
passed("Multicast ping written by SendWithAddress");
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
EXPECT_EQ(count, sizeof(uint32_t));
|
||||
|
||||
// Wait for server to fail to receive
|
||||
PumpEvents();
|
||||
if (NS_WARN_IF(NS_SUCCEEDED(timerCb->mResult))) {
|
||||
return -1;
|
||||
}
|
||||
waiter->Wait(1);
|
||||
ASSERT_FALSE(NS_SUCCEEDED(timerCb->mResult));
|
||||
timer->Cancel();
|
||||
passed("Server failed to receive ping correctly");
|
||||
|
||||
// Reset state
|
||||
mozilla::net::NetAddr anyAddr;
|
||||
@ -436,38 +400,28 @@ main(int32_t argc, char *argv[])
|
||||
client->SetMulticastInterfaceAddr(anyAddr);
|
||||
|
||||
// Leave multicast group
|
||||
printf("Leave multicast group\n");
|
||||
rv = server->LeaveMulticastAddr(multicastAddr, nullptr);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return -1;
|
||||
}
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
// Send multicast ping
|
||||
timerCb->mResult = NS_OK;
|
||||
timer->InitWithCallback(timerCb, MULTICAST_TIMEOUT, nsITimer::TYPE_ONE_SHOT);
|
||||
rv = client->SendWithAddress(&multicastAddr, (uint8_t*)&data, sizeof(uint32_t), &count);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return -1;
|
||||
}
|
||||
REQUIRE_EQUAL(count, sizeof(uint32_t), "Error");
|
||||
passed("Multicast ping written by SendWithAddress");
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
EXPECT_EQ(count, sizeof(uint32_t));
|
||||
|
||||
// Wait for server to fail to receive
|
||||
PumpEvents();
|
||||
if (NS_WARN_IF(NS_SUCCEEDED(timerCb->mResult))) {
|
||||
return -1;
|
||||
}
|
||||
waiter->Wait(1);
|
||||
ASSERT_FALSE(NS_SUCCEEDED(timerCb->mResult));
|
||||
timer->Cancel();
|
||||
passed("Server failed to receive ping correctly");
|
||||
goto close;
|
||||
|
||||
goto close; // suppress warning about unused label
|
||||
|
||||
close:
|
||||
// Close server
|
||||
printf("*** Attempting to close server ...\n");
|
||||
server->Close();
|
||||
client->Close();
|
||||
PumpEvents();
|
||||
passed("Server closed");
|
||||
|
||||
return 0; // failure is a non-zero return
|
||||
// Wait for client and server to see closing
|
||||
waiter->Wait(2);
|
||||
}
|
||||
|
@ -1,159 +0,0 @@
|
||||
/* 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 "stdio.h"
|
||||
#include "TestCommon.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nspr.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsISocketTransport.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIInputStream.h"
|
||||
|
||||
#define UDP_PORT 9050
|
||||
|
||||
#define UDP_ASSERT(condition, message) \
|
||||
PR_BEGIN_MACRO \
|
||||
NS_ASSERTION(condition, message); \
|
||||
if (!(condition)) { \
|
||||
returnCode = -1; \
|
||||
break; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#define UDP_ASSERT_PRSTATUS(message) \
|
||||
PR_BEGIN_MACRO \
|
||||
NS_ASSERTION(status == PR_SUCCESS, message); \
|
||||
if (status != PR_SUCCESS) { \
|
||||
PRErrorCode err = PR_GetError(); \
|
||||
fprintf(stderr, \
|
||||
"FAIL nspr: %s: (%08x) %s\n", \
|
||||
message, \
|
||||
err, \
|
||||
PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT)); \
|
||||
returnCode = -1; \
|
||||
break; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#define UDP_ASSERT_NSRESULT(message) \
|
||||
PR_BEGIN_MACRO \
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), message); \
|
||||
if (NS_FAILED(rv)) { \
|
||||
fprintf(stderr, "FAIL UDPSocket: %s: %08x\n", \
|
||||
message, rv); \
|
||||
returnCode = -1; \
|
||||
break; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
int returnCode = 0;
|
||||
nsresult rv = NS_OK;
|
||||
PRFileDesc *serverFD = nullptr;
|
||||
|
||||
do { // act both as a scope for nsCOMPtrs to be released before XPCOM
|
||||
// shutdown, as well as a easy way to abort the test
|
||||
PRStatus status = PR_SUCCESS;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
||||
UDP_ASSERT(registrar, "Null nsIComponentRegistrar");
|
||||
if (registrar)
|
||||
registrar->AutoRegister(nullptr);
|
||||
|
||||
// listen for a incoming UDP connection on localhost
|
||||
serverFD = PR_OpenUDPSocket(PR_AF_INET);
|
||||
UDP_ASSERT(serverFD, "Cannot open UDP socket for listening");
|
||||
|
||||
PRSocketOptionData socketOptions;
|
||||
socketOptions.option = PR_SockOpt_Nonblocking;
|
||||
socketOptions.value.non_blocking = false;
|
||||
status = PR_SetSocketOption(serverFD, &socketOptions);
|
||||
UDP_ASSERT_PRSTATUS("Failed to set server socket as blocking");
|
||||
|
||||
PRNetAddr addr;
|
||||
status = PR_InitializeNetAddr(PR_IpAddrLoopback, UDP_PORT, &addr);
|
||||
UDP_ASSERT_PRSTATUS("Failed to initialize loopback address");
|
||||
|
||||
status = PR_Bind(serverFD, &addr);
|
||||
UDP_ASSERT_PRSTATUS("Failed to bind server socket");
|
||||
|
||||
// dummy IOService to get around bug 379890
|
||||
nsCOMPtr<nsISupports> ios =
|
||||
do_GetService("@mozilla.org/network/io-service;1");
|
||||
|
||||
// and have a matching UDP connection for the client
|
||||
nsCOMPtr<nsISocketTransportService> sts =
|
||||
do_GetService("@mozilla.org/network/socket-transport-service;1", &rv);
|
||||
UDP_ASSERT_NSRESULT("Cannot get socket transport service");
|
||||
|
||||
nsCOMPtr<nsISocketTransport> transport;
|
||||
const char *protocol = "udp";
|
||||
rv = sts->CreateTransport(&protocol, 1, NS_LITERAL_CSTRING("localhost"),
|
||||
UDP_PORT, nullptr, getter_AddRefs(transport));
|
||||
UDP_ASSERT_NSRESULT("Cannot create transport");
|
||||
|
||||
uint32_t count, read;
|
||||
const uint32_t data = 0xFF0056A9;
|
||||
|
||||
// write to the output stream
|
||||
nsCOMPtr<nsIOutputStream> outstream;
|
||||
rv = transport->OpenOutputStream(nsITransport::OPEN_BLOCKING,
|
||||
0, 0, getter_AddRefs(outstream));
|
||||
UDP_ASSERT_NSRESULT("Cannot open output stream");
|
||||
|
||||
rv = outstream->Write((const char*)&data, sizeof(uint32_t), &count);
|
||||
UDP_ASSERT_NSRESULT("Cannot write to output stream");
|
||||
UDP_ASSERT(count == sizeof(uint32_t),
|
||||
"Did not write enough bytes to output stream");
|
||||
|
||||
// read from NSPR to check it's the same
|
||||
count = PR_RecvFrom(serverFD, &read, sizeof(uint32_t), 0, &addr, 1);
|
||||
UDP_ASSERT(count == sizeof(uint32_t),
|
||||
"Did not read enough bytes from NSPR");
|
||||
status = (read == data ? PR_SUCCESS : PR_FAILURE);
|
||||
UDP_ASSERT_PRSTATUS("Did not read expected data from NSPR");
|
||||
|
||||
// write to NSPR
|
||||
count = PR_SendTo(serverFD, &data, sizeof(uint32_t), 0, &addr, 1);
|
||||
status = (count == sizeof(uint32_t) ? PR_SUCCESS : PR_FAILURE);
|
||||
UDP_ASSERT_PRSTATUS("Did not write enough bytes to NSPR");
|
||||
|
||||
// read from stream
|
||||
nsCOMPtr<nsIInputStream> instream;
|
||||
rv = transport->OpenInputStream(nsITransport::OPEN_BLOCKING,
|
||||
0, 0, getter_AddRefs(instream));
|
||||
UDP_ASSERT_NSRESULT("Cannot open input stream");
|
||||
|
||||
rv = instream->Read((char*)&read, sizeof(uint32_t), &count);
|
||||
UDP_ASSERT_NSRESULT("Cannot read from input stream");
|
||||
UDP_ASSERT(count == sizeof(uint32_t),
|
||||
"Did not read enough bytes from input stream");
|
||||
UDP_ASSERT(read == data, "Did not read expected data from stream");
|
||||
|
||||
} while (false); // release all XPCOM things
|
||||
if (serverFD) {
|
||||
PRStatus status = PR_Close(serverFD);
|
||||
if (status != PR_SUCCESS) {
|
||||
PRErrorCode err = PR_GetError();
|
||||
fprintf(stderr, "FAIL: Cannot close server: (%08x) %s\n",
|
||||
err, PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
|
||||
}
|
||||
}
|
||||
rv = NS_ShutdownXPCOM(nullptr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
@ -1,135 +0,0 @@
|
||||
#include "TestCommon.h"
|
||||
#include <stdio.h>
|
||||
#include "nsIURLParser.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
static void
|
||||
print_field(const char *label, char *str, int32_t len)
|
||||
{
|
||||
char c = str[len];
|
||||
str[len] = '\0';
|
||||
printf("[%s=%s]\n", label, str);
|
||||
str[len] = c;
|
||||
}
|
||||
|
||||
#define PRINT_FIELD(x) \
|
||||
print_field(# x, x, x ## Len)
|
||||
|
||||
#define PRINT_SUBFIELD(base, x) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (x ## Len != -1) \
|
||||
print_field(# x, base + x ## Pos, x ## Len); \
|
||||
PR_END_MACRO
|
||||
|
||||
static void
|
||||
parse_authority(nsIURLParser *urlParser, char *auth, int32_t authLen)
|
||||
{
|
||||
PRINT_FIELD(auth);
|
||||
|
||||
uint32_t usernamePos, passwordPos;
|
||||
int32_t usernameLen, passwordLen;
|
||||
uint32_t hostnamePos;
|
||||
int32_t hostnameLen, port;
|
||||
|
||||
urlParser->ParseAuthority(auth, authLen,
|
||||
&usernamePos, &usernameLen,
|
||||
&passwordPos, &passwordLen,
|
||||
&hostnamePos, &hostnameLen,
|
||||
&port);
|
||||
|
||||
PRINT_SUBFIELD(auth, username);
|
||||
PRINT_SUBFIELD(auth, password);
|
||||
PRINT_SUBFIELD(auth, hostname);
|
||||
if (port != -1)
|
||||
printf("[port=%d]\n", port);
|
||||
}
|
||||
|
||||
static void
|
||||
parse_file_path(nsIURLParser *urlParser, char *filepath, int32_t filepathLen)
|
||||
{
|
||||
PRINT_FIELD(filepath);
|
||||
|
||||
uint32_t dirPos, basePos, extPos;
|
||||
int32_t dirLen, baseLen, extLen;
|
||||
|
||||
urlParser->ParseFilePath(filepath, filepathLen,
|
||||
&dirPos, &dirLen,
|
||||
&basePos, &baseLen,
|
||||
&extPos, &extLen);
|
||||
|
||||
PRINT_SUBFIELD(filepath, dir);
|
||||
PRINT_SUBFIELD(filepath, base);
|
||||
PRINT_SUBFIELD(filepath, ext);
|
||||
}
|
||||
|
||||
static void
|
||||
parse_path(nsIURLParser *urlParser, char *path, int32_t pathLen)
|
||||
{
|
||||
PRINT_FIELD(path);
|
||||
|
||||
uint32_t filePos, queryPos, refPos;
|
||||
int32_t fileLen, queryLen, refLen;
|
||||
|
||||
urlParser->ParsePath(path, pathLen,
|
||||
&filePos, &fileLen,
|
||||
&queryPos, &queryLen,
|
||||
&refPos, &refLen);
|
||||
|
||||
if (fileLen != -1)
|
||||
parse_file_path(urlParser, path + filePos, fileLen);
|
||||
PRINT_SUBFIELD(path, query);
|
||||
PRINT_SUBFIELD(path, ref);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: TestURLParser [-std|-noauth|-auth] <url>\n");
|
||||
return -1;
|
||||
}
|
||||
nsCOMPtr<nsIURLParser> urlParser;
|
||||
if (strcmp(argv[1], "-noauth") == 0) {
|
||||
urlParser = do_GetService(NS_NOAUTHURLPARSER_CONTRACTID);
|
||||
argv[1] = argv[2];
|
||||
}
|
||||
else if (strcmp(argv[1], "-auth") == 0) {
|
||||
urlParser = do_GetService(NS_AUTHURLPARSER_CONTRACTID);
|
||||
argv[1] = argv[2];
|
||||
}
|
||||
else {
|
||||
urlParser = do_GetService(NS_STDURLPARSER_CONTRACTID);
|
||||
if (strcmp(argv[1], "-std") == 0)
|
||||
argv[1] = argv[2];
|
||||
else
|
||||
printf("assuming -std\n");
|
||||
}
|
||||
if (urlParser) {
|
||||
printf("have urlParser @%p\n", static_cast<void*>(urlParser.get()));
|
||||
|
||||
char *spec = argv[1];
|
||||
uint32_t schemePos, authPos, pathPos;
|
||||
int32_t schemeLen, authLen, pathLen;
|
||||
|
||||
urlParser->ParseURL(spec, -1,
|
||||
&schemePos, &schemeLen,
|
||||
&authPos, &authLen,
|
||||
&pathPos, &pathLen);
|
||||
|
||||
if (schemeLen != -1)
|
||||
PRINT_SUBFIELD(spec, scheme);
|
||||
if (authLen != -1)
|
||||
parse_authority(urlParser, spec + authPos, authLen);
|
||||
if (pathLen != -1)
|
||||
parse_path(urlParser, spec + pathPos, pathLen);
|
||||
}
|
||||
else
|
||||
printf("no urlParser\n");
|
||||
return 0;
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* 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 "TestCommon.h"
|
||||
#include <algorithm>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#include "nsIUploadChannel.h"
|
||||
|
||||
#include "NetwerkTestLogging.h"
|
||||
//
|
||||
// set NSPR_LOG_MODULES=Test:5
|
||||
//
|
||||
static PRLogModuleInfo *gTestLog = nullptr;
|
||||
#define LOG(args) MOZ_LOG(gTestLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// InputTestConsumer
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class InputTestConsumer : public nsIStreamListener
|
||||
{
|
||||
virtual ~InputTestConsumer();
|
||||
|
||||
public:
|
||||
|
||||
InputTestConsumer();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
};
|
||||
|
||||
InputTestConsumer::InputTestConsumer()
|
||||
{
|
||||
}
|
||||
|
||||
InputTestConsumer::~InputTestConsumer() = default;
|
||||
|
||||
NS_IMPL_ISUPPORTS(InputTestConsumer,
|
||||
nsIStreamListener,
|
||||
nsIRequestObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
|
||||
{
|
||||
LOG(("InputTestConsumer::OnStartRequest\n"));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnDataAvailable(nsIRequest *request,
|
||||
nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
uint64_t aSourceOffset,
|
||||
uint32_t aLength)
|
||||
{
|
||||
char buf[1025];
|
||||
uint32_t amt, size;
|
||||
nsresult rv;
|
||||
|
||||
while (aLength) {
|
||||
size = std::min<uint32_t>(aLength, sizeof(buf));
|
||||
rv = aIStream->Read(buf, size, &amt);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ASSERTION((NS_BASE_STREAM_WOULD_BLOCK != rv),
|
||||
"The stream should never block.");
|
||||
return rv;
|
||||
}
|
||||
aLength -= amt;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context,
|
||||
nsresult aStatus)
|
||||
{
|
||||
LOG(("InputTestConsumer::OnStopRequest [status=%x]\n", aStatus));
|
||||
QuitPumpingEvents();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: %s <url> <file-to-upload>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
char* uriSpec = argv[1];
|
||||
char* fileName = argv[2];
|
||||
|
||||
gTestLog = PR_NewLogModule("Test");
|
||||
|
||||
{
|
||||
nsCOMPtr<nsIServiceManager> servMan;
|
||||
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
||||
|
||||
// first thing to do is create ourselves a stream that
|
||||
// is to be uploaded.
|
||||
nsCOMPtr<nsIInputStream> uploadStream;
|
||||
rv = NS_NewPostDataStream(getter_AddRefs(uploadStream),
|
||||
true,
|
||||
nsDependentCString(fileName)); // XXX UTF-8
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
// create our url.
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), uriSpec);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
nsCOMPtr<nsIPrincipal> systemPrincipal;
|
||||
rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = NS_NewChannel(getter_AddRefs(channel),
|
||||
uri,
|
||||
systemPrincipal,
|
||||
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS,
|
||||
nsIContentPolicy::TYPE_OTHER);
|
||||
if (NS_FAILED(rv)) return -1;
|
||||
|
||||
// QI and set the upload stream
|
||||
nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(channel));
|
||||
uploadChannel->SetUploadStream(uploadStream, EmptyCString(), -1);
|
||||
|
||||
// create a dummy listener
|
||||
InputTestConsumer* listener;
|
||||
|
||||
listener = new InputTestConsumer;
|
||||
if (!listener) {
|
||||
NS_ERROR("Failed to create a new stream listener!");
|
||||
return -1;
|
||||
}
|
||||
NS_ADDREF(listener);
|
||||
|
||||
channel->AsyncOpen2(listener);
|
||||
|
||||
PumpEvents();
|
||||
} // this scopes the nsCOMPtrs
|
||||
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
||||
rv = NS_ShutdownXPCOM(nullptr);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -14,56 +14,23 @@ XPCSHELL_TESTS_MANIFESTS += [
|
||||
'unit_ipc/xpcshell.ini',
|
||||
]
|
||||
|
||||
GeckoSimplePrograms([
|
||||
'PropertiesTest',
|
||||
'ReadNTLM',
|
||||
'TestBlockingSocket',
|
||||
'TestDNS',
|
||||
'TestIncrementalDownload',
|
||||
'TestOpen',
|
||||
'TestProtocols',
|
||||
'TestServ',
|
||||
'TestStreamLoader',
|
||||
'TestUpload',
|
||||
'TestURLParser',
|
||||
'urltest',
|
||||
])
|
||||
|
||||
# XXX Make this work in libxul builds.
|
||||
#SIMPLE_PROGRAMS += [
|
||||
# TestIDN',
|
||||
# TestIOThreads',
|
||||
# TestSocketTransport',
|
||||
# TestStreamPump',
|
||||
# TestStreamTransport',
|
||||
# TestUDPSocketProvider',
|
||||
#]
|
||||
|
||||
CppUnitTests([
|
||||
'TestBind',
|
||||
'TestCookie',
|
||||
'TestUDPSocket',
|
||||
])
|
||||
FINAL_LIBRARY = 'xul-gtest'
|
||||
UNIFIED_SOURCES += [
|
||||
'TestBind.cpp',
|
||||
'TestCookie.cpp',
|
||||
'TestUDPSocket.cpp',
|
||||
]
|
||||
|
||||
if CONFIG['OS_TARGET'] == 'WINNT':
|
||||
CppUnitTests([
|
||||
'TestNamedPipeService'
|
||||
])
|
||||
UNIFIED_SOURCES += [
|
||||
'TestNamedPipeService.cpp',
|
||||
]
|
||||
|
||||
RESOURCE_FILES += [
|
||||
'urlparse.dat',
|
||||
'urlparse_unx.dat',
|
||||
]
|
||||
|
||||
USE_LIBS += ['static:js']
|
||||
|
||||
if CONFIG['ENABLE_INTL_API'] and CONFIG['MOZ_ICU_DATA_ARCHIVE']:
|
||||
# The ICU libraries linked into libmozjs will not include the ICU data,
|
||||
# so link it directly.
|
||||
USE_LIBS += ['icudata']
|
||||
|
||||
CXXFLAGS += CONFIG['TK_CFLAGS']
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
if CONFIG['GNU_CXX']:
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user