webengine/osswebengine/WebKit/DefaultDelegates/WebDefaultPolicyDelegate.m
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2005 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 <WebKit/WebDataSource.h>
       
    30 #import <WebKit/WebDefaultPolicyDelegate.h>
       
    31 #import <WebKit/WebFrame.h>
       
    32 #import <WebKit/WebPolicyDelegatePrivate.h>
       
    33 #import <WebKit/WebView.h>
       
    34 #import <WebKit/WebViewPrivate.h>
       
    35 
       
    36 #import <Foundation/NSURLConnection.h>
       
    37 #import <Foundation/NSURLRequest.h>
       
    38 #import <Foundation/NSURLResponse.h>
       
    39 #import <JavaScriptCore/Assertions.h>
       
    40 
       
    41 
       
    42 @implementation WebDefaultPolicyDelegate
       
    43 
       
    44 static WebDefaultPolicyDelegate *sharedDelegate = nil;
       
    45 
       
    46 // Return a object with vanilla implementations of the protocol's methods
       
    47 // Note this feature relies on our default delegate being stateless
       
    48 + (WebDefaultPolicyDelegate *)sharedPolicyDelegate
       
    49 {
       
    50     if (!sharedDelegate) {
       
    51         sharedDelegate = [[WebDefaultPolicyDelegate alloc] init];
       
    52     }
       
    53     return sharedDelegate;
       
    54 }
       
    55 
       
    56 - (void)webView: (WebView *)wv unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame
       
    57 {
       
    58     LOG_ERROR("called unableToImplementPolicyWithError:%@ inFrame:%@", error, frame);
       
    59 }
       
    60 
       
    61 
       
    62 - (void)webView: (WebView *)wv decidePolicyForMIMEType:(NSString *)type
       
    63                                                request:(NSURLRequest *)request
       
    64                                                  frame:(WebFrame *)frame
       
    65                                       decisionListener:(id <WebPolicyDecisionListener>)listener;
       
    66 {
       
    67     if ([[request URL] isFileURL]) {
       
    68         BOOL isDirectory = NO;
       
    69         [[NSFileManager defaultManager] fileExistsAtPath:[[request URL] path] isDirectory:&isDirectory];
       
    70         
       
    71         if (isDirectory) {
       
    72             [listener ignore];
       
    73         } else if([WebView canShowMIMEType:type]) {
       
    74             [listener use];
       
    75         } else{
       
    76             [listener ignore];
       
    77         }
       
    78     } else if ([WebView canShowMIMEType:type]) {
       
    79         [listener use];
       
    80     } else {
       
    81         [listener ignore];
       
    82     }
       
    83 }
       
    84 
       
    85 - (void)webView: (WebView *)wv decidePolicyForNavigationAction:(NSDictionary *)actionInformation 
       
    86                                                        request:(NSURLRequest *)request
       
    87                                                          frame:(WebFrame *)frame
       
    88                                               decisionListener:(id <WebPolicyDecisionListener>)listener
       
    89 {
       
    90     WebNavigationType navType = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue];
       
    91 
       
    92     if ([WebView _canHandleRequest:request]) {
       
    93         [listener use];
       
    94     } else if (navType == WebNavigationTypePlugInRequest) {
       
    95         [listener use];
       
    96     } else {
       
    97         // A file URL shouldn't fall through to here, but if it did,
       
    98         // it would be a security risk to open it.
       
    99         if (![[request URL] isFileURL]) {
       
   100             [[NSWorkspace sharedWorkspace] openURL:[request URL]];
       
   101         }
       
   102         [listener ignore];
       
   103     }
       
   104 }
       
   105 
       
   106 - (void)webView: (WebView *)wv decidePolicyForNewWindowAction:(NSDictionary *)actionInformation 
       
   107                                                       request:(NSURLRequest *)request
       
   108                                                  newFrameName:(NSString *)frameName
       
   109                                              decisionListener:(id <WebPolicyDecisionListener>)listener
       
   110 {
       
   111     [listener use];
       
   112 }
       
   113 
       
   114 // Temporary SPI needed for <rdar://problem/3951283> can view pages from the back/forward cache that should be disallowed by Parental Controls
       
   115 - (BOOL)webView:(WebView *)webView shouldGoToHistoryItem:(WebHistoryItem *)item
       
   116 {
       
   117     return YES;
       
   118 }
       
   119 
       
   120 @end
       
   121