Backout d1f27bcc360a (Bug 849114) for windows bustage CLOSED TREE

This commit is contained in:
John Schoenick 2013-03-08 16:20:11 -08:00
parent 2f37c8ad63
commit 668baedbb6
6 changed files with 147 additions and 230 deletions

View File

@ -160,6 +160,7 @@ CPPSRCS += \
nsHTMLAudioElement.cpp \
nsHTMLMediaElement.cpp \
MediaError.cpp \
nsMediaFragmentURIParser.cpp \
HTMLSourceElement.cpp \
TimeRanges.cpp \
nsHTMLVideoElement.cpp \
@ -187,7 +188,6 @@ INCLUDES += \
-I$(srcdir)/../../../../editor/libeditor/base \
-I$(srcdir)/../../../../editor/libeditor/text \
-I$(srcdir)/../../../../editor/txmgr/src \
-I$(srcdir)/../../../../netwerk/base/src \
-I$(srcdir) \
-I$(topsrcdir)/xpcom/ds \
$(NULL)

View File

@ -2501,15 +2501,24 @@ nsresult nsHTMLMediaElement::NewURIFromString(const nsAutoString& aURISpec, nsIU
void nsHTMLMediaElement::ProcessMediaFragmentURI()
{
nsMediaFragmentURIParser parser(mLoadingSrc);
if (mDecoder && parser.HasEndTime()) {
mFragmentEnd = parser.GetEndTime();
nsAutoCString ref;
GetCurrentSpec(ref);
nsMediaFragmentURIParser parser(ref);
parser.Parse();
double start = parser.GetStartTime();
if (mDecoder) {
double end = parser.GetEndTime();
if (end < 0.0 || end > start) {
mFragmentEnd = end;
}
else {
start = -1.0;
end = -1.0;
}
}
if (parser.HasStartTime()) {
SetCurrentTime(parser.GetStartTime());
mFragmentStart = parser.GetStartTime();
if (start > 0.0) {
SetCurrentTime(start);
mFragmentStart = start;
}
}

View File

@ -3,32 +3,21 @@
/* 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 <utility>
#include "nsTArray.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsEscape.h"
#include "nsMediaFragmentURIParser.h"
using std::pair;
using std::make_pair;
nsMediaFragmentURIParser::nsMediaFragmentURIParser(nsIURI* aURI)
: mStart(0.0)
, mEnd(-1.0)
, mClip()
, mClipUnit(eClipUnit_Pixel)
, mHasStart(false)
, mHasEnd(false)
, mHasClip(false)
nsMediaFragmentURIParser::nsMediaFragmentURIParser(const nsCString& aSpec)
{
nsAutoCString ref;
aURI->GetRef(ref);
Parse(ref);
nsReadingIterator<char> start, end;
aSpec.BeginReading(start);
aSpec.EndReading(end);
if (FindCharInReadable('#', start, end)) {
mHash = Substring(++start, end);
}
}
bool nsMediaFragmentURIParser::ParseNPT(nsDependentSubstring& aString)
bool nsMediaFragmentURIParser::ParseNPT(nsDependentSubstring& aString, double& aStart, double& aEnd)
{
nsDependentSubstring original(aString);
if (aString.Length() > 4 &&
@ -44,11 +33,11 @@ bool nsMediaFragmentURIParser::ParseNPT(nsDependentSubstring& aString)
double start = -1.0;
double end = -1.0;
ParseNPTTime(aString, start);
if (ParseNPTTime(aString, start)) {
aStart = start;
}
if (aString.Length() == 0) {
mStart = start;
mHasStart = true;
return true;
}
@ -64,17 +53,15 @@ bool nsMediaFragmentURIParser::ParseNPT(nsDependentSubstring& aString)
return false;
}
ParseNPTTime(aString, end);
if (ParseNPTTime(aString, end)) {
aEnd = end;
}
if (end <= start || aString.Length() != 0) {
if (aString.Length() != 0) {
aString.Rebind(original, 0);
return false;
}
mStart = start;
mHasStart = true;
mEnd = end;
mHasEnd = true;
return true;
}
@ -265,83 +252,9 @@ bool nsMediaFragmentURIParser::ParseNPTSS(nsDependentSubstring& aString, uint32_
return false;
}
static bool ParseInteger(nsDependentSubstring& aString,
int32_t& aResult)
void nsMediaFragmentURIParser::Parse()
{
uint32_t index = FirstNonDigit(aString, 0);
if (index == 0) {
return false;
}
nsDependentSubstring n(aString, 0, index);
nsresult ec;
int32_t s = PromiseFlatString(n).ToInteger(&ec);
if (NS_FAILED(ec)) {
return false;
}
aString.Rebind(aString, index);
aResult = s;
return true;
}
static bool ParseCommaSeparator(nsDependentSubstring& aString)
{
if (aString.Length() > 1 && aString[0] == ',') {
aString.Rebind(aString, 1);
return true;
}
return false;
}
bool nsMediaFragmentURIParser::ParseXYWH(nsDependentSubstring& aString)
{
int32_t x, y, w, h;
ClipUnit clipUnit;
// Determine units.
if (StringBeginsWith(aString, NS_LITERAL_STRING("pixel:"))) {
clipUnit = eClipUnit_Pixel;
aString.Rebind(aString, 6);
} else if (StringBeginsWith(aString, NS_LITERAL_STRING("percent:"))) {
clipUnit = eClipUnit_Percent;
aString.Rebind(aString, 8);
} else {
clipUnit = eClipUnit_Pixel;
}
// Read and validate coordinates.
if (ParseInteger(aString, x) && x >= 0 &&
ParseCommaSeparator(aString) &&
ParseInteger(aString, y) && y >= 0 &&
ParseCommaSeparator(aString) &&
ParseInteger(aString, w) && w > 0 &&
ParseCommaSeparator(aString) &&
ParseInteger(aString, h) && h > 0 &&
aString.Length() == 0) {
// Reject invalid percentage coordinates.
if (clipUnit == eClipUnit_Percent &&
(x + w > 100 || y + h > 100)) {
return false;
}
mClip.SetRect(x, y, w, h);
mClipUnit = clipUnit;
mHasClip = true;
return true;
}
return false;
}
void nsMediaFragmentURIParser::Parse(nsACString& aRef)
{
// Create an array of possibly-invalid media fragments.
nsTArray< std::pair<nsCString, nsCString> > fragments;
nsCCharSeparatedTokenizer tokenizer(aRef, '&');
nsCCharSeparatedTokenizer tokenizer(mHash, '&');
while (tokenizer.hasMoreTokens()) {
const nsCSubstring& nv = tokenizer.nextToken();
int32_t index = nv.FindChar('=');
@ -351,23 +264,43 @@ void nsMediaFragmentURIParser::Parse(nsACString& aRef)
NS_UnescapeURL(StringHead(nv, index), esc_Ref | esc_AlwaysCopy, name);
NS_UnescapeURL(Substring(nv, index + 1, nv.Length()),
esc_Ref | esc_AlwaysCopy, value);
//nsAutoString a = NS_ConvertUTF8toUTF16(name);
fragments.AppendElement(make_pair(name, value));
}
}
// Parse the media fragment values.
bool gotTemporal = false;
bool gotSpatial = false;
for (uint32_t i = fragments.Length() ; i > 0 && !(gotTemporal && gotSpatial); --i) {
if (!gotTemporal && fragments[i - 1].first.EqualsLiteral("t")) {
nsAutoString value = NS_ConvertUTF8toUTF16(fragments[i - 1].second);
nsDependentSubstring utf16Value(value, 0);
gotTemporal = ParseNPT(utf16Value);
} else if (!gotSpatial && fragments[i - 1].first.EqualsLiteral("xywh")) {
nsAutoString value = NS_ConvertUTF8toUTF16(fragments[i - 1].second);
nsDependentSubstring utf16Value(value, 0);
gotSpatial = ParseXYWH(utf16Value);
nsAutoString a = NS_ConvertUTF8toUTF16(name);
nsAutoString b = NS_ConvertUTF8toUTF16(value);
mFragments.AppendElement(Pair(a, b));
}
}
}
double nsMediaFragmentURIParser::GetStartTime()
{
for (uint32_t i = 0; i < mFragments.Length(); ++i) {
uint32_t index = mFragments.Length() - i - 1;
if (mFragments[index].mName.EqualsLiteral("t")) {
double start = -1;
double end = -1;
nsDependentSubstring s(mFragments[index].mValue, 0);
if (ParseNPT(s, start, end)) {
return start;
}
}
}
return 0.0;
}
double nsMediaFragmentURIParser::GetEndTime()
{
for (uint32_t i = 0; i < mFragments.Length(); ++i) {
uint32_t index = mFragments.Length() - i - 1;
if (mFragments[index].mName.EqualsLiteral("t")) {
double start = -1;
double end = -1;
nsDependentSubstring s(mFragments[index].mValue, 0);
if (ParseNPT(s, start, end)) {
return end;
}
}
}
return -1;
}

View File

@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=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/. */
#if !defined(nsMediaFragmentURIParser_h__)
#define nsMediaFragmentURIParser_h__
#include "nsString.h"
#include "nsTArray.h"
// Class to handle parsing of a W3C media fragment URI as per
// spec at: http://www.w3.org/TR/media-frags/
// Only the temporaral URI portion of the spec is implemented.
// To use:
// a) Construct an instance with the URI containing the fragment
// b) Call Parse() method to parse the fragment
// c) Use GetStartTime() and GetEndTime() to get the start/end
// times from any temporal fragment included in the URI.
class nsMediaFragmentURIParser
{
struct Pair
{
Pair(const nsAString& aName, const nsAString& aValue) :
mName(aName), mValue(aValue) { }
nsString mName;
nsString mValue;
};
public:
// Create a parser, with the URL including fragment identifier
// in 'aSpec'.
nsMediaFragmentURIParser(const nsCString& aSpec);
// Parse the URI fragment included in the URI that was passed
// on construction.
void Parse();
// Return the start time in seconds obtained from the URI
// fragment. If no start time or no valid temporal fragment
// exists then 0 is returned.
double GetStartTime();
// Return the end time in seconds obtained from the URI
// fragment. If no end time or no valid temporal fragment
// exists then -1 is returned.
double GetEndTime();
private:
// The following methods parse the fragment as per the media
// fragments specification. 'aString' contains the remaining
// fragment data to be parsed. The method returns true
// if the parse was successful and leaves the remaining unparsed
// data in 'aString'. If the parse fails then false is returned
// and 'aString' is left as it was when called.
bool ParseNPT(nsDependentSubstring& aString, double& aStart, double& aEnd);
bool ParseNPTTime(nsDependentSubstring& aString, double& aTime);
bool ParseNPTSec(nsDependentSubstring& aString, double& aSec);
bool ParseNPTFraction(nsDependentSubstring& aString, double& aFraction);
bool ParseNPTMMSS(nsDependentSubstring& aString, double& aTime);
bool ParseNPTHHMMSS(nsDependentSubstring& aString, double& aTime);
bool ParseNPTHH(nsDependentSubstring& aString, uint32_t& aHour);
bool ParseNPTMM(nsDependentSubstring& aString, uint32_t& aMinute);
bool ParseNPTSS(nsDependentSubstring& aString, uint32_t& aSecond);
// Fragment portion of the URI given on construction
nsAutoCString mHash;
// An array of name/value pairs containing the media fragments
// parsed from the URI.
nsTArray<Pair> mFragments;
};
#endif

View File

@ -81,12 +81,6 @@ CPPSRCS = \
NetworkActivityMonitor.cpp \
$(NULL)
ifdef MOZ_MEDIA
CPPSRCS += \
nsMediaFragmentURIParser.cpp \
$(NULL)
endif
LOCAL_INCLUDES += -I$(topsrcdir)/dom/base
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)

View File

@ -1,94 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=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/. */
#if !defined(nsMediaFragmentURIParser_h__)
#define nsMediaFragmentURIParser_h__
#include "nsIURI.h"
#include "nsString.h"
#include "nsRect.h"
// Class to handle parsing of a W3C media fragment URI as per
// spec at: http://www.w3.org/TR/media-frags/
// Only the temporaral URI portion of the spec is implemented.
// To use:
// a) Construct an instance with the URI containing the fragment
// b) Check for the validity of the values you are interested in
// using e.g. HasStartTime().
// c) If the values are valid, obtain them using e.g. GetStartTime().
enum ClipUnit
{
eClipUnit_Pixel,
eClipUnit_Percent,
};
class nsMediaFragmentURIParser
{
public:
// Create a parser with the provided URI.
nsMediaFragmentURIParser(nsIURI* aURI);
// True if a valid temporal media fragment indicated a start time.
bool HasStartTime() const { return mHasStart; }
// If a valid temporal media fragment indicated a start time, returns
// it in units of seconds. If not, defaults to 0.
double GetStartTime() const { return mStart; }
// True if a valid temporal media fragment indicated an end time.
bool HasEndTime() const { return mHasEnd; }
// If a valid temporal media fragment indicated an end time, returns
// it in units of seconds. If not, defaults to -1.
double GetEndTime() const { return mEnd; }
// True if a valid spatial media fragment indicated a clipping region.
bool HasClip() const { return mHasClip; }
// If a valid spatial media fragment indicated a clipping region,
// returns the region. If not, returns an empty region. The unit
// used depends on the value returned by GetClipUnit().
nsIntRect GetClip() const { return mClip; }
// If a valid spatial media fragment indicated a clipping region,
// returns the unit used - either pixels or percents.
ClipUnit GetClipUnit() const { return mClipUnit; }
private:
// Parse the URI ref provided, looking for media fragments. This is
// the top-level parser the invokes the others below.
void Parse(nsACString& aRef);
// The following methods parse the fragment as per the media
// fragments specification. 'aString' contains the remaining
// fragment data to be parsed. The method returns true
// if the parse was successful and leaves the remaining unparsed
// data in 'aString'. If the parse fails then false is returned
// and 'aString' is left as it was when called.
bool ParseNPT(nsDependentSubstring& aString);
bool ParseNPTTime(nsDependentSubstring& aString, double& aTime);
bool ParseNPTSec(nsDependentSubstring& aString, double& aSec);
bool ParseNPTFraction(nsDependentSubstring& aString, double& aFraction);
bool ParseNPTMMSS(nsDependentSubstring& aString, double& aTime);
bool ParseNPTHHMMSS(nsDependentSubstring& aString, double& aTime);
bool ParseNPTHH(nsDependentSubstring& aString, uint32_t& aHour);
bool ParseNPTMM(nsDependentSubstring& aString, uint32_t& aMinute);
bool ParseNPTSS(nsDependentSubstring& aString, uint32_t& aSecond);
bool ParseXYWH(nsDependentSubstring& aString);
// Media fragment information.
double mStart;
double mEnd;
nsIntRect mClip;
ClipUnit mClipUnit;
// Validity bits for each type of media fragment information.
bool mHasStart : 1;
bool mHasEnd : 1;
bool mHasClip : 1;
};
#endif