• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "Clipboard.h"
28 
29 #include "DOMImplementation.h"
30 #include "Frame.h"
31 #include "FrameLoader.h"
32 #include "Image.h"
33 
34 namespace WebCore {
35 
Clipboard(ClipboardAccessPolicy policy,bool isForDragging)36 Clipboard::Clipboard(ClipboardAccessPolicy policy, bool isForDragging)
37     : m_policy(policy)
38     , m_dragStarted(false)
39     , m_forDragging(isForDragging)
40     , m_dragImage(0)
41 {
42 }
43 
setAccessPolicy(ClipboardAccessPolicy policy)44 void Clipboard::setAccessPolicy(ClipboardAccessPolicy policy)
45 {
46     // once you go numb, can never go back
47     ASSERT(m_policy != ClipboardNumb || policy == ClipboardNumb);
48     m_policy = policy;
49 }
50 
51 // These "conversion" methods are called by both WebCore and WebKit, and never make sense to JS, so we don't
52 // worry about security for these. They don't allow access to the pasteboard anyway.
53 
dragOpFromIEOp(const String & op)54 static DragOperation dragOpFromIEOp(const String& op)
55 {
56     // yep, it's really just this fixed set
57     if (op == "none")
58         return DragOperationNone;
59     if (op == "copy")
60         return DragOperationCopy;
61     if (op == "link")
62         return DragOperationLink;
63     if (op == "move")
64         return DragOperationGeneric;
65     if (op == "copyLink")
66         return (DragOperation)(DragOperationCopy | DragOperationLink);
67     if (op == "copyMove")
68         return (DragOperation)(DragOperationCopy | DragOperationGeneric | DragOperationMove);
69     if (op == "linkMove")
70         return (DragOperation)(DragOperationLink | DragOperationGeneric | DragOperationMove);
71     if (op == "all")
72         return DragOperationEvery;
73     return DragOperationPrivate;  // really a marker for "no conversion"
74 }
75 
IEOpFromDragOp(DragOperation op)76 static String IEOpFromDragOp(DragOperation op)
77 {
78     bool moveSet = !!((DragOperationGeneric | DragOperationMove) & op);
79 
80     if ((moveSet && (op & DragOperationCopy) && (op & DragOperationLink))
81         || (op == DragOperationEvery))
82         return "all";
83     if (moveSet && (op & DragOperationCopy))
84         return "copyMove";
85     if (moveSet && (op & DragOperationLink))
86         return "linkMove";
87     if ((op & DragOperationCopy) && (op & DragOperationLink))
88         return "copyLink";
89     if (moveSet)
90         return "move";
91     if (op & DragOperationCopy)
92         return "copy";
93     if (op & DragOperationLink)
94         return "link";
95     return "none";
96 }
97 
sourceOperation(DragOperation & op) const98 bool Clipboard::sourceOperation(DragOperation& op) const
99 {
100     if (m_effectAllowed.isNull())
101         return false;
102     op = dragOpFromIEOp(m_effectAllowed);
103     return true;
104 }
105 
destinationOperation(DragOperation & op) const106 bool Clipboard::destinationOperation(DragOperation& op) const
107 {
108     if (m_dropEffect.isNull())
109         return false;
110     op = dragOpFromIEOp(m_dropEffect);
111     return true;
112 }
113 
setSourceOperation(DragOperation op)114 void Clipboard::setSourceOperation(DragOperation op)
115 {
116     m_effectAllowed = IEOpFromDragOp(op);
117 }
118 
setDestinationOperation(DragOperation op)119 void Clipboard::setDestinationOperation(DragOperation op)
120 {
121     m_dropEffect = IEOpFromDragOp(op);
122 }
123 
setDropEffect(const String & effect)124 void Clipboard::setDropEffect(const String &effect)
125 {
126     if (!m_forDragging)
127         return;
128 
129     if (m_policy == ClipboardReadable || m_policy == ClipboardTypesReadable)
130         m_dropEffect = effect;
131 }
132 
setEffectAllowed(const String & effect)133 void Clipboard::setEffectAllowed(const String &effect)
134 {
135     if (!m_forDragging)
136         return;
137 
138     if (m_policy == ClipboardWritable)
139         m_effectAllowed = effect;
140 }
141 
142 } // namespace WebCore
143