mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
7adb8133f5
- missing bit of 989499 and some other files (23b0597ba6) - Bug 1233666 - Remove hacks for getting frame pointer for x86/x64 gcc. r=glandium (bfe8f59916) - Bug 1176266: In TimeStamp_posix.cpp, check for XP_LINUX instead of LINUX, and add missing #include, to allow strrchr usage. r=BenWa (56c725cffa) - Bug 1167230 - Don't pack ProfileEntry on ARM. r=shu (89f880e0cb) - Bug 1209779 - Ensure that all null elements are written when streaming profiler JSON; r=shu (2bae5addc6) - missing bit of Bug 1141712 - Make LUL (55f1276545) - Bug 1061800 - Add breakpad ids to profiler in Linux. r=BenWa (994fd1a941) - Bug 829621 - Compute the breakpad-id for OS X. r=BenWa. (e129580174) - missing of Bug 938157 - Lightweight CFI/EXIDX (b355dc3140) - Bug 1193838 - Allow ProfileGatherer to gather profiles from exiting processes. r=BenWa (5ab1a6a3c9) - align some missing stuff (5ebecd2364) - align some missing stuff (b8ff7aa361) - Bug 1164315 - Update key fingerprint for bitbucket.org; r=me (c1a3fbd930) - Bug 1178955 - Refactor config path selection; r=smacleod (89552bb0ac) - Bug 1195445 - Update host key fingerprint for bugzilla.mozilla.org (3783541088) - Bug 1218903 - Update bmo fingerprint. r=fubar, a=Tomcat (5b836fc585) - Bug 1178955 - Print config path on failure; r=smacleod (f5499f3771) - Bug 1185113 - Support setting more secure file permissions; r=smacleod (7dbf6b22fd) - Bug 1184229 - Detect multiple version-control-tools repos in Mercurial config; r=smacleod (16c24072a9) - Bug 978514 - mach mercurial-setup: Use mqext from the version-control-tools repo (1fa5765e8a) - Bug 1178955 - Don't pass config paths to updater; r=smacleod (80fcb05121) - Bug 1197527 - Don't unnecessarily attempt to create extensions directory in MercurialUpdater; r=gps (9b049c3ff8) - Bug 1164812 - mach mercurial-setup: Always mark the v-c-t repo as needing update (bd631208bd) - Bug 1197527 - Always clone version-control-tools in MercurialSetupWizard; r=gps (6990e8f589) - Bug 1197527 - Consolidate obtaining hg path into mozversioncontrol.get_hg_path; r=gps (e0b029a8e9) - Bug 1200458 - Skip permission check for .hgrc on Windows in hgsetup wizard. r=gps DONTBUILD (cc5b0d6daf) - Bug 1168466 - Bump minimum Mercurial version; r=smacleod (7fde47cfbe) - Bug 1185113 - Clarify language around Bugzilla credentials; r=smacleod (9166fdfbf9) - Bug 1185112 - Don't prompt for Bugzilla username/password if cookies defined; r=smacleod (cd87c96823) - Bug 1188931 - Fix hgsetup wizard. r=gps (68a6b46be4) - Bug 1200461 - Prompt for Bugzilla API Key instead of password; r=smacleod (780fb5d85d) - Bug 1228580 - ./mach mercurial-setup should use ~ to set up extension paths, not my literal home directory. r=gps (7a0c839880) - Bug 1231192 - Mark Mercurial 3.5.2 as oldest non-legacy version; r=smacleod (8f69483333) - Bug 1231192 - Bump some minimum Mercurial version; r=smacleod (916c56a852) - Bug 1162093 - Add "push-to-try" from version-control-tools to the mercurial setup wizard prompt.;r=gps (d29c7cf63a) - Bug 1168466 - Prompt to install bundleclone extension; r=smacleod (780ce90a08) - Bug 1185557 - Print relevant config options; r=smacleod (2f3f7e0161) - Bug 1231192 - Support clonebundles feature; r=smacleod (dcba1ccd34) - Bug 1231192 - Offer to install hg wip; r=smacleod (c42ebce5c8) - Bug 1231192 - Only install host fingerprints if not running secure Python+hg; r=smacleod (3154a2497b) - Bug 1178955 - Error when semicolon comments are seen; r=smacleod (e1f7081bb6) - Bug 1231989 - Prompt to install hgwatchman extension; r=ahal (0eddf0c1c8) - Bug 1178955 - Print line number for parse errors; r=smacleod (5369468cf1) - Bug 1185557 - Only prompt to install progress on Mercurial <3.5; r=smacleod (401f362265) - Bug 1232747 - Check for ssl.SSLContext existence; r=dminor (d505b07c5c) - Bug 1144629 - UnicodeDecodeError in ./mach mercurial-setup. r=gps, r=glandium (611d3ec83e) - Bug 1216970 - Make the copying more obvious in ProfilerImpl::GetStacktrace. r=froydnj (085625e113) - Bug 1190466 - tools/rb/find-leakers.pl re-written in Python r=mccr8 (4bfdcad13e) - Bug 1116478 - Open web content handlers in the proper tab in e10s. r=billm (ff8e11f45e) - Bug 1213437 - Less data copying when handling structured clones in MessageManager, r=baku (c4e2a13253) - const-var (69d17f312d) - Bug 1203090 - Ensure we always use '/' as the starting path separator for the DOM path of the Directorys initially returned by HTMLInputElement.getFilesAndDirectories. r=baku (1325bbc40c) - Bug 1209975 - Stop using dom::Promise::MaybeRejectBrokenly() in GetDirectoryListingTask. r=baku (2106790950) - Bug 1209924 - Implement a general filtering mechanism for Directory::GetFilesAndDirectories, and add filtering of sensitive files/directories. r=baku (27b4a26262) - Force a repaint after DXGI device resets. (bug 1188019, r=bas) (09c999e6e5) - Bug 1163911 - Make responsive images block the document load event while the load task is queued. r=jst (0ee0e3db79) - Bug 1166138 - Make img srcset react to resize/viewport changes, r=jdm (91674519e6) - Bug 1194893 - Pref for default file upload directory. r=smaug (ec6d33d983) - bug 1116409: switch update server to sha2 cert; update in-tree pinning. r=rstrong,snorp,mfinkle,dkeeler (7c8f631f27) - bug 1116409: fix cert pinning on backup cert for aus5.mozilla.org. r=typofix (3c690cbc6d) - Bug 1167048 - Change default font for Thai script from serif to sans-serif. r=smontagu (15dc86c389) - Bug 1205570 - fix up font prefs for x-math lang group. r=heycam (03f1820752) - Bug 1071769: Use DrawTargetTiled on B2G. r=Bas (b80ce768f1) - fix misspatch of 1149343 (541dd7aac8) - Bug 1199766 - Disable ICE TCP SO gathering via user pref. r=bwc (80cdc9c662) - Bug 1187472 - only log UDP and TCP candidate gathering failures. r=bwc (bc3dcb02d0) - Bug 1190615 - Skip non-UDP STUN servers for UDP sockets. r=bwc (a2d1d914b5) - Bug 1187775 - skip host and reflexive ICE candidates if relay-only. r=bwc (7e2cba1685) - Bug 1185198 - use port 9 for TCP active candidates. r=bwc (0a89cb199d) - Bug 1177921 - Fix typo in STUN server name. r=drno (1ad43ced6b) - Bug 1178349 - Enable ice_unittests on desktop linux on CI. r=bwc (ce5ece8264) - Bug 1189041 - Add option to only gather addresses for default route. r=bwc (3651f2ff06) - Bug 1189040: add a whitelist for network interfaces to use with ICE/webrtc r=ekr (6f693af72c) - Bug 1189198 - don't start STUN transactions with a protocol mis-match. r=mtseng (a3b410e2a8) - Bug 1208096 - Handle various failure cases for TURN gathering better. r=drno (1d8e173448) - Bug 1211389 - Make absolutely sure the relay->srflx pointer doesn't dangle. r=drno (d59b0bf08d) - Bug 1215616: use base address for server rflx ICE candidates r=bwc (89d07331ac) - Bug 1207451 - removed framing from multi_tcp API. r=bwc (317f40f490) - Bug 1186590 - Part 1 - Enable interface prioritizer on all platforms. r=drno (036a69fdb3) - Bug 1194019 - New defaults for gather tests. r=bwc (8343ceab56) - Bug 1144933: Only check that remote candidate is loopback in TestLoopbackOnlySortOf. r=drno (1f53d824e4) - Bug 1186590 - Part 2 - Move hard-coded interface priority list into nrinterfaceprioritizer, and simplify some functions. r=drno (9f20fad21b) - Bug 1152137 - Part 1: Test case. r=ekr (6b50f06d90) - Bug 1152137 - Part 2: Remove attributes that could not be initted properly instead of just freeing them. r=ekr (ccdf81294a) - Bug 1200763 - Remove hard-coded STUN IP address from ice_unittest, and do a DNS lookup instead. r=drno (ae54a83363) - Bug 1208176 - Part 1: Add a couple of interface names. r=drno (b7ead0b476) - Bug 1208176 - Part 2: Add a one-sided trickle test case to ice_unittest. r=drno (ad6afedb1c) - Bug 1037618 - Relax candidate verification for TCP. r=bwc (0cad14c89e) - Bug 1208176 - Part 3: Be forgiving when we see prflx instead of host candidates in ice_unittest. r=drno (50bdec2ba3) - Bug 1035428: Re-register writeable callback after partially servicing the send queue. r=drno (2fdb7880fa) - Bug 1135753 - Mark some overridden virtual functions in WebRTC as MOZ_OVERRIDE; r=mt (97f451c97d) - Bug 950660: Part 4: Bridge TCPSocketChild to nr_socket r=bwc,jdm (654587b321) - Bug 971357: Log STUN responses at INFO instead of DEBUG. r=ekr (81b500df17) - Bug 1006809 - update triggered check behavior to RFC 5245. r+bwc r=mjf (31b718b5e5) - Bug 1208278 - improved STUN request timeout handling. r=bwc (cf470fb12f) - Bug 1142964 - Fix ICE tiebreaker on Windows. r=bwc (0d2fd78252) - Bug 1219557 - don't pair candidates from different reserved networks. r=mt r=bwc (24d3e5106c) - Bug 1220441 - Improve gather trickle ice unit tests. r=bwc r=mjf (96f76c6c8c) - Bug 1205421 - fix DNS resolution of STUN server in ice_unittest. r=bwc (5d5b153358) - Bug 1206465 - removed ice_ctx from TestStunTcpServer. r=bwc (9a0df03894) - ug 1008792 - Check for valid pointer before using. r=bwc (7660fd0a71) - Bug 1233101 - Use MOZ_LIKELY in js_new etc to help branch prediction; r=terrence (31fb244734) - Bug 1225565 - Fix module import cycle detection r=shu (370dc26ee8) - Bug 1225558 - Improve module error messages r=shu (83b6038bb3) - Bug 1225561 - Don't allow a module to export non-existent local bindings r=shu (41f065891a) - Bug 1233124 - Remove mis-named duplicate typedefs for rooted import and export entries r=terrence (17a60bdb39) - Bug 1208464 - Implement proposed ES7 functions Object.values and Object.entries. r=evilpie (615193d0fb) - Bug 1226549 - added assert check for matches pointer in for prevent null dereference. r=hv1989 (d321ad0385) - Bug 1232113 - "Make the format specifiers in JS_snprintf() invocations more portable". r=jcoppeard (7c58b79a53) - Bug 1232446 - Re-enable method calls in SelfHosted code using new anti-content checks. (r=till) (ba7dc22ff8) - Bug 1232159 - Stop using pseudo-Uint32Array in SelfHosted code. (r=till) (c325f8ff58) - Bug 1226235 - Print file and line info for failing assert in self-hosted code. r=efaust (4a8d54d38b) - fix misspatch (fca2efc1f1) - Bug 1186003 - Switch automated builds to Gtk+3. r=mshal (658ad843b7) - Bug 1181342 - tooltool manifests and build-clang config for clang 3.6 r=rail (6264b4df68) - Bug 1181342 - Follow up to use the unpack feature of tooltool instead of setup.sh r=glandium (96bb3b2062) - Bug 1181255 - Mozconfigs for tsan builds. r=glandium (19250f4cc1) - Bug 1181255 - Get tsan builds on gtk3. r=glandium (e5ffd1c02f) - Bug 1187664 - Create a fontconfig cache so that Firefox doesn't have to do it itself when run on build automation. r=mshal (8ce567bd4c) - Bug 1188780 - Include debug symbols in gtk3 tooltool package. r=mshal (a5b573aa58) - Bug 1188780: remove setup.sh invocations, as they fail outside the mock environment; r=glandium a=RyanVM (058e306cac) - Bug 1178513 - Fix non-unified bustage. r=wchen (543d1e5497) - Bug 1162789 - Add a comment explaining why mForm is not set to null during unlink (eaa2a82048) - Bug 1189655 - Define MOZ_HAVE_CXX11_CONSTEXPR on VS2015 or later. r=Waldo (2d134e3b41) - Bug 1231758 - Fix bogus assertion in BCE for Annex B function assignment. (r=jorendorff) (701b2530b9) - Bug 1233100 - Ensure that derived constructor bad return value errors are thrown before leaving the containing block. (r=shu) (52f5bcf0a5) - Bug 1232022, 1232449 - Address forgotten review nits and fix bogus error message. (rs=Waldo) (dfd9d5e388) - Bug 1233121 - Refactor ObjectBox tracing r=terrence (876a140535) - Bug 1231647 - Check for duplicate exported let and const in modules r=shu (99f53ad443)
1416 lines
40 KiB
C++
1416 lines
40 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/ArrayUtils.h"
|
|
#include "mozilla/BasicEvents.h"
|
|
|
|
#include "DataTransfer.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
#include "nsISupportsPrimitives.h"
|
|
#include "nsIScriptSecurityManager.h"
|
|
#include "mozilla/dom/DOMStringList.h"
|
|
#include "nsError.h"
|
|
#include "nsIDragService.h"
|
|
#include "nsIClipboard.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsIContent.h"
|
|
#include "nsCRT.h"
|
|
#include "nsIScriptObjectPrincipal.h"
|
|
#include "nsIScriptContext.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsIScriptGlobalObject.h"
|
|
#include "nsVariant.h"
|
|
#include "mozilla/dom/ContentChild.h"
|
|
#include "mozilla/dom/DataTransferBinding.h"
|
|
#include "mozilla/dom/Directory.h"
|
|
#include "mozilla/dom/Element.h"
|
|
#include "mozilla/dom/FileList.h"
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
#include "mozilla/dom/OSFileSystem.h"
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
inline void
|
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
|
TransferItem& aField,
|
|
const char* aName,
|
|
uint32_t aFlags = 0)
|
|
{
|
|
ImplCycleCollectionTraverse(aCallback, aField.mData, aName, aFlags);
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DataTransfer)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DataTransfer)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFiles)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mItems)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDragTarget)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDragImage)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DataTransfer)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFiles)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mItems)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDragTarget)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDragImage)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(DataTransfer)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DataTransfer)
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DataTransfer)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DataTransfer)
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::dom::DataTransfer)
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDataTransfer)
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDataTransfer)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
// the size of the array
|
|
const char DataTransfer::sEffects[8][9] = {
|
|
"none", "copy", "move", "copyMove", "link", "copyLink", "linkMove", "all"
|
|
};
|
|
|
|
DataTransfer::DataTransfer(nsISupports* aParent, EventMessage aEventMessage,
|
|
bool aIsExternal, int32_t aClipboardType)
|
|
: mParent(aParent)
|
|
, mDropEffect(nsIDragService::DRAGDROP_ACTION_NONE)
|
|
, mEffectAllowed(nsIDragService::DRAGDROP_ACTION_UNINITIALIZED)
|
|
, mEventMessage(aEventMessage)
|
|
, mCursorState(false)
|
|
, mReadOnly(true)
|
|
, mIsExternal(aIsExternal)
|
|
, mUserCancelled(false)
|
|
, mIsCrossDomainSubFrameDrop(false)
|
|
, mClipboardType(aClipboardType)
|
|
, mDragImageX(0)
|
|
, mDragImageY(0)
|
|
{
|
|
// For these events, we want to be able to add data to the data transfer, so
|
|
// clear the readonly state. Otherwise, the data is already present. For
|
|
// external usage, cache the data from the native clipboard or drag.
|
|
if (aEventMessage == eCut ||
|
|
aEventMessage == eCopy ||
|
|
aEventMessage == eDragStart ||
|
|
aEventMessage == eLegacyDragGesture) {
|
|
mReadOnly = false;
|
|
} else if (mIsExternal) {
|
|
if (aEventMessage == ePaste) {
|
|
CacheExternalClipboardFormats();
|
|
} else if (aEventMessage >= eDragDropEventFirst &&
|
|
aEventMessage <= eDragDropEventLast) {
|
|
CacheExternalDragFormats();
|
|
}
|
|
}
|
|
}
|
|
|
|
DataTransfer::DataTransfer(nsISupports* aParent,
|
|
EventMessage aEventMessage,
|
|
const uint32_t aEffectAllowed,
|
|
bool aCursorState,
|
|
bool aIsExternal,
|
|
bool aUserCancelled,
|
|
bool aIsCrossDomainSubFrameDrop,
|
|
int32_t aClipboardType,
|
|
nsTArray<nsTArray<TransferItem> >& aItems,
|
|
Element* aDragImage,
|
|
uint32_t aDragImageX,
|
|
uint32_t aDragImageY)
|
|
: mParent(aParent)
|
|
, mDropEffect(nsIDragService::DRAGDROP_ACTION_NONE)
|
|
, mEffectAllowed(aEffectAllowed)
|
|
, mEventMessage(aEventMessage)
|
|
, mCursorState(aCursorState)
|
|
, mReadOnly(true)
|
|
, mIsExternal(aIsExternal)
|
|
, mUserCancelled(aUserCancelled)
|
|
, mIsCrossDomainSubFrameDrop(aIsCrossDomainSubFrameDrop)
|
|
, mClipboardType(aClipboardType)
|
|
, mItems(aItems)
|
|
, mDragImage(aDragImage)
|
|
, mDragImageX(aDragImageX)
|
|
, mDragImageY(aDragImageY)
|
|
{
|
|
MOZ_ASSERT(mParent);
|
|
// The items are copied from aItems into mItems. There is no need to copy
|
|
// the actual data in the items as the data transfer will be read only. The
|
|
// draggesture and dragstart events are the only times when items are
|
|
// modifiable, but those events should have been using the first constructor
|
|
// above.
|
|
NS_ASSERTION(aEventMessage != eLegacyDragGesture &&
|
|
aEventMessage != eDragStart,
|
|
"invalid event type for DataTransfer constructor");
|
|
}
|
|
|
|
DataTransfer::~DataTransfer()
|
|
{}
|
|
|
|
// static
|
|
already_AddRefed<DataTransfer>
|
|
DataTransfer::Constructor(const GlobalObject& aGlobal,
|
|
const nsAString& aEventType, bool aIsExternal,
|
|
ErrorResult& aRv)
|
|
{
|
|
nsAutoCString onEventType("on");
|
|
AppendUTF16toUTF8(aEventType, onEventType);
|
|
nsCOMPtr<nsIAtom> eventTypeAtom = do_GetAtom(onEventType);
|
|
if (!eventTypeAtom) {
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
return nullptr;
|
|
}
|
|
|
|
EventMessage eventMessage = nsContentUtils::GetEventMessage(eventTypeAtom);
|
|
RefPtr<DataTransfer> transfer = new DataTransfer(aGlobal.GetAsSupports(),
|
|
eventMessage, aIsExternal,
|
|
-1);
|
|
return transfer.forget();
|
|
}
|
|
|
|
JSObject*
|
|
DataTransfer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
{
|
|
return DataTransferBinding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetDropEffect(nsAString& aDropEffect)
|
|
{
|
|
nsString dropEffect;
|
|
GetDropEffect(dropEffect);
|
|
aDropEffect = dropEffect;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::SetDropEffect(const nsAString& aDropEffect)
|
|
{
|
|
// the drop effect can only be 'none', 'copy', 'move' or 'link'.
|
|
for (uint32_t e = 0; e <= nsIDragService::DRAGDROP_ACTION_LINK; e++) {
|
|
if (aDropEffect.EqualsASCII(sEffects[e])) {
|
|
// don't allow copyMove
|
|
if (e != (nsIDragService::DRAGDROP_ACTION_COPY |
|
|
nsIDragService::DRAGDROP_ACTION_MOVE))
|
|
mDropEffect = e;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetEffectAllowed(nsAString& aEffectAllowed)
|
|
{
|
|
nsString effectAllowed;
|
|
GetEffectAllowed(effectAllowed);
|
|
aEffectAllowed = effectAllowed;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::SetEffectAllowed(const nsAString& aEffectAllowed)
|
|
{
|
|
if (aEffectAllowed.EqualsLiteral("uninitialized")) {
|
|
mEffectAllowed = nsIDragService::DRAGDROP_ACTION_UNINITIALIZED;
|
|
return NS_OK;
|
|
}
|
|
|
|
static_assert(nsIDragService::DRAGDROP_ACTION_NONE == 0,
|
|
"DRAGDROP_ACTION_NONE constant is wrong");
|
|
static_assert(nsIDragService::DRAGDROP_ACTION_COPY == 1,
|
|
"DRAGDROP_ACTION_COPY constant is wrong");
|
|
static_assert(nsIDragService::DRAGDROP_ACTION_MOVE == 2,
|
|
"DRAGDROP_ACTION_MOVE constant is wrong");
|
|
static_assert(nsIDragService::DRAGDROP_ACTION_LINK == 4,
|
|
"DRAGDROP_ACTION_LINK constant is wrong");
|
|
|
|
for (uint32_t e = 0; e < ArrayLength(sEffects); e++) {
|
|
if (aEffectAllowed.EqualsASCII(sEffects[e])) {
|
|
mEffectAllowed = e;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetDropEffectInt(uint32_t* aDropEffect)
|
|
{
|
|
*aDropEffect = mDropEffect;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::SetDropEffectInt(uint32_t aDropEffect)
|
|
{
|
|
mDropEffect = aDropEffect;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetEffectAllowedInt(uint32_t* aEffectAllowed)
|
|
{
|
|
*aEffectAllowed = mEffectAllowed;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::SetEffectAllowedInt(uint32_t aEffectAllowed)
|
|
{
|
|
mEffectAllowed = aEffectAllowed;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetMozUserCancelled(bool* aUserCancelled)
|
|
{
|
|
*aUserCancelled = MozUserCancelled();
|
|
return NS_OK;
|
|
}
|
|
|
|
FileList*
|
|
DataTransfer::GetFiles(ErrorResult& aRv)
|
|
{
|
|
return GetFilesInternal(aRv, nsContentUtils::SubjectPrincipal());
|
|
}
|
|
|
|
FileList*
|
|
DataTransfer::GetFilesInternal(ErrorResult& aRv, nsIPrincipal* aSubjectPrincipal)
|
|
{
|
|
if (mEventMessage != eDrop &&
|
|
mEventMessage != eLegacyDragDrop &&
|
|
mEventMessage != ePaste) {
|
|
return nullptr;
|
|
}
|
|
|
|
if (!mFiles) {
|
|
mFiles = new FileList(static_cast<nsIDOMDataTransfer*>(this));
|
|
|
|
uint32_t count = mItems.Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
nsCOMPtr<nsIVariant> variant;
|
|
aRv = GetDataAtInternal(NS_ConvertUTF8toUTF16(kFileMime), i, aSubjectPrincipal, getter_AddRefs(variant));
|
|
if (aRv.Failed()) {
|
|
return nullptr;
|
|
}
|
|
|
|
if (!variant)
|
|
continue;
|
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
nsresult rv = variant->GetAsISupports(getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv))
|
|
continue;
|
|
|
|
nsCOMPtr<nsIFile> file = do_QueryInterface(supports);
|
|
|
|
RefPtr<File> domFile;
|
|
if (file) {
|
|
#ifdef DEBUG
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
bool isDir;
|
|
file->IsDirectory(&isDir);
|
|
MOZ_ASSERT(!isDir, "How did we get here?");
|
|
}
|
|
#endif
|
|
domFile = File::CreateFromFile(GetParentObject(), file);
|
|
} else {
|
|
nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(supports);
|
|
if (!blobImpl) {
|
|
continue;
|
|
}
|
|
|
|
MOZ_ASSERT(blobImpl->IsFile());
|
|
|
|
domFile = File::Create(GetParentObject(), blobImpl);
|
|
MOZ_ASSERT(domFile);
|
|
}
|
|
|
|
if (!mFiles->Append(domFile)) {
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
return nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
return mFiles;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetFiles(nsIDOMFileList** aFileList)
|
|
{
|
|
ErrorResult rv;
|
|
NS_IF_ADDREF(*aFileList = GetFilesInternal(rv, nsContentUtils::GetSystemPrincipal()));
|
|
return rv.StealNSResult();
|
|
}
|
|
|
|
already_AddRefed<DOMStringList>
|
|
DataTransfer::Types()
|
|
{
|
|
ErrorResult rv;
|
|
return MozTypesAt(0, rv);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetTypes(nsISupports** aTypes)
|
|
{
|
|
RefPtr<DOMStringList> types = Types();
|
|
types.forget(aTypes);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
DataTransfer::GetData(const nsAString& aFormat, nsAString& aData,
|
|
ErrorResult& aRv)
|
|
{
|
|
// return an empty string if data for the format was not found
|
|
aData.Truncate();
|
|
|
|
nsCOMPtr<nsIVariant> data;
|
|
nsresult rv = GetDataAtInternal(aFormat, 0, nsContentUtils::SubjectPrincipal(), getter_AddRefs(data));
|
|
if (NS_FAILED(rv)) {
|
|
if (rv != NS_ERROR_DOM_INDEX_SIZE_ERR) {
|
|
aRv.Throw(rv);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (data) {
|
|
nsAutoString stringdata;
|
|
data->GetAsAString(stringdata);
|
|
|
|
// for the URL type, parse out the first URI from the list. The URIs are
|
|
// separated by newlines
|
|
nsAutoString lowercaseFormat;
|
|
nsContentUtils::ASCIIToLower(aFormat, lowercaseFormat);
|
|
|
|
if (lowercaseFormat.EqualsLiteral("url")) {
|
|
int32_t lastidx = 0, idx;
|
|
int32_t length = stringdata.Length();
|
|
while (lastidx < length) {
|
|
idx = stringdata.FindChar('\n', lastidx);
|
|
// lines beginning with # are comments
|
|
if (stringdata[lastidx] == '#') {
|
|
if (idx == -1)
|
|
break;
|
|
}
|
|
else {
|
|
if (idx == -1)
|
|
aData.Assign(Substring(stringdata, lastidx));
|
|
else
|
|
aData.Assign(Substring(stringdata, lastidx, idx - lastidx));
|
|
aData = nsContentUtils::TrimWhitespace<nsCRT::IsAsciiSpace>(aData, true);
|
|
return;
|
|
}
|
|
lastidx = idx + 1;
|
|
}
|
|
}
|
|
else {
|
|
aData = stringdata;
|
|
}
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetData(const nsAString& aFormat, nsAString& aData)
|
|
{
|
|
ErrorResult rv;
|
|
GetData(aFormat, aData, rv);
|
|
return rv.StealNSResult();
|
|
}
|
|
|
|
void
|
|
DataTransfer::SetData(const nsAString& aFormat, const nsAString& aData,
|
|
ErrorResult& aRv)
|
|
{
|
|
RefPtr<nsVariantCC> variant = new nsVariantCC();
|
|
variant->SetAsAString(aData);
|
|
|
|
aRv = SetDataAtInternal(aFormat, variant, 0, nsContentUtils::SubjectPrincipal());
|
|
}
|
|
|
|
void
|
|
DataTransfer::ClearData(const Optional<nsAString>& aFormat, ErrorResult& aRv)
|
|
{
|
|
if (mReadOnly) {
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
return;
|
|
}
|
|
|
|
if (mItems.Length() == 0) {
|
|
return;
|
|
}
|
|
|
|
if (aFormat.WasPassed()) {
|
|
MozClearDataAtHelper(aFormat.Value(), 0, aRv);
|
|
} else {
|
|
MozClearDataAtHelper(EmptyString(), 0, aRv);
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::ClearData(const nsAString& aFormat)
|
|
{
|
|
Optional<nsAString> format;
|
|
format = &aFormat;
|
|
ErrorResult rv;
|
|
ClearData(format, rv);
|
|
return rv.StealNSResult();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetMozItemCount(uint32_t* aCount)
|
|
{
|
|
*aCount = MozItemCount();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetMozCursor(nsAString& aCursorState)
|
|
{
|
|
nsString cursor;
|
|
GetMozCursor(cursor);
|
|
aCursorState = cursor;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::SetMozCursor(const nsAString& aCursorState)
|
|
{
|
|
// Lock the cursor to an arrow during the drag.
|
|
mCursorState = aCursorState.EqualsLiteral("default");
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
already_AddRefed<nsINode>
|
|
DataTransfer::GetMozSourceNode()
|
|
{
|
|
nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
|
|
if (!dragSession) {
|
|
return nullptr;
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> sourceNode;
|
|
dragSession->GetSourceNode(getter_AddRefs(sourceNode));
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(sourceNode);
|
|
if (node && !nsContentUtils::LegacyIsCallerNativeCode()
|
|
&& !nsContentUtils::CanCallerAccess(node)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return node.forget();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::GetMozSourceNode(nsIDOMNode** aSourceNode)
|
|
{
|
|
nsCOMPtr<nsINode> sourceNode = GetMozSourceNode();
|
|
if (!sourceNode) {
|
|
*aSourceNode = nullptr;
|
|
return NS_OK;
|
|
}
|
|
|
|
return CallQueryInterface(sourceNode, aSourceNode);
|
|
}
|
|
|
|
already_AddRefed<DOMStringList>
|
|
DataTransfer::MozTypesAt(uint32_t aIndex, ErrorResult& aRv) const
|
|
{
|
|
// Only the first item is valid for clipboard events
|
|
if (aIndex > 0 &&
|
|
(mEventMessage == eCut || mEventMessage == eCopy ||
|
|
mEventMessage == ePaste)) {
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<DOMStringList> types = new DOMStringList();
|
|
if (aIndex < mItems.Length()) {
|
|
bool addFile = false;
|
|
// note that you can retrieve the types regardless of their principal
|
|
const nsTArray<TransferItem>& item = mItems[aIndex];
|
|
for (uint32_t i = 0; i < item.Length(); i++) {
|
|
const nsString& format = item[i].mFormat;
|
|
types->Add(format);
|
|
if (!addFile) {
|
|
addFile = format.EqualsASCII(kFileMime);
|
|
}
|
|
}
|
|
|
|
if (addFile) {
|
|
// If this is a content caller, and a file is in the data transfer, remove
|
|
// the non-file types. This prevents alternate text forms of the file
|
|
// from being returned.
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
|
types->Clear();
|
|
types->Add(NS_LITERAL_STRING(kFileMime));
|
|
}
|
|
|
|
types->Add(NS_LITERAL_STRING("Files"));
|
|
}
|
|
}
|
|
|
|
return types.forget();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::MozTypesAt(uint32_t aIndex, nsISupports** aTypes)
|
|
{
|
|
ErrorResult rv;
|
|
RefPtr<DOMStringList> types = MozTypesAt(aIndex, rv);
|
|
types.forget(aTypes);
|
|
return rv.StealNSResult();
|
|
}
|
|
|
|
nsresult
|
|
DataTransfer::GetDataAtNoSecurityCheck(const nsAString& aFormat, uint32_t aIndex,
|
|
nsIVariant** aData)
|
|
{
|
|
return GetDataAtInternal(aFormat, aIndex, nsContentUtils::GetSystemPrincipal(), aData);
|
|
}
|
|
|
|
nsresult
|
|
DataTransfer::GetDataAtInternal(const nsAString& aFormat, uint32_t aIndex,
|
|
nsIPrincipal* aSubjectPrincipal, nsIVariant** aData)
|
|
{
|
|
*aData = nullptr;
|
|
|
|
if (aFormat.IsEmpty())
|
|
return NS_OK;
|
|
|
|
if (aIndex >= mItems.Length()) {
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
}
|
|
|
|
// Only the first item is valid for clipboard events
|
|
if (aIndex > 0 &&
|
|
(mEventMessage == eCut || mEventMessage == eCopy ||
|
|
mEventMessage == ePaste)) {
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
}
|
|
|
|
nsAutoString format;
|
|
GetRealFormat(aFormat, format);
|
|
|
|
nsTArray<TransferItem>& item = mItems[aIndex];
|
|
|
|
// If this is a content caller, and a file is in the data transfer, only
|
|
// return the file type.
|
|
if (!format.EqualsLiteral(kFileMime) &&
|
|
!nsContentUtils::IsSystemPrincipal(nsContentUtils::SubjectPrincipal())) {
|
|
uint32_t count = item.Length();
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
if (item[i].mFormat.EqualsLiteral(kFileMime)) {
|
|
return NS_OK;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check if the caller is allowed to access the drag data. Callers with
|
|
// chrome privileges can always read the data. During the
|
|
// drop event, allow retrieving the data except in the case where the
|
|
// source of the drag is in a child frame of the caller. In that case,
|
|
// we only allow access to data of the same principal. During other events,
|
|
// only allow access to the data with the same principal.
|
|
bool checkFormatItemPrincipal = mIsCrossDomainSubFrameDrop ||
|
|
(mEventMessage != eDrop && mEventMessage != eLegacyDragDrop &&
|
|
mEventMessage != ePaste);
|
|
|
|
uint32_t count = item.Length();
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
TransferItem& formatitem = item[i];
|
|
if (formatitem.mFormat.Equals(format)) {
|
|
if (formatitem.mPrincipal && checkFormatItemPrincipal &&
|
|
!aSubjectPrincipal->Subsumes(formatitem.mPrincipal)) {
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
}
|
|
|
|
if (!formatitem.mData) {
|
|
FillInExternalData(formatitem, aIndex);
|
|
} else {
|
|
nsCOMPtr<nsISupports> data;
|
|
formatitem.mData->GetAsISupports(getter_AddRefs(data));
|
|
// Make sure the code that is calling us is same-origin with the data.
|
|
nsCOMPtr<EventTarget> pt = do_QueryInterface(data);
|
|
if (pt) {
|
|
nsresult rv = NS_OK;
|
|
nsIScriptContext* c = pt->GetContextForEventHandlers(&rv);
|
|
NS_ENSURE_TRUE(c && NS_SUCCEEDED(rv), NS_ERROR_DOM_SECURITY_ERR);
|
|
nsIGlobalObject* go = c->GetGlobalObject();
|
|
NS_ENSURE_TRUE(go, NS_ERROR_DOM_SECURITY_ERR);
|
|
nsCOMPtr<nsIScriptObjectPrincipal> sp = do_QueryInterface(go);
|
|
MOZ_ASSERT(sp, "This cannot fail on the main thread.");
|
|
nsIPrincipal* dataPrincipal = sp->GetPrincipal();
|
|
NS_ENSURE_TRUE(dataPrincipal, NS_ERROR_DOM_SECURITY_ERR);
|
|
NS_ENSURE_TRUE(aSubjectPrincipal->Subsumes(dataPrincipal), NS_ERROR_DOM_SECURITY_ERR);
|
|
}
|
|
}
|
|
*aData = formatitem.mData;
|
|
NS_IF_ADDREF(*aData);
|
|
return NS_OK;
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
DataTransfer::MozGetDataAt(JSContext* aCx, const nsAString& aFormat,
|
|
uint32_t aIndex,
|
|
JS::MutableHandle<JS::Value> aRetval,
|
|
mozilla::ErrorResult& aRv)
|
|
{
|
|
nsCOMPtr<nsIVariant> data;
|
|
aRv = GetDataAtInternal(aFormat, aIndex, nsContentUtils::SubjectPrincipal(), getter_AddRefs(data));
|
|
if (aRv.Failed()) {
|
|
return;
|
|
}
|
|
|
|
if (!data) {
|
|
aRetval.setNull();
|
|
return;
|
|
}
|
|
|
|
JS::Rooted<JS::Value> result(aCx);
|
|
if (!VariantToJsval(aCx, data, aRetval)) {
|
|
aRv = NS_ERROR_FAILURE;
|
|
return;
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
DataTransfer::SetDataAtInternal(const nsAString& aFormat, nsIVariant* aData,
|
|
uint32_t aIndex, nsIPrincipal* aSubjectPrincipal)
|
|
{
|
|
if (aFormat.IsEmpty()) {
|
|
return NS_OK;
|
|
}
|
|
|
|
if (mReadOnly) {
|
|
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
|
|
}
|
|
|
|
// Specifying an index less than the current length will replace an existing
|
|
// item. Specifying an index equal to the current length will add a new item.
|
|
if (aIndex > mItems.Length()) {
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
}
|
|
|
|
// Only the first item is valid for clipboard events
|
|
if (aIndex > 0 &&
|
|
(mEventMessage == eCut || mEventMessage == eCopy ||
|
|
mEventMessage == ePaste)) {
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
}
|
|
|
|
// Don't allow non-chrome to add non-string or file data. We block file
|
|
// promises as well which are used internally for drags to the desktop.
|
|
if (!nsContentUtils::IsSystemPrincipal(aSubjectPrincipal)) {
|
|
if (aFormat.EqualsLiteral(kFilePromiseMime) ||
|
|
aFormat.EqualsLiteral(kFileMime)) {
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
}
|
|
|
|
uint16_t type;
|
|
aData->GetDataType(&type);
|
|
if (type == nsIDataType::VTYPE_INTERFACE ||
|
|
type == nsIDataType::VTYPE_INTERFACE_IS) {
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
}
|
|
}
|
|
|
|
return SetDataWithPrincipal(aFormat, aData, aIndex, aSubjectPrincipal);
|
|
}
|
|
|
|
void
|
|
DataTransfer::MozSetDataAt(JSContext* aCx, const nsAString& aFormat,
|
|
JS::Handle<JS::Value> aData,
|
|
uint32_t aIndex, ErrorResult& aRv)
|
|
{
|
|
nsCOMPtr<nsIVariant> data;
|
|
aRv = nsContentUtils::XPConnect()->JSValToVariant(aCx, aData,
|
|
getter_AddRefs(data));
|
|
if (!aRv.Failed()) {
|
|
aRv = SetDataAtInternal(aFormat, data, aIndex, nsContentUtils::SubjectPrincipal());
|
|
}
|
|
}
|
|
|
|
void
|
|
DataTransfer::MozClearDataAt(const nsAString& aFormat, uint32_t aIndex,
|
|
ErrorResult& aRv)
|
|
{
|
|
if (mReadOnly) {
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
return;
|
|
}
|
|
|
|
if (aIndex >= mItems.Length()) {
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
return;
|
|
}
|
|
|
|
// Only the first item is valid for clipboard events
|
|
if (aIndex > 0 &&
|
|
(mEventMessage == eCut || mEventMessage == eCopy ||
|
|
mEventMessage == ePaste)) {
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
return;
|
|
}
|
|
|
|
MozClearDataAtHelper(aFormat, aIndex, aRv);
|
|
}
|
|
|
|
void
|
|
DataTransfer::MozClearDataAtHelper(const nsAString& aFormat, uint32_t aIndex,
|
|
ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(!mReadOnly);
|
|
MOZ_ASSERT(aIndex < mItems.Length());
|
|
MOZ_ASSERT(aIndex == 0 ||
|
|
(mEventMessage != eCut && mEventMessage != eCopy &&
|
|
mEventMessage != ePaste));
|
|
|
|
nsAutoString format;
|
|
GetRealFormat(aFormat, format);
|
|
|
|
nsIPrincipal* principal = nsContentUtils::SubjectPrincipal();
|
|
|
|
// if the format is empty, clear all formats
|
|
bool clearall = format.IsEmpty();
|
|
|
|
nsTArray<TransferItem>& item = mItems[aIndex];
|
|
// count backwards so that the count and index don't have to be adjusted
|
|
// after removing an element
|
|
for (int32_t i = item.Length() - 1; i >= 0; i--) {
|
|
TransferItem& formatitem = item[i];
|
|
if (clearall || formatitem.mFormat.Equals(format)) {
|
|
// don't allow removing data that has a stronger principal
|
|
bool subsumes;
|
|
if (formatitem.mPrincipal && principal &&
|
|
(NS_FAILED(principal->Subsumes(formatitem.mPrincipal, &subsumes)) || !subsumes)) {
|
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
|
return;
|
|
}
|
|
|
|
item.RemoveElementAt(i);
|
|
|
|
// if a format was specified, break out. Otherwise, loop around until
|
|
// all formats have been removed
|
|
if (!clearall)
|
|
break;
|
|
}
|
|
}
|
|
|
|
// if the last format for an item is removed, remove the entire item
|
|
if (!item.Length())
|
|
mItems.RemoveElementAt(aIndex);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::MozClearDataAt(const nsAString& aFormat, uint32_t aIndex)
|
|
{
|
|
ErrorResult rv;
|
|
MozClearDataAt(aFormat, aIndex, rv);
|
|
return rv.StealNSResult();
|
|
}
|
|
|
|
void
|
|
DataTransfer::SetDragImage(Element& aImage, int32_t aX, int32_t aY,
|
|
ErrorResult& aRv)
|
|
{
|
|
if (mReadOnly) {
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
return;
|
|
}
|
|
|
|
mDragImage = &aImage;
|
|
mDragImageX = aX;
|
|
mDragImageY = aY;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::SetDragImage(nsIDOMElement* aImage, int32_t aX, int32_t aY)
|
|
{
|
|
ErrorResult rv;
|
|
nsCOMPtr<Element> image = do_QueryInterface(aImage);
|
|
if (image) {
|
|
SetDragImage(*image, aX, aY, rv);
|
|
}
|
|
return rv.StealNSResult();
|
|
}
|
|
|
|
static already_AddRefed<OSFileSystem>
|
|
MakeOrReuseFileSystem(const nsAString& aNewLocalRootPath,
|
|
OSFileSystem* aFS,
|
|
nsPIDOMWindow* aWindow)
|
|
{
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
RefPtr<OSFileSystem> fs;
|
|
if (aFS) {
|
|
const nsAString& prevLocalRootPath = aFS->GetLocalRootPath();
|
|
if (aNewLocalRootPath == prevLocalRootPath) {
|
|
fs = aFS;
|
|
}
|
|
}
|
|
if (!fs) {
|
|
fs = new OSFileSystem(aNewLocalRootPath);
|
|
fs->Init(aWindow);
|
|
}
|
|
return fs.forget();
|
|
}
|
|
|
|
already_AddRefed<Promise>
|
|
DataTransfer::GetFilesAndDirectories(ErrorResult& aRv)
|
|
{
|
|
nsCOMPtr<nsINode> parentNode = do_QueryInterface(mParent);
|
|
if (!parentNode) {
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
return nullptr;
|
|
}
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = parentNode->OwnerDoc()->GetScopeObject();
|
|
MOZ_ASSERT(global);
|
|
if (!global) {
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<Promise> p = Promise::Create(global, aRv);
|
|
if (aRv.Failed()) {
|
|
return nullptr;
|
|
}
|
|
|
|
if (!mFiles) {
|
|
GetFiles(aRv);
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
Sequence<OwningFileOrDirectory> filesAndDirsSeq;
|
|
|
|
if (mFiles && mFiles->Length()) {
|
|
if (!filesAndDirsSeq.SetLength(mFiles->Length(), mozilla::fallible_t())) {
|
|
p->MaybeReject(NS_ERROR_OUT_OF_MEMORY);
|
|
return p.forget();
|
|
}
|
|
|
|
nsPIDOMWindow* window = parentNode->OwnerDoc()->GetInnerWindow();
|
|
|
|
RefPtr<OSFileSystem> fs;
|
|
for (uint32_t i = 0; i < mFiles->Length(); ++i) {
|
|
if (mFiles->Item(i)->Impl()->IsDirectory()) {
|
|
#if defined(ANDROID) || defined(MOZ_B2G)
|
|
MOZ_ASSERT(false,
|
|
"Directory picking should have been redirected to normal "
|
|
"file picking for platforms that don't have a directory "
|
|
"picker");
|
|
#endif
|
|
nsAutoString path;
|
|
mFiles->Item(i)->GetMozFullPathInternal(path, aRv);
|
|
if (aRv.Failed()) {
|
|
return nullptr;
|
|
}
|
|
int32_t leafSeparatorIndex = path.RFind(FILE_PATH_SEPARATOR);
|
|
nsDependentSubstring dirname = Substring(path, 0, leafSeparatorIndex);
|
|
nsDependentSubstring basename = Substring(path, leafSeparatorIndex);
|
|
fs = MakeOrReuseFileSystem(dirname, fs, window);
|
|
RefPtr<Directory> directory = new Directory(fs, basename);
|
|
directory->SetContentFilters(NS_LITERAL_STRING("filter-out-sensitive"));
|
|
filesAndDirsSeq[i].SetAsDirectory() = directory;
|
|
} else {
|
|
filesAndDirsSeq[i].SetAsFile() = mFiles->Item(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
p->MaybeResolve(filesAndDirsSeq);
|
|
|
|
return p.forget();
|
|
}
|
|
|
|
void
|
|
DataTransfer::AddElement(Element& aElement, ErrorResult& aRv)
|
|
{
|
|
if (mReadOnly) {
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
return;
|
|
}
|
|
|
|
mDragTarget = &aElement;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
DataTransfer::AddElement(nsIDOMElement* aElement)
|
|
{
|
|
NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
|
|
|
|
nsCOMPtr<Element> element = do_QueryInterface(aElement);
|
|
NS_ENSURE_TRUE(element, NS_ERROR_INVALID_ARG);
|
|
|
|
ErrorResult rv;
|
|
AddElement(*element, rv);
|
|
return rv.StealNSResult();
|
|
}
|
|
|
|
nsresult
|
|
DataTransfer::Clone(nsISupports* aParent, EventMessage aEventMessage,
|
|
bool aUserCancelled, bool aIsCrossDomainSubFrameDrop,
|
|
DataTransfer** aNewDataTransfer)
|
|
{
|
|
DataTransfer* newDataTransfer =
|
|
new DataTransfer(aParent, aEventMessage, mEffectAllowed, mCursorState,
|
|
mIsExternal, aUserCancelled, aIsCrossDomainSubFrameDrop,
|
|
mClipboardType, mItems, mDragImage, mDragImageX,
|
|
mDragImageY);
|
|
|
|
*aNewDataTransfer = newDataTransfer;
|
|
NS_ADDREF(*aNewDataTransfer);
|
|
return NS_OK;
|
|
}
|
|
|
|
already_AddRefed<nsISupportsArray>
|
|
DataTransfer::GetTransferables(nsIDOMNode* aDragTarget)
|
|
{
|
|
MOZ_ASSERT(aDragTarget);
|
|
|
|
nsCOMPtr<nsINode> dragNode = do_QueryInterface(aDragTarget);
|
|
if (!dragNode) {
|
|
return nullptr;
|
|
}
|
|
|
|
nsIDocument* doc = dragNode->GetCurrentDoc();
|
|
if (!doc) {
|
|
return nullptr;
|
|
}
|
|
|
|
return GetTransferables(doc->GetLoadContext());
|
|
}
|
|
|
|
already_AddRefed<nsISupportsArray>
|
|
DataTransfer::GetTransferables(nsILoadContext* aLoadContext)
|
|
{
|
|
|
|
nsCOMPtr<nsISupportsArray> transArray =
|
|
do_CreateInstance("@mozilla.org/supports-array;1");
|
|
if (!transArray) {
|
|
return nullptr;
|
|
}
|
|
|
|
uint32_t count = mItems.Length();
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
nsCOMPtr<nsITransferable> transferable = GetTransferable(i, aLoadContext);
|
|
if (transferable) {
|
|
transArray->AppendElement(transferable);
|
|
}
|
|
}
|
|
|
|
return transArray.forget();
|
|
}
|
|
|
|
already_AddRefed<nsITransferable>
|
|
DataTransfer::GetTransferable(uint32_t aIndex, nsILoadContext* aLoadContext)
|
|
{
|
|
if (aIndex >= mItems.Length()) {
|
|
return nullptr;
|
|
}
|
|
|
|
nsTArray<TransferItem>& item = mItems[aIndex];
|
|
uint32_t count = item.Length();
|
|
if (!count) {
|
|
return nullptr;
|
|
}
|
|
|
|
nsCOMPtr<nsITransferable> transferable =
|
|
do_CreateInstance("@mozilla.org/widget/transferable;1");
|
|
if (!transferable) {
|
|
return nullptr;
|
|
}
|
|
transferable->Init(aLoadContext);
|
|
|
|
bool added = false;
|
|
for (uint32_t f = 0; f < count; f++) {
|
|
const TransferItem& formatitem = item[f];
|
|
if (!formatitem.mData) { // skip empty items
|
|
continue;
|
|
}
|
|
|
|
uint32_t length;
|
|
nsCOMPtr<nsISupports> convertedData;
|
|
if (!ConvertFromVariant(formatitem.mData, getter_AddRefs(convertedData), &length)) {
|
|
continue;
|
|
}
|
|
|
|
// the underlying drag code uses text/unicode, so use that instead of text/plain
|
|
const char* format;
|
|
NS_ConvertUTF16toUTF8 utf8format(formatitem.mFormat);
|
|
if (utf8format.EqualsLiteral("text/plain")) {
|
|
format = kUnicodeMime;
|
|
} else {
|
|
format = utf8format.get();
|
|
}
|
|
|
|
// if a converter is set for a format, set the converter for the
|
|
// transferable and don't add the item
|
|
nsCOMPtr<nsIFormatConverter> converter = do_QueryInterface(convertedData);
|
|
if (converter) {
|
|
transferable->AddDataFlavor(format);
|
|
transferable->SetConverter(converter);
|
|
continue;
|
|
}
|
|
|
|
nsresult rv = transferable->SetTransferData(format, convertedData, length);
|
|
if (NS_FAILED(rv)) {
|
|
return nullptr;
|
|
}
|
|
|
|
added = true;
|
|
}
|
|
|
|
// only return the transferable if data was successfully added to it
|
|
if (added) {
|
|
return transferable.forget();
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
bool
|
|
DataTransfer::ConvertFromVariant(nsIVariant* aVariant,
|
|
nsISupports** aSupports,
|
|
uint32_t* aLength)
|
|
{
|
|
*aSupports = nullptr;
|
|
*aLength = 0;
|
|
|
|
uint16_t type;
|
|
aVariant->GetDataType(&type);
|
|
if (type == nsIDataType::VTYPE_INTERFACE ||
|
|
type == nsIDataType::VTYPE_INTERFACE_IS) {
|
|
nsCOMPtr<nsISupports> data;
|
|
if (NS_FAILED(aVariant->GetAsISupports(getter_AddRefs(data))))
|
|
return false;
|
|
|
|
nsCOMPtr<nsIFlavorDataProvider> fdp = do_QueryInterface(data);
|
|
if (fdp) {
|
|
// for flavour data providers, use kFlavorHasDataProvider (which has the
|
|
// value 0) as the length.
|
|
fdp.forget(aSupports);
|
|
*aLength = nsITransferable::kFlavorHasDataProvider;
|
|
}
|
|
else {
|
|
// wrap the item in an nsISupportsInterfacePointer
|
|
nsCOMPtr<nsISupportsInterfacePointer> ptrSupports =
|
|
do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID);
|
|
if (!ptrSupports)
|
|
return false;
|
|
|
|
ptrSupports->SetData(data);
|
|
ptrSupports.forget(aSupports);
|
|
|
|
*aLength = sizeof(nsISupportsInterfacePointer *);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
char16_t* chrs;
|
|
uint32_t len = 0;
|
|
nsresult rv = aVariant->GetAsWStringWithSize(&len, &chrs);
|
|
if (NS_FAILED(rv))
|
|
return false;
|
|
|
|
nsAutoString str;
|
|
str.Adopt(chrs, len);
|
|
|
|
nsCOMPtr<nsISupportsString>
|
|
strSupports(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
|
if (!strSupports)
|
|
return false;
|
|
|
|
strSupports->SetData(str);
|
|
|
|
strSupports.forget(aSupports);
|
|
|
|
// each character is two bytes
|
|
*aLength = str.Length() << 1;
|
|
|
|
return true;
|
|
}
|
|
|
|
void
|
|
DataTransfer::ClearAll()
|
|
{
|
|
mItems.Clear();
|
|
}
|
|
|
|
nsresult
|
|
DataTransfer::SetDataWithPrincipal(const nsAString& aFormat,
|
|
nsIVariant* aData,
|
|
uint32_t aIndex,
|
|
nsIPrincipal* aPrincipal)
|
|
{
|
|
nsAutoString format;
|
|
GetRealFormat(aFormat, format);
|
|
|
|
// check if the item for the format already exists. In that case,
|
|
// just replace it.
|
|
TransferItem* formatitem;
|
|
if (aIndex < mItems.Length()) {
|
|
nsTArray<TransferItem>& item = mItems[aIndex];
|
|
uint32_t count = item.Length();
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
TransferItem& itemformat = item[i];
|
|
if (itemformat.mFormat.Equals(format)) {
|
|
// don't allow replacing data that has a stronger principal
|
|
bool subsumes;
|
|
if (itemformat.mPrincipal && aPrincipal &&
|
|
(NS_FAILED(aPrincipal->Subsumes(itemformat.mPrincipal, &subsumes)) || !subsumes))
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
itemformat.mPrincipal = aPrincipal;
|
|
itemformat.mData = aData;
|
|
return NS_OK;
|
|
}
|
|
}
|
|
|
|
// add a new format
|
|
formatitem = item.AppendElement();
|
|
}
|
|
else {
|
|
NS_ASSERTION(aIndex == mItems.Length(), "Index out of range");
|
|
|
|
// add a new index
|
|
nsTArray<TransferItem>* item = mItems.AppendElement();
|
|
NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
formatitem = item->AppendElement();
|
|
}
|
|
|
|
NS_ENSURE_TRUE(formatitem, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
formatitem->mFormat = format;
|
|
formatitem->mPrincipal = aPrincipal;
|
|
formatitem->mData = aData;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
DataTransfer::GetRealFormat(const nsAString& aInFormat, nsAString& aOutFormat)
|
|
{
|
|
// treat text/unicode as equivalent to text/plain
|
|
nsAutoString lowercaseFormat;
|
|
nsContentUtils::ASCIIToLower(aInFormat, lowercaseFormat);
|
|
if (lowercaseFormat.EqualsLiteral("text") || lowercaseFormat.EqualsLiteral("text/unicode"))
|
|
aOutFormat.AssignLiteral("text/plain");
|
|
else if (lowercaseFormat.EqualsLiteral("url"))
|
|
aOutFormat.AssignLiteral("text/uri-list");
|
|
else
|
|
aOutFormat.Assign(lowercaseFormat);
|
|
}
|
|
|
|
void
|
|
DataTransfer::CacheExternalData(const char* aFormat, uint32_t aIndex, nsIPrincipal* aPrincipal)
|
|
{
|
|
if (strcmp(aFormat, kUnicodeMime) == 0) {
|
|
SetDataWithPrincipal(NS_LITERAL_STRING("text/plain"), nullptr, aIndex, aPrincipal);
|
|
} else {
|
|
if (strcmp(aFormat, kURLDataMime) == 0) {
|
|
SetDataWithPrincipal(NS_LITERAL_STRING("text/uri-list"), nullptr, aIndex, aPrincipal);
|
|
}
|
|
SetDataWithPrincipal(NS_ConvertUTF8toUTF16(aFormat), nullptr, aIndex, aPrincipal);
|
|
}
|
|
}
|
|
|
|
void
|
|
DataTransfer::CacheExternalDragFormats()
|
|
{
|
|
// Called during the constructor to cache the formats available from an
|
|
// external drag. The data associated with each format will be set to null.
|
|
// This data will instead only be retrieved in FillInExternalDragData when
|
|
// asked for, as it may be time consuming for the source application to
|
|
// generate it.
|
|
|
|
nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
|
|
if (!dragSession)
|
|
return;
|
|
|
|
// make sure that the system principal is used for external drags
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
|
nsCOMPtr<nsIPrincipal> sysPrincipal;
|
|
ssm->GetSystemPrincipal(getter_AddRefs(sysPrincipal));
|
|
|
|
// there isn't a way to get a list of the formats that might be available on
|
|
// all platforms, so just check for the types that can actually be imported
|
|
// XXXndeakin there are some other formats but those are platform specific.
|
|
const char* formats[] = { kFileMime, kHTMLMime, kRTFMime, kURLMime, kURLDataMime, kUnicodeMime };
|
|
|
|
uint32_t count;
|
|
dragSession->GetNumDropItems(&count);
|
|
for (uint32_t c = 0; c < count; c++) {
|
|
for (uint32_t f = 0; f < ArrayLength(formats); f++) {
|
|
// IsDataFlavorSupported doesn't take an index as an argument and just
|
|
// checks if any of the items support a particular flavor, even though
|
|
// the GetData method does take an index. Here, we just assume that
|
|
// every item being dragged has the same set of flavors.
|
|
bool supported;
|
|
dragSession->IsDataFlavorSupported(formats[f], &supported);
|
|
// if the format is supported, add an item to the array with null as
|
|
// the data. When retrieved, GetRealData will read the data.
|
|
if (supported) {
|
|
CacheExternalData(formats[f], c, sysPrincipal);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
DataTransfer::CacheExternalClipboardFormats()
|
|
{
|
|
NS_ASSERTION(mEventMessage == ePaste,
|
|
"caching clipboard data for invalid event");
|
|
|
|
// Called during the constructor for paste events to cache the formats
|
|
// available on the clipboard. As with CacheExternalDragFormats, the
|
|
// data will only be retrieved when needed.
|
|
|
|
nsCOMPtr<nsIClipboard> clipboard = do_GetService("@mozilla.org/widget/clipboard;1");
|
|
if (!clipboard || mClipboardType < 0) {
|
|
return;
|
|
}
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
|
nsCOMPtr<nsIPrincipal> sysPrincipal;
|
|
ssm->GetSystemPrincipal(getter_AddRefs(sysPrincipal));
|
|
|
|
// there isn't a way to get a list of the formats that might be available on
|
|
// all platforms, so just check for the types that can actually be imported
|
|
const char* formats[] = { kFileMime, kHTMLMime, kRTFMime, kURLMime, kURLDataMime, kUnicodeMime };
|
|
|
|
for (uint32_t f = 0; f < mozilla::ArrayLength(formats); ++f) {
|
|
// check each format one at a time
|
|
bool supported;
|
|
clipboard->HasDataMatchingFlavors(&(formats[f]), 1, mClipboardType, &supported);
|
|
// if the format is supported, add an item to the array with null as
|
|
// the data. When retrieved, GetRealData will read the data.
|
|
if (supported) {
|
|
CacheExternalData(formats[f], 0, sysPrincipal);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
DataTransfer::FillInExternalData(TransferItem& aItem, uint32_t aIndex)
|
|
{
|
|
NS_PRECONDITION(mIsExternal, "Not an external data transfer");
|
|
|
|
if (aItem.mData) {
|
|
return;
|
|
}
|
|
|
|
// only drag and paste events should be calling FillInExternalData
|
|
NS_ASSERTION(mEventMessage != eCut && mEventMessage != eCopy,
|
|
"clipboard event with empty data");
|
|
|
|
NS_ConvertUTF16toUTF8 utf8format(aItem.mFormat);
|
|
const char* format = utf8format.get();
|
|
if (strcmp(format, "text/plain") == 0)
|
|
format = kUnicodeMime;
|
|
else if (strcmp(format, "text/uri-list") == 0)
|
|
format = kURLDataMime;
|
|
|
|
nsCOMPtr<nsITransferable> trans =
|
|
do_CreateInstance("@mozilla.org/widget/transferable;1");
|
|
if (!trans)
|
|
return;
|
|
|
|
trans->Init(nullptr);
|
|
trans->AddDataFlavor(format);
|
|
|
|
if (mEventMessage == ePaste) {
|
|
MOZ_ASSERT(aIndex == 0, "index in clipboard must be 0");
|
|
|
|
nsCOMPtr<nsIClipboard> clipboard = do_GetService("@mozilla.org/widget/clipboard;1");
|
|
if (!clipboard || mClipboardType < 0) {
|
|
return;
|
|
}
|
|
|
|
clipboard->GetData(trans, mClipboardType);
|
|
} else {
|
|
nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
|
|
if (!dragSession) {
|
|
return;
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
// Since this is an external drag, the source document will always be null.
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
dragSession->GetSourceDocument(getter_AddRefs(domDoc));
|
|
MOZ_ASSERT(!domDoc);
|
|
#endif
|
|
|
|
dragSession->GetData(trans, aIndex);
|
|
}
|
|
|
|
uint32_t length = 0;
|
|
nsCOMPtr<nsISupports> data;
|
|
trans->GetTransferData(format, getter_AddRefs(data), &length);
|
|
if (!data)
|
|
return;
|
|
|
|
RefPtr<nsVariantCC> variant = new nsVariantCC();
|
|
|
|
nsCOMPtr<nsISupportsString> supportsstr = do_QueryInterface(data);
|
|
if (supportsstr) {
|
|
nsAutoString str;
|
|
supportsstr->GetData(str);
|
|
variant->SetAsAString(str);
|
|
}
|
|
else {
|
|
nsCOMPtr<nsISupportsCString> supportscstr = do_QueryInterface(data);
|
|
if (supportscstr) {
|
|
nsAutoCString str;
|
|
supportscstr->GetData(str);
|
|
variant->SetAsACString(str);
|
|
} else {
|
|
variant->SetAsISupports(data);
|
|
}
|
|
}
|
|
|
|
aItem.mData = variant;
|
|
}
|
|
|
|
void
|
|
DataTransfer::FillAllExternalData()
|
|
{
|
|
if (mIsExternal) {
|
|
for (uint32_t i = 0; i < mItems.Length(); ++i) {
|
|
nsTArray<TransferItem>& itemArray = mItems[i];
|
|
for (uint32_t j = 0; j < itemArray.Length(); ++j) {
|
|
if (!itemArray[j].mData) {
|
|
FillInExternalData(itemArray[j], i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|