• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2005, 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 *
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 "WebDOMOperationsPrivate.h"
30
31#import "DOMDocumentInternal.h"
32#import "DOMNodeInternal.h"
33#import "DOMRangeInternal.h"
34#import "WebArchiveInternal.h"
35#import "WebDataSourcePrivate.h"
36#import "WebFrameInternal.h"
37#import "WebFramePrivate.h"
38#import "WebKitNSStringExtras.h"
39#import <WebCore/CSSHelper.h>
40#import <WebCore/Document.h>
41#import <WebCore/LegacyWebArchive.h>
42#import <WebCore/markup.h>
43#import <WebKit/DOMExtensions.h>
44#import <WebKit/DOMHTML.h>
45#import <wtf/Assertions.h>
46
47using namespace WebCore;
48
49@implementation DOMNode (WebDOMNodeOperations)
50
51- (WebArchive *)webArchive
52{
53    return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(core(self))] autorelease];
54}
55
56- (NSString *)markupString
57{
58    return createFullMarkup(core(self));
59}
60
61@end
62
63/* This doesn't appear to be used by anyone.  We should consider removing this. */
64@implementation DOMNode (WebDOMNodeOperationsInternal)
65
66- (NSArray *)_subresourceURLs
67{
68    ListHashSet<KURL> urls;
69    core(self)->getSubresourceURLs(urls);
70    if (!urls.size())
71        return nil;
72
73    NSMutableArray *array = [NSMutableArray arrayWithCapacity:urls.size()];
74    ListHashSet<KURL>::iterator end = urls.end();
75    for (ListHashSet<KURL>::iterator it = urls.begin(); it != end; ++it)
76        [array addObject:(NSURL *)*it];
77
78    return array;
79}
80
81@end
82
83@implementation DOMDocument (WebDOMDocumentOperations)
84
85- (WebFrame *)webFrame
86{
87    Document* document = core(self);
88    Frame* frame = document->frame();
89    if (!frame)
90        return nil;
91    return kit(frame);
92}
93
94- (NSURL *)URLWithAttributeString:(NSString *)string
95{
96    // FIXME: Is deprecatedParseURL appropriate here?
97    return core(self)->completeURL(deprecatedParseURL(string));
98}
99
100@end
101
102@implementation DOMDocument (WebDOMDocumentOperationsInternal)
103
104/* This doesn't appear to be used by anyone.  We should consider removing this. */
105- (DOMRange *)_createRangeWithNode:(DOMNode *)node
106{
107    DOMRange *range = [self createRange];
108    [range selectNode:node];
109    return range;
110}
111
112- (DOMRange *)_documentRange
113{
114    return [self _createRangeWithNode:[self documentElement]];
115}
116
117@end
118
119@implementation DOMDocument (WebDOMDocumentOperationsPrivate)
120
121- (NSArray *)_focusableNodes
122{
123    Vector<RefPtr<Node> > nodes;
124    core(self)->getFocusableNodes(nodes);
125    NSMutableArray *array = [NSMutableArray arrayWithCapacity:nodes.size()];
126    for (unsigned i = 0; i < nodes.size(); ++i)
127        [array addObject:kit(nodes[i].get())];
128    return array;
129}
130
131@end
132
133@implementation DOMRange (WebDOMRangeOperations)
134
135- (WebArchive *)webArchive
136{
137    return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(core(self))] autorelease];
138}
139
140- (NSString *)markupString
141{
142    return createFullMarkup(core(self));
143}
144
145@end
146
147@implementation DOMHTMLFrameElement (WebDOMHTMLFrameElementOperations)
148
149- (WebFrame *)contentFrame
150{
151    return [[self contentDocument] webFrame];
152}
153
154@end
155
156@implementation DOMHTMLIFrameElement (WebDOMHTMLIFrameElementOperations)
157
158- (WebFrame *)contentFrame
159{
160    return [[self contentDocument] webFrame];
161}
162
163@end
164
165@implementation DOMHTMLObjectElement (WebDOMHTMLObjectElementOperations)
166
167- (WebFrame *)contentFrame
168{
169    return [[self contentDocument] webFrame];
170}
171
172@end
173