1 | /* $Id: ClipboardStreamImpl-win.cpp 78897 2019-05-31 15:23:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * ClipboardStreamImpl-win.cpp - Shared Clipboard IStream object implementation (for CF_HDROP).
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_SHARED_CLIPBOARD
|
---|
23 | #include <VBox/GuestHost/SharedClipboard-win.h>
|
---|
24 |
|
---|
25 | #include <iprt/asm.h>
|
---|
26 | #include <iprt/ldr.h>
|
---|
27 | #include <iprt/thread.h>
|
---|
28 |
|
---|
29 | #include <VBox/GuestHost/SharedClipboard.h>
|
---|
30 | #include <VBox/GuestHost/SharedClipboard-win.h>
|
---|
31 | #include <strsafe.h>
|
---|
32 |
|
---|
33 | #include <VBox/log.h>
|
---|
34 |
|
---|
35 |
|
---|
36 | /*********************************************************************************************************************************
|
---|
37 | * Structures and Typedefs *
|
---|
38 | *********************************************************************************************************************************/
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 | /*********************************************************************************************************************************
|
---|
43 | * Static variables *
|
---|
44 | *********************************************************************************************************************************/
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | VBoxClipboardWinStreamImpl::VBoxClipboardWinStreamImpl(SharedClipboardProvider *pProvider, SharedClipboardURIObject *pURIObj)
|
---|
49 | : m_lRefCount(1)
|
---|
50 | , m_pProvider(pProvider)
|
---|
51 | , m_pURIObj(pURIObj)
|
---|
52 | {
|
---|
53 | AssertPtr(m_pProvider);
|
---|
54 | AssertPtr(m_pURIObj);
|
---|
55 |
|
---|
56 | LogFunc(("szSrcPath=%s, cbSize=%RU64\n", m_pURIObj->GetSourcePathAbs().c_str(), m_pURIObj->GetSize()));
|
---|
57 |
|
---|
58 | m_pProvider->AddRef();
|
---|
59 | }
|
---|
60 |
|
---|
61 | VBoxClipboardWinStreamImpl::~VBoxClipboardWinStreamImpl(void)
|
---|
62 | {
|
---|
63 | LogFlowThisFuncEnter();
|
---|
64 | m_pProvider->Release();
|
---|
65 | }
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * IUnknown methods.
|
---|
69 | */
|
---|
70 |
|
---|
71 | STDMETHODIMP VBoxClipboardWinStreamImpl::QueryInterface(REFIID iid, void ** ppvObject)
|
---|
72 | {
|
---|
73 | AssertPtrReturn(ppvObject, E_INVALIDARG);
|
---|
74 |
|
---|
75 | if ( iid == IID_IStream
|
---|
76 | || iid == IID_IUnknown)
|
---|
77 | {
|
---|
78 | AddRef();
|
---|
79 | *ppvObject = this;
|
---|
80 | return S_OK;
|
---|
81 | }
|
---|
82 |
|
---|
83 | *ppvObject = 0;
|
---|
84 | return E_NOINTERFACE;
|
---|
85 | }
|
---|
86 |
|
---|
87 | STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::AddRef(void)
|
---|
88 | {
|
---|
89 | LONG lCount = InterlockedIncrement(&m_lRefCount);
|
---|
90 | LogFlowFunc(("lCount=%RI32\n", lCount));
|
---|
91 | return lCount;
|
---|
92 | }
|
---|
93 |
|
---|
94 | STDMETHODIMP_(ULONG) VBoxClipboardWinStreamImpl::Release(void)
|
---|
95 | {
|
---|
96 | LONG lCount = InterlockedDecrement(&m_lRefCount);
|
---|
97 | LogFlowFunc(("lCount=%RI32\n", m_lRefCount));
|
---|
98 | if (lCount == 0)
|
---|
99 | {
|
---|
100 | delete this;
|
---|
101 | return 0;
|
---|
102 | }
|
---|
103 |
|
---|
104 | return lCount;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * IStream methods.
|
---|
109 | */
|
---|
110 |
|
---|
111 | STDMETHODIMP VBoxClipboardWinStreamImpl::Clone(IStream** ppStream)
|
---|
112 | {
|
---|
113 | RT_NOREF(ppStream);
|
---|
114 |
|
---|
115 | LogFlowFuncEnter();
|
---|
116 | return E_NOTIMPL;
|
---|
117 | }
|
---|
118 |
|
---|
119 | STDMETHODIMP VBoxClipboardWinStreamImpl::Commit(DWORD dwFrags)
|
---|
120 | {
|
---|
121 | RT_NOREF(dwFrags);
|
---|
122 |
|
---|
123 | LogFlowThisFuncEnter();
|
---|
124 | return E_NOTIMPL;
|
---|
125 | }
|
---|
126 |
|
---|
127 | STDMETHODIMP VBoxClipboardWinStreamImpl::CopyTo(IStream *pDestStream, ULARGE_INTEGER nBytesToCopy, ULARGE_INTEGER *nBytesRead,
|
---|
128 | ULARGE_INTEGER *nBytesWritten)
|
---|
129 | {
|
---|
130 | RT_NOREF(pDestStream, nBytesToCopy, nBytesRead, nBytesWritten);
|
---|
131 |
|
---|
132 | LogFlowThisFuncEnter();
|
---|
133 | return E_NOTIMPL;
|
---|
134 | }
|
---|
135 |
|
---|
136 | STDMETHODIMP VBoxClipboardWinStreamImpl::LockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes,DWORD dwFlags)
|
---|
137 | {
|
---|
138 | RT_NOREF(nStart, nBytes, dwFlags);
|
---|
139 |
|
---|
140 | LogFlowThisFuncEnter();
|
---|
141 | return E_NOTIMPL;
|
---|
142 | }
|
---|
143 |
|
---|
144 | STDMETHODIMP VBoxClipboardWinStreamImpl::Read(void *pvBuffer, ULONG nBytesToRead, ULONG *nBytesRead)
|
---|
145 | {
|
---|
146 | LogFlowThisFuncEnter();
|
---|
147 |
|
---|
148 | AssertPtr(m_pURIObj);
|
---|
149 | if (m_pURIObj->IsComplete())
|
---|
150 | {
|
---|
151 | /* There can be 0-byte files. */
|
---|
152 | AssertMsg(m_pURIObj->GetSize() == 0, ("Object is complete -- can't read from it anymore\n"));
|
---|
153 | if (nBytesRead)
|
---|
154 | *nBytesRead = 0; /** @todo If the file size is 0, already return at least 1 byte, else the whole operation will fail. */
|
---|
155 | return S_OK; /* Don't report any failures back to Windows. */
|
---|
156 | }
|
---|
157 |
|
---|
158 | const uint64_t cbSize = m_pURIObj->GetSize();
|
---|
159 | const uint64_t cbProcessed = m_pURIObj->GetProcessed();
|
---|
160 |
|
---|
161 | const size_t cbToRead = RT_MIN(cbSize - cbProcessed, nBytesToRead);
|
---|
162 | size_t cbRead = 0;
|
---|
163 |
|
---|
164 | int rc = VINF_SUCCESS;
|
---|
165 |
|
---|
166 | if (cbToRead)
|
---|
167 | rc = m_pProvider->ReadData(pvBuffer, cbToRead, &cbRead);
|
---|
168 |
|
---|
169 | if (nBytesRead)
|
---|
170 | *nBytesRead = (ULONG)cbRead;
|
---|
171 |
|
---|
172 | LogFlowThisFunc(("rc=%Rrc, cbSize=%RU64, cbProcessed=%RU64 -> cbToRead=%zu, cbRead=%zu\n",
|
---|
173 | rc, cbSize, cbProcessed, cbToRead, cbRead));
|
---|
174 | return RT_SUCCESS(rc) ? S_OK : E_FAIL;
|
---|
175 | }
|
---|
176 |
|
---|
177 | STDMETHODIMP VBoxClipboardWinStreamImpl::Revert(void)
|
---|
178 | {
|
---|
179 | LogFlowThisFuncEnter();
|
---|
180 | return E_NOTIMPL;
|
---|
181 | }
|
---|
182 |
|
---|
183 | STDMETHODIMP VBoxClipboardWinStreamImpl::Seek(LARGE_INTEGER nMove, DWORD dwOrigin, ULARGE_INTEGER* nNewPos)
|
---|
184 | {
|
---|
185 | RT_NOREF(nMove, dwOrigin, nNewPos);
|
---|
186 |
|
---|
187 | LogFlowThisFuncEnter();
|
---|
188 | return E_NOTIMPL;
|
---|
189 | }
|
---|
190 |
|
---|
191 | STDMETHODIMP VBoxClipboardWinStreamImpl::SetSize(ULARGE_INTEGER nNewSize)
|
---|
192 | {
|
---|
193 | RT_NOREF(nNewSize);
|
---|
194 |
|
---|
195 | LogFlowThisFuncEnter();
|
---|
196 | return E_NOTIMPL;
|
---|
197 | }
|
---|
198 |
|
---|
199 | STDMETHODIMP VBoxClipboardWinStreamImpl::Stat(STATSTG *statstg, DWORD dwFlags)
|
---|
200 | {
|
---|
201 | RT_NOREF(statstg, dwFlags);
|
---|
202 |
|
---|
203 | LogFlowThisFuncEnter();
|
---|
204 | return E_NOTIMPL;
|
---|
205 | }
|
---|
206 |
|
---|
207 | STDMETHODIMP VBoxClipboardWinStreamImpl::UnlockRegion(ULARGE_INTEGER nStart, ULARGE_INTEGER nBytes, DWORD dwFlags)
|
---|
208 | {
|
---|
209 | RT_NOREF(nStart, nBytes, dwFlags);
|
---|
210 |
|
---|
211 | LogFlowThisFuncEnter();
|
---|
212 | return E_NOTIMPL;
|
---|
213 | }
|
---|
214 |
|
---|
215 | STDMETHODIMP VBoxClipboardWinStreamImpl::Write(const void *pvBuffer, ULONG nBytesToRead, ULONG *nBytesRead)
|
---|
216 | {
|
---|
217 | RT_NOREF(pvBuffer, nBytesToRead, nBytesRead);
|
---|
218 |
|
---|
219 | LogFlowThisFuncEnter();
|
---|
220 | return E_NOTIMPL;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * Own stuff.
|
---|
225 | */
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Factory to create our own IStream implementation.
|
---|
229 | *
|
---|
230 | * @returns HRESULT
|
---|
231 | * @param pProvider Pointer to Shared Clipboard provider to use.
|
---|
232 | * @param pURIObj Pointer to URI object to handle.
|
---|
233 | * @param ppStream Where to return the created stream object on success.
|
---|
234 | */
|
---|
235 | /* static */
|
---|
236 | HRESULT VBoxClipboardWinStreamImpl::Create(SharedClipboardProvider *pProvider, SharedClipboardURIObject *pURIObj,
|
---|
237 | IStream **ppStream)
|
---|
238 | {
|
---|
239 | AssertPtrReturn(pProvider, E_POINTER);
|
---|
240 |
|
---|
241 | VBoxClipboardWinStreamImpl *pStream = new VBoxClipboardWinStreamImpl(pProvider, pURIObj);
|
---|
242 | if (pStream)
|
---|
243 | {
|
---|
244 | pStream->AddRef();
|
---|
245 |
|
---|
246 | *ppStream = pStream;
|
---|
247 | return S_OK;
|
---|
248 | }
|
---|
249 |
|
---|
250 | return E_FAIL;
|
---|
251 | }
|
---|
252 |
|
---|