diff options
author | Ben Murdoch <benm@google.com> | 2011-05-13 16:23:25 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-05-16 11:35:02 +0100 |
commit | 65f03d4f644ce73618e5f4f50dd694b26f55ae12 (patch) | |
tree | f478babb801e720de7bfaee23443ffe029f58731 /Source/WebKit/mac/DefaultDelegates | |
parent | 47de4a2fb7262c7ebdb9cd133ad2c54c187454d0 (diff) | |
download | external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.zip external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.gz external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.bz2 |
Merge WebKit at r75993: Initial merge by git.
Change-Id: I602bbdc3974787a3b0450456a30a7868286921c3
Diffstat (limited to 'Source/WebKit/mac/DefaultDelegates')
8 files changed, 820 insertions, 0 deletions
diff --git a/Source/WebKit/mac/DefaultDelegates/WebDefaultContextMenuDelegate.h b/Source/WebKit/mac/DefaultDelegates/WebDefaultContextMenuDelegate.h new file mode 100644 index 0000000..98ef76b --- /dev/null +++ b/Source/WebKit/mac/DefaultDelegates/WebDefaultContextMenuDelegate.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Foundation/Foundation.h> + +#import <WebKit/WebDefaultUIDelegate.h> + +@interface WebDefaultUIDelegate (WebContextMenu) +@end diff --git a/Source/WebKit/mac/DefaultDelegates/WebDefaultContextMenuDelegate.mm b/Source/WebKit/mac/DefaultDelegates/WebDefaultContextMenuDelegate.mm new file mode 100644 index 0000000..2ee7d8b --- /dev/null +++ b/Source/WebKit/mac/DefaultDelegates/WebDefaultContextMenuDelegate.mm @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "WebDefaultContextMenuDelegate.h" + +#import "WebDOMOperations.h" +#import "WebDataSourcePrivate.h" +#import "WebDefaultUIDelegate.h" +#import "WebFrameInternal.h" +#import "WebFrameView.h" +#import "WebHTMLViewPrivate.h" +#import "WebLocalizableStrings.h" +#import "WebNSPasteboardExtras.h" +#import "WebNSURLRequestExtras.h" +#import "WebPolicyDelegate.h" +#import "WebUIDelegate.h" +#import "WebUIDelegatePrivate.h" +#import "WebViewInternal.h" +#import <Foundation/NSURLConnection.h> +#import <Foundation/NSURLRequest.h> +#import <WebCore/Editor.h> +#import <WebCore/Frame.h> +#import <WebCore/FrameLoader.h> +#import <WebKit/DOM.h> +#import <WebKit/DOMPrivate.h> +#import <wtf/Assertions.h> + +@implementation WebDefaultUIDelegate (WebContextMenu) + +- (NSMenuItem *)menuItemWithTag:(int)tag target:(id)target representedObject:(id)representedObject +{ + NSMenuItem *menuItem = [[[NSMenuItem alloc] init] autorelease]; + [menuItem setTag:tag]; + [menuItem setTarget:target]; // can be nil + [menuItem setRepresentedObject:representedObject]; + + NSString *title = nil; + SEL action = NULL; + + switch(tag) { + case WebMenuItemTagCopy: + title = UI_STRING("Copy", "Copy context menu item"); + action = @selector(copy:); + break; + case WebMenuItemTagGoBack: + title = UI_STRING("Back", "Back context menu item"); + action = @selector(goBack:); + break; + case WebMenuItemTagGoForward: + title = UI_STRING("Forward", "Forward context menu item"); + action = @selector(goForward:); + break; + case WebMenuItemTagStop: + title = UI_STRING("Stop", "Stop context menu item"); + action = @selector(stopLoading:); + break; + case WebMenuItemTagReload: + title = UI_STRING("Reload", "Reload context menu item"); + action = @selector(reload:); + break; + case WebMenuItemTagSearchInSpotlight: + title = UI_STRING("Search in Spotlight", "Search in Spotlight context menu item"); + action = @selector(_searchWithSpotlightFromMenu:); + break; + case WebMenuItemTagSearchWeb: + title = UI_STRING("Search in Google", "Search in Google context menu item"); + action = @selector(_searchWithGoogleFromMenu:); + break; + case WebMenuItemTagLookUpInDictionary: + title = UI_STRING("Look Up in Dictionary", "Look Up in Dictionary context menu item"); + action = @selector(_lookUpInDictionaryFromMenu:); + break; + case WebMenuItemTagOpenFrameInNewWindow: + title = UI_STRING("Open Frame in New Window", "Open Frame in New Window context menu item"); + action = @selector(_openFrameInNewWindowFromMenu:); + break; + default: + ASSERT_NOT_REACHED(); + return nil; + } + + if (title) + [menuItem setTitle:title]; + + [menuItem setAction:action]; + + return menuItem; +} + +- (void)appendDefaultItems:(NSArray *)defaultItems toArray:(NSMutableArray *)menuItems +{ + ASSERT_ARG(menuItems, menuItems != nil); + if ([defaultItems count] > 0) { + ASSERT(![[menuItems lastObject] isSeparatorItem]); + if (![[defaultItems objectAtIndex:0] isSeparatorItem]) { + [menuItems addObject:[NSMenuItem separatorItem]]; + + NSEnumerator *e = [defaultItems objectEnumerator]; + NSMenuItem *item; + while ((item = [e nextObject]) != nil) { + [menuItems addObject:item]; + } + } + } +} + +- (NSArray *)webView:(WebView *)wv contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems +{ + // The defaultMenuItems here are ones supplied by the WebDocumentView protocol implementation. WebPDFView is + // one case that has non-nil default items here. + NSMutableArray *menuItems = [NSMutableArray array]; + + WebFrame *webFrame = [element objectForKey:WebElementFrameKey]; + + if ([[element objectForKey:WebElementIsSelectedKey] boolValue]) { + // The Spotlight and Google items are implemented in WebView, and require that the + // current document view conforms to WebDocumentText + ASSERT([[[webFrame frameView] documentView] conformsToProtocol:@protocol(WebDocumentText)]); + [menuItems addObject:[self menuItemWithTag:WebMenuItemTagSearchInSpotlight target:nil representedObject:element]]; + [menuItems addObject:[self menuItemWithTag:WebMenuItemTagSearchWeb target:nil representedObject:element]]; + [menuItems addObject:[NSMenuItem separatorItem]]; + + // FIXME 4184640: The Look Up in Dictionary item is only implemented in WebHTMLView, and so is present but + // dimmed for other cases where WebElementIsSelectedKey is present. It would probably + // be better not to include it in the menu if the documentView isn't a WebHTMLView, but that could break + // existing clients that have code that relies on it being present (unlikely for clients outside of Apple, + // but Safari has such code). + [menuItems addObject:[self menuItemWithTag:WebMenuItemTagLookUpInDictionary target:nil representedObject:element]]; + [menuItems addObject:[NSMenuItem separatorItem]]; + [menuItems addObject:[self menuItemWithTag:WebMenuItemTagCopy target:nil representedObject:element]]; + } else { + WebView *wv = [webFrame webView]; + if ([wv canGoBack]) { + [menuItems addObject:[self menuItemWithTag:WebMenuItemTagGoBack target:wv representedObject:element]]; + } + if ([wv canGoForward]) { + [menuItems addObject:[self menuItemWithTag:WebMenuItemTagGoForward target:wv representedObject:element]]; + } + if ([wv isLoading]) { + [menuItems addObject:[self menuItemWithTag:WebMenuItemTagStop target:wv representedObject:element]]; + } else { + [menuItems addObject:[self menuItemWithTag:WebMenuItemTagReload target:wv representedObject:element]]; + } + + if (webFrame != [wv mainFrame]) { + [menuItems addObject:[self menuItemWithTag:WebMenuItemTagOpenFrameInNewWindow target:wv representedObject:element]]; + } + } + + // Add the default items at the end, if any, after a separator + [self appendDefaultItems:defaultMenuItems toArray:menuItems]; + + return menuItems; +} + +@end diff --git a/Source/WebKit/mac/DefaultDelegates/WebDefaultEditingDelegate.h b/Source/WebKit/mac/DefaultDelegates/WebDefaultEditingDelegate.h new file mode 100644 index 0000000..c0f7c5b --- /dev/null +++ b/Source/WebKit/mac/DefaultDelegates/WebDefaultEditingDelegate.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Foundation/Foundation.h> + +@interface WebDefaultEditingDelegate : NSObject ++ (WebDefaultEditingDelegate *)sharedEditingDelegate; +@end diff --git a/Source/WebKit/mac/DefaultDelegates/WebDefaultEditingDelegate.m b/Source/WebKit/mac/DefaultDelegates/WebDefaultEditingDelegate.m new file mode 100644 index 0000000..bf7ee17 --- /dev/null +++ b/Source/WebKit/mac/DefaultDelegates/WebDefaultEditingDelegate.m @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Cocoa/Cocoa.h> + +#import <WebKit/WebDefaultEditingDelegate.h> + +#import <WebKit/DOM.h> +#import <WebKit/WebEditingDelegate.h> +#import <WebKit/WebEditingDelegatePrivate.h> +#import <WebKit/WebView.h> + +@implementation WebDefaultEditingDelegate + +static WebDefaultEditingDelegate *sharedDelegate = nil; + ++ (WebDefaultEditingDelegate *)sharedEditingDelegate +{ + if (!sharedDelegate) { + sharedDelegate = [[WebDefaultEditingDelegate alloc] init]; + } + return sharedDelegate; +} + +- (BOOL)webView:(WebView *)webView shouldShowDeleteInterfaceForElement:(DOMHTMLElement *)element +{ + return NO; +} + +- (BOOL)webView:(WebView *)webView shouldBeginEditingInDOMRange:(DOMRange *)range +{ + return YES; +} + +- (BOOL)webView:(WebView *)webView shouldEndEditingInDOMRange:(DOMRange *)range +{ + return YES; +} + +- (BOOL)webView:(WebView *)webView shouldInsertNode:(DOMNode *)node replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action +{ + return YES; +} + +- (BOOL)webView:(WebView *)webView shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action +{ + return YES; +} + +- (BOOL)webView:(WebView *)webView shouldDeleteDOMRange:(DOMRange *)range +{ + return YES; +} + +- (BOOL)webView:(WebView *)webView shouldChangeSelectedDOMRange:(DOMRange *)currentRange toDOMRange:(DOMRange *)proposedRange affinity:(NSSelectionAffinity)selectionAffinity stillSelecting:(BOOL)flag +{ + return YES; +} + +- (BOOL)webView:(WebView *)webView shouldApplyStyle:(DOMCSSStyleDeclaration *)style toElementsInDOMRange:(DOMRange *)range +{ + return YES; +} + +- (BOOL)webView:(WebView *)webView shouldMoveRangeAfterDelete:(DOMRange *)range replacingRange:(DOMRange *)rangeToBeReplaced +{ + return YES; +} + +- (BOOL)webView:(WebView *)webView shouldChangeTypingStyle:(DOMCSSStyleDeclaration *)currentStyle toStyle:(DOMCSSStyleDeclaration *)proposedStyle +{ + return YES; +} + +- (BOOL)webView:(WebView *)webView doCommandBySelector:(SEL)selector +{ + return NO; +} + +- (void)webView:(WebView *)webView didWriteSelectionToPasteboard:(NSPasteboard *)pasteboard +{ +} + +- (void)webView:(WebView *)webView didSetSelectionTypesForPasteboard:(NSPasteboard *)pasteboard +{ +} + +- (void)webViewDidBeginEditing:(NSNotification *)notification +{ +} + +- (void)webViewDidChange:(NSNotification *)notification +{ +} + +- (void)webViewDidEndEditing:(NSNotification *)notification +{ +} + +- (void)webViewDidChangeTypingStyle:(NSNotification *)notification +{ +} + +- (void)webViewDidChangeSelection:(NSNotification *)notification +{ +} + +- (NSUndoManager *)undoManagerForWebView:(WebView *)webView +{ + return nil; +} + +@end diff --git a/Source/WebKit/mac/DefaultDelegates/WebDefaultPolicyDelegate.h b/Source/WebKit/mac/DefaultDelegates/WebDefaultPolicyDelegate.h new file mode 100644 index 0000000..3796864 --- /dev/null +++ b/Source/WebKit/mac/DefaultDelegates/WebDefaultPolicyDelegate.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Foundation/Foundation.h> + +/*! + @class WebDefaultPolicyDelegate + @discussion WebDefaultPolicyDelegate will be used as a WebView's + default policy delegate. It can be subclassed to modify policies. +*/ +@interface WebDefaultPolicyDelegate : NSObject ++ (WebDefaultPolicyDelegate *)sharedPolicyDelegate; +@end + diff --git a/Source/WebKit/mac/DefaultDelegates/WebDefaultPolicyDelegate.m b/Source/WebKit/mac/DefaultDelegates/WebDefaultPolicyDelegate.m new file mode 100644 index 0000000..bad87d5 --- /dev/null +++ b/Source/WebKit/mac/DefaultDelegates/WebDefaultPolicyDelegate.m @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2005, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "WebDefaultPolicyDelegate.h" + +#import "WebDataSource.h" +#import "WebFrame.h" +#import "WebPolicyDelegatePrivate.h" +#import "WebViewInternal.h" +#import <Foundation/NSURLConnection.h> +#import <Foundation/NSURLRequest.h> +#import <Foundation/NSURLResponse.h> +#import <wtf/Assertions.h> + +@implementation WebDefaultPolicyDelegate + +static WebDefaultPolicyDelegate *sharedDelegate = nil; + +// Return a object with vanilla implementations of the protocol's methods +// Note this feature relies on our default delegate being stateless ++ (WebDefaultPolicyDelegate *)sharedPolicyDelegate +{ + if (!sharedDelegate) { + sharedDelegate = [[WebDefaultPolicyDelegate alloc] init]; + } + return sharedDelegate; +} + +- (void)webView: (WebView *)wv unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame +{ + LOG_ERROR("called unableToImplementPolicyWithError:%@ inFrame:%@", error, frame); +} + + +- (void)webView: (WebView *)wv decidePolicyForMIMEType:(NSString *)type + request:(NSURLRequest *)request + frame:(WebFrame *)frame + decisionListener:(id <WebPolicyDecisionListener>)listener +{ + if ([[request URL] isFileURL]) { + BOOL isDirectory = NO; + BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:[[request URL] path] isDirectory:&isDirectory]; + + if (exists && !isDirectory && [wv _canShowMIMEType:type]) + [listener use]; + else + [listener ignore]; + } else if ([wv _canShowMIMEType:type]) + [listener use]; + else + [listener ignore]; +} + +- (void)webView: (WebView *)wv decidePolicyForNavigationAction:(NSDictionary *)actionInformation + request:(NSURLRequest *)request + frame:(WebFrame *)frame + decisionListener:(id <WebPolicyDecisionListener>)listener +{ + WebNavigationType navType = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue]; + + if ([WebView _canHandleRequest:request forMainFrame:frame == [wv mainFrame]]) { + [listener use]; + } else if (navType == WebNavigationTypePlugInRequest) { + [listener use]; + } else { + // A file URL shouldn't fall through to here, but if it did, + // it would be a security risk to open it. + if (![[request URL] isFileURL]) { + [[NSWorkspace sharedWorkspace] openURL:[request URL]]; + } + [listener ignore]; + } +} + +- (void)webView: (WebView *)wv decidePolicyForNewWindowAction:(NSDictionary *)actionInformation + request:(NSURLRequest *)request + newFrameName:(NSString *)frameName + decisionListener:(id <WebPolicyDecisionListener>)listener +{ + [listener use]; +} + +// Temporary SPI needed for <rdar://problem/3951283> can view pages from the back/forward cache that should be disallowed by Parental Controls +- (BOOL)webView:(WebView *)webView shouldGoToHistoryItem:(WebHistoryItem *)item +{ + return YES; +} + +@end + diff --git a/Source/WebKit/mac/DefaultDelegates/WebDefaultUIDelegate.h b/Source/WebKit/mac/DefaultDelegates/WebDefaultUIDelegate.h new file mode 100644 index 0000000..4315121 --- /dev/null +++ b/Source/WebKit/mac/DefaultDelegates/WebDefaultUIDelegate.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Foundation/Foundation.h> + +@interface WebDefaultUIDelegate : NSObject +{ + IBOutlet NSMenu *defaultMenu; +} ++ (WebDefaultUIDelegate *)sharedUIDelegate; +@end diff --git a/Source/WebKit/mac/DefaultDelegates/WebDefaultUIDelegate.m b/Source/WebKit/mac/DefaultDelegates/WebDefaultUIDelegate.m new file mode 100644 index 0000000..a327fd4 --- /dev/null +++ b/Source/WebKit/mac/DefaultDelegates/WebDefaultUIDelegate.m @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Cocoa/Cocoa.h> + +#import <Foundation/NSURLRequest.h> + +#import <WebKit/WebDefaultUIDelegate.h> +#import <WebKit/WebJavaScriptTextInputPanel.h> +#import <WebKit/WebView.h> +#import <WebKit/WebUIDelegatePrivate.h> +#import <WebKit/DOM.h> +#import "WebTypesInternal.h" + +@interface NSApplication (DeclarationStolenFromAppKit) +- (void)_cycleWindowsReversed:(BOOL)reversed; +@end + +@implementation WebDefaultUIDelegate + +static WebDefaultUIDelegate *sharedDelegate = nil; + +// Return a object with vanilla implementations of the protocol's methods +// Note this feature relies on our default delegate being stateless. This +// is probably an invalid assumption for the WebUIDelegate. +// If we add any real functionality to this default delegate we probably +// won't be able to use a singleton. ++ (WebDefaultUIDelegate *)sharedUIDelegate +{ + if (!sharedDelegate) { + sharedDelegate = [[WebDefaultUIDelegate alloc] init]; + } + return sharedDelegate; +} + +- (WebView *)webView: (WebView *)wv createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features +{ + // If the new API method doesn't exist, fallback to the old version of createWebViewWithRequest + // for backwards compatability + if (![[wv UIDelegate] respondsToSelector:@selector(webView:createWebViewWithRequest:windowFeatures:)] && [[wv UIDelegate] respondsToSelector:@selector(webView:createWebViewWithRequest:)]) + return [[wv UIDelegate] webView:wv createWebViewWithRequest:request]; + return nil; +} + +- (void)webViewShow: (WebView *)wv +{ +} + +- (void)webViewClose: (WebView *)wv +{ + [[wv window] close]; +} + +- (void)webViewFocus: (WebView *)wv +{ + [[wv window] makeKeyAndOrderFront:wv]; +} + +- (void)webViewUnfocus: (WebView *)wv +{ + if ([[wv window] isKeyWindow] || [[[wv window] attachedSheet] isKeyWindow]) { + [NSApp _cycleWindowsReversed:FALSE]; + } +} + +- (NSResponder *)webViewFirstResponder: (WebView *)wv +{ + return [[wv window] firstResponder]; +} + +- (void)webView: (WebView *)wv makeFirstResponder:(NSResponder *)responder +{ + [[wv window] makeFirstResponder:responder]; +} + +- (void)webView: (WebView *)wv setStatusText:(NSString *)text +{ +} + +- (NSString *)webViewStatusText: (WebView *)wv +{ + return nil; +} + +- (void)webView: (WebView *)wv mouseDidMoveOverElement:(NSDictionary *)elementInformation modifierFlags:(NSUInteger)modifierFlags +{ +} + +- (BOOL)webViewAreToolbarsVisible: (WebView *)wv +{ + return NO; +} + +- (void)webView: (WebView *)wv setToolbarsVisible:(BOOL)visible +{ +} + +- (BOOL)webViewIsStatusBarVisible: (WebView *)wv +{ + return NO; +} + +- (void)webView: (WebView *)wv setStatusBarVisible:(BOOL)visible +{ +} + +- (BOOL)webViewIsResizable: (WebView *)wv +{ + return [[wv window] showsResizeIndicator]; +} + +- (void)webView: (WebView *)wv setResizable:(BOOL)resizable +{ + // FIXME: This doesn't actually change the resizability of the window, + // only visibility of the indicator. + [[wv window] setShowsResizeIndicator:resizable]; +} + +- (void)webView: (WebView *)wv setFrame:(NSRect)frame +{ + [[wv window] setFrame:frame display:YES]; +} + +- (NSRect)webViewFrame: (WebView *)wv +{ + NSWindow *window = [wv window]; + return window == nil ? NSZeroRect : [window frame]; +} + +- (void)webView: (WebView *)wv runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame +{ + // FIXME: We want a default here, but that would add localized strings. +} + +- (BOOL)webView: (WebView *)wv runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame +{ + // FIXME: We want a default here, but that would add localized strings. + return NO; +} + +- (NSString *)webView: (WebView *)wv runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame +{ + WebJavaScriptTextInputPanel *panel = [[WebJavaScriptTextInputPanel alloc] initWithPrompt:prompt text:defaultText]; + [panel showWindow:nil]; + NSString *result; + if ([NSApp runModalForWindow:[panel window]]) { + result = [panel text]; + } else { + result = nil; + } + [[panel window] close]; + [panel release]; + return result; +} + +- (void)webView: (WebView *)wv runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener +{ + // FIXME: We want a default here, but that would add localized strings. +} + +- (void)webView:(WebView *)sender printFrameView:(WebFrameView *)frameView +{ +} + + +- (BOOL)webView:(WebView *)webView shouldBeginDragForElement:(NSDictionary *)element dragImage:(NSImage *)dragImage mouseDownEvent:(NSEvent *)mouseDownEvent mouseDraggedEvent:(NSEvent *)mouseDraggedEvent +{ + return YES; +} + +- (NSUInteger)webView:(WebView *)webView dragDestinationActionMaskForDraggingInfo:(id <NSDraggingInfo>)draggingInfo +{ + return WebDragDestinationActionAny; +} + +- (void)webView:(WebView *)webView willPerformDragDestinationAction:(WebDragDestinationAction)action forDraggingInfo:(id <NSDraggingInfo>)draggingInfo +{ +} + +- (NSUInteger)webView:(WebView *)webView dragSourceActionMaskForPoint:(NSPoint)point +{ + return WebDragSourceActionAny; +} + +- (void)webView:(WebView *)webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:(NSPoint)point withPasteboard:(NSPasteboard *)pasteboard +{ +} + +- (void)webView:(WebView *)sender didDrawRect:(NSRect)rect +{ +} + +- (void)webView:(WebView *)sender didScrollDocumentInFrameView:(WebFrameView *)frameView +{ +} + +- (void)webView:(WebView *)sender willPopupMenu:(NSMenu *)menu +{ +} + +- (void)webView:(WebView *)sender contextMenuItemSelected:(NSMenuItem *)item forElement:(NSDictionary *)element +{ +} + +- (void)webView:(WebView *)sender exceededApplicationCacheOriginQuotaForSecurityOrigin:(WebSecurityOrigin *)origin +{ +} + +- (BOOL)webView:(WebView *)sender shouldReplaceUploadFile:(NSString *)path usingGeneratedFilename:(NSString **)filename +{ + return NO; +} + +- (NSString *)webView:(WebView *)sender generateReplacementFile:(NSString *)path +{ + return nil; +} + +@end |