Merge inbound to m-c.

This commit is contained in:
Ryan VanderMeulen 2013-11-25 14:13:56 -05:00
commit f78e36ac4a
79 changed files with 904 additions and 314 deletions

View File

@ -268,7 +268,8 @@ EventSource::Init(nsISupports* aOwner,
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = convManager->GetUnicodeDecoder("UTF-8", getter_AddRefs(mUnicodeDecoder));
rv = convManager->GetUnicodeDecoderRaw("UTF-8",
getter_AddRefs(mUnicodeDecoder));
NS_ENSURE_SUCCESS(rv, rv);
// the constructor should throw a SYNTAX_ERROR only if it fails resolving the

View File

@ -540,7 +540,8 @@ nsDOMFileReader::ConvertStream(const char *aFileData,
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
rv = charsetConverter->GetUnicodeDecoder(aCharset, getter_AddRefs(unicodeDecoder));
rv = charsetConverter->GetUnicodeDecoderRaw(aCharset,
getter_AddRefs(unicodeDecoder));
NS_ENSURE_SUCCESS(rv, rv);
int32_t destLength;

View File

@ -2724,7 +2724,8 @@ nsDocument::InitCSP(nsIChannel* aChannel)
if (csp) {
// Copy into principal
nsIPrincipal* principal = GetPrincipal();
principal->SetCsp(csp);
rv = principal->SetCsp(csp);
NS_ENSURE_SUCCESS(rv, rv);
#ifdef PR_LOGGING
PR_LOG(gCspPRLog, PR_LOG_DEBUG,
("Inserted CSP into principal %p", principal));
@ -3289,16 +3290,12 @@ nsDocument::GetBaseTarget(nsAString &aBaseTarget)
void
nsDocument::SetDocumentCharacterSet(const nsACString& aCharSetID)
{
// XXX it would be a good idea to assert the sanity of the argument,
// but before we figure out what to do about non-Encoding Standard
// encodings in the charset menu and in mailnews, assertions are futile.
if (!mCharacterSet.Equals(aCharSetID)) {
mCharacterSet = aCharSetID;
#ifdef DEBUG
nsAutoCString canonicalName;
nsCharsetAlias::GetPreferred(aCharSetID, canonicalName);
NS_ASSERTION(canonicalName.Equals(aCharSetID),
"charset name must be canonical");
#endif
int32_t n = mCharSetObservers.Length();
for (int32_t i = 0; i < n; i++) {

View File

@ -48,6 +48,7 @@
#include "nsSandboxFlags.h"
#include "nsContentTypeParser.h"
#include "nsINetworkSeer.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/CORSMode.h"
#include "mozilla/Attributes.h"
@ -1197,15 +1198,15 @@ nsScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData,
if (!unicodeDecoder &&
aChannel &&
NS_SUCCEEDED(aChannel->GetContentCharset(charset)) &&
!charset.IsEmpty()) {
charsetConv->GetUnicodeDecoder(charset.get(),
getter_AddRefs(unicodeDecoder));
EncodingUtils::FindEncodingForLabel(charset, charset)) {
charsetConv->GetUnicodeDecoderRaw(charset.get(),
getter_AddRefs(unicodeDecoder));
}
if (!unicodeDecoder && !aHintCharset.IsEmpty()) {
CopyUTF16toUTF8(aHintCharset, charset);
charsetConv->GetUnicodeDecoder(charset.get(),
getter_AddRefs(unicodeDecoder));
if (!unicodeDecoder &&
EncodingUtils::FindEncodingForLabel(aHintCharset, charset)) {
charsetConv->GetUnicodeDecoderRaw(charset.get(),
getter_AddRefs(unicodeDecoder));
}
if (!unicodeDecoder && aDocument) {

View File

@ -30,6 +30,8 @@ support-files =
file_bug503832.html
file_bug655270.html
file_bug670318.html
file_bug941562-child.html
file_bug941562.html
print_postdata.sjs
test-form_sjis.html
@ -58,6 +60,7 @@ support-files =
[browser_bug670318.js]
[browser_bug673467.js]
[browser_bug92473.js]
[browser_bug941562.js]
[browser_loadDisallowInherit.js]
[browser_loadURI.js]
[browser_search_notification.js]

View File

@ -0,0 +1,39 @@
function test() {
waitForExplicitFinish();
var rootDir = "http://mochi.test:8888/browser/docshell/test/browser/";
gBrowser.selectedTab = gBrowser.addTab(rootDir + "file_bug941562.html");
gBrowser.selectedBrowser.addEventListener("load", afterOpen, true);
}
function afterOpen(event) {
if (event.target != gBrowser.contentDocument) {
return;
}
gBrowser.selectedBrowser.removeEventListener("load", afterOpen, true);
gBrowser.selectedBrowser.addEventListener("load", afterChangeCharset, true);
is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u20AC'), 140, "Parent doc should be windows-1252 initially");
is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u4E2D'), 77, "Child doc should be HZ-GB-2312 initially");
BrowserSetForcedCharacterSet("windows-1251");
}
function afterChangeCharset(event) {
if (event.target != gBrowser.contentDocument) {
return;
}
gBrowser.selectedBrowser.removeEventListener("load", afterChangeCharset, true);
is(gBrowser.contentDocument.documentElement.textContent.indexOf('\u0402'), 140, "Parent doc should decode as windows-1251 subsequently");
is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.documentElement.textContent.indexOf('\u4E2D'), 77, "Child doc should decode as HZ-GB-2312 subsequently");
is(gBrowser.contentDocument.characterSet, "windows-1251", "Parent doc should report windows-1251 subsequently");
is(gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument.characterSet, "HZ-GB-2312", "Child doc should report HZ-GB-2312 subsequently");
gBrowser.removeCurrentTab();
finish();
}

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="hz-gb-2312">
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>meta declaration in parent and meta HZ in child</title>
</head>
<body>
<p>China if decoded as HZ: ~{VP~}</p>
</body>
</html>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="windows-1252">
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>meta declaration in parent and meta HZ in child</title>
</head>
<body>
<h1>meta declaration in parent and meta HZ in child</h1>
<p>Euro sign if decoded as Windows-1252: €</p>
<p>a with diaeresis if decoded as Windows-1252: ä</p>
<iframe src="file_bug941562-child.html"></iframe>
</body>
</html>

View File

@ -38,6 +38,8 @@ EncodingUtils::IsAsciiCompatible(const nsACString& aPreferredName)
return !(aPreferredName.LowerCaseEqualsLiteral("utf-16") ||
aPreferredName.LowerCaseEqualsLiteral("utf-16be") ||
aPreferredName.LowerCaseEqualsLiteral("utf-16le") ||
aPreferredName.LowerCaseEqualsLiteral("replacement") ||
aPreferredName.LowerCaseEqualsLiteral("hz-gb-2312") ||
aPreferredName.LowerCaseEqualsLiteral("utf-7") ||
aPreferredName.LowerCaseEqualsLiteral("x-imap4-modified-utf7"));
}

View File

@ -21,8 +21,9 @@ TextDecoder::Init(const nsAString& aEncoding, const bool aFatal,
EncodingUtils::TrimSpaceCharacters(label);
// Let encoding be the result of getting an encoding from label.
// If encoding is failure, throw a TypeError.
if (!EncodingUtils::FindEncodingForLabel(label, mEncoding)) {
// If encoding is failure or replacement, throw a TypeError.
if (!EncodingUtils::FindEncodingForLabel(label, mEncoding) ||
mEncoding.EqualsLiteral("replacement")) {
aRv.ThrowTypeError(MSG_ENCODING_NOT_SUPPORTED, &label);
return;
}

View File

@ -215,8 +215,10 @@ ks_c_5601-1989=EUC-KR
ksc5601=EUC-KR
ksc_5601=EUC-KR
windows-949=EUC-KR
csiso2022kr=ISO-2022-KR
iso-2022-kr=ISO-2022-KR
csiso2022kr=replacement
iso-2022-kr=replacement
iso-2022-cn=replacement
iso-2022-cn-ext=replacement
utf-16=UTF-16LE
utf-16le=UTF-16LE
utf-16be=UTF-16BE

View File

@ -0,0 +1 @@
<meta charset=utf-8><EFBFBD>

View File

@ -0,0 +1 @@
<meta charset=iso-2022-cn>

View File

@ -0,0 +1,3 @@
<!DOCTYPE html>
<meta charset=utf-8>
<iframe src="data:text/html;charset=utf-8,<2C><iframe src='data:text/html;charset=utf-8,PASS'></iframe>" width=400 height=200></iframe>

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html class=reftest-wait>
<meta charset=utf-8>
<script>
function runTest() {
var r = document.documentElement;
var d = window[0].document;
var i = d.createElement("iframe");
i.src = "data:text/html,PASS";
i.onload = function() {
r.removeAttribute("class");
}
d.body.appendChild(i);
}
</script>
<body onload="runTest();">
<iframe src="bug863728-1.html" width=400 height=200></iframe>

View File

@ -0,0 +1,5 @@
<link rel=stylesheet href="data:text/css;charset=iso-2022-kr,html { background-color: red }">
<link rel=stylesheet href="data:text/css,html { background-color: red }" charset="iso-2022-cn-ext">
<link rel=stylesheet href='data:text/css,@charset "csiso2022kr"; html { background-color: red }'>
<script src="data:text/javascript;charset=iso-2022-kr,document.write('FAIL');"></script>
<script src="data:text/javascript,document.write('FAIL');" charset="iso-2022-kr"></script>

View File

@ -0,0 +1,3 @@
== bug863728-1.html bug863728-1-ref.html
== bug863728-2.html bug863728-2-ref.html
== bug863728-3.html bug863728-3-ref.html

View File

@ -349,11 +349,10 @@ function testDecoderGetEncoding()
{encoding: "iso-2022-jp", labels: ["csiso2022jp", "iso-2022-jp"]},
{encoding: "shift_jis", labels: ["csshiftjis", "ms_kanji", "shift-jis", "shift_jis", "sjis", "windows-31j", "x-sjis"]},
{encoding: "euc-kr", labels: ["cseuckr", "csksc56011987", "euc-kr", "iso-ir-149", "korean", "ks_c_5601-1987", "ks_c_5601-1989", "ksc5601", "ksc_5601", "windows-949"]},
{encoding: "iso-2022-kr", labels: ["csiso2022kr", "iso-2022-kr"]},
{encoding: "utf-16le", labels: ["utf-16", "utf-16le"]},
{encoding: "utf-16be", labels: ["utf-16be"]},
{encoding: "x-user-defined", labels: ["x-user-defined"]},
{error: "TypeError", labels: ["x-windows-949", "\u0130SO-8859-1"]},
{error: "TypeError", labels: ["x-windows-949", "\u0130SO-8859-1", "csiso2022kr", "iso-2022-kr", "iso-2022-cn", "iso-2022-cn-ext", "replacement"]},
];
for (var le of labelEncodings) {

View File

@ -24,7 +24,6 @@ setup({explicit_timeout: true});
<script type="text/javascript" src="unit/test_iso-2022-jp.js"></script>
<script type="text/javascript" src="unit/test_shift_jis.js"></script>
<script type="text/javascript" src="unit/test_euc-kr.js"></script>
<script type="text/javascript" src="unit/test_iso-2022-kr.js"></script>
</body>
</html>

View File

@ -6,6 +6,5 @@
[test_gbk.js]
[test_hz-gb-2312.js]
[test_iso-2022-jp.js]
[test_iso-2022-kr.js]
[test_shift_jis.js]
[test_singlebytes.js]

File diff suppressed because one or more lines are too long

View File

@ -297,7 +297,7 @@ test(
test(
function () {
var encodings = ["utf-8", "ibm866", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-8-i", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "iso-8859-16", "koi8-r", "koi8-u", "macintosh", "windows-874", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255", "windows-1256", "windows-1257", "windows-1258", "x-mac-cyrillic", "gbk", "gb18030", "hz-gb-2312", "big5", "euc-jp", "iso-2022-jp", "shift_jis", "euc-kr", "iso-2022-kr", "x-user-defined"];
var encodings = ["utf-8", "ibm866", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-8-i", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "iso-8859-16", "koi8-r", "koi8-u", "macintosh", "windows-874", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255", "windows-1256", "windows-1257", "windows-1258", "x-mac-cyrillic", "gbk", "gb18030", "hz-gb-2312", "big5", "euc-jp", "iso-2022-jp", "shift_jis", "euc-kr", "x-user-defined"];
encodings.forEach(function (encoding) {
var string = '', bytes = [];
@ -308,8 +308,6 @@ test(
continue;
if (encoding === "iso-2022-jp" && i === 0x1B)
continue;
if (encoding === "iso-2022-kr" && (i === 0x0E || i === 0x0F || i === 0x1B))
continue;
string += String.fromCharCode(i);
bytes.push(i);
@ -344,7 +342,7 @@ test(
var utf_encodings = ["utf-8", "utf-16le", "utf-16be"];
var legacy_encodings = ["ibm866", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-8-i", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "iso-8859-16", "koi8-r", "koi8-u", "macintosh", "windows-874", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255", "windows-1256", "windows-1257", "windows-1258", "x-mac-cyrillic", "gbk", "gb18030", "hz-gb-2312", "big5", "euc-jp", "iso-2022-jp", "shift_jis", "euc-kr", "iso-2022-kr", "x-user-defined"];
var legacy_encodings = ["ibm866", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-8-i", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "iso-8859-16", "koi8-r", "koi8-u", "macintosh", "windows-874", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255", "windows-1256", "windows-1257", "windows-1258", "x-mac-cyrillic", "gbk", "gb18030", "hz-gb-2312", "big5", "euc-jp", "iso-2022-jp", "shift_jis", "euc-kr", "x-user-defined"];
utf_encodings.forEach(function(encoding) {
assert_equals(TextDecoder(encoding).encoding, encoding);

View File

@ -8,6 +8,5 @@ tail =
[test_gbk.js]
[test_hz-gb-2312.js]
[test_iso-2022-jp.js]
[test_iso-2022-kr.js]
[test_shift_jis.js]
[test_singlebytes.js]

View File

@ -15,17 +15,9 @@
<script type="text/javascript;version=1.7">
function runTest() {
if (!SpecialPowers.isMainProcess()) {
window.runTest = function() {
todo(false, "Figure out this test for child processes!");
SimpleTest.finish();
return;
}
}
// doing this IDBRequest should not be able to retrieve the filename and
// line number.
//setTimeout(indexedDB.deleteDatabase.bind(indexedDB), 0, 'x');
setTimeout(indexedDB.deleteDatabase.bind(indexedDB), 0, 'x');
setTimeout(function() {
ok(true, "Still alive");
SimpleTest.finish();

View File

@ -185,5 +185,5 @@ const SequenceModel TIS620ThaiModel =
ThaiLangModel,
(float)0.926386,
false,
"TIS-620"
"windows-874"
};

View File

@ -22,7 +22,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=488426
<script class="testbody" type="text/javascript">
/** Test for Bug 488426 **/
CharsetDetectionTests("bug488426_text.html",
"TIS-620",
"windows-874",
new Array("universal_charset_detector"));
</script>
</pre>

View File

@ -606,19 +606,32 @@ DrawTargetSkia::Mask(const Pattern &aSource,
raster->addLayer(maskPaint);
SkSafeUnref(paint.mPaint.setRasterizer(raster));
// Skia only uses the mask rasterizer when we are drawing a path/rect.
// Take our destination bounds and convert them into user space to use
// as the path to draw.
SkPath path;
path.addRect(SkRect::MakeWH(SkScalar(mSize.width), SkScalar(mSize.height)));
Matrix temp = mTransform;
temp.Invert();
SkMatrix mat;
GfxMatrixToSkiaMatrix(temp, mat);
path.transform(mat);
mCanvas->drawRect(SkRectCoveringWholeSurface(), paint.mPaint);
}
mCanvas->drawPath(path, paint.mPaint);
void
DrawTargetSkia::MaskSurface(const Pattern &aSource,
SourceSurface *aMask,
Point aOffset,
const DrawOptions &aOptions)
{
MarkChanged();
AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
SkPaint maskPaint;
SetPaintPattern(maskPaint, SurfacePattern(aMask, EXTEND_CLAMP));
SkMatrix transform = maskPaint.getShader()->getLocalMatrix();
transform.postTranslate(SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y));
maskPaint.getShader()->setLocalMatrix(transform);
SkLayerRasterizer *raster = new SkLayerRasterizer();
raster->addLayer(maskPaint);
SkSafeUnref(paint.mPaint.setRasterizer(raster));
IntSize size = aMask->GetSize();
Rect rect = Rect(aOffset.x, aOffset.y, size.width, size.height);
mCanvas->drawRect(RectToSkRect(rect), paint.mPaint);
}
TemporaryRef<SourceSurface>
@ -869,6 +882,14 @@ DrawTargetSkia::MarkChanged()
}
}
// Return a rect (in user space) that covers the entire surface by applying
// the inverse of GetTransform() to (0, 0, mSize.width, mSize.height).
SkRect
DrawTargetSkia::SkRectCoveringWholeSurface() const
{
return RectToSkRect(mTransform.TransformBounds(Rect(0, 0, mSize.width, mSize.height)));
}
void
DrawTargetSkia::SnapshotDestroyed()
{

View File

@ -78,7 +78,7 @@ public:
virtual void MaskSurface(const Pattern &aSource,
SourceSurface *aMask,
Point aOffset,
const DrawOptions &aOptions = DrawOptions()) { MOZ_ASSERT(0); };
const DrawOptions &aOptions = DrawOptions());
virtual void PushClip(const Path *aPath);
virtual void PushClipRect(const Rect& aRect);
virtual void PopClip();
@ -125,6 +125,8 @@ private:
void MarkChanged();
SkRect SkRectCoveringWholeSurface() const;
#ifdef USE_SKIA_GPU
/*
* These members have inter-dependencies, but do not keep each other alive, so

View File

@ -87,6 +87,7 @@ x-mac-hebrew.notForBrowser = true
x-imap4-modified-utf7.notForBrowser = true
utf-7.notForBrowser = true
ibm864.notForBrowser = true
replacement.notForBrowser = true
x-mac-arabic.isInternal = true
x-mac-farsi.isInternal = true
@ -95,6 +96,7 @@ x-imap4-modified-utf7.isInternal = true
utf-7.isInternal = true
t.61-8bit.isInternal = true
ibm864.isInternal = true
replacement.isInternal = true
t.61-8bit.notForOutgoing = true
utf-7.notForOutgoing = true
@ -110,7 +112,7 @@ iso-8859-8-e.notForOutgoing = true
iso-8859-8.notForOutgoing = true
iso-2022-kr.notForOutgoing = true
x-johab.notForOutgoing = true
replacement.notForOutgoing = true
// XXX : there are some entries only necessary for Gtk/Xlib builds
// to map XLFD registry-encoding pairs to langGroups. they can be
@ -119,6 +121,7 @@ x-johab.notForOutgoing = true
// XXX : todo: move to something based on BCP 47 (RFC 5646);
// these should primarily specify script (and sometimes region),
// but NOT language.
// See also https://bugzilla.mozilla.org/show_bug.cgi?id=756022
// e.g. x-western -> *-Latn-155 (Western Europe)
// x-central-euro -> *-Latn-151 (Eastern Europe)
// x-baltic -> *-Latn-154 (Northern Europe)
@ -194,6 +197,7 @@ utf-16be.LangGroup = x-unicode
utf-16le.LangGroup = x-unicode
utf-7.LangGroup = x-unicode
x-imap4-modified-utf7.LangGroup = x-unicode
replacement.LangGroup = x-unicode
viscii.LangGroup = x-western
x-viet-tcvn5712.LangGroup = x-western
x-viet-vps.LangGroup = x-western
@ -244,3 +248,4 @@ euc-kr.isMultibyte = true
x-johab.isMultibyte = true
utf-7.isMultibyte = true
utf-8.isMultibyte = true
replacement.isMultibyte = true

View File

@ -11,6 +11,7 @@ UNIFIED_SOURCES += [
'nsCP1252ToUnicode.cpp',
'nsISO88591ToUnicode.cpp',
'nsMacRomanToUnicode.cpp',
'nsReplacementToUnicode.cpp',
'nsScriptableUConv.cpp',
'nsTextToSubURI.cpp',
'nsUConvModule.cpp',

View File

@ -0,0 +1,56 @@
/* 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 "nsReplacementToUnicode.h"
nsReplacementToUnicode::nsReplacementToUnicode()
: mSeenByte(false)
{
}
NS_IMETHODIMP
nsReplacementToUnicode::Convert(const char* aSrc,
int32_t* aSrcLength,
PRUnichar* aDest,
int32_t* aDestLength)
{
if (mSeenByte || !(*aSrcLength)) {
*aDestLength = 0;
return NS_PARTIAL_MORE_INPUT;
}
if (mErrBehavior == kOnError_Signal) {
mSeenByte = true;
*aSrcLength = 0;
*aDestLength = 0;
return NS_ERROR_ILLEGAL_INPUT;
}
if (!(*aDestLength)) {
*aSrcLength = -1;
return NS_PARTIAL_MORE_OUTPUT;
}
mSeenByte = true;
*aDest = 0xFFFD;
*aDestLength = 1;
return NS_PARTIAL_MORE_INPUT;
}
NS_IMETHODIMP
nsReplacementToUnicode::GetMaxLength(const char* aSrc,
int32_t aSrcLength,
int32_t* aDestLength)
{
if (!mSeenByte && aSrcLength > 0) {
*aDestLength = 1;
} else {
*aDestLength = 0;
}
return NS_EXACT_LENGTH;
}
NS_IMETHODIMP
nsReplacementToUnicode::Reset()
{
mSeenByte = false;
return NS_OK;
}

View File

@ -0,0 +1,37 @@
/* 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/. */
#ifndef nsReplacementToUnicode_h_
#define nsReplacementToUnicode_h_
#include "nsUCSupport.h"
#define NS_REPLACEMENTTOUNICODE_CID \
{ 0xd24b24da, 0xc607, 0x489a, \
{ 0xb5, 0xf0, 0x67, 0x91, 0xf4, 0x45, 0x45, 0x6d } }
#define NS_REPLACEMENTTOUNICODE_CONTRACTID \
"@mozilla.org/intl/unicode/decoder;1?charset=replacement"
class nsReplacementToUnicode : public nsBasicDecoderSupport
{
public:
nsReplacementToUnicode();
NS_IMETHOD Convert(const char* aSrc,
int32_t* aSrcLength,
PRUnichar* aDest,
int32_t* aDestLength);
NS_IMETHOD GetMaxLength(const char* aSrc,
int32_t aSrcLength,
int32_t* aDestLength);
NS_IMETHOD Reset();
private:
bool mSeenByte;
};
#endif // nsReplacementToUnicode_h_

View File

@ -21,6 +21,7 @@
#include "nsISO88591ToUnicode.h"
#include "nsCP1252ToUnicode.h"
#include "nsMacRomanToUnicode.h"
#include "nsReplacementToUnicode.h"
#include "nsUTF8ToUnicode.h"
#include "nsUnicodeToISO88591.h"
#include "nsUnicodeToCP1252.h"
@ -219,6 +220,7 @@ NS_UCONV_REG_UNREG("ISO-8859-1", NS_ISO88591TOUNICODE_CID, NS_UNICODETOISO88591_
NS_UCONV_REG_UNREG("windows-1252", NS_CP1252TOUNICODE_CID, NS_UNICODETOCP1252_CID)
NS_UCONV_REG_UNREG("macintosh", NS_MACROMANTOUNICODE_CID, NS_UNICODETOMACROMAN_CID)
NS_UCONV_REG_UNREG("UTF-8", NS_UTF8TOUNICODE_CID, NS_UNICODETOUTF8_CID)
NS_UCONV_REG_UNREG("replacement", NS_REPLACEMENTTOUNICODE_CID, NS_UNICODETOUTF8_CID)
// ucvlatin
NS_UCONV_REG_UNREG("us-ascii", NS_ASCIITOUNICODE_CID, NS_UNICODETOASCII_CID)
@ -332,6 +334,7 @@ NS_CONVERTER_REGISTRY_END
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToUTF8)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUTF8ToUnicode)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsReplacementToUnicode)
// ucvlatin
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUTF7ToUnicode)
@ -506,6 +509,7 @@ NS_DEFINE_NAMED_CID(NS_ISO88591TOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_CP1252TOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_MACROMANTOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_UTF8TOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_REPLACEMENTTOUNICODE_CID);
NS_DEFINE_NAMED_CID(NS_UNICODETOISO88591_CID);
NS_DEFINE_NAMED_CID(NS_UNICODETOCP1252_CID);
NS_DEFINE_NAMED_CID(NS_UNICODETOMACROMAN_CID);
@ -690,6 +694,7 @@ static const mozilla::Module::CIDEntry kUConvCIDs[] = {
{ &kNS_ISO88591TOUNICODE_CID, false, nullptr, nsISO88591ToUnicodeConstructor },
{ &kNS_CP1252TOUNICODE_CID, false, nullptr, nsCP1252ToUnicodeConstructor },
{ &kNS_MACROMANTOUNICODE_CID, false, nullptr, nsMacRomanToUnicodeConstructor },
{ &kNS_REPLACEMENTTOUNICODE_CID, false, nullptr, nsReplacementToUnicodeConstructor },
{ &kNS_UTF8TOUNICODE_CID, false, nullptr, nsUTF8ToUnicodeConstructor },
{ &kNS_UNICODETOISO88591_CID, false, nullptr, nsUnicodeToISO88591Constructor },
{ &kNS_UNICODETOCP1252_CID, false, nullptr, nsUnicodeToCP1252Constructor },
@ -877,6 +882,7 @@ static const mozilla::Module::ContractIDEntry kUConvContracts[] = {
{ NS_ISO88591TOUNICODE_CONTRACTID, &kNS_ISO88591TOUNICODE_CID },
{ NS_CP1252TOUNICODE_CONTRACTID, &kNS_CP1252TOUNICODE_CID },
{ NS_MACROMANTOUNICODE_CONTRACTID, &kNS_MACROMANTOUNICODE_CID },
{ NS_REPLACEMENTTOUNICODE_CONTRACTID, &kNS_REPLACEMENTTOUNICODE_CID },
{ NS_UTF8TOUNICODE_CONTRACTID, &kNS_UTF8TOUNICODE_CID },
{ NS_UNICODETOISO88591_CONTRACTID, &kNS_UNICODETOISO88591_CID },
{ NS_UNICODETOCP1252_CONTRACTID, &kNS_UNICODETOCP1252_CID },

View File

@ -34,7 +34,10 @@ while (decoderList.hasMore()) {
// Skip UTF-16 variants. (Other non-ASCII compatible encodings will be
// ignored anyway because of bug 601429
if (decoder.substring(0, 6) == "UTF-16")
if (decoder.substring(0, 6) == "UTF-16" ||
decoder == "replacement" ||
decoder == "ISO-2022-KR" ||
decoder == "ISO-2022-CN")
continue;
data = encodeURI(testContent);

View File

@ -99,6 +99,7 @@ var encoderList = [
"gbk",
"HZ-GB-2312",
"gb18030",
"replacement",
];
var decoderList = [
@ -183,6 +184,7 @@ var decoderList = [
"gb18030",
"ISO-2022-KR",
"ISO-2022-CN",
"replacement",
];
function verifyList(aEnumerator, aList)

View File

@ -43,6 +43,11 @@ const JSFunctionSpec ParallelArrayObject::methods[] = {
JS_FS_END
};
const JSPropertySpec ParallelArrayObject::properties[] = {
JS_SELF_HOSTED_GET("length", "ParallelArrayLength", JSPROP_PERMANENT),
JS_PS_END
};
const Class ParallelArrayObject::protoClass = {
"ParallelArray",
JSCLASS_HAS_CACHED_PROTO(JSProto_ParallelArray),
@ -220,37 +225,12 @@ ParallelArrayObject::initClass(JSContext *cx, HandleObject obj)
cx->names().ParallelArray, 0));
if (!ctor ||
!LinkConstructorAndPrototype(cx, ctor, proto) ||
!DefinePropertiesAndBrand(cx, proto, nullptr, methods) ||
!DefinePropertiesAndBrand(cx, proto, properties, methods) ||
!DefineConstructorAndPrototype(cx, global, key, ctor, proto))
{
return nullptr;
}
// Define the length getter.
{
const char lengthStr[] = "ParallelArrayLength";
JSAtom *atom = Atomize(cx, lengthStr, strlen(lengthStr));
if (!atom)
return nullptr;
Rooted<PropertyName *> lengthProp(cx, atom->asPropertyName());
RootedValue lengthValue(cx);
if (!cx->global()->getIntrinsicValue(cx, lengthProp, &lengthValue))
return nullptr;
RootedObject lengthGetter(cx, &lengthValue.toObject());
if (!lengthGetter)
return nullptr;
RootedId lengthId(cx, AtomToId(cx->names().length));
unsigned flags = JSPROP_PERMANENT | JSPROP_SHARED | JSPROP_GETTER;
RootedValue value(cx, UndefinedValue());
if (!DefineNativeProperty(cx, proto, lengthId, value,
JS_DATA_TO_FUNC_PTR(PropertyOp, lengthGetter.get()), nullptr,
flags, 0, 0))
{
return nullptr;
}
}
return proto;
}

View File

@ -15,6 +15,7 @@ class ParallelArrayObject : public JSObject
{
static const Class protoClass;
static const JSFunctionSpec methods[];
static const JSPropertySpec properties[];
static const uint32_t NumFixedSlots = 4;
static const uint32_t NumCtors = 4;
static FixedHeapPtr<PropertyName> ctorNames[NumCtors];

View File

@ -872,7 +872,7 @@ ArrayType::create(JSContext *cx,
JS_ASSERT(prototypeVal.isObject()); // immutable binding
RootedObject obj(
cx, NewObjectWithClassProto(cx, &ArrayType::class_,
cx, NewObjectWithGivenProto(cx, &ArrayType::class_,
&prototypeVal.toObject(), cx->global()));
if (!obj)
return nullptr;
@ -1145,7 +1145,7 @@ StructType::create(JSContext *cx, HandleObject metaTypeObject,
JS_ASSERT(prototypeVal.isObject()); // immutable binding
RootedObject obj(
cx, NewObjectWithClassProto(cx, &StructType::class_,
cx, NewObjectWithGivenProto(cx, &StructType::class_,
&prototypeVal.toObject(), cx->global()));
if (!obj)
return nullptr;
@ -1249,15 +1249,15 @@ StructType::construct(JSContext *cx, unsigned int argc, Value *vp)
template<typename T>
static bool
DefineSimpleTypeObject(JSContext *cx,
HandleObject global,
Handle<GlobalObject *> global,
HandleObject module,
typename T::TypeRepr::Type type,
HandlePropertyName className)
{
RootedObject funcProto(cx, JS_GetFunctionPrototype(cx, global));
RootedObject funcProto(cx, global->getOrCreateFunctionPrototype(cx));
JS_ASSERT(funcProto);
RootedObject numFun(cx, NewObjectWithClassProto(cx, &T::class_, funcProto, global));
RootedObject numFun(cx, NewObjectWithGivenProto(cx, &T::class_, funcProto, global));
if (!numFun)
return false;
@ -1521,7 +1521,7 @@ js_InitTypedObjectClass(JSContext *cx, HandleObject obj)
if (!objProto)
return nullptr;
RootedObject module(cx, NewObjectWithClassProto(cx, &JSObject::class_,
RootedObject module(cx, NewObjectWithGivenProto(cx, &JSObject::class_,
objProto, global));
if (!module)
return nullptr;

View File

@ -2916,13 +2916,24 @@ MOZ_ARG_WITH_STRING(nspr-libs,
AC_SUBST(NSPR_CFLAGS)
AC_SUBST(NSPR_LIBS)
JS_THREADSAFE=1
MOZ_ARG_DISABLE_BOOL(threadsafe,
[ --disable-threadsafe Disable support for multiple threads.],
JS_THREADSAFE= ,
JS_THREADSAFE=1 )
if test -n "$JS_THREADSAFE"; then
AC_DEFINE(JS_THREADSAFE)
fi
if test "$_USE_SYSTEM_NSPR" || (test "$NSPR_CFLAGS" -o "$NSPR_LIBS"); then
_HAS_NSPR=1
fi
case "$target" in
*linux*|*darwin*|*dragonfly*|*freebsd*|*netbsd*|*openbsd*)
if test -z "$_HAS_NSPR"; then JS_POSIX_NSPR_DEFAULT=1; fi
if test -z "$_HAS_NSPR" && test "$JS_THREADSAFE"; then
JS_POSIX_NSPR_DEFAULT=1
fi
;;
esac
@ -2936,6 +2947,8 @@ if test -n "$JS_POSIX_NSPR"; then
AC_DEFINE(JS_POSIX_NSPR)
fi
AC_SUBST(JS_POSIX_NSPR)
dnl Pass either --with-system-nspr or (--with-nspr-cflags and
dnl --with-nspr-libs), but not both.
if test "$_USE_SYSTEM_NSPR" && (test "$NSPR_CFLAGS" -o "$NSPR_LIBS"); then
@ -4108,15 +4121,6 @@ elif test "$OS_ARCH" != "WINNT" -a "$OS_ARCH" != "OS2"; then
AC_DEFINE(XP_UNIX)
fi
JS_THREADSAFE=1
MOZ_ARG_DISABLE_BOOL(threadsafe,
[ --disable-threadsafe Disable support for multiple threads.],
JS_THREADSAFE= ,
JS_THREADSAFE=1 )
if test -n "$JS_THREADSAFE"; then
AC_DEFINE(JS_THREADSAFE)
fi
if test "$MOZ_DEBUG"; then
AC_DEFINE(MOZ_REFLOW_PERF)
AC_DEFINE(MOZ_REFLOW_PERF_DSP)

View File

@ -3242,6 +3242,15 @@ JS_DefineProperties(JSContext *cx, JSObject *objArg, const JSPropertySpec *ps)
// If you have self-hosted getter/setter, you can't have a
// native one.
JS_ASSERT(!ps->getter.op && !ps->setter.op);
/*
* During creation of the self-hosting global, we ignore all
* self-hosted properties, as that means we're currently setting up
* the global object that the self-hosted code is then compiled
* in. That means that Self-hosted properties can't be used in the
* self-hosting global itself, right now.
*/
if (cx->runtime()->isSelfHostingGlobal(cx->global()))
continue;
ok = DefineSelfHostedProperty(cx, obj, ps->name,
ps->selfHostedGetter,
@ -4146,6 +4155,8 @@ JS_DefineFunctions(JSContext *cx, JSObject *objArg, const JSFunctionSpec *fs)
* call paths then call InitializeLazyFunctionScript if !hasScript.
*/
if (fs->selfHostedName) {
JS_ASSERT(!fs->call.op);
JS_ASSERT(!fs->call.info);
/*
* During creation of the self-hosting global, we ignore all
* self-hosted functions, as that means we're currently setting up
@ -4153,8 +4164,6 @@ JS_DefineFunctions(JSContext *cx, JSObject *objArg, const JSFunctionSpec *fs)
* in. Self-hosted functions can access each other via their names,
* but not via the builtin classes they get installed into.
*/
JS_ASSERT(!fs->call.op);
JS_ASSERT(!fs->call.info);
if (cx->runtime()->isSelfHostingGlobal(cx->global()))
continue;

View File

@ -1475,7 +1475,10 @@ static const JSFunctionSpec math_static_methods[] = {
JSObject *
js_InitMathClass(JSContext *cx, HandleObject obj)
{
RootedObject Math(cx, NewObjectWithClassProto(cx, &MathClass, nullptr, obj, SingletonObject));
RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx));
if (!proto)
return nullptr;
RootedObject Math(cx, NewObjectWithGivenProto(cx, &MathClass, proto, obj, SingletonObject));
if (!Math)
return nullptr;

View File

@ -873,8 +873,8 @@ js_InitJSONClass(JSContext *cx, HandleObject obj)
if (!global->getOrCreateBooleanPrototype(cx))
return nullptr;
RootedObject JSON(cx, NewObjectWithClassProto(cx, &JSONClass, nullptr,
global, SingletonObject));
RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx));
RootedObject JSON(cx, NewObjectWithClassProto(cx, &JSONClass, proto, global, SingletonObject));
if (!JSON)
return nullptr;

View File

@ -3313,7 +3313,10 @@ JS_InitReflect(JSContext *cx, JSObject *objArg)
};
RootedObject obj(cx, objArg);
RootedObject Reflect(cx, NewObjectWithClassProto(cx, &JSObject::class_, nullptr,
RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx));
if (!proto)
return nullptr;
RootedObject Reflect(cx, NewObjectWithGivenProto(cx, &JSObject::class_, proto,
obj, SingletonObject));
if (!Reflect)
return nullptr;

View File

@ -170,7 +170,6 @@ UNIFIED_SOURCES += [
'vm/Monitor.cpp',
'vm/ObjectImpl.cpp',
'vm/OldDebugAPI.cpp',
'vm/PosixNSPR.cpp',
'vm/Probes.cpp',
'vm/PropertyKey.cpp',
'vm/ProxyObject.cpp',
@ -206,6 +205,11 @@ SOURCES += [
'jsutil.cpp',
]
if CONFIG['JS_POSIX_NSPR']:
UNIFIED_SOURCES += [
'vm/PosixNSPR.cpp',
]
if CONFIG['MOZ_INSTRUMENTS']:
SOURCES += [
'devtools/Instruments.cpp',

View File

@ -387,7 +387,11 @@ GlobalObject::initFunctionAndObjectClasses(JSContext *cx)
if (cx->runtime()->isSelfHostingGlobal(self)) {
intrinsicsHolder = self;
} else {
intrinsicsHolder = NewObjectWithClassProto(cx, &JSObject::class_, nullptr, self, TenuredObject);
RootedObject proto(cx, self->getOrCreateObjectPrototype(cx));
if (!proto)
return nullptr;
intrinsicsHolder = NewObjectWithGivenProto(cx, &JSObject::class_, proto, self,
TenuredObject);
if (!intrinsicsHolder)
return nullptr;
}
@ -483,6 +487,9 @@ GlobalObject::initStandardClasses(JSContext *cx, Handle<GlobalObject*> global)
GlobalObject::initSetIteratorProto(cx, global) &&
#if EXPOSE_INTL_API
js_InitIntlClass(cx, global) &&
#endif
#if ENABLE_PARALLEL_JS
js_InitParallelArrayClass(cx, global) &&
#endif
true;
}

View File

@ -9,6 +9,10 @@
#ifdef JS_POSIX_NSPR
#ifndef JS_THREADSAFE
#error "This file must not be included in non-threadsafe mode"
#endif
#include <pthread.h>
#include <stdint.h>

View File

@ -331,12 +331,12 @@ GetViewListRef(ArrayBufferObject *obj)
return reinterpret_cast<OldObjectRepresentationHack*>(obj->getElementsHeader())->views;
}
bool
ArrayBufferObject::neuterViews(JSContext *cx)
/* static */ bool
ArrayBufferObject::neuterViews(JSContext *cx, Handle<ArrayBufferObject*> buffer)
{
ArrayBufferViewObject *view;
size_t numViews = 0;
for (view = GetViewList(this); view; view = view->nextView()) {
for (view = GetViewList(buffer); view; view = view->nextView()) {
numViews++;
view->neuter();
@ -346,26 +346,26 @@ ArrayBufferObject::neuterViews(JSContext *cx)
// neuterAsmJSArrayBuffer adjusts state specific to the ArrayBuffer data
// itself, but it only affects the behavior of views
if (isAsmJSArrayBuffer()) {
if (!ArrayBufferObject::neuterAsmJSArrayBuffer(cx, *this))
if (buffer->isAsmJSArrayBuffer()) {
if (!ArrayBufferObject::neuterAsmJSArrayBuffer(cx, *buffer))
return false;
}
// Remove buffer from the list of buffers with > 1 view.
if (numViews > 1 && GetViewList(this)->bufferLink() != UNSET_BUFFER_LINK) {
ArrayBufferObject *prev = compartment()->gcLiveArrayBuffers;
if (prev == this) {
compartment()->gcLiveArrayBuffers = GetViewList(prev)->bufferLink();
if (numViews > 1 && GetViewList(buffer)->bufferLink() != UNSET_BUFFER_LINK) {
ArrayBufferObject *prev = buffer->compartment()->gcLiveArrayBuffers;
if (prev == buffer) {
buffer->compartment()->gcLiveArrayBuffers = GetViewList(prev)->bufferLink();
} else {
for (ArrayBufferObject *buf = GetViewList(prev)->bufferLink();
buf;
buf = GetViewList(buf)->bufferLink())
for (ArrayBufferObject *b = GetViewList(prev)->bufferLink();
b;
b = GetViewList(b)->bufferLink())
{
if (buf == this) {
GetViewList(prev)->setBufferLink(GetViewList(buf)->bufferLink());
if (b == buffer) {
GetViewList(prev)->setBufferLink(GetViewList(b)->bufferLink());
break;
}
prev = buf;
prev = b;
}
}
}
@ -705,7 +705,7 @@ ArrayBufferObject::stealContents(JSContext *cx, Handle<ArrayBufferObject*> buffe
// Neuter the views, which may also mprotect(PROT_NONE) the buffer. So do
// it after copying out the data.
if (!buffer->neuterViews(cx))
if (!ArrayBufferObject::neuterViews(cx, buffer))
return false;
if (!own) {
@ -4062,7 +4062,7 @@ JS_NeuterArrayBuffer(JSContext *cx, HandleObject obj)
}
Rooted<ArrayBufferObject*> buffer(cx, &obj->as<ArrayBufferObject>());
if (!buffer->neuterViews(cx))
if (!ArrayBufferObject::neuterViews(cx, buffer))
return false;
buffer->neuter(cx);
return true;

View File

@ -198,7 +198,7 @@ class ArrayBufferObject : public JSObject
/*
* Neuter all views of an ArrayBuffer.
*/
bool neuterViews(JSContext *cx);
static bool neuterViews(JSContext *cx, Handle<ArrayBufferObject*> buffer);
inline uint8_t * dataPointer() const {
return (uint8_t *) elements;

View File

@ -32,6 +32,10 @@ while (decoderList.hasMore()) {
data = encodeUTF16BE(testContent);
else if (decoder == "UTF-16" || decoder == "UTF-16LE")
data = encodeUTF16LE(testContent);
else if (decoder == "replacement" ||
decoder == "ISO-2022-KR" ||
decoder == "ISO-2022-CN")
continue;
else
data = encodeURI(testContent);
var dataURI = "data:text/html;charset=" + decoder + "," + data;

View File

@ -786,6 +786,67 @@ nsBlockFrame::ComputeTightBounds(gfxContext* aContext) const
return ComputeSimpleTightBounds(aContext);
}
/* virtual */ nsresult
nsBlockFrame::GetPrefWidthTightBounds(nsRenderingContext* aRenderingContext,
nscoord* aX,
nscoord* aXMost)
{
nsIFrame* firstInFlow = FirstContinuation();
if (firstInFlow != this) {
return firstInFlow->GetPrefWidthTightBounds(aRenderingContext, aX, aXMost);
}
*aX = 0;
*aXMost = 0;
nsresult rv;
InlinePrefWidthData data;
for (nsBlockFrame* curFrame = this; curFrame;
curFrame = static_cast<nsBlockFrame*>(curFrame->GetNextContinuation())) {
for (line_iterator line = curFrame->begin_lines(), line_end = curFrame->end_lines();
line != line_end; ++line)
{
nscoord childX, childXMost;
if (line->IsBlock()) {
data.ForceBreak(aRenderingContext);
rv = line->mFirstChild->GetPrefWidthTightBounds(aRenderingContext,
&childX, &childXMost);
NS_ENSURE_SUCCESS(rv, rv);
*aX = std::min(*aX, childX);
*aXMost = std::max(*aXMost, childXMost);
} else {
if (!curFrame->GetPrevContinuation() &&
line == curFrame->begin_lines()) {
// Only add text-indent if it has no percentages; using a
// percentage basis of 0 unconditionally would give strange
// behavior for calc(10%-3px).
const nsStyleCoord &indent = StyleText()->mTextIndent;
if (indent.ConvertsToLength()) {
data.currentLine += nsRuleNode::ComputeCoordPercentCalc(indent, 0);
}
}
// XXX Bug NNNNNN Should probably handle percentage text-indent.
data.line = &line;
data.lineContainer = curFrame;
nsIFrame *kid = line->mFirstChild;
for (int32_t i = 0, i_end = line->GetChildCount(); i != i_end;
++i, kid = kid->GetNextSibling()) {
rv = kid->GetPrefWidthTightBounds(aRenderingContext, &childX,
&childXMost);
NS_ENSURE_SUCCESS(rv, rv);
*aX = std::min(*aX, data.currentLine + childX);
*aXMost = std::max(*aXMost, data.currentLine + childXMost);
kid->AddInlinePrefWidth(aRenderingContext, &data);
}
}
}
}
data.ForceBreak(aRenderingContext);
return NS_OK;
}
static bool
AvailableSpaceShrunk(const nsRect& aOldAvailableSpace,
const nsRect& aNewAvailableSpace)

View File

@ -261,6 +261,10 @@ public:
virtual nsRect ComputeTightBounds(gfxContext* aContext) const MOZ_OVERRIDE;
virtual nsresult GetPrefWidthTightBounds(nsRenderingContext* aContext,
nscoord* aX,
nscoord* aXMost) MOZ_OVERRIDE;
/**
* Compute the final height of this frame.
*

View File

@ -1563,8 +1563,8 @@ MainAxisPositionTracker::
}
mJustifyContent = aFlexContainerFrame->StylePosition()->mJustifyContent;
// If packing space is negative, 'justify' behaves like 'start', and
// 'distribute' behaves like 'center'. In those cases, it's simplest to
// If packing space is negative, 'space-between' behaves like 'flex-start',
// and 'space-around' behaves like 'center'. In those cases, it's simplest to
// just pretend we have a different 'justify-content' value and share code.
if (mPackingSpaceRemaining < 0) {
if (mJustifyContent == NS_STYLE_JUSTIFY_CONTENT_SPACE_BETWEEN) {
@ -1863,7 +1863,7 @@ SingleLineCrossAxisPositionTracker::
case NS_STYLE_ALIGN_ITEMS_FLEX_START:
case NS_STYLE_ALIGN_ITEMS_STRETCH:
// No space to skip over -- we're done.
// NOTE: 'stretch' behaves like 'start' once we've stretched any
// NOTE: 'stretch' behaves like 'flex-start' once we've stretched any
// auto-sized items (which we've already done).
break;
case NS_STYLE_ALIGN_ITEMS_FLEX_END:

View File

@ -4049,6 +4049,14 @@ nsFrame::ComputeSimpleTightBounds(gfxContext* aContext) const
return r;
}
/* virtual */ nsresult
nsIFrame::GetPrefWidthTightBounds(nsRenderingContext* aContext,
nscoord* aX,
nscoord* aXMost)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* virtual */ nsSize
nsFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
nsSize aCBSize, nscoord aAvailableWidth,

View File

@ -1832,6 +1832,26 @@ public:
*/
virtual nsRect ComputeTightBounds(gfxContext* aContext) const;
/**
* This function is similar to GetPrefWidth and ComputeTightBounds: it
* computes the left and right coordinates of a preferred tight bounding
* rectangle for the frame. This is a rectangle that would enclose the pixels
* that are drawn if we lay out the element without taking any optional line
* breaks. The rectangle is in appunits and relative to the origin of this
* frame. Currently, this function is only implemented for nsBlockFrame and
* nsTextFrame and is used to determine intrinsic widths of MathML token
* elements.
* @param aContext a rendering context that can be used if we need
* to do measurement
* @param aX computed left coordinate of the tight bounding rectangle
* @param aXMost computed intrinsic width of the tight bounding rectangle
*
*/
virtual nsresult GetPrefWidthTightBounds(nsRenderingContext* aContext,
nscoord* aX,
nscoord* aXMost);
/**
* Pre-reflow hook. Before a frame is reflowed this method will be called.
* This call will always be invoked at least once before a subsequent Reflow

View File

@ -2609,17 +2609,20 @@ GetEndOfTrimmedText(const nsTextFragment* aFrag, const nsStyleText* aStyleText,
nsTextFrame::TrimmedOffsets
nsTextFrame::GetTrimmedOffsets(const nsTextFragment* aFrag,
bool aTrimAfter)
bool aTrimAfter, bool aPostReflow)
{
NS_ASSERTION(mTextRun, "Need textrun here");
// This should not be used during reflow. We need our TEXT_REFLOW_FLAGS
// to be set correctly. If our parent wasn't reflowed due to the frame
// tree being too deep then the return value doesn't matter.
NS_ASSERTION(!(GetStateBits() & NS_FRAME_FIRST_REFLOW) ||
(GetParent()->GetStateBits() & NS_FRAME_TOO_DEEP_IN_FRAME_TREE),
"Can only call this on frames that have been reflowed");
NS_ASSERTION(!(GetStateBits() & NS_FRAME_IN_REFLOW),
"Can only call this on frames that are not being reflowed");
if (aPostReflow) {
// This should not be used during reflow. We need our TEXT_REFLOW_FLAGS
// to be set correctly. If our parent wasn't reflowed due to the frame
// tree being too deep then the return value doesn't matter.
NS_ASSERTION(!(GetStateBits() & NS_FRAME_FIRST_REFLOW) ||
(GetParent()->GetStateBits() &
NS_FRAME_TOO_DEEP_IN_FRAME_TREE),
"Can only call this on frames that have been reflowed");
NS_ASSERTION(!(GetStateBits() & NS_FRAME_IN_REFLOW),
"Can only call this on frames that are not being reflowed");
}
TrimmedOffsets offsets = { GetContentOffset(), GetContentLength() };
const nsStyleText* textStyle = StyleText();
@ -2628,7 +2631,7 @@ nsTextFrame::GetTrimmedOffsets(const nsTextFragment* aFrag,
if (textStyle->WhiteSpaceIsSignificant())
return offsets;
if (GetStateBits() & TEXT_START_OF_LINE) {
if (!aPostReflow || (GetStateBits() & TEXT_START_OF_LINE)) {
int32_t whitespaceCount =
GetTrimmableWhitespaceCount(aFrag,
offsets.mStart, offsets.mLength, 1);
@ -2636,7 +2639,7 @@ nsTextFrame::GetTrimmedOffsets(const nsTextFragment* aFrag,
offsets.mLength -= whitespaceCount;
}
if (aTrimAfter && (GetStateBits() & TEXT_END_OF_LINE)) {
if (aTrimAfter && (!aPostReflow || (GetStateBits() & TEXT_END_OF_LINE))) {
// This treats a trailing 'pre-line' newline as trimmable. That's fine,
// it's actually what we want since we want whitespace before it to
// be trimmed.
@ -2809,6 +2812,8 @@ public:
// Call this after construction if you're not going to reflow the text
void InitializeForDisplay(bool aTrimAfter);
void InitializeForMeasure();
virtual void GetSpacing(uint32_t aStart, uint32_t aLength, Spacing* aSpacing);
virtual gfxFloat GetHyphenWidth();
virtual void GetHyphenationBreaks(uint32_t aStart, uint32_t aLength,
@ -3249,6 +3254,17 @@ PropertyProvider::InitializeForDisplay(bool aTrimAfter)
SetupJustificationSpacing();
}
void
PropertyProvider::InitializeForMeasure()
{
nsTextFrame::TrimmedOffsets trimmed =
mFrame->GetTrimmedOffsets(mFrag, true, false);
mStart.SetOriginalOffset(trimmed.mStart);
mLength = trimmed.mLength;
SetupJustificationSpacing();
}
static uint32_t GetSkippedDistance(const gfxSkipCharsIterator& aStart,
const gfxSkipCharsIterator& aEnd)
{
@ -7287,6 +7303,31 @@ nsTextFrame::ComputeTightBounds(gfxContext* aContext) const
return RoundOut(metrics.mBoundingBox) + nsPoint(0, mAscent);
}
/* virtual */ nsresult
nsTextFrame::GetPrefWidthTightBounds(nsRenderingContext* aContext,
nscoord* aX,
nscoord* aXMost)
{
gfxSkipCharsIterator iter =
const_cast<nsTextFrame*>(this)->EnsureTextRun(nsTextFrame::eInflated);
if (!mTextRun)
return NS_ERROR_FAILURE;
PropertyProvider provider(const_cast<nsTextFrame*>(this), iter,
nsTextFrame::eInflated);
provider.InitializeForMeasure();
gfxTextRun::Metrics metrics =
mTextRun->MeasureText(provider.GetStart().GetSkippedOffset(),
ComputeTransformedLength(provider),
gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS,
aContext->ThebesContext(), &provider);
*aX = metrics.mBoundingBox.x;
*aXMost = metrics.mBoundingBox.XMost();
return NS_OK;
}
static bool
HasSoftHyphenBefore(const nsTextFragment* aFrag, gfxTextRun* aTextRun,
int32_t aStartOffset, const gfxSkipCharsIterator& aIter)

View File

@ -221,6 +221,9 @@ public:
nsSize aMargin, nsSize aBorder, nsSize aPadding,
uint32_t aFlags) MOZ_OVERRIDE;
virtual nsRect ComputeTightBounds(gfxContext* aContext) const MOZ_OVERRIDE;
virtual nsresult GetPrefWidthTightBounds(nsRenderingContext* aContext,
nscoord* aX,
nscoord* aXMost) MOZ_OVERRIDE;
NS_IMETHOD Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aMetrics,
const nsHTMLReflowState& aReflowState,
@ -511,7 +514,7 @@ public:
int32_t GetEnd() const { return mStart + mLength; }
};
TrimmedOffsets GetTrimmedOffsets(const nsTextFragment* aFrag,
bool aTrimAfter);
bool aTrimAfter, bool aPostReflow = true);
// Similar to Reflow(), but for use from nsLineLayout
void ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,

View File

@ -29,6 +29,7 @@ NS_IMPL_FRAMEARENA_HELPERS(nsMathMLContainerFrame)
NS_QUERYFRAME_HEAD(nsMathMLContainerFrame)
NS_QUERYFRAME_ENTRY(nsIMathMLFrame)
NS_QUERYFRAME_ENTRY(nsMathMLContainerFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
// =============================================================================
@ -985,7 +986,11 @@ nsMathMLContainerFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
{
nscoord result;
DISPLAY_MIN_WIDTH(this, result);
result = GetIntrinsicWidth(aRenderingContext);
nsHTMLReflowMetrics desiredSize;
GetIntrinsicWidthMetrics(aRenderingContext, desiredSize);
nsBoundingMetrics bm = desiredSize.mBoundingMetrics;
// We include the overflow to compensate for FixInterFrameSpacing.
result = std::max(bm.width, bm.rightBearing) - std::min(0, bm.leftBearing);
return result;
}
@ -994,29 +999,46 @@ nsMathMLContainerFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
{
nscoord result;
DISPLAY_MIN_WIDTH(this, result);
result = GetIntrinsicWidth(aRenderingContext);
nsHTMLReflowMetrics desiredSize;
GetIntrinsicWidthMetrics(aRenderingContext, desiredSize);
nsBoundingMetrics bm = desiredSize.mBoundingMetrics;
// We include the overflow to compensate for FixInterFrameSpacing.
result = std::max(bm.width, bm.rightBearing) - std::min(0, bm.leftBearing);
return result;
}
/* virtual */ nscoord
nsMathMLContainerFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext)
/* virtual */ void
nsMathMLContainerFrame::GetIntrinsicWidthMetrics(nsRenderingContext* aRenderingContext, nsHTMLReflowMetrics& aDesiredSize)
{
// Get child widths
nsIFrame* childFrame = mFrames.FirstChild();
while (childFrame) {
// XXX This includes margin while Reflow currently doesn't consider
// margin, so we may end up with too much space, but, with stretchy
// characters, this is an approximation anyway.
nscoord width =
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, childFrame,
nsLayoutUtils::PREF_WIDTH);
nsHTMLReflowMetrics childDesiredSize;
childDesiredSize.width = width;
childDesiredSize.mBoundingMetrics.width = width;
// TODO: we need nsIFrame::GetIntrinsicHBounds() for better values here.
childDesiredSize.mBoundingMetrics.leftBearing = 0;
childDesiredSize.mBoundingMetrics.rightBearing = width;
nsMathMLContainerFrame* containerFrame = do_QueryFrame(childFrame);
if (containerFrame) {
containerFrame->GetIntrinsicWidthMetrics(aRenderingContext,
childDesiredSize);
} else {
// XXX This includes margin while Reflow currently doesn't consider
// margin, so we may end up with too much space, but, with stretchy
// characters, this is an approximation anyway.
nscoord width =
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, childFrame,
nsLayoutUtils::PREF_WIDTH);
childDesiredSize.width = width;
childDesiredSize.mBoundingMetrics.width = width;
childDesiredSize.mBoundingMetrics.leftBearing = 0;
childDesiredSize.mBoundingMetrics.rightBearing = width;
nscoord x, xMost;
if (NS_SUCCEEDED(childFrame->GetPrefWidthTightBounds(aRenderingContext,
&x, &xMost))) {
childDesiredSize.mBoundingMetrics.leftBearing = x;
childDesiredSize.mBoundingMetrics.rightBearing = xMost;
}
}
SaveReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
childDesiredSize.mBoundingMetrics);
@ -1025,15 +1047,12 @@ nsMathMLContainerFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext)
}
// Measure
nsHTMLReflowMetrics desiredSize;
nsresult rv = MeasureForWidth(*aRenderingContext, desiredSize);
nsresult rv = MeasureForWidth(*aRenderingContext, aDesiredSize);
if (NS_FAILED(rv)) {
ReflowError(*aRenderingContext, desiredSize);
ReflowError(*aRenderingContext, aDesiredSize);
}
ClearSavedChildMetrics();
return desiredSize.width;
}
/* virtual */ nsresult

View File

@ -33,6 +33,7 @@ class nsMathMLContainerFrame : public nsContainerFrame,
public:
nsMathMLContainerFrame(nsStyleContext* aContext) : nsContainerFrame(aContext) {}
NS_DECL_QUERYFRAME_TARGET(nsMathMLContainerFrame)
NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS
@ -92,16 +93,18 @@ public:
nsIFrame* aOldFrame) MOZ_OVERRIDE;
/**
* Both GetMinWidth and GetPrefWidth return whatever
* GetIntrinsicWidth returns.
* Both GetMinWidth and GetPrefWidth use the intrinsic width metrics
* returned by GetIntrinsicMetrics, including ink overflow.
*/
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
/**
* Return the intrinsic width of the frame's content area.
* Return the intrinsic horizontal metrics of the frame's content area.
*/
virtual nscoord GetIntrinsicWidth(nsRenderingContext *aRenderingContext);
virtual void
GetIntrinsicWidthMetrics(nsRenderingContext* aRenderingContext,
nsHTMLReflowMetrics& aDesiredSize);
NS_IMETHOD
Reflow(nsPresContext* aPresContext,

View File

@ -564,8 +564,8 @@ GetMaxCharWidth(nsPresContext* aPresContext,
return width;
}
/* virtual */ nscoord
nsMathMLmfencedFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext)
/* virtual */ void
nsMathMLmfencedFrame::GetIntrinsicWidthMetrics(nsRenderingContext* aRenderingContext, nsHTMLReflowMetrics& aDesiredSize)
{
nscoord width = 0;
@ -607,7 +607,10 @@ nsMathMLmfencedFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext)
NS_MATHML_OPERATOR_FORM_POSTFIX, font->mScriptLevel, em);
}
return width;
aDesiredSize.width = width;
aDesiredSize.mBoundingMetrics.width = width;
aDesiredSize.mBoundingMetrics.leftBearing = 0;
aDesiredSize.mBoundingMetrics.rightBearing = width;
}
nscoord

View File

@ -42,8 +42,9 @@ public:
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
virtual nscoord
GetIntrinsicWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
virtual void
GetIntrinsicWidthMetrics(nsRenderingContext* aRenderingContext,
nsHTMLReflowMetrics& aDesiredSize) MOZ_OVERRIDE;
NS_IMETHOD
AttributeChanged(int32_t aNameSpaceID,

View File

@ -986,28 +986,36 @@ nsMathMLmoFrame::MarkIntrinsicWidthsDirty()
nsMathMLContainerFrame::MarkIntrinsicWidthsDirty();
}
/* virtual */ nscoord
nsMathMLmoFrame::GetIntrinsicWidth(nsRenderingContext *aRenderingContext)
/* virtual */ void
nsMathMLmoFrame::GetIntrinsicWidthMetrics(nsRenderingContext *aRenderingContext, nsHTMLReflowMetrics& aDesiredSize)
{
ProcessOperatorData();
nscoord width;
if (UseMathMLChar()) {
uint32_t stretchHint = GetStretchHint(mFlags, mPresentationData, true);
width = mMathMLChar.
aDesiredSize.width = mMathMLChar.
GetMaxWidth(PresContext(), *aRenderingContext,
stretchHint, mMaxSize,
NS_MATHML_OPERATOR_MAXSIZE_IS_ABSOLUTE(mFlags));
}
else {
width = nsMathMLTokenFrame::GetIntrinsicWidth(aRenderingContext);
nsMathMLTokenFrame::GetIntrinsicWidthMetrics(aRenderingContext,
aDesiredSize);
}
// leadingSpace and trailingSpace are actually applied to the outermost
// embellished container but for determining total intrinsic width it should
// be safe to include it for the core here instead.
width += mEmbellishData.leadingSpace + mEmbellishData.trailingSpace;
return width;
bool isRTL = StyleVisibility()->mDirection;
aDesiredSize.width +=
mEmbellishData.leadingSpace + mEmbellishData.trailingSpace;
aDesiredSize.mBoundingMetrics.width = aDesiredSize.width;
if (isRTL) {
aDesiredSize.mBoundingMetrics.leftBearing += mEmbellishData.trailingSpace;
aDesiredSize.mBoundingMetrics.rightBearing += mEmbellishData.trailingSpace;
} else {
aDesiredSize.mBoundingMetrics.leftBearing += mEmbellishData.leadingSpace;
aDesiredSize.mBoundingMetrics.rightBearing += mEmbellishData.leadingSpace;
}
}
NS_IMETHODIMP

View File

@ -46,8 +46,9 @@ public:
virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE;
virtual nscoord
GetIntrinsicWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
virtual void
GetIntrinsicWidthMetrics(nsRenderingContext* aRenderingContext,
nsHTMLReflowMetrics& aDesiredSize) MOZ_OVERRIDE;
NS_IMETHOD
AttributeChanged(int32_t aNameSpaceID,

View File

@ -350,17 +350,16 @@ nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
return NS_OK;
}
/* virtual */ nscoord
nsMathMLmrootFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext)
/* virtual */ void
nsMathMLmrootFrame::GetIntrinsicWidthMetrics(nsRenderingContext* aRenderingContext, nsHTMLReflowMetrics& aDesiredSize)
{
nsIFrame* baseFrame = mFrames.FirstChild();
nsIFrame* indexFrame = nullptr;
if (baseFrame)
indexFrame = baseFrame->GetNextSibling();
if (!indexFrame || indexFrame->GetNextSibling()) {
nsHTMLReflowMetrics desiredSize;
ReflowError(*aRenderingContext, desiredSize);
return desiredSize.width;
ReflowError(*aRenderingContext, aDesiredSize);
return;
}
nscoord baseWidth =
@ -375,7 +374,12 @@ nsMathMLmrootFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext)
GetRadicalXOffsets(indexWidth, sqrWidth, aRenderingContext->FontMetrics(),
nullptr, &dxSqr);
return dxSqr + sqrWidth + baseWidth;
nscoord width = dxSqr + sqrWidth + baseWidth;
aDesiredSize.width = width;
aDesiredSize.mBoundingMetrics.width = width;
aDesiredSize.mBoundingMetrics.leftBearing = 0;
aDesiredSize.mBoundingMetrics.rightBearing = width;
}
// ----------------------

View File

@ -40,8 +40,9 @@ public:
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus) MOZ_OVERRIDE;
virtual nscoord
GetIntrinsicWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
virtual void
GetIntrinsicWidthMetrics(nsRenderingContext* aRenderingContext,
nsHTMLReflowMetrics& aDesiredSize) MOZ_OVERRIDE;
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,

View File

@ -39,6 +39,7 @@ skip-if(B2G) == quotes-1.xhtml quotes-1-ref.xhtml
!= stretchy-underbar-1.xhtml stretchy-underbar-1-ref.xhtml
== table-width-1.xhtml table-width-1-ref.xhtml
== table-width-2.html table-width-2-ref.html
fails-if(OSX||/^Windows\x20NT\x206\.[12]/.test(http.oscpu)||Android) == table-width-3.html table-width-3-ref.html
== underbar-width-1.xhtml underbar-width-1-ref.xhtml
== mathml-type-supported.xhtml mathml-type-supported-ref.xml
== mtable-align-negative-rownumber.html mtable-align-negative-rownumber-ref.html

View File

@ -0,0 +1,100 @@
<!doctype>
<html>
<head>
<title>table-width-3</title>
<meta charset="utf-8"/>
<style type="text/css">
html { background-color: grey; }
td { border: 1px solid white;
padding: 0;
background-color: black;
color: red; }
mi, mtext { font-size: 3em; }
span { font-style: italic; display: inline-block; }
</style>
</head>
<body>
<table>
<tr>
<td>
<math>
<mphantom>
<mi>f</mi>
</mphantom>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mphantom>
<mi>f</mi>
</mphantom>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mphantom>
<mi>f</mi>
<mi>f</mi>
<mi>f</mi>
</mphantom>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mphantom>
<mi style="font-style: italic;">fff</mi>
</mphantom>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mphantom>
<mtext><span>fff</span></mtext>
</mphantom>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mphantom>
<mtext><span>f</span></mtext>
<mtext><span>f</span></mtext>
<mtext><span>f</span></mtext>
</mphantom>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mphantom>
<mtext><span>f</span><span>f</span><span>f</span></mtext>
</mphantom>
</math>
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,87 @@
<!doctype>
<html>
<head>
<title>table-width-3</title>
<meta charset="utf-8"/>
<style type="text/css">
html { background-color: grey; }
td { border: 1px solid white;
padding: 0;
background-color: black;
color: black; }
mi, mtext { font-size: 3em; }
span { font-style: italic; display: inline-block; }
</style>
</head>
<body>
<table>
<tr>
<td>
<math>
<mi>f</mi>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mi> f </mi>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mi>f</mi>
<mi>f</mi>
<mi>f</mi>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mi style="font-style: italic;">fff</mi>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mtext><span>fff</span></mtext>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mtext><span>f</span></mtext>
<mtext><span>f</span></mtext>
<mtext><span>f</span></mtext>
</math>
</td>
</tr>
</table>
<table>
<tr>
<td>
<math>
<mtext><span>f</span><span>f</span><span>f</span></mtext>
</math>
</td>
</tr>
</table>
</body>
</html>

View File

@ -343,3 +343,6 @@ skip-if(B2G) include box-sizing/reftest.list
# invalidation - only run on B2G
skip-if(!B2G) include invalidation/reftest.list
# encodings
include ../../dom/encoding/test/reftest/reftest.list

View File

@ -472,6 +472,8 @@ get_dht (j_decompress_ptr cinfo)
for (i = 0; i < count; i++)
INPUT_BYTE(cinfo, huffval[i], return FALSE);
MEMZERO(&huffval[count], (256-count)*SIZEOF(UINT8));
length -= count;
if (index & 0x10) { /* AC table definition */

View File

@ -10,7 +10,7 @@
#define logging_h__
#if defined(PR_LOG)
#error "Must #include logging.h before before any IPDL-generated files or other files that #include prlog.h."
#error "Must #include logging.h before any IPDL-generated files or other files that #include prlog.h."
#endif
// Enforce logging under production builds for MOZ_MTLOG friends.

View File

@ -181,7 +181,16 @@ nsUnicharStreamLoader::DetermineCharset()
do_GetService(kCharsetConverterManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = ccm->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mDecoder));
// Sadly, nsIUnicharStreamLoader is exposed to extensions, so we can't
// assume mozilla::css::Loader to be the only caller. Since legacy
// charset alias code doesn't know about the replacement encoding,
// special-case it here, but let other stuff go through legacy alias
// resolution for now.
if (mCharset.EqualsLiteral("replacement")) {
rv = ccm->GetUnicodeDecoderRaw(mCharset.get(), getter_AddRefs(mDecoder));
} else {
rv = ccm->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mDecoder));
}
if (NS_FAILED(rv)) return rv;
// Process the data into mBuffer

View File

@ -2,8 +2,6 @@
* 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 "nsICharsetConverterManager.h"
#include "nsServiceManagerUtils.h"
#include "nsEncoderDecoderUtils.h"
#include "nsTraceRefcnt.h"
@ -12,15 +10,12 @@
using mozilla::dom::EncodingUtils;
void
nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsIUnicodeDecoder** decoder, nsACString& charset)
nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsACString& charset)
{
readable = bytes;
stateLoop(stateSave);
readable = nullptr;
if (mUnicodeDecoder) {
mUnicodeDecoder.forget(decoder);
charset.Assign(mCharset);
}
charset.Assign(mCharset);
}
bool
@ -29,47 +24,17 @@ nsHtml5MetaScanner::tryCharset(nsString* charset)
// This code needs to stay in sync with
// nsHtml5StreamParser::internalEncodingDeclaration. Unfortunately, the
// trickery with member fields here leads to some copy-paste reuse. :-(
nsresult res = NS_OK;
nsCOMPtr<nsICharsetConverterManager> convManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
if (NS_FAILED(res)) {
NS_ERROR("Could not get CharsetConverterManager service.");
return false;
}
nsAutoCString label;
CopyUTF16toUTF8(*charset, label);
nsAutoCString encoding;
CopyUTF16toUTF8(*charset, encoding);
encoding.Trim(" \t\r\n\f");
if (encoding.LowerCaseEqualsLiteral("utf-16") ||
encoding.LowerCaseEqualsLiteral("utf-16be") ||
encoding.LowerCaseEqualsLiteral("utf-16le")) {
if (!EncodingUtils::FindEncodingForLabel(label, encoding)) {
return false;
}
if (encoding.EqualsLiteral("UTF-16BE") ||
encoding.EqualsLiteral("UTF-16LE")) {
mCharset.Assign("UTF-8");
res = convManager->GetUnicodeDecoderRaw(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
if (NS_FAILED(res)) {
NS_ERROR("Could not get decoder for UTF-8.");
return false;
}
return true;
}
nsAutoCString preferred;
if (!EncodingUtils::FindEncodingForLabel(encoding, preferred)) {
return false;
}
if (preferred.LowerCaseEqualsLiteral("utf-16") ||
preferred.LowerCaseEqualsLiteral("utf-16be") ||
preferred.LowerCaseEqualsLiteral("utf-16le") ||
preferred.LowerCaseEqualsLiteral("utf-7") ||
preferred.LowerCaseEqualsLiteral("x-imap4-modified-utf7")) {
return false;
}
res = convManager->GetUnicodeDecoderRaw(preferred.get(), getter_AddRefs(mUnicodeDecoder));
if (res == NS_ERROR_UCONV_NOCONV) {
return false;
} else if (NS_FAILED(res)) {
NS_ERROR("Getting an encoding decoder failed in a bad way.");
mUnicodeDecoder = nullptr;
return false;
} else {
NS_ASSERTION(mUnicodeDecoder, "Getter nsresult and object don't match.");
mCharset.Assign(preferred);
return true;
}
mCharset.Assign(encoding);
return true;
}

View File

@ -3,10 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
private:
nsCOMPtr<nsIUnicodeDecoder> mUnicodeDecoder;
nsCString mCharset;
inline int32_t read() {
return readable->read();
}
public:
void sniff(nsHtml5ByteReadable* bytes, nsIUnicodeDecoder** decoder, nsACString& charset);
void sniff(nsHtml5ByteReadable* bytes, nsACString& charset);

View File

@ -238,8 +238,16 @@ nsHtml5StreamParser::Notify(const char* aCharset, nsDetectionConfident aConf)
NS_ASSERTION(IsParserThread(), "Wrong thread!");
if (aConf == eBestAnswer || aConf == eSureAnswer) {
mFeedChardet = false; // just in case
nsAutoCString encoding;
if (!EncodingUtils::FindEncodingForLabel(nsDependentCString(aCharset),
encoding)) {
return NS_OK;
}
if (encoding.EqualsLiteral("replacement")) {
return NS_OK;
}
if (HasDecoder()) {
if (mCharset.Equals(aCharset)) {
if (mCharset.Equals(encoding)) {
NS_ASSERTION(mCharsetSource < kCharsetFromAutoDetection,
"Why are we running chardet at all?");
mCharsetSource = kCharsetFromAutoDetection;
@ -247,8 +255,7 @@ nsHtml5StreamParser::Notify(const char* aCharset, nsDetectionConfident aConf)
} else {
// We've already committed to a decoder. Request a reload from the
// docshell.
nsAutoCString charset(aCharset);
mTreeBuilder->NeedsCharsetSwitchTo(charset,
mTreeBuilder->NeedsCharsetSwitchTo(encoding,
kCharsetFromAutoDetection,
0);
FlushTreeOpsAndDisarmTimer();
@ -257,7 +264,7 @@ nsHtml5StreamParser::Notify(const char* aCharset, nsDetectionConfident aConf)
} else {
// Got a confident answer from the sniffing buffer. That code will
// take care of setting up the decoder.
mCharset.Assign(aCharset);
mCharset.Assign(encoding);
mCharsetSource = kCharsetFromAutoDetection;
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
}
@ -299,7 +306,8 @@ nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const
nsresult rv = NS_OK;
nsCOMPtr<nsICharsetConverterManager> convManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = convManager->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
rv = convManager->GetUnicodeDecoderRaw(mCharset.get(),
getter_AddRefs(mUnicodeDecoder));
if (rv == NS_ERROR_UCONV_NOCONV) {
mCharset.AssignLiteral("windows-1252"); // lower case is the raw form
mCharsetSource = kCharsetFromFallback;
@ -307,16 +315,6 @@ nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
}
NS_ENSURE_SUCCESS(rv, rv);
return WriteSniffingBufferAndCurrentSegment(aFromSegment, aCount, aWriteCount);
}
nsresult
nsHtml5StreamParser::WriteSniffingBufferAndCurrentSegment(const uint8_t* aFromSegment, // can be null
uint32_t aCount,
uint32_t* aWriteCount)
{
NS_ASSERTION(IsParserThread(), "Wrong thread!");
nsresult rv = NS_OK;
if (mSniffingBuffer) {
uint32_t writeCount;
rv = WriteStreamBytes(mSniffingBuffer, mSniffingLength, &writeCount);
@ -710,29 +708,22 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
// if we get here, there either was no BOM or the BOM sniffing isn't complete
// yet
MOZ_ASSERT(mCharsetSource != kCharsetFromByteOrderMark,
"Should not come here if BOM was found.");
MOZ_ASSERT(mCharsetSource != kCharsetFromOtherComponent,
"kCharsetFromOtherComponent is for XSLT.");
if (mBomState == BOM_SNIFFING_OVER &&
mCharsetSource >= kCharsetFromChannel) {
// There was no BOM and the charset came from channel or higher. mCharset
// still contains the charset from the channel or higher as set by an
mCharsetSource == kCharsetFromChannel) {
// There was no BOM and the charset came from channel. mCharset
// still contains the charset from the channel as set by an
// earlier call to SetDocumentCharset(), since we didn't find a BOM and
// overwrite mCharset.
nsCOMPtr<nsICharsetConverterManager> convManager =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID);
convManager->GetUnicodeDecoder(mCharset.get(),
getter_AddRefs(mUnicodeDecoder));
if (mUnicodeDecoder) {
mFeedChardet = false;
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
mMetaScanner = nullptr;
return WriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount,
aWriteCount);
} else {
// nsHTMLDocument is supposed to make sure this does not happen. Let's
// deal with this anyway, since who knows how kCharsetFromOtherComponent
// is used.
mCharsetSource = kCharsetFromFallback;
}
// overwrite mCharset. (Note that if the user has overridden the charset,
// we don't come here but check <meta> for XSS-dangerous charsets first.)
mFeedChardet = false;
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount, aWriteCount);
}
if (!mMetaScanner && (mMode == NORMAL ||
@ -748,17 +739,31 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
if (mMode == NORMAL || mMode == VIEW_SOURCE_HTML || mMode == LOAD_AS_DATA) {
nsHtml5ByteReadable readable(aFromSegment, aFromSegment +
countToSniffingLimit);
mMetaScanner->sniff(&readable, getter_AddRefs(mUnicodeDecoder), mCharset);
if (mUnicodeDecoder) {
// meta scan successful
nsAutoCString encoding;
mMetaScanner->sniff(&readable, encoding);
if (!encoding.IsEmpty()) {
// meta scan successful; honor overrides unless meta is XSS-dangerous
if ((mCharsetSource == kCharsetFromParentForced ||
mCharsetSource == kCharsetFromUserForced) &&
EncodingUtils::IsAsciiCompatible(encoding)) {
// Honor override
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
mCharset.Assign(encoding);
mCharsetSource = kCharsetFromMetaPrescan;
mFeedChardet = false;
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
mMetaScanner = nullptr;
return WriteSniffingBufferAndCurrentSegment(aFromSegment, aCount,
aWriteCount);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
}
if (mCharsetSource == kCharsetFromParentForced ||
mCharsetSource == kCharsetFromUserForced) {
// meta not found, honor override
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
return FinalizeSniffing(aFromSegment, aCount, aWriteCount,
countToSniffingLimit);
}
@ -766,16 +771,23 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
// not the last buffer
if (mMode == NORMAL || mMode == VIEW_SOURCE_HTML || mMode == LOAD_AS_DATA) {
nsHtml5ByteReadable readable(aFromSegment, aFromSegment + aCount);
mMetaScanner->sniff(&readable, getter_AddRefs(mUnicodeDecoder), mCharset);
if (mUnicodeDecoder) {
// meta scan successful
nsAutoCString encoding;
mMetaScanner->sniff(&readable, encoding);
if (!encoding.IsEmpty()) {
// meta scan successful; honor overrides unless meta is XSS-dangerous
if ((mCharsetSource == kCharsetFromParentForced ||
mCharsetSource == kCharsetFromUserForced) &&
EncodingUtils::IsAsciiCompatible(encoding)) {
// Honor override
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount, aWriteCount);
}
mCharset.Assign(encoding);
mCharsetSource = kCharsetFromMetaPrescan;
mFeedChardet = false;
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
mMetaScanner = nullptr;
return WriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount,
aWriteCount);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount, aWriteCount);
}
}
@ -975,9 +987,11 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
mFeedChardet = false;
// Instantiate the converter here to avoid BOM sniffing.
nsCOMPtr<nsICharsetConverterManager> convManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
nsCOMPtr<nsICharsetConverterManager> convManager =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = convManager->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
rv = convManager->GetUnicodeDecoderRaw(mCharset.get(),
getter_AddRefs(mUnicodeDecoder));
// if we failed to get a decoder, there will be fallback, so don't propagate
// the error.
if (NS_FAILED(rv)) {

View File

@ -322,21 +322,6 @@ class nsHtml5StreamParser : public nsIStreamListener,
uint32_t aCount,
uint32_t* aWriteCount);
/**
* Write the sniffing buffer into the Unicode decoder followed by the
* current network buffer.
*
* @param aFromSegment The current network buffer or null if the sniffing
* buffer is being flushed due to network stream ending.
* @param aCount The number of bytes in aFromSegment (ignored if
* aFromSegment is null)
* @param aWriteCount Return value for how many bytes got read from the
* buffer.
*/
nsresult WriteSniffingBufferAndCurrentSegment(const uint8_t* aFromSegment,
uint32_t aCount,
uint32_t* aWriteCount);
/**
* Initialize the Unicode decoder, mark the BOM as the source and
* drop the sniffer.

View File

@ -506,6 +506,7 @@
"dom/indexedDB/test/test_blob_archive.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_blob_worker_crash.html": "Bug 931116, b2g desktop specific, bug 927889 still present",
"dom/indexedDB/test/test_blob_simple.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_bug937006.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_clear.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_complex_keyPaths.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_count.html": "Bug 931116, b2g desktop specific, initial triage",

View File

@ -50,8 +50,11 @@ ThreadStackHelper::Shutdown()
}
ThreadStackHelper::ThreadStackHelper()
: mPseudoStack(mozilla_get_pseudo_stack())
, mStackBuffer()
:
#ifdef MOZ_ENABLE_PROFILER_SPS
mPseudoStack(mozilla_get_pseudo_stack()),
#endif
mStackBuffer()
, mMaxStackSize(mStackBuffer.capacity())
{
#if defined(XP_LINUX)
@ -147,15 +150,20 @@ ThreadStackHelper::SigAction(int aSignal, siginfo_t* aInfo, void* aContext)
bool
ThreadStackHelper::PrepareStackBuffer(Stack& aStack) {
aStack.clear();
#ifdef MOZ_ENABLE_PROFILER_SPS
if (!mPseudoStack) {
return false;
}
mStackBuffer.clear();
return mStackBuffer.reserve(mMaxStackSize);
#else
return false;
#endif
}
void
ThreadStackHelper::FillStackBuffer() {
#ifdef MOZ_ENABLE_PROFILER_SPS
size_t reservedSize = mMaxStackSize;
// Go from front to back
@ -170,6 +178,7 @@ ThreadStackHelper::FillStackBuffer() {
}
// If we exited early due to buffer size, expand the buffer for next time
mMaxStackSize += (end - entry);
#endif
}
} // namespace mozilla

View File

@ -40,7 +40,9 @@ public:
typedef Telemetry::HangHistogram::Stack Stack;
private:
#ifdef MOZ_ENABLE_PROFILER_SPS
const PseudoStack* const mPseudoStack;
#endif
Stack mStackBuffer;
size_t mMaxStackSize;