/src/mozilla-central/widget/nsDragServiceProxy.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
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/. */ |
6 | | |
7 | | #include "nsDragServiceProxy.h" |
8 | | #include "nsIDocument.h" |
9 | | #include "nsISupportsPrimitives.h" |
10 | | #include "mozilla/dom/TabChild.h" |
11 | | #include "mozilla/gfx/2D.h" |
12 | | #include "mozilla/UniquePtr.h" |
13 | | #include "mozilla/Unused.h" |
14 | | #include "nsContentUtils.h" |
15 | | |
16 | | using mozilla::ipc::Shmem; |
17 | | using mozilla::dom::TabChild; |
18 | | using mozilla::dom::OptionalShmem; |
19 | | using mozilla::LayoutDeviceIntRect; |
20 | | using mozilla::Maybe; |
21 | | |
22 | | nsDragServiceProxy::nsDragServiceProxy() |
23 | 0 | { |
24 | 0 | } |
25 | | |
26 | | nsDragServiceProxy::~nsDragServiceProxy() |
27 | 0 | { |
28 | 0 | } |
29 | | |
30 | | static void |
31 | | GetPrincipalURIFromNode(nsCOMPtr<nsINode>& sourceNode, |
32 | | nsCString& aPrincipalURISpec) |
33 | 0 | { |
34 | 0 | if (!sourceNode) { |
35 | 0 | return; |
36 | 0 | } |
37 | 0 | |
38 | 0 | nsCOMPtr<nsIPrincipal> principal = sourceNode->NodePrincipal(); |
39 | 0 | nsCOMPtr<nsIURI> principalURI; |
40 | 0 | nsresult rv = principal->GetURI(getter_AddRefs(principalURI)); |
41 | 0 | if (NS_FAILED(rv) || !principalURI) { |
42 | 0 | return; |
43 | 0 | } |
44 | 0 | |
45 | 0 | principalURI->GetSpec(aPrincipalURISpec); |
46 | 0 | } |
47 | | |
48 | | nsresult |
49 | | nsDragServiceProxy::InvokeDragSessionImpl(nsIArray* aArrayTransferables, |
50 | | const Maybe<CSSIntRegion>& aRegion, |
51 | | uint32_t aActionType) |
52 | 0 | { |
53 | 0 | NS_ENSURE_STATE(mSourceDocument->GetDocShell()); |
54 | 0 | TabChild* child = TabChild::GetFrom(mSourceDocument->GetDocShell()); |
55 | 0 | NS_ENSURE_STATE(child); |
56 | 0 | nsTArray<mozilla::dom::IPCDataTransfer> dataTransfers; |
57 | 0 | nsContentUtils::TransferablesToIPCTransferables(aArrayTransferables, |
58 | 0 | dataTransfers, |
59 | 0 | false, |
60 | 0 | child->Manager(), |
61 | 0 | nullptr); |
62 | 0 |
|
63 | 0 | nsCString principalURISpec; |
64 | 0 | GetPrincipalURIFromNode(mSourceNode, principalURISpec); |
65 | 0 |
|
66 | 0 | LayoutDeviceIntRect dragRect; |
67 | 0 | if (mHasImage || mSelection) { |
68 | 0 | nsPresContext* pc; |
69 | 0 | RefPtr<mozilla::gfx::SourceSurface> surface; |
70 | 0 | DrawDrag(mSourceNode, aRegion, mScreenPosition, &dragRect, &surface, &pc); |
71 | 0 |
|
72 | 0 | if (surface) { |
73 | 0 | RefPtr<mozilla::gfx::DataSourceSurface> dataSurface = |
74 | 0 | surface->GetDataSurface(); |
75 | 0 | if (dataSurface) { |
76 | 0 | size_t length; |
77 | 0 | int32_t stride; |
78 | 0 | Maybe<Shmem> maybeShm = nsContentUtils::GetSurfaceData(dataSurface, |
79 | 0 | &length, |
80 | 0 | &stride, |
81 | 0 | child); |
82 | 0 | if (maybeShm.isNothing()) { |
83 | 0 | return NS_ERROR_FAILURE; |
84 | 0 | } |
85 | 0 | |
86 | 0 | auto surfaceData = maybeShm.value(); |
87 | 0 |
|
88 | 0 | // Save the surface data to shared memory. |
89 | 0 | if (!surfaceData.IsReadable() || !surfaceData.get<char>()) { |
90 | 0 | NS_WARNING("Failed to create shared memory for drag session."); |
91 | 0 | return NS_ERROR_FAILURE; |
92 | 0 | } |
93 | 0 |
|
94 | 0 | mozilla::Unused << |
95 | 0 | child->SendInvokeDragSession(dataTransfers, aActionType, surfaceData, |
96 | 0 | stride, dataSurface->GetFormat(), |
97 | 0 | dragRect, principalURISpec); |
98 | 0 | StartDragSession(); |
99 | 0 | return NS_OK; |
100 | 0 | } |
101 | 0 | } |
102 | 0 | } |
103 | 0 |
|
104 | 0 | mozilla::Unused << child->SendInvokeDragSession(dataTransfers, aActionType, |
105 | 0 | mozilla::void_t(), 0, static_cast<gfx::SurfaceFormat>(0), dragRect, |
106 | 0 | principalURISpec); |
107 | 0 | StartDragSession(); |
108 | 0 | return NS_OK; |
109 | 0 | } |