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