2 // WebPluginContainerCheck.m
5 // Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
8 #import <WebKit/WebPluginContainerCheck.h>
10 #import <Foundation/NSDictionary.h>
11 #import <Foundation/NSURL.h>
12 #import <Foundation/NSURLRequest.h>
13 #import <WebKit/WebAssertions.h>
14 #import <WebKit/WebBridge.h>
15 #import <WebKit/WebFrame.h>
16 #import <WebKit/WebPluginContainer.h>
17 #import <WebKit/WebPluginContainerPrivate.h>
18 #import <WebKit/WebPluginController.h>
19 #import <WebKit/WebPolicyDelegate.h>
20 #import <WebKit/WebPolicyDelegatePrivate.h>
21 #import <WebKit/WebView.h>
22 #import <WebKit/WebViewPrivate.h>
23 #import <objc/objc-runtime.h>
25 @implementation WebPluginContainerCheck
27 + (id)checkWithRequest:(NSURLRequest *)request target:(NSString *)target resultObject:(id)obj selector:(SEL)selector controller:(WebPluginController *)controller
29 return [[[self alloc] initWithRequest:request target:target resultObject:obj selector:selector controller:controller] autorelease];
32 - (id)initWithRequest:(NSURLRequest *)request target:(NSString *)target resultObject:(id)obj selector:(SEL)selector controller:(WebPluginController *)controller
34 if (!(self = [super init]))
37 _request = [request copy];
38 _target = [target copy];
39 _resultObject = [obj retain];
40 _resultSelector = selector;
42 // controller owns us so don't retain, to avoid cycle
43 _controller = controller;
50 // mandatory to complete or cancel before releasing this object
56 // mandatory to complete or cancel before releasing this object
61 - (void)_continueWithPolicy:(WebPolicyAction)policy
63 void (*callBack)(id, SEL, BOOL) = (void (*)(id, SEL, BOOL))objc_msgSend;
64 (*callBack) (_resultObject, _resultSelector, (policy == WebPolicyUse));
66 // this will call indirectly call cancel
67 [_controller _webPluginContainerCancelCheckIfAllowedToLoadRequest:self];
70 - (BOOL)_isForbiddenFileLoad
73 WebBridge *bridge = [_controller bridge];
74 if (![bridge canLoadURL:[_request URL] fromReferrer:[bridge referrer] hideReferrer:&ignore]) {
75 [self _continueWithPolicy:WebPolicyIgnore];
82 - (NSDictionary *)_actionInformationWithURL:(NSURL *)URL
84 return [NSDictionary dictionaryWithObjectsAndKeys:
85 [NSNumber numberWithInt:WebNavigationTypePlugInRequest], WebActionNavigationTypeKey,
86 [NSNumber numberWithInt:0], WebActionModifierFlagsKey,
87 URL, WebActionOriginalURLKey,
91 - (void)_askPolicyDelegate
93 WebView *webView = [_controller webView];
95 WebFrame *targetFrame;
96 if ([_target length] > 0) {
97 targetFrame = [[_controller webFrame] findFrameNamed:_target];
99 targetFrame = [_controller webFrame];
102 NSDictionary *action = [self _actionInformationWithURL:[_request URL]];
104 _listener = [[WebPolicyDecisionListener alloc] _initWithTarget:self action:@selector(_continueWithPolicy:)];
106 if (targetFrame == nil) {
107 // would open new window
108 [[webView _policyDelegateForwarder] webView:webView
109 decidePolicyForNewWindowAction:action
112 decisionListener:_listener];
114 // would target existing frame
115 [[webView _policyDelegateForwarder] webView:webView
116 decidePolicyForNavigationAction:action
119 decisionListener:_listener];
128 if ([self _isForbiddenFileLoad])
131 [self _askPolicyDelegate];
145 [_listener _invalidate];
149 [_resultObject autorelease];