Bug 1793629 - Implement attention indicator for the unified extensions button, r...
[gecko.git] / widget / nsDragServiceProxy.cpp
blobef0f7cafe839e2f95ee4ef1a4396b08c3d220ac1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsDragServiceProxy.h"
8 #include "mozilla/dom/Document.h"
9 #include "mozilla/dom/BrowserChild.h"
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/net/CookieJarSettings.h"
12 #include "mozilla/UniquePtr.h"
13 #include "mozilla/Unused.h"
14 #include "nsContentUtils.h"
16 using mozilla::CSSIntRegion;
17 using mozilla::LayoutDeviceIntRect;
18 using mozilla::Maybe;
19 using mozilla::Nothing;
20 using mozilla::Some;
21 using mozilla::dom::BrowserChild;
22 using mozilla::gfx::DataSourceSurface;
23 using mozilla::gfx::SourceSurface;
24 using mozilla::gfx::SurfaceFormat;
25 using mozilla::ipc::Shmem;
27 nsDragServiceProxy::nsDragServiceProxy() = default;
29 nsDragServiceProxy::~nsDragServiceProxy() = default;
31 nsresult nsDragServiceProxy::InvokeDragSessionImpl(
32 nsIArray* aArrayTransferables, const Maybe<CSSIntRegion>& aRegion,
33 uint32_t aActionType) {
34 NS_ENSURE_STATE(mSourceDocument->GetDocShell());
35 BrowserChild* child = BrowserChild::GetFrom(mSourceDocument->GetDocShell());
36 NS_ENSURE_STATE(child);
37 nsTArray<mozilla::dom::IPCDataTransfer> dataTransfers;
38 nsContentUtils::TransferablesToIPCTransferables(
39 aArrayTransferables, dataTransfers, false, child->Manager(), nullptr);
41 nsCOMPtr<nsIPrincipal> principal;
42 if (mSourceNode) {
43 principal = mSourceNode->NodePrincipal();
46 nsCOMPtr<nsIContentSecurityPolicy> csp;
47 if (mSourceDocument) {
48 csp = mSourceDocument->GetCsp();
49 mSourceWindowContext = mSourceDocument->GetWindowContext();
52 nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
53 cookieJarSettings = mSourceDocument->CookieJarSettings();
54 mozilla::net::CookieJarSettingsArgs csArgs;
55 mozilla::net::CookieJarSettings::Cast(cookieJarSettings)->Serialize(csArgs);
57 LayoutDeviceIntRect dragRect;
58 if (mHasImage || mSelection) {
59 nsPresContext* pc;
60 RefPtr<SourceSurface> surface;
61 DrawDrag(mSourceNode, aRegion, mScreenPosition, &dragRect, &surface, &pc);
63 if (surface) {
64 RefPtr<DataSourceSurface> dataSurface = surface->GetDataSurface();
65 if (dataSurface) {
66 size_t length;
67 int32_t stride;
68 auto surfaceData =
69 nsContentUtils::GetSurfaceData(*dataSurface, &length, &stride);
70 if (surfaceData.isNothing()) {
71 NS_WARNING("Failed to create shared memory for drag session.");
72 return NS_ERROR_FAILURE;
75 mozilla::Unused << child->SendInvokeDragSession(
76 std::move(dataTransfers), aActionType, std::move(surfaceData),
77 stride, dataSurface->GetFormat(), dragRect, principal, csp, csArgs,
78 mSourceWindowContext);
79 StartDragSession();
80 return NS_OK;
85 mozilla::Unused << child->SendInvokeDragSession(
86 std::move(dataTransfers), aActionType, Nothing(), 0,
87 static_cast<SurfaceFormat>(0), dragRect, principal, csp, csArgs,
88 mSourceWindowContext);
89 StartDragSession();
90 return NS_OK;