2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2013-02-14 19:59:21 +04:00
|
|
|
|
|
|
|
#include "mozilla/dom/MediaError.h"
|
2017-08-04 13:46:26 +03:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2013-02-14 19:59:21 +04:00
|
|
|
#include "mozilla/dom/MediaErrorBinding.h"
|
2017-08-04 13:46:26 +03:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "jsapi.h"
|
2019-04-06 01:52:04 +03:00
|
|
|
#include "js/Warnings.h" // JS::WarnASCII
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MediaError, mParent)
|
2013-02-14 19:59:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaError)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaError)
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2013-02-14 19:59:21 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaError)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2016-09-15 18:41:35 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2008-07-09 12:22:20 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2016-09-10 17:56:09 +03:00
|
|
|
MediaError::MediaError(HTMLMediaElement* aParent, uint16_t aCode,
|
|
|
|
const nsACString& aMessage)
|
|
|
|
: mParent(aParent), mCode(aCode), mMessage(aMessage) {}
|
2008-07-09 12:22:20 +04:00
|
|
|
|
2016-09-15 18:41:35 +03:00
|
|
|
void MediaError::GetMessage(nsAString& aResult) const {
|
2017-08-04 13:46:26 +03:00
|
|
|
// When fingerprinting resistance is enabled, only messages in this list
|
|
|
|
// can be returned to content script.
|
|
|
|
static const std::unordered_set<std::string> whitelist = {
|
|
|
|
"404: Not Found"
|
|
|
|
// TODO
|
|
|
|
};
|
|
|
|
|
|
|
|
bool shouldBlank = (whitelist.find(mMessage.get()) == whitelist.end());
|
|
|
|
|
|
|
|
if (shouldBlank) {
|
|
|
|
// Print a warning message to JavaScript console to alert developers of
|
|
|
|
// a non-whitelisted error message.
|
|
|
|
nsAutoCString message =
|
|
|
|
nsLiteralCString(
|
|
|
|
"This error message will be blank when "
|
|
|
|
"privacy.resistFingerprinting = true."
|
|
|
|
" If it is really necessary, please add it to the whitelist in"
|
|
|
|
" MediaError::GetMessage: ") +
|
|
|
|
mMessage;
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* ownerDoc = mParent->OwnerDoc();
|
2017-08-04 13:46:26 +03:00
|
|
|
AutoJSAPI api;
|
|
|
|
if (api.Init(ownerDoc->GetScopeObject())) {
|
|
|
|
// We prefer this API because it can also print to our debug log and
|
|
|
|
// try server's log viewer.
|
2019-04-06 01:52:04 +03:00
|
|
|
JS::WarnASCII(api.cx(), "%s", message.get());
|
2017-08-04 13:46:26 +03:00
|
|
|
} else {
|
2019-04-06 01:52:04 +03:00
|
|
|
// If failed to use JS::WarnASCII, fall back to
|
2017-08-04 13:46:26 +03:00
|
|
|
// nsContentUtils::ReportToConsoleNonLocalized, which can only print to
|
|
|
|
// JavaScript console.
|
|
|
|
nsContentUtils::ReportToConsoleNonLocalized(
|
|
|
|
NS_ConvertASCIItoUTF16(message), nsIScriptError::warningFlag,
|
|
|
|
"MediaError"_ns, ownerDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsContentUtils::IsCallerChrome() &&
|
2019-03-05 15:42:50 +03:00
|
|
|
nsContentUtils::ShouldResistFingerprinting(mParent->OwnerDoc()) &&
|
|
|
|
shouldBlank) {
|
2017-08-04 13:46:26 +03:00
|
|
|
aResult.Truncate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-10 17:56:09 +03:00
|
|
|
CopyUTF8toUTF16(mMessage, aResult);
|
2016-09-09 08:43:25 +03:00
|
|
|
}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* MediaError::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return MediaError_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-14 19:59:21 +04:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|