|
1 /* |
|
2 * Copyright (C) 2005, 2006 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 "WebPolicyDelegatePrivate.h" |
|
30 |
|
31 #import <WebCore/FrameLoaderTypes.h> |
|
32 #import <objc/objc-runtime.h> |
|
33 |
|
34 using namespace WebCore; |
|
35 |
|
36 NSString *WebActionNavigationTypeKey = @"WebActionNavigationTypeKey"; |
|
37 NSString *WebActionElementKey = @"WebActionElementKey"; |
|
38 NSString *WebActionButtonKey = @"WebActionButtonKey"; |
|
39 NSString *WebActionModifierFlagsKey = @"WebActionModifierFlagsKey"; |
|
40 NSString *WebActionOriginalURLKey = @"WebActionOriginalURLKey"; |
|
41 |
|
42 @interface WebPolicyDecisionListenerPrivate : NSObject |
|
43 { |
|
44 @public |
|
45 id target; |
|
46 SEL action; |
|
47 } |
|
48 |
|
49 - (id)initWithTarget:(id)target action:(SEL)action; |
|
50 |
|
51 @end |
|
52 |
|
53 @implementation WebPolicyDecisionListenerPrivate |
|
54 |
|
55 - (id)initWithTarget:(id)t action:(SEL)a |
|
56 { |
|
57 self = [super init]; |
|
58 if (!self) |
|
59 return nil; |
|
60 target = [t retain]; |
|
61 action = a; |
|
62 return self; |
|
63 } |
|
64 |
|
65 - (void)dealloc |
|
66 { |
|
67 [target release]; |
|
68 [super dealloc]; |
|
69 } |
|
70 |
|
71 @end |
|
72 |
|
73 @implementation WebPolicyDecisionListener |
|
74 |
|
75 - (id)_initWithTarget:(id)target action:(SEL)action |
|
76 { |
|
77 self = [super init]; |
|
78 if (!self) |
|
79 return nil; |
|
80 _private = [[WebPolicyDecisionListenerPrivate alloc] initWithTarget:target action:action]; |
|
81 return self; |
|
82 } |
|
83 |
|
84 -(void)dealloc |
|
85 { |
|
86 [_private release]; |
|
87 [super dealloc]; |
|
88 } |
|
89 |
|
90 - (void)_usePolicy:(PolicyAction)policy |
|
91 { |
|
92 if (_private->target) |
|
93 ((void (*)(id, SEL, PolicyAction))objc_msgSend)(_private->target, _private->action, policy); |
|
94 } |
|
95 |
|
96 - (void)_invalidate |
|
97 { |
|
98 id target = _private->target; |
|
99 _private->target = nil; |
|
100 [target release]; |
|
101 } |
|
102 |
|
103 // WebPolicyDecisionListener implementation |
|
104 |
|
105 - (void)use |
|
106 { |
|
107 [self _usePolicy:PolicyUse]; |
|
108 } |
|
109 |
|
110 - (void)ignore |
|
111 { |
|
112 [self _usePolicy:PolicyIgnore]; |
|
113 } |
|
114 |
|
115 - (void)download |
|
116 { |
|
117 [self _usePolicy:PolicyDownload]; |
|
118 } |
|
119 |
|
120 @end |