2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #import <WebKit/WebDOMOperationsPrivate.h>
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>
41 #import <WebKit/DOMSVG.h>
44 @implementation DOMNode (WebDOMNodeOperations)
46 - (WebFrameBridge *)_bridge
48 return (WebFrameBridge *)[WebFrameBridge bridgeForDOMDocument:[self ownerDocument]];
51 - (WebArchive *)webArchive
53 return [WebArchiver archiveNode:self];
56 - (NSString *)markupString
58 return [[self _bridge] markupStringFromNode:self nodes:nil];
61 - (NSArray *)_URLsFromSelectors:(SEL)firstSel, ...
63 NSMutableArray *URLs = [NSMutableArray array];
66 va_start(args, firstSel);
68 SEL selector = firstSel;
72 id attributeValue = [self performSelector:selector];
73 if ([attributeValue isKindOfClass:[DOMSVGAnimatedString class]])
74 string = [(DOMSVGAnimatedString*)attributeValue animVal];
76 string = attributeValue;
78 NSString *string = [self performSelector:selector];
80 if ([string length] > 0)
81 [URLs addObject:[[self ownerDocument] URLWithAttributeString:string]];
82 } while ((selector = va_arg(args, SEL)) != nil);
89 - (NSArray *)_subresourceURLs
96 @implementation DOMDocument (WebDOMDocumentOperations)
98 - (WebFrame *)webFrame
100 return [[self _bridge] webFrame];
103 - (NSURL *)URLWithAttributeString:(NSString *)string
105 return [[self _bridge] URLWithAttributeString:string];
110 @implementation DOMDocument (WebDOMDocumentOperationsPrivate)
112 - (DOMRange *)_createRangeWithNode:(DOMNode *)node
114 DOMRange *range = [self createRange];
115 [range selectNode:node];
119 - (DOMRange *)_documentRange
121 return [self _createRangeWithNode:[self documentElement]];
126 @implementation DOMRange (WebDOMRangeOperations)
128 - (WebFrameBridge *)_bridge
130 return [[self startContainer] _bridge];
133 - (WebArchive *)webArchive
135 return [WebArchiver archiveRange:self];
138 - (NSString *)markupString
140 return [[self _bridge] markupStringFromRange:self nodes:nil];
145 @implementation DOMHTMLBodyElement (WebDOMHTMLBodyElementOperationsPrivate)
147 - (NSArray *)_subresourceURLs
149 return [self _URLsFromSelectors:@selector(background), nil];
154 @implementation DOMHTMLInputElement (WebDOMHTMLInputElementOperationsPrivate)
156 - (NSArray *)_subresourceURLs
158 return [self _URLsFromSelectors:@selector(src), nil];
163 @implementation DOMHTMLLinkElement (WebDOMHTMLLinkElementOperationsPrivate)
165 - (NSArray *)_subresourceURLs
167 NSString *relName = [self rel];
168 if ([relName _webkit_isCaseInsensitiveEqualToString:@"stylesheet"] || [relName _webkit_isCaseInsensitiveEqualToString:@"icon"]) {
169 return [self _URLsFromSelectors:@selector(href), nil];
176 @implementation DOMHTMLScriptElement (WebDOMHTMLScriptElementOperationsPrivate)
178 - (NSArray *)_subresourceURLs
180 return [self _URLsFromSelectors:@selector(src), nil];
185 @implementation DOMHTMLImageElement (WebDOMHTMLImageElementOperationsPrivate)
187 - (NSArray *)_subresourceURLs
189 SEL useMapSelector = [[self useMap] hasPrefix:@"#"] ? nil : @selector(useMap);
190 return [self _URLsFromSelectors:@selector(src), useMapSelector, nil];
197 @implementation DOMSVGImageElement (WebDOMSVGImageElementOperationsPrivate)
199 - (NSArray *)_subresourceURLs
201 return [self _URLsFromSelectors:@selector(href), nil];
208 @implementation DOMProcessingInstruction (WebDOMProcessingInstructionOperationsPrivate)
210 - (NSString *)_stylesheetURL
212 DOMStyleSheet *styleSheet = [self sheet];
214 return [styleSheet href];
218 - (NSArray *)_subresourceURLs
220 return [self _URLsFromSelectors:@selector(_stylesheetURL), nil];
225 @implementation DOMHTMLEmbedElement (WebDOMHTMLEmbedElementOperationsPrivate)
227 - (NSArray *)_subresourceURLs
229 return [self _URLsFromSelectors:@selector(src), nil];
234 @implementation DOMHTMLObjectElement (WebDOMHTMLObjectElementOperationsPrivate)
236 - (NSArray *)_subresourceURLs
238 SEL useMapSelector = [[self useMap] hasPrefix:@"#"] ? nil : @selector(useMap);
239 return [self _URLsFromSelectors:@selector(data), useMapSelector, nil];
244 @implementation DOMHTMLParamElement (WebDOMHTMLParamElementOperationsPrivate)
246 - (NSArray *)_subresourceURLs
248 NSString *paramName = [self name];
249 if ([paramName _webkit_isCaseInsensitiveEqualToString:@"data"] ||
250 [paramName _webkit_isCaseInsensitiveEqualToString:@"movie"] ||
251 [paramName _webkit_isCaseInsensitiveEqualToString:@"src"]) {
252 return [self _URLsFromSelectors:@selector(value), nil];
259 @implementation DOMHTMLTableElement (WebDOMHTMLTableElementOperationsPrivate)
261 - (NSString *)_web_background
263 return [self getAttribute:@"background"];
266 - (NSArray *)_subresourceURLs
268 return [self _URLsFromSelectors:@selector(_web_background), nil];
273 @implementation DOMHTMLTableCellElement (WebDOMHTMLTableCellElementOperationsPrivate)
275 - (NSString *)_web_background
277 return [self getAttribute:@"background"];
280 - (NSArray *)_subresourceURLs
282 return [self _URLsFromSelectors:@selector(_web_background), nil];
287 @implementation DOMHTMLFrameElement (WebDOMHTMLFrameElementOperations)
289 - (WebFrame *)contentFrame
291 return [[self contentDocument] webFrame];
296 @implementation DOMHTMLIFrameElement (WebDOMHTMLIFrameElementOperations)
298 - (WebFrame *)contentFrame
300 return [[self contentDocument] webFrame];
305 @implementation DOMHTMLObjectElement (WebDOMHTMLObjectElementOperations)
307 - (WebFrame *)contentFrame
309 return [[self contentDocument] webFrame];