Bug 826740 - Part c: Pass a JS::Value instead of an nsIVariant to nsIDOMHTMLCanvasElement.toDataURL; r=khuey

This commit is contained in:
Ms2ger 2013-04-13 09:05:22 +02:00
parent 232412192b
commit ef15912c48
3 changed files with 21 additions and 22 deletions

View File

@ -163,8 +163,9 @@ protected:
const nsAString& aOptions,
nsIInputStream** aStream,
bool& aFellBackToPNG);
nsresult ToDataURLImpl(const nsAString& aMimeType,
nsIVariant* aEncoderOptions,
nsresult ToDataURLImpl(JSContext* aCx,
const nsAString& aMimeType,
const JS::Value& aEncoderOptions,
nsAString& aDataURL);
nsresult MozGetAsFileImpl(const nsAString& aName,
const nsAString& aType,

View File

@ -341,15 +341,15 @@ HTMLCanvasElement::ParseAttribute(int32_t aNamespaceID,
// HTMLCanvasElement::toDataURL
NS_IMETHODIMP
HTMLCanvasElement::ToDataURL(const nsAString& aType, nsIVariant* aParams,
nsAString& aDataURL)
HTMLCanvasElement::ToDataURL(const nsAString& aType, const JS::Value& aParams,
JSContext* aCx, nsAString& aDataURL)
{
// do a trust check if this is a write-only canvas
if (mWriteOnly && !nsContentUtils::IsCallerChrome()) {
return NS_ERROR_DOM_SECURITY_ERR;
}
return ToDataURLImpl(aType, aParams, aDataURL);
return ToDataURLImpl(aCx, aType, aParams, aDataURL);
}
// HTMLCanvasElement::mozFetchAsStream
@ -465,8 +465,9 @@ HTMLCanvasElement::ExtractData(const nsAString& aType,
}
nsresult
HTMLCanvasElement::ToDataURLImpl(const nsAString& aMimeType,
nsIVariant* aEncoderOptions,
HTMLCanvasElement::ToDataURLImpl(JSContext* aCx,
const nsAString& aMimeType,
const JS::Value& aEncoderOptions,
nsAString& aDataURL)
{
bool fallbackToPNG = false;
@ -487,16 +488,10 @@ HTMLCanvasElement::ToDataURLImpl(const nsAString& aMimeType,
// Quality parameter is only valid for the image/jpeg MIME type
if (type.EqualsLiteral("image/jpeg")) {
uint16_t vartype;
if (aEncoderOptions &&
NS_SUCCEEDED(aEncoderOptions->GetDataType(&vartype)) &&
vartype <= nsIDataType::VTYPE_DOUBLE) {
double quality;
if (aEncoderOptions.isNumber()) {
double quality = aEncoderOptions.toNumber();
// Quality must be between 0.0 and 1.0, inclusive
if (NS_SUCCEEDED(aEncoderOptions->GetAsDouble(&quality)) &&
quality >= 0.0 && quality <= 1.0) {
if (quality >= 0.0 && quality <= 1.0) {
params.AppendLiteral("quality=");
params.AppendInt(NS_lround(quality * 100.0));
}
@ -507,11 +502,13 @@ HTMLCanvasElement::ToDataURLImpl(const nsAString& aMimeType,
// The proprietary option -moz-parse-options will take a image lib encoder
// parse options string as is and pass it to the encoder.
bool usingCustomParseOptions = false;
if (params.Length() == 0) {
if (params.Length() == 0 && aEncoderOptions.isString()) {
NS_NAMED_LITERAL_STRING(mozParseOptions, "-moz-parse-options:");
nsAutoString paramString;
if (NS_SUCCEEDED(aEncoderOptions->GetAsAString(paramString)) &&
StringBeginsWith(paramString, mozParseOptions)) {
nsDependentJSString paramString;
if (!paramString.init(aCx, aEncoderOptions.toString())) {
return NS_ERROR_FAILURE;
}
if (StringBeginsWith(paramString, mozParseOptions)) {
nsDependentSubstring parseOptions = Substring(paramString,
mozParseOptions.Length(),
paramString.Length() -

View File

@ -46,7 +46,7 @@ interface nsIFileCallback : nsISupports {
void receive(in nsIDOMBlob file);
};
[scriptable, uuid(83d84fe5-cd02-41ff-ac86-668775627d82)]
[scriptable, uuid(ba777030-783e-43b6-b85d-0670da81acb8)]
interface nsIDOMHTMLCanvasElement : nsIDOMHTMLElement
{
attribute unsigned long width;
@ -61,8 +61,9 @@ interface nsIDOMHTMLCanvasElement : nsIDOMHTMLElement
// toDataURL(); -- defaults to image/png
// toDataURL(type); -- uses given type
// toDataURL(type, params); -- uses given type, and any valid parameters
[implicit_jscontext]
DOMString toDataURL([optional] in DOMString type,
[optional] in nsIVariant params);
[optional] in jsval params);
// Valid calls are
// mozGetAsFile(name); -- defaults to image/png