~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to services/plugins/dndcp/dndGuest/guestDnDDest.cc

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2010 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation version 2.1 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 
11
 * License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
/**
 
20
 * @guestDnDDest.cc --
 
21
 *
 
22
 * Implementation of common layer GuestDnDDest object for guest.
 
23
 */
 
24
 
 
25
 
 
26
#include "guestDnD.hh"
 
27
 
 
28
extern "C" {
 
29
   #include "dndClipboard.h"
 
30
   #include "debug.h"
 
31
}
 
32
 
 
33
 
 
34
/**
 
35
 * Constructor.
 
36
 *
 
37
 * @param[in] mgr guest DnD manager
 
38
 */
 
39
 
 
40
GuestDnDDest::GuestDnDDest(GuestDnDMgr *mgr)
 
41
 : mMgr(mgr)
 
42
{
 
43
   ASSERT(mMgr);
 
44
   mMgr->GetRpc()->destPrivDragEnterChanged.connect(
 
45
      sigc::mem_fun(this, &GuestDnDDest::OnRpcPrivDragEnter));
 
46
   mMgr->GetRpc()->destPrivDragLeaveChanged.connect(
 
47
      sigc::mem_fun(this, &GuestDnDDest::OnRpcPrivDragLeave));
 
48
   mMgr->GetRpc()->destPrivDropChanged.connect(
 
49
      sigc::mem_fun(this, &GuestDnDDest::OnRpcPrivDrop));
 
50
   mMgr->GetRpc()->destDropChanged.connect(
 
51
      sigc::mem_fun(this, &GuestDnDDest::OnRpcDrop));
 
52
   mMgr->GetRpc()->destCancelChanged.connect(
 
53
      sigc::mem_fun(this, &GuestDnDDest::OnRpcCancel));
 
54
 
 
55
   CPClipboard_Init(&mClipboard);
 
56
}
 
57
 
 
58
 
 
59
/**
 
60
 * Destructor.
 
61
 */
 
62
 
 
63
GuestDnDDest::~GuestDnDDest(void)
 
64
{
 
65
   CPClipboard_Destroy(&mClipboard);
 
66
}
 
67
 
 
68
 
 
69
/**
 
70
 * Guest UI got dragEnter with valid data. Send dragEnter cmd to controller.
 
71
 *
 
72
 * @param[in] clip cross-platform clipboard data.
 
73
 */
 
74
 
 
75
void
 
76
GuestDnDDest::UIDragEnter(const CPClipboard *clip)
 
77
{
 
78
   if (!mMgr->IsDragEnterAllowed()) {
 
79
      Debug("%s: not allowed.\n", __FUNCTION__);
 
80
      return;
 
81
   }
 
82
 
 
83
   Debug("%s: entering.\n", __FUNCTION__);
 
84
 
 
85
   if (GUEST_DND_DEST_DRAGGING == mMgr->GetState() ||
 
86
       GUEST_DND_PRIV_DRAGGING == mMgr->GetState()) {
 
87
      /*
 
88
       * In GH DnD case, if DnD already happened, user may drag back into guest
 
89
       * VM and drag into the detection window again, and trigger the
 
90
       * DragEnter. In this case, ignore the DragEnter.
 
91
       */
 
92
      Debug("%s: already in state %d for GH DnD, ignoring.\n",
 
93
            __FUNCTION__, mMgr->GetState());
 
94
      return;
 
95
   }
 
96
 
 
97
   if (GUEST_DND_SRC_DRAGGING == mMgr->GetState()) {
 
98
      /*
 
99
       * In HG DnD case, if DnD already happened, user may also drag into the
 
100
       * detection window again. The DragEnter should also be ignored.
 
101
       */
 
102
      Debug("%s: already in SRC_DRAGGING state, ignoring\n", __FUNCTION__);
 
103
      return;
 
104
   }
 
105
 
 
106
   /*
 
107
    * In Unity mode, there is no QueryPendingDrag signal, so may get called
 
108
    * with state READY.
 
109
    */
 
110
   if (mMgr->GetState() != GUEST_DND_QUERY_EXITING &&
 
111
       mMgr->GetState() != GUEST_DND_READY) {
 
112
      Debug("%s: Bad state: %d, reset\n", __FUNCTION__, mMgr->GetState());
 
113
      goto error;
 
114
   }
 
115
 
 
116
   CPClipboard_Clear(&mClipboard);
 
117
   CPClipboard_Copy(&mClipboard, clip);
 
118
 
 
119
   if (!mMgr->GetRpc()->DestDragEnter(mMgr->GetSessionId(), clip)) {
 
120
      Debug("%s: DestDragEnter failed\n", __FUNCTION__);
 
121
      goto error;
 
122
   }
 
123
 
 
124
   mMgr->SetState(GUEST_DND_DEST_DRAGGING);
 
125
   Debug("%s: state changed to DEST_DRAGGING\n", __FUNCTION__);
 
126
   return;
 
127
 
 
128
error:
 
129
   mMgr->ResetDnD();
 
130
}
 
131
 
 
132
 
 
133
/**
 
134
 * User drags back to guest during GH DnD. Change state machine to
 
135
 * PRIV_DRAGGING state.
 
136
 *
 
137
 * @param[in] sessionId active session id the controller assigned.
 
138
 */
 
139
 
 
140
void
 
141
GuestDnDDest::OnRpcPrivDragEnter(uint32 sessionId)
 
142
{
 
143
   Debug("%s: entering.\n", __FUNCTION__);
 
144
 
 
145
   if (GUEST_DND_DEST_DRAGGING != mMgr->GetState()) {
 
146
      Debug("%s: Bad state: %d, reset\n", __FUNCTION__, mMgr->GetState());
 
147
      goto error;
 
148
   }
 
149
 
 
150
   mMgr->SetState(GUEST_DND_PRIV_DRAGGING);
 
151
   Debug("%s: state changed to PRIV_DRAGGING\n", __FUNCTION__);
 
152
   return;
 
153
 
 
154
error:
 
155
   mMgr->ResetDnD();
 
156
}
 
157
 
 
158
 
 
159
/**
 
160
 * User drags away from guest during GH DnD. Change state machine to
 
161
 * SRC_DRAGGING state.
 
162
 *
 
163
 * @param[in] sessionId active session id the controller assigned.
 
164
 * @param[in] x mouse position x.
 
165
 * @param[in] y mouse position y.
 
166
 */
 
167
 
 
168
void
 
169
GuestDnDDest::OnRpcPrivDragLeave(uint32 sessionId,
 
170
                                 int32 x,
 
171
                                 int32 y)
 
172
{
 
173
   Debug("%s: entering.\n", __FUNCTION__);
 
174
 
 
175
   if (GUEST_DND_PRIV_DRAGGING != mMgr->GetState()) {
 
176
      Debug("%s: Bad state: %d, reset\n", __FUNCTION__, mMgr->GetState());
 
177
      goto error;
 
178
   }
 
179
 
 
180
   mMgr->SetState(GUEST_DND_DEST_DRAGGING);
 
181
   mMgr->destMoveDetWndToMousePosChanged.emit();
 
182
   Debug("%s: state changed to DEST_DRAGGING\n", __FUNCTION__);
 
183
   return;
 
184
 
 
185
error:
 
186
   mMgr->ResetDnD();
 
187
}
 
188
 
 
189
 
 
190
/**
 
191
 * User drops inside guest during GH DnD. Simulate the mouse drop, hide
 
192
 * detection window, and reset state machine.
 
193
 *
 
194
 * @param[in] sessionId active session id the controller assigned.
 
195
 * @param[in] x mouse position x.
 
196
 * @param[in] y mouse position y.
 
197
 */
 
198
 
 
199
void
 
200
GuestDnDDest::OnRpcPrivDrop(uint32 sessionId,
 
201
                            int32 x,
 
202
                            int32 y)
 
203
{
 
204
   mMgr->privDropChanged.emit(x, y);
 
205
   mMgr->HideDetWnd();
 
206
   mMgr->SetState(GUEST_DND_READY);
 
207
   Debug("%s: state changed to GUEST_DND_READY, session id changed to 0\n",
 
208
         __FUNCTION__);
 
209
}
 
210
 
 
211
 
 
212
/**
 
213
 * User drops outside of guest during GH DnD. Simply cancel the local DnD.
 
214
 *
 
215
 * @param[in] sessionId active session id the controller assigned.
 
216
 * @param[in] x mouse position x.
 
217
 * @param[in] y mouse position y.
 
218
 */
 
219
 
 
220
void
 
221
GuestDnDDest::OnRpcDrop(uint32 sessionId,
 
222
                        int32 x,
 
223
                        int32 y)
 
224
{
 
225
   OnRpcCancel(sessionId);
 
226
}
 
227
 
 
228
 
 
229
/**
 
230
 * Cancel current GH DnD.
 
231
 *
 
232
 * @param[in] sessionId active session id the controller assigned.
 
233
 */
 
234
 
 
235
void
 
236
GuestDnDDest::OnRpcCancel(uint32 sessionId)
 
237
{
 
238
   mMgr->DelayHideDetWnd();
 
239
   mMgr->RemoveUngrabTimeout();
 
240
   mMgr->destCancelChanged.emit();
 
241
   mMgr->SetState(GUEST_DND_READY);
 
242
   Debug("%s: state changed to GUEST_DND_READY, session id changed to 0\n",
 
243
         __FUNCTION__);
 
244
}
 
245