Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1552)

Side by Side Diff: Source/WebCore/platform/mac/DragDataMac.mm

Issue 13713003: Remove all of WebCore/platform/mac which is not mentioned in WebCore.gypi. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added back a couple needed headers Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2007 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 #import "config.h"
27 #import "DragData.h"
28
29 #if ENABLE(DRAG_SUPPORT)
30 #import "Document.h"
31 #import "DocumentFragment.h"
32 #import "DOMDocumentFragment.h"
33 #import "DOMDocumentFragmentInternal.h"
34 #import "Editor.h"
35 #import "EditorClient.h"
36 #import "Frame.h"
37 #import "MIMETypeRegistry.h"
38 #import "Pasteboard.h"
39 #import "PasteboardStrategy.h"
40 #import "PlatformStrategies.h"
41 #import "Range.h"
42
43 namespace WebCore {
44
45 DragData::DragData(DragDataRef data, const IntPoint& clientPosition, const IntPo int& globalPosition,
46 DragOperation sourceOperationMask, DragApplicationFlags flags)
47 : m_clientPosition(clientPosition)
48 , m_globalPosition(globalPosition)
49 , m_platformDragData(data)
50 , m_draggingSourceOperationMask(sourceOperationMask)
51 , m_applicationFlags(flags)
52 , m_pasteboardName([[m_platformDragData draggingPasteboard] name])
53 {
54 }
55
56 DragData::DragData(const String& dragStorageName, const IntPoint& clientPosition , const IntPoint& globalPosition,
57 DragOperation sourceOperationMask, DragApplicationFlags flags)
58 : m_clientPosition(clientPosition)
59 , m_globalPosition(globalPosition)
60 , m_platformDragData(0)
61 , m_draggingSourceOperationMask(sourceOperationMask)
62 , m_applicationFlags(flags)
63 , m_pasteboardName(dragStorageName)
64 {
65 }
66
67 bool DragData::canSmartReplace() const
68 {
69 return Pasteboard(m_pasteboardName).canSmartReplace();
70 }
71
72 bool DragData::containsColor() const
73 {
74 Vector<String> types;
75 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName );
76 return types.contains(String(NSColorPboardType));
77 }
78
79 bool DragData::containsFiles() const
80 {
81 Vector<String> types;
82 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName );
83 return types.contains(String(NSFilenamesPboardType));
84 }
85
86 unsigned DragData::numberOfFiles() const
87 {
88 Vector<String> files;
89 platformStrategies()->pasteboardStrategy()->getPathnamesForType(files, Strin g(NSFilenamesPboardType), m_pasteboardName);
90 return files.size();
91 }
92
93 void DragData::asFilenames(Vector<String>& result) const
94 {
95 platformStrategies()->pasteboardStrategy()->getPathnamesForType(result, Stri ng(NSFilenamesPboardType), m_pasteboardName);
96 }
97
98 bool DragData::containsPlainText() const
99 {
100 Vector<String> types;
101 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName );
102
103 return types.contains(String(NSStringPboardType))
104 || types.contains(String(NSRTFDPboardType))
105 || types.contains(String(NSRTFPboardType))
106 || types.contains(String(NSFilenamesPboardType))
107 || platformStrategies()->pasteboardStrategy()->stringForType(String(NSUR LPboardType), m_pasteboardName).length();
108 }
109
110 String DragData::asPlainText(Frame *frame) const
111 {
112 return Pasteboard(m_pasteboardName).plainText(frame);
113 }
114
115 Color DragData::asColor() const
116 {
117 return platformStrategies()->pasteboardStrategy()->color(m_pasteboardName);
118 }
119
120 bool DragData::containsCompatibleContent() const
121 {
122 Vector<String> types;
123 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName );
124 return types.contains(String(WebArchivePboardType))
125 || types.contains(String(NSHTMLPboardType))
126 || types.contains(String(NSFilenamesPboardType))
127 || types.contains(String(NSTIFFPboardType))
128 || types.contains(String(NSPDFPboardType))
129 || types.contains(String(NSURLPboardType))
130 || types.contains(String(NSRTFDPboardType))
131 || types.contains(String(NSRTFPboardType))
132 || types.contains(String(NSStringPboardType))
133 || types.contains(String(NSColorPboardType))
134 || types.contains(String(kUTTypePNG));
135 }
136
137 bool DragData::containsURL(Frame* frame, FilenameConversionPolicy filenamePolicy ) const
138 {
139 return !asURL(frame, filenamePolicy).isEmpty();
140 }
141
142 String DragData::asURL(Frame* frame, FilenameConversionPolicy filenamePolicy, St ring* title) const
143 {
144 // FIXME: Use filenamePolicy.
145 (void)filenamePolicy;
146
147 if (title) {
148 String URLTitleString = platformStrategies()->pasteboardStrategy()->stri ngForType(String(WebURLNamePboardType), m_pasteboardName);
149 if (!URLTitleString.isEmpty())
150 *title = URLTitleString;
151 }
152
153 Vector<String> types;
154 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName );
155
156 // FIXME: using the editorClient to call into WebKit, for now, since
157 // calling webkit_canonicalize from WebCore involves migrating a sizable amo unt of
158 // helper code that should either be done in a separate patch or figured out in another way.
159
160 if (types.contains(String(NSURLPboardType))) {
161 NSURL *URLFromPasteboard = [NSURL URLWithString:platformStrategies()->pa steboardStrategy()->stringForType(String(NSURLPboardType), m_pasteboardName)];
162 NSString *scheme = [URLFromPasteboard scheme];
163 // Cannot drop other schemes unless <rdar://problem/10562662> and <rdar: //problem/11187315> are fixed.
164 if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https" ])
165 return [frame->editor()->client()->canonicalizeURL(URLFromPasteboard ) absoluteString];
166 }
167
168 if (types.contains(String(NSStringPboardType))) {
169 NSURL *URLFromPasteboard = [NSURL URLWithString:platformStrategies()->pa steboardStrategy()->stringForType(String(NSStringPboardType), m_pasteboardName)] ;
170 NSString *scheme = [URLFromPasteboard scheme];
171 // Pasteboard content is not trusted, because JavaScript code can modify it. We can sanitize it for URLs and other typed content, but not for strings.
172 // The result of this function is used to initiate navigation, so we sho uldn't allow arbitrary file URLs.
173 // FIXME: Should we allow only http family schemes, or anything non-loca l?
174 if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https" ])
175 return [frame->editor()->client()->canonicalizeURL(URLFromPasteboard ) absoluteString];
176 }
177
178 if (types.contains(String(NSFilenamesPboardType))) {
179 Vector<String> files;
180 platformStrategies()->pasteboardStrategy()->getPathnamesForType(files, S tring(NSFilenamesPboardType), m_pasteboardName);
181 if (files.size() == 1) {
182 BOOL isDirectory;
183 if ([[NSFileManager defaultManager] fileExistsAtPath:files[0] isDire ctory:&isDirectory] && isDirectory)
184 return String();
185 return [frame->editor()->client()->canonicalizeURL([NSURL fileURLWit hPath:files[0]]) absoluteString];
186 }
187 }
188
189 return String();
190 }
191
192 PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, PassRefPtr<Range > range, bool allowPlainText, bool& chosePlainText) const
193 {
194 return Pasteboard(m_pasteboardName).documentFragment(frame, range, allowPlai nText, chosePlainText);
195 }
196
197 } // namespace WebCore
198
199 #endif // ENABLE(DRAG_SUPPORT)
OLDNEW
« no previous file with comments | « Source/WebCore/platform/mac/DisplaySleepDisabler.cpp ('k') | Source/WebCore/platform/mac/DragImageMac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698