|
1 /* |
|
2 * Copyright (C) 2005 Apple Computer, 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 * |
|
8 * 1. Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * 2. Redistributions in binary form must reproduce the above copyright |
|
11 * notice, this list of conditions and the following disclaimer in the |
|
12 * documentation and/or other materials provided with the distribution. |
|
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
14 * its contributors may be used to endorse or promote products derived |
|
15 * from this software without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #import <WebKit/WebDOMOperationsPrivate.h> |
|
30 |
|
31 #import <WebKit/DOMExtensions.h> |
|
32 #import <WebKit/DOMHTML.h> |
|
33 #import <JavaScriptCore/Assertions.h> |
|
34 #import <WebKit/WebFrameBridge.h> |
|
35 #import <WebKit/WebDataSourcePrivate.h> |
|
36 #import <WebKit/WebFramePrivate.h> |
|
37 #import <WebKit/WebKitNSStringExtras.h> |
|
38 #import <WebKit/WebArchiver.h> |
|
39 |
|
40 |
|
41 @implementation DOMNode (WebDOMNodeOperations) |
|
42 |
|
43 - (WebFrameBridge *)_bridge |
|
44 { |
|
45 return (WebFrameBridge *)[WebFrameBridge bridgeForDOMDocument:[self ownerDocument]]; |
|
46 } |
|
47 |
|
48 - (WebArchive *)webArchive |
|
49 { |
|
50 return [WebArchiver archiveNode:self]; |
|
51 } |
|
52 |
|
53 - (NSString *)markupString |
|
54 { |
|
55 return [[self _bridge] markupStringFromNode:self nodes:nil]; |
|
56 } |
|
57 |
|
58 - (NSArray *)_URLsFromSelectors:(SEL)firstSel, ... |
|
59 { |
|
60 NSMutableArray *URLs = [NSMutableArray array]; |
|
61 |
|
62 va_list args; |
|
63 va_start(args, firstSel); |
|
64 |
|
65 SEL selector = firstSel; |
|
66 do { |
|
67 NSString *string = [self performSelector:selector]; |
|
68 if ([string length] > 0) { |
|
69 [URLs addObject:[[self ownerDocument] URLWithAttributeString:string]]; |
|
70 } |
|
71 } while ((selector = va_arg(args, SEL)) != nil); |
|
72 |
|
73 va_end(args); |
|
74 |
|
75 return URLs; |
|
76 } |
|
77 |
|
78 - (NSArray *)_subresourceURLs |
|
79 { |
|
80 return nil; |
|
81 } |
|
82 |
|
83 @end |
|
84 |
|
85 @implementation DOMDocument (WebDOMDocumentOperations) |
|
86 |
|
87 - (WebFrame *)webFrame |
|
88 { |
|
89 return [[self _bridge] webFrame]; |
|
90 } |
|
91 |
|
92 - (NSURL *)URLWithAttributeString:(NSString *)string |
|
93 { |
|
94 return [[self _bridge] URLWithAttributeString:string]; |
|
95 } |
|
96 |
|
97 @end |
|
98 |
|
99 @implementation DOMDocument (WebDOMDocumentOperationsPrivate) |
|
100 |
|
101 - (DOMRange *)_createRangeWithNode:(DOMNode *)node |
|
102 { |
|
103 DOMRange *range = [self createRange]; |
|
104 [range selectNode:node]; |
|
105 return range; |
|
106 } |
|
107 |
|
108 - (DOMRange *)_documentRange |
|
109 { |
|
110 return [self _createRangeWithNode:[self documentElement]]; |
|
111 } |
|
112 |
|
113 @end |
|
114 |
|
115 @implementation DOMRange (WebDOMRangeOperations) |
|
116 |
|
117 - (WebFrameBridge *)_bridge |
|
118 { |
|
119 return [[self startContainer] _bridge]; |
|
120 } |
|
121 |
|
122 - (WebArchive *)webArchive |
|
123 { |
|
124 return [WebArchiver archiveRange:self]; |
|
125 } |
|
126 |
|
127 - (NSString *)markupString |
|
128 { |
|
129 return [[self _bridge] markupStringFromRange:self nodes:nil]; |
|
130 } |
|
131 |
|
132 @end |
|
133 |
|
134 @implementation DOMHTMLBodyElement (WebDOMHTMLBodyElementOperationsPrivate) |
|
135 |
|
136 - (NSArray *)_subresourceURLs |
|
137 { |
|
138 return [self _URLsFromSelectors:@selector(background), nil]; |
|
139 } |
|
140 |
|
141 @end |
|
142 |
|
143 @implementation DOMHTMLInputElement (WebDOMHTMLInputElementOperationsPrivate) |
|
144 |
|
145 - (NSArray *)_subresourceURLs |
|
146 { |
|
147 return [self _URLsFromSelectors:@selector(src), nil]; |
|
148 } |
|
149 |
|
150 @end |
|
151 |
|
152 @implementation DOMHTMLLinkElement (WebDOMHTMLLinkElementOperationsPrivate) |
|
153 |
|
154 - (NSArray *)_subresourceURLs |
|
155 { |
|
156 NSString *relName = [self rel]; |
|
157 if ([relName _webkit_isCaseInsensitiveEqualToString:@"stylesheet"] || [relName _webkit_isCaseInsensitiveEqualToString:@"icon"]) { |
|
158 return [self _URLsFromSelectors:@selector(href), nil]; |
|
159 } |
|
160 return nil; |
|
161 } |
|
162 |
|
163 @end |
|
164 |
|
165 @implementation DOMHTMLScriptElement (WebDOMHTMLScriptElementOperationsPrivate) |
|
166 |
|
167 - (NSArray *)_subresourceURLs |
|
168 { |
|
169 return [self _URLsFromSelectors:@selector(src), nil]; |
|
170 } |
|
171 |
|
172 @end |
|
173 |
|
174 @implementation DOMHTMLImageElement (WebDOMHTMLImageElementOperationsPrivate) |
|
175 |
|
176 - (NSArray *)_subresourceURLs |
|
177 { |
|
178 SEL useMapSelector = [[self useMap] hasPrefix:@"#"] ? nil : @selector(useMap); |
|
179 return [self _URLsFromSelectors:@selector(src), useMapSelector, nil]; |
|
180 } |
|
181 |
|
182 @end |
|
183 |
|
184 @implementation DOMHTMLEmbedElement (WebDOMHTMLEmbedElementOperationsPrivate) |
|
185 |
|
186 - (NSArray *)_subresourceURLs |
|
187 { |
|
188 return [self _URLsFromSelectors:@selector(src), nil]; |
|
189 } |
|
190 |
|
191 @end |
|
192 |
|
193 @implementation DOMHTMLObjectElement (WebDOMHTMLObjectElementOperationsPrivate) |
|
194 |
|
195 - (NSArray *)_subresourceURLs |
|
196 { |
|
197 SEL useMapSelector = [[self useMap] hasPrefix:@"#"] ? nil : @selector(useMap); |
|
198 return [self _URLsFromSelectors:@selector(data), useMapSelector, nil]; |
|
199 } |
|
200 |
|
201 @end |
|
202 |
|
203 @implementation DOMHTMLParamElement (WebDOMHTMLParamElementOperationsPrivate) |
|
204 |
|
205 - (NSArray *)_subresourceURLs |
|
206 { |
|
207 NSString *paramName = [self name]; |
|
208 if ([paramName _webkit_isCaseInsensitiveEqualToString:@"data"] || |
|
209 [paramName _webkit_isCaseInsensitiveEqualToString:@"movie"] || |
|
210 [paramName _webkit_isCaseInsensitiveEqualToString:@"src"]) { |
|
211 return [self _URLsFromSelectors:@selector(value), nil]; |
|
212 } |
|
213 return nil; |
|
214 } |
|
215 |
|
216 @end |
|
217 |
|
218 @implementation DOMHTMLTableElement (WebDOMHTMLTableElementOperationsPrivate) |
|
219 |
|
220 - (NSString *)_web_background |
|
221 { |
|
222 return [self getAttribute:@"background"]; |
|
223 } |
|
224 |
|
225 - (NSArray *)_subresourceURLs |
|
226 { |
|
227 return [self _URLsFromSelectors:@selector(_web_background), nil]; |
|
228 } |
|
229 |
|
230 @end |
|
231 |
|
232 @implementation DOMHTMLTableCellElement (WebDOMHTMLTableCellElementOperationsPrivate) |
|
233 |
|
234 - (NSString *)_web_background |
|
235 { |
|
236 return [self getAttribute:@"background"]; |
|
237 } |
|
238 |
|
239 - (NSArray *)_subresourceURLs |
|
240 { |
|
241 return [self _URLsFromSelectors:@selector(_web_background), nil]; |
|
242 } |
|
243 |
|
244 @end |
|
245 |
|
246 @implementation DOMHTMLFrameElement (WebDOMHTMLFrameElementOperations) |
|
247 |
|
248 - (WebFrame *)contentFrame |
|
249 { |
|
250 return [[self contentDocument] webFrame]; |
|
251 } |
|
252 |
|
253 @end |
|
254 |
|
255 @implementation DOMHTMLIFrameElement (WebDOMHTMLIFrameElementOperations) |
|
256 |
|
257 - (WebFrame *)contentFrame |
|
258 { |
|
259 return [[self contentDocument] webFrame]; |
|
260 } |
|
261 |
|
262 @end |
|
263 |
|
264 @implementation DOMHTMLObjectElement (WebDOMHTMLObjectElementOperations) |
|
265 |
|
266 - (WebFrame *)contentFrame |
|
267 { |
|
268 return [[self contentDocument] webFrame]; |
|
269 } |
|
270 |
|
271 @end |