|
1 /* |
|
2 * Copyright (C) 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 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 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 "WebIconFetcher.h" |
|
27 |
|
28 #import "WebFrameInternal.h" |
|
29 #import "WebIconFetcherInternal.h" |
|
30 |
|
31 #import <WebCore/Frame.h> |
|
32 #import <WebCore/IconFetcher.h> |
|
33 #import <WebCore/SharedBuffer.h> |
|
34 #import <wtf/PassRefPtr.h> |
|
35 |
|
36 using namespace WebCore; |
|
37 |
|
38 class WebIconFetcherClient : public IconFetcherClient { |
|
39 public: |
|
40 WebIconFetcherClient(id target, SEL selector) |
|
41 : m_target(target) |
|
42 , m_selector(selector) |
|
43 { |
|
44 } |
|
45 |
|
46 virtual void finishedFetchingIcon(PassRefPtr<SharedBuffer> iconData) |
|
47 { |
|
48 RetainPtr<NSData> data; |
|
49 if (iconData) |
|
50 data = iconData->createNSData(); |
|
51 |
|
52 [m_target performSelector:m_selector withObject:m_fetcher.get() withObject:data.get()]; |
|
53 |
|
54 delete this; |
|
55 } |
|
56 |
|
57 void setFetcher(WebIconFetcher *fetcher) { m_fetcher = fetcher; } |
|
58 |
|
59 private: |
|
60 RetainPtr<WebIconFetcher> m_fetcher; |
|
61 id m_target; |
|
62 SEL m_selector; |
|
63 }; |
|
64 |
|
65 @implementation WebIconFetcher |
|
66 |
|
67 - (id)init |
|
68 { |
|
69 return nil; |
|
70 } |
|
71 |
|
72 - (void)dealloc |
|
73 { |
|
74 if (_private) |
|
75 reinterpret_cast<IconFetcher*>(_private)->deref(); |
|
76 |
|
77 [super dealloc]; |
|
78 } |
|
79 |
|
80 - (void)finalize |
|
81 { |
|
82 if (_private) |
|
83 reinterpret_cast<IconFetcher*>(_private)->deref(); |
|
84 |
|
85 [super finalize]; |
|
86 } |
|
87 |
|
88 - (void)cancel |
|
89 { |
|
90 reinterpret_cast<IconFetcher*>(_private)->cancel(); |
|
91 } |
|
92 |
|
93 @end |
|
94 |
|
95 @implementation WebIconFetcher (WebInternal) |
|
96 |
|
97 - (id)_initWithIconFetcher:(PassRefPtr<IconFetcher>)iconFetcher client:(WebIconFetcherClient *)client |
|
98 { |
|
99 ASSERT(iconFetcher); |
|
100 |
|
101 self = [super init]; |
|
102 if (!self) |
|
103 return nil; |
|
104 |
|
105 client->setFetcher(self); |
|
106 _private = reinterpret_cast<WebIconFetcherPrivate*>(iconFetcher.releaseRef()); |
|
107 |
|
108 return self; |
|
109 } |
|
110 |
|
111 + (WebIconFetcher *)_fetchApplicationIconForFrame:(WebFrame *)webFrame |
|
112 target:(id)target |
|
113 selector:(SEL)selector |
|
114 { |
|
115 Frame* frame = core(webFrame); |
|
116 |
|
117 WebIconFetcherClient* client = new WebIconFetcherClient(target, selector); |
|
118 |
|
119 RefPtr<IconFetcher> fetcher = IconFetcher::create(frame, client); |
|
120 |
|
121 if (!fetcher) |
|
122 return nil; |
|
123 |
|
124 return [[[WebIconFetcher alloc] _initWithIconFetcher:fetcher.release() client:client] autorelease]; |
|
125 } |
|
126 |
|
127 @end |
|
128 |