Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6f6005c3d | ||
|
|
f33c594827 | ||
|
|
5f4e7f21a0 | ||
|
|
272b8e43ac | ||
|
|
1ea0595e59 |
No files matched your search
@@ -30,6 +30,7 @@
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/dom/Clipboard.h"
|
||||
#ifdef MOZ_GAMEPAD
|
||||
#include "mozilla/dom/GamepadServiceTest.h"
|
||||
#endif
|
||||
@@ -1489,5 +1490,14 @@ Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow, nsIURI* aURI,
|
||||
return siteSpecificUA->GetUserAgentForURIAndWindow(aURI, aWindow, aUserAgent);
|
||||
}
|
||||
|
||||
Clipboard*
|
||||
Navigator::Clipboard()
|
||||
{
|
||||
if (!mClipboard) {
|
||||
mClipboard = new dom::Clipboard(GetWindow());
|
||||
}
|
||||
return mClipboard;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
@@ -37,6 +37,7 @@ class WakeLock;
|
||||
class ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
|
||||
class ServiceWorkerContainer;
|
||||
class DOMRequest;
|
||||
class Clipboard;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
@@ -210,6 +211,8 @@ public:
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<ServiceWorkerContainer> ServiceWorker();
|
||||
|
||||
dom::Clipboard* Clipboard();
|
||||
|
||||
void GetLanguages(nsTArray<nsString>& aLanguages);
|
||||
|
||||
@@ -263,6 +266,7 @@ private:
|
||||
RefPtr<DesktopNotificationCenter> mNotification;
|
||||
RefPtr<PowerManager> mPowerManager;
|
||||
RefPtr<network::Connection> mConnection;
|
||||
RefPtr<dom::Clipboard> mClipboard;
|
||||
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
||||
RefPtr<system::AudioChannelManager> mAudioChannelManager;
|
||||
#endif
|
||||
|
||||
@@ -156,6 +156,10 @@ DOMInterfaces = {
|
||||
'headerFile': 'mozilla/dom/workers/bindings/ServiceWorkerClients.h',
|
||||
},
|
||||
|
||||
'Clipboard' : {
|
||||
'implicitJSContext' : ['write', 'writeText', 'read', 'readText'],
|
||||
},
|
||||
|
||||
'console': {
|
||||
'nativeType': 'mozilla::dom::Console',
|
||||
},
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/AbstractThread.h"
|
||||
#include "mozilla/dom/Clipboard.h"
|
||||
#include "mozilla/dom/ClipboardBinding.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/DataTransfer.h"
|
||||
#include "mozilla/dom/DataTransferItemList.h"
|
||||
#include "mozilla/dom/DataTransferItem.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "nsIClipboard.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsITransferable.h"
|
||||
#include "nsArrayUtils.h"
|
||||
|
||||
|
||||
static mozilla::LazyLogModule gClipboardLog("Clipboard");
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
Clipboard::Clipboard(nsPIDOMWindowInner* aWindow)
|
||||
: DOMEventTargetHelper(aWindow)
|
||||
{
|
||||
}
|
||||
|
||||
Clipboard::~Clipboard()
|
||||
{
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Clipboard::ReadHelper(JSContext* aCx, nsIPrincipal& aSubjectPrincipal,
|
||||
ClipboardReadType aClipboardReadType, ErrorResult& aRv)
|
||||
{
|
||||
// Create a new promise
|
||||
RefPtr<Promise> p = dom::Promise::Create(GetOwnerGlobal(), aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// We always reject reading from clipboard for sec reasons.
|
||||
MOZ_LOG(GetClipboardLog(), LogLevel::Debug, ("Clipboard, ReadHelper, "
|
||||
"Don't have permissions for reading\n"));
|
||||
p->MaybeRejectWithUndefined();
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Clipboard::Read(JSContext* aCx, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv)
|
||||
{
|
||||
return ReadHelper(aCx, aSubjectPrincipal, eRead, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Clipboard::ReadText(JSContext* aCx, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv)
|
||||
{
|
||||
return ReadHelper(aCx, aSubjectPrincipal, eReadText, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Clipboard::Write(JSContext* aCx, DataTransfer& aData, nsIPrincipal& aSubjectPrincipal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
// Create a promise
|
||||
RefPtr<Promise> p = dom::Promise::Create(GetOwnerGlobal(), aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// We want to disable this if dom.allow_cut_copy is false, or
|
||||
// it doesn't meet the other requirements for copying to clipboard
|
||||
if (!nsContentUtils::IsCutCopyAllowed()) {
|
||||
MOZ_LOG(GetClipboardLog(), LogLevel::Debug,
|
||||
("Clipboard, Write, Not allowed to write to clipboard\n"));
|
||||
p->MaybeRejectWithUndefined();
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
// Get the clipboard service
|
||||
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1"));
|
||||
if (!clipboard) {
|
||||
p->MaybeRejectWithUndefined();
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
nsPIDOMWindowInner* owner = GetOwner();
|
||||
nsIDocument* doc = owner ? owner->GetDoc() : nullptr;
|
||||
nsILoadContext* context = doc ? doc->GetLoadContext() : nullptr;
|
||||
if (!context) {
|
||||
p->MaybeRejectWithUndefined();
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
// Get the transferable
|
||||
RefPtr<nsITransferable> transferable = aData.GetTransferable(0, context);
|
||||
if (!transferable) {
|
||||
p->MaybeRejectWithUndefined();
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
// Create a runnable
|
||||
RefPtr<nsIRunnable> r = NS_NewRunnableFunction(
|
||||
[transferable, p, clipboard]() {
|
||||
nsresult rv = clipboard->SetData(transferable,
|
||||
/* owner of the transferable */ nullptr,
|
||||
nsIClipboard::kGlobalClipboard);
|
||||
if (NS_FAILED(rv)) {
|
||||
p->MaybeRejectWithUndefined();
|
||||
return;
|
||||
}
|
||||
p->MaybeResolveWithUndefined();
|
||||
return;
|
||||
});
|
||||
// Dispatch the runnable
|
||||
NS_DispatchToCurrentThread(r.forget());
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Clipboard::WriteText(JSContext* aCx, const nsAString& aData,
|
||||
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv)
|
||||
{
|
||||
// We create a data transfer with text/plain format so that
|
||||
// we can reuse the Clipboard::Write(...) member function
|
||||
// We want isExternal = true in order to use the data transfer object to perform a write
|
||||
RefPtr<DataTransfer> dataTransfer = new DataTransfer(this, eCopy,
|
||||
/* is external */ true,
|
||||
/* clipboard type */ -1);
|
||||
dataTransfer->SetData(NS_LITERAL_STRING(kTextMime), aData, aSubjectPrincipal, aRv);
|
||||
return Write(aCx, *dataTransfer, aSubjectPrincipal, aRv);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
Clipboard::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return ClipboardBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
/* static */ LogModule*
|
||||
Clipboard::GetClipboardLog()
|
||||
{
|
||||
return gClipboardLog;
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(Clipboard)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Clipboard,
|
||||
DOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Clipboard,
|
||||
DOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Clipboard)
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(Clipboard, DOMEventTargetHelper)
|
||||
NS_IMPL_RELEASE_INHERITED(Clipboard, DOMEventTargetHelper)
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
@@ -0,0 +1,60 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_Clipboard_h_
|
||||
#define mozilla_dom_Clipboard_h_
|
||||
|
||||
#include "nsString.h"
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/dom/DataTransfer.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
enum ClipboardReadType {
|
||||
eRead,
|
||||
eReadText,
|
||||
};
|
||||
|
||||
class Promise;
|
||||
|
||||
// https://www.w3.org/TR/clipboard-apis/#clipboard-interface
|
||||
class Clipboard : public DOMEventTargetHelper
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Clipboard,
|
||||
DOMEventTargetHelper)
|
||||
|
||||
IMPL_EVENT_HANDLER(message)
|
||||
//IMPL_EVENT_HANDLER(messageerror)
|
||||
|
||||
explicit Clipboard(nsPIDOMWindowInner* aWindow);
|
||||
already_AddRefed<Promise> Read(JSContext* aCx, nsIPrincipal& aSubjectPrincipal,
|
||||
ErrorResult& aRv);
|
||||
already_AddRefed<Promise> ReadText(JSContext* aCx, nsIPrincipal& aSubjectPrincipal,
|
||||
ErrorResult& aRv);
|
||||
already_AddRefed<Promise> Write(JSContext* aCx, DataTransfer& aData,
|
||||
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv);
|
||||
already_AddRefed<Promise> WriteText(JSContext* aCx, const nsAString& aData,
|
||||
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv);
|
||||
|
||||
static LogModule* GetClipboardLog();
|
||||
|
||||
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
private:
|
||||
already_AddRefed<Promise> ReadHelper(JSContext* aCx, nsIPrincipal& aSubjectPrincipal,
|
||||
ClipboardReadType aClipboardReadType, ErrorResult& aRv);
|
||||
|
||||
~Clipboard();
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
#endif // mozilla_dom_Clipboard_h_
|
||||
@@ -0,0 +1,85 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/dom/ClipboardItem.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/Record.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
||||
ClipboardItem::ItemEntry& aField,
|
||||
const char* aName, uint32_t aFlags = 0) {
|
||||
ImplCycleCollectionTraverse(aCallback, aField.mBlob, aName, aFlags);
|
||||
}
|
||||
|
||||
void ImplCycleCollectionUnlink(ClipboardItem::ItemEntry& aField) {
|
||||
ImplCycleCollectionUnlink(aField.mBlob);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ClipboardItem, mOwner, mItems)
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(ClipboardItem, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(ClipboardItem, Release)
|
||||
|
||||
ClipboardItem::ClipboardItem(nsISupports* aOwner,
|
||||
const dom::PresentationStyle aPresentationStyle,
|
||||
nsTArray<ItemEntry>&& aItems)
|
||||
: mOwner(aOwner),
|
||||
mPresentationStyle(aPresentationStyle),
|
||||
mItems(std::move(aItems)) {}
|
||||
|
||||
// static
|
||||
already_AddRefed<ClipboardItem> ClipboardItem::Constructor(
|
||||
const GlobalObject& aGlobal,
|
||||
const Record<nsString, OwningNonNull<Blob>>& aItems,
|
||||
const ClipboardItemOptions& aOptions, ErrorResult& aRv) {
|
||||
if (aItems.Entries().IsEmpty()) {
|
||||
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsTArray<ItemEntry> items;
|
||||
for (const auto& entry : aItems.Entries()) {
|
||||
ItemEntry* item = items.AppendElement();
|
||||
item->mType = entry.mKey;
|
||||
item->mBlob = entry.mValue;
|
||||
}
|
||||
|
||||
RefPtr<ClipboardItem> item = new ClipboardItem(
|
||||
aGlobal.GetAsSupports(), aOptions.mPresentationStyle, std::move(items));
|
||||
return item.forget();
|
||||
}
|
||||
|
||||
void ClipboardItem::GetTypes(nsTArray<nsString>& aTypes) const {
|
||||
for (const auto& item : mItems) {
|
||||
aTypes.AppendElement(item.mType);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> ClipboardItem::GetType(const nsAString& aType,
|
||||
ErrorResult& aRv) {
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
|
||||
RefPtr<Promise> p = Promise::Create(global, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (const auto& item : mItems) {
|
||||
if (item.mType == aType) {
|
||||
p->MaybeResolve(item.mBlob);
|
||||
return p.forget();
|
||||
}
|
||||
}
|
||||
|
||||
p->MaybeReject(NS_ERROR_UNEXPECTED);
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
ClipboardItem::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
||||
return ClipboardItemBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom
|
||||
@@ -0,0 +1,61 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_ClipboardItem_h_
|
||||
#define mozilla_dom_ClipboardItem_h_
|
||||
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/ClipboardBinding.h"
|
||||
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
struct ClipboardItemOptions;
|
||||
template <typename KeyType, typename ValueType>
|
||||
class Record;
|
||||
class Promise;
|
||||
|
||||
class ClipboardItem final : public nsWrapperCache {
|
||||
public:
|
||||
struct ItemEntry {
|
||||
nsString mType;
|
||||
RefPtr<Blob> mBlob;
|
||||
};
|
||||
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ClipboardItem)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(ClipboardItem)
|
||||
|
||||
ClipboardItem(nsISupports* aOwner, dom::PresentationStyle aPresentationStyle,
|
||||
nsTArray<ItemEntry>&& aItems);
|
||||
|
||||
static already_AddRefed<ClipboardItem> Constructor(
|
||||
const GlobalObject& aGlobal,
|
||||
const Record<nsString, OwningNonNull<Blob>>& aItems,
|
||||
const ClipboardItemOptions& aOptions, ErrorResult& aRv);
|
||||
|
||||
dom::PresentationStyle PresentationStyle() const {
|
||||
return mPresentationStyle;
|
||||
};
|
||||
void GetTypes(nsTArray<nsString>& aTypes) const;
|
||||
|
||||
already_AddRefed<Promise> GetType(const nsAString& aType, ErrorResult& aRv);
|
||||
|
||||
nsISupports* GetParentObject() const { return mOwner; }
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
private:
|
||||
~ClipboardItem() = default;
|
||||
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
dom::PresentationStyle mPresentationStyle;
|
||||
nsTArray<ItemEntry> mItems;
|
||||
};
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
||||
#endif // mozilla_dom_ClipboardItem_h_
|
||||
@@ -1204,16 +1204,12 @@ DataTransfer::ConvertFromVariant(nsIVariant* aVariant,
|
||||
return true;
|
||||
}
|
||||
|
||||
char16_t* chrs;
|
||||
uint32_t len = 0;
|
||||
nsresult rv = aVariant->GetAsWStringWithSize(&len, &chrs);
|
||||
nsAutoString str;
|
||||
nsresult rv = aVariant->GetAsAString(str);
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsAutoString str;
|
||||
str.Adopt(chrs, len);
|
||||
|
||||
nsCOMPtr<nsISupportsString>
|
||||
strSupports(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
||||
if (!strSupports) {
|
||||
@@ -1225,7 +1221,7 @@ DataTransfer::ConvertFromVariant(nsIVariant* aVariant,
|
||||
strSupports.forget(aSupports);
|
||||
|
||||
// each character is two bytes
|
||||
*aLength = str.Length() << 1;
|
||||
*aLength = str.Length() * 2;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1410,9 +1406,7 @@ DataTransfer::CacheExternalClipboardFormats()
|
||||
return;
|
||||
}
|
||||
|
||||
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
||||
nsCOMPtr<nsIPrincipal> sysPrincipal;
|
||||
ssm->GetSystemPrincipal(getter_AddRefs(sysPrincipal));
|
||||
nsCOMPtr<nsIPrincipal> sysPrincipal = nsContentUtils::GetSystemPrincipal();
|
||||
|
||||
// Check if the clipboard has any files
|
||||
bool hasFileData = false;
|
||||
|
||||
@@ -315,6 +315,7 @@ protected:
|
||||
uint32_t aIndex, nsIPrincipal* aSubjectPrincipal);
|
||||
|
||||
friend class ContentParent;
|
||||
friend class Clipboard;
|
||||
|
||||
void FillAllExternalData();
|
||||
|
||||
|
||||
@@ -152,7 +152,8 @@ DataTransferItemList::Add(const nsAString& aData,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIVariant> data(new storage::TextVariant(aData));
|
||||
RefPtr<nsVariantCC> data(new nsVariantCC());
|
||||
data->SetAsAString(aData);
|
||||
|
||||
nsAutoString format;
|
||||
mDataTransfer->GetRealFormat(aType, format);
|
||||
|
||||
@@ -37,7 +37,9 @@ EXPORTS.mozilla.dom += [
|
||||
'AnimationEvent.h',
|
||||
'BeforeAfterKeyboardEvent.h',
|
||||
'BeforeUnloadEvent.h',
|
||||
'Clipboard.h',
|
||||
'ClipboardEvent.h',
|
||||
'ClipboardItem.h',
|
||||
'CommandEvent.h',
|
||||
'CompositionEvent.h',
|
||||
'ConstructibleEventTarget.h',
|
||||
@@ -78,7 +80,9 @@ UNIFIED_SOURCES += [
|
||||
'AsyncEventDispatcher.cpp',
|
||||
'BeforeAfterKeyboardEvent.cpp',
|
||||
'BeforeUnloadEvent.cpp',
|
||||
'Clipboard.cpp',
|
||||
'ClipboardEvent.cpp',
|
||||
'ClipboardItem.cpp',
|
||||
'CommandEvent.cpp',
|
||||
'CompositionEvent.cpp',
|
||||
'ConstructibleEventTarget.cpp',
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* http://www.w3.org/TR/geolocation-API
|
||||
*
|
||||
* Copyright © 2018 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
|
||||
[SecureContext, Exposed=Window, Pref="dom.events.asyncClipboard"]
|
||||
interface Clipboard : EventTarget {
|
||||
[Pref="dom.events.asyncClipboard.dataTransfer", Throws, NeedsSubjectPrincipal]
|
||||
Promise<DataTransfer> read();
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
Promise<DOMString> readText();
|
||||
[Pref="dom.events.asyncClipboard.dataTransfer", Throws, NeedsSubjectPrincipal]
|
||||
Promise<void> write(DataTransfer data);
|
||||
[Throws, NeedsSubjectPrincipal]
|
||||
Promise<void> writeText(DOMString data);
|
||||
};
|
||||
|
||||
|
||||
// Note: The spec uses ClipboardItemData instead of Blob.
|
||||
// All current implementers however use Blob. Spec change needed.
|
||||
// typedef (DOMString or Blob) ClipboardItemDataType;
|
||||
// typedef Promise<ClipboardItemDataType> ClipboardItemData;
|
||||
// callback ClipboardItemDelayedCallback = ClipboardItemData ();
|
||||
|
||||
[Constructor(record<DOMString, Blob> items, optional ClipboardItemOptions options),
|
||||
SecureContext, Exposed=Window, Pref="dom.events.asyncClipboard.clipboardItem"]
|
||||
interface ClipboardItem {
|
||||
// NYI:
|
||||
// static ClipboardItem createDelayed(
|
||||
// record<DOMString, ClipboardItemDelayedCallback> items,
|
||||
// optional ClipboardItemOptions options = {});
|
||||
|
||||
readonly attribute PresentationStyle presentationStyle;
|
||||
// NYI:
|
||||
// readonly attribute long long lastModified;
|
||||
// readonly attribute boolean delayed;
|
||||
|
||||
// TODO: Use FrozenArray once available. (Bug 1236777)
|
||||
// readonly attribute FrozenArray<DOMString> types;
|
||||
[Frozen, Cached, Pure]
|
||||
readonly attribute sequence<DOMString> types;
|
||||
|
||||
[Throws]
|
||||
Promise<Blob> getType(DOMString type);
|
||||
};
|
||||
|
||||
enum PresentationStyle { "unspecified", "inline", "attachment" };
|
||||
|
||||
dictionary ClipboardItemOptions {
|
||||
PresentationStyle presentationStyle = "unspecified";
|
||||
};
|
||||
@@ -308,3 +308,9 @@ partial interface Navigator {
|
||||
interface NavigatorConcurrentHardware {
|
||||
readonly attribute unsigned long long hardwareConcurrency;
|
||||
};
|
||||
|
||||
// https://www.w3.org/TR/clipboard-apis/#navigator-interface
|
||||
partial interface Navigator {
|
||||
[Pref="dom.events.asyncClipboard", SecureContext, SameObject]
|
||||
readonly attribute Clipboard clipboard;
|
||||
};
|
||||
@@ -72,6 +72,7 @@ WEBIDL_FILES = [
|
||||
'ChromeUtils.webidl',
|
||||
'Client.webidl',
|
||||
'Clients.webidl',
|
||||
'Clipboard.webidl',
|
||||
'ClipboardEvent.webidl',
|
||||
'CommandEvent.webidl',
|
||||
'Comment.webidl',
|
||||
|
||||
@@ -5100,3 +5100,10 @@ pref("media.sourceErrorDetails.enabled", true);
|
||||
#else
|
||||
pref("media.sourceErrorDetails.enabled", false);
|
||||
#endif
|
||||
|
||||
// Whether Navigator.Clipboard methods are a thing.
|
||||
pref("dom.events.asyncClipboard", false);
|
||||
// Whether arbitrary data transfer methods (not plaintext) are allowed.
|
||||
pref("dom.events.asyncClipboard.dataTransfer", false);
|
||||
// Whether to use ClipboardItem spec or not.
|
||||
pref("dom.events.asyncClipboard.clipboardItem", false);
|
||||
@@ -229,14 +229,15 @@ private:
|
||||
mResolveValues.SetLength(aDependentPromises);
|
||||
}
|
||||
|
||||
void Resolve(size_t aIndex, ResolveValueType&& aResolveValue)
|
||||
{
|
||||
template <typename ResolveValueType_>
|
||||
void Resolve(size_t aIndex, ResolveValueType_&& aResolveValue) {
|
||||
if (!mPromise) {
|
||||
// Already rejected.
|
||||
return;
|
||||
}
|
||||
|
||||
mResolveValues[aIndex].emplace(Move(aResolveValue));
|
||||
mResolveValues[aIndex].emplace(
|
||||
std::forward<ResolveValueType_>(aResolveValue));
|
||||
if (--mOutstandingPromises == 0) {
|
||||
nsTArray<ResolveValueType> resolveValues;
|
||||
resolveValues.SetCapacity(mResolveValues.Length());
|
||||
@@ -250,14 +251,14 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void Reject(RejectValueType&& aRejectValue)
|
||||
{
|
||||
template <typename RejectValueType_>
|
||||
void Reject(RejectValueType_&& aRejectValue) {
|
||||
if (!mPromise) {
|
||||
// Already rejected.
|
||||
return;
|
||||
}
|
||||
|
||||
mPromise->Reject(Move(aRejectValue), __func__);
|
||||
mPromise->Reject(std::forward<RejectValueType_>(aRejectValue), __func__);
|
||||
mPromise = nullptr;
|
||||
mResolveValues.Clear();
|
||||
}
|
||||
@@ -269,6 +270,15 @@ private:
|
||||
RefPtr<typename AllPromiseType::Private> mPromise;
|
||||
size_t mOutstandingPromises;
|
||||
};
|
||||
|
||||
typedef std::conditional_t<IsExclusive, ResolveValueType&&,
|
||||
const ResolveValueType&>
|
||||
ResolveValueTypeParam;
|
||||
|
||||
typedef std::conditional_t<IsExclusive, RejectValueType&&,
|
||||
const RejectValueType&>
|
||||
RejectValueTypeParam;
|
||||
|
||||
public:
|
||||
|
||||
static RefPtr<AllPromiseType> All(AbstractThread* aProcessingThread, nsTArray<RefPtr<MozPromise>>& aPromises)
|
||||
@@ -276,8 +286,8 @@ public:
|
||||
RefPtr<AllPromiseHolder> holder = new AllPromiseHolder(aPromises.Length());
|
||||
for (size_t i = 0; i < aPromises.Length(); ++i) {
|
||||
aPromises[i]->Then(aProcessingThread, __func__,
|
||||
[holder, i] (ResolveValueType aResolveValue) -> void { holder->Resolve(i, Move(aResolveValue)); },
|
||||
[holder] (RejectValueType aRejectValue) -> void { holder->Reject(Move(aRejectValue)); }
|
||||
[holder, i] (ResolveValueTypeParam aResolveValue) -> void { holder->Resolve(i, Move(aResolveValue)); },
|
||||
[holder] (RejectValueTypeParam aRejectValue) -> void { holder->Reject(Move(aRejectValue)); }
|
||||
);
|
||||
}
|
||||
return holder->Promise();
|
||||
|
||||
Reference in new issue
Block a user