Commit 6e207f09 authored by mitz@apple.com's avatar mitz@apple.com

[Mac] Transition MiniBrowser to the Cocoa API: policy delegate

https://bugs.webkit.org/show_bug.cgi?id=125046

Reviewed by Sam Weinig.

* MiniBrowser/mac/AppDelegate.m:
(-[BrowserAppDelegate newWindow:]): Added WK_API_ENABLED guards.
(-[BrowserAppDelegate openDocument:]): Ditto.
* MiniBrowser/mac/WK2BrowserWindowController.h: Ditto. Also moved ivar declarations from the
interface to the implementation.
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController awakeFromNib]): Changed to set the policy delegate instead of
the policy client.
(-[WK2BrowserWindowController browsingContextController:decidePolicyForNavigationAction:decisionHandler:]):
Moved policy client implementation into this delegate method.
(-[WK2BrowserWindowController browsingContextController:decidePolicyForNewWindowAction:decisionHandler:]):
Ditto.
(-[WK2BrowserWindowController browsingContextController:decidePolicyForResponseAction:decisionHandler:]):
Ditto.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159902 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2e76acd6
2013-12-01 Dan Bernstein <mitz@apple.com>
[Mac] Transition MiniBrowser to the Cocoa API: policy delegate
https://bugs.webkit.org/show_bug.cgi?id=125046
Reviewed by Sam Weinig.
* MiniBrowser/mac/AppDelegate.m:
(-[BrowserAppDelegate newWindow:]): Added WK_API_ENABLED guards.
(-[BrowserAppDelegate openDocument:]): Ditto.
* MiniBrowser/mac/WK2BrowserWindowController.h: Ditto. Also moved ivar declarations from the
interface to the implementation.
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController awakeFromNib]): Changed to set the policy delegate instead of
the policy client.
(-[WK2BrowserWindowController browsingContextController:decidePolicyForNavigationAction:decisionHandler:]):
Moved policy client implementation into this delegate method.
(-[WK2BrowserWindowController browsingContextController:decidePolicyForNewWindowAction:decisionHandler:]):
Ditto.
(-[WK2BrowserWindowController browsingContextController:decidePolicyForResponseAction:decisionHandler:]):
Ditto.
2013-12-01 Dan Bernstein <mitz@apple.com>
[Mac] Remove the MiniBrowser injected bundle
......
......@@ -125,8 +125,10 @@ - (IBAction)newWindow:(id)sender
if (![sender respondsToSelector:@selector(tag)] || [sender tag] == WebKit1NewWindowTag)
controller = [[WK1BrowserWindowController alloc] initWithWindowNibName:@"BrowserWindow"];
#if WK_API_ENABLED
else if ([sender tag] == WebKit2NewWindowTag)
controller = [[WK2BrowserWindowController alloc] initWithContext:_processContext pageGroup:_pageGroup];
#endif
if (!controller)
return;
......@@ -192,6 +194,7 @@ - (IBAction)openDocument:(id)sender
return;
}
#if WK_API_ENABLED
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel beginWithCompletionHandler:^(NSInteger result) {
if (result != NSOKButton)
......@@ -204,6 +207,7 @@ - (IBAction)openDocument:(id)sender
NSURL *url = [openPanel.URLs objectAtIndex:0];
[newBrowserWindowController loadURLString:[url absoluteString]];
}];
#endif // WK_API_ENABLED
}
@end
......@@ -25,12 +25,12 @@
#import "BrowserWindowController.h"
@interface WK2BrowserWindowController : BrowserWindowController<BrowserController> {
WKContextRef _context;
WKPageGroupRef _pageGroup;
WKView *_webView;
}
#if WK_API_ENABLED
@interface WK2BrowserWindowController : BrowserWindowController <BrowserController>
- (id)initWithContext:(WKContextRef)context pageGroup:(WKPageGroupRef)pageGroup;
@end
#endif // WK_API_ENABLED
......@@ -25,13 +25,17 @@
#import "WK2BrowserWindowController.h"
#if WK_API_ENABLED
#import "AppDelegate.h"
#import <WebKit2/WKBrowsingContextController.h>
#import <WebKit2/WKBrowsingContextPolicyDelegate.h>
#import <WebKit2/WKPagePrivate.h>
#import <WebKit2/WKStringCF.h>
#import <WebKit2/WKURLCF.h>
#import <WebKit2/WKViewPrivate.h>
@interface WK2BrowserWindowController ()
@interface WK2BrowserWindowController () <WKBrowsingContextPolicyDelegate>
- (void)didStartProgress;
- (void)didChangeProgress:(double)value;
- (void)didFinishProgress;
......@@ -44,7 +48,11 @@ - (void)didSameDocumentNavigationForFrame:(WKFrameRef)frame;
- (BOOL)isPaginated;
@end
@implementation WK2BrowserWindowController
@implementation WK2BrowserWindowController {
WKContextRef _context;
WKPageGroupRef _pageGroup;
WKView *_webView;
}
- (id)initWithContext:(WKContextRef)context pageGroup:(WKPageGroupRef)pageGroup
{
......@@ -61,6 +69,7 @@ - (void)dealloc
{
WKRelease(_context);
WKRelease(_pageGroup);
_webView.browsingContextController.policyDelegate = nil;
[_webView release];
[super dealloc];
......@@ -412,25 +421,6 @@ static void didChangeBackForwardList(WKPageRef page, WKBackForwardListItemRef ad
[(WK2BrowserWindowController *)clientInfo validateToolbar];
}
// MARK: Policy Client Callbacks
static void decidePolicyForNavigationAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKFrameRef originatingFrame, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
{
LOG(@"decidePolicyForNavigationAction");
WKFramePolicyListenerUse(listener);
}
static void decidePolicyForNewWindowAction(WKPageRef page, WKFrameRef frame, WKFrameNavigationType navigationType, WKEventModifiers modifiers, WKEventMouseButton mouseButton, WKURLRequestRef request, WKStringRef frameName, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
{
LOG(@"decidePolicyForNewWindowAction");
WKFramePolicyListenerUse(listener);
}
static void decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, bool canShowMIMEType, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
{
WKFramePolicyListenerUse(listener);
}
// MARK: UI Client Callbacks
static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef request, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton button, const void* clientInfo)
......@@ -666,18 +656,8 @@ - (void)awakeFromNib
0, // pluginLoadPolicy
};
WKPageSetPageLoaderClient(_webView.pageRef, &loadClient);
WKPagePolicyClient policyClient = {
kWKPagePolicyClientCurrentVersion,
self, /* clientInfo */
0, /* decidePolicyForNavigationAction_deprecatedForUseWithV0 */
decidePolicyForNewWindowAction,
0, /* decidePolicyForResponse_deprecatedForUseWithV */
0, /* unableToImplementPolicy */
decidePolicyForNavigationAction,
decidePolicyForResponse,
};
WKPageSetPagePolicyClient(_webView.pageRef, &policyClient);
_webView.browsingContextController.policyDelegate = self;
WKPageUIClient uiClient = {
kWKPageUIClientCurrentVersion,
......@@ -847,4 +827,25 @@ - (IBAction)find:(id)sender
WKPageFindString(_webView.pageRef, string, kWKFindOptionsCaseInsensitive | kWKFindOptionsWrapAround | kWKFindOptionsShowFindIndicator | kWKFindOptionsShowOverlay, 100);
}
#pragma mark WKBrowsingContextPolicyDelegate
- (void)browsingContextController:(WKBrowsingContextController *)browsingContext decidePolicyForNavigationAction:(NSDictionary *)actionInformation decisionHandler:(WKPolicyDecisionHandler)decisionHandler
{
LOG(@"decidePolicyForNavigationAction");
decisionHandler(WKPolicyDecisionAllow);
}
- (void)browsingContextController:(WKBrowsingContextController *)browsingContext decidePolicyForNewWindowAction:(NSDictionary *)actionInformation decisionHandler:(WKPolicyDecisionHandler)decisionHandler
{
LOG(@"decidePolicyForNewWindowAction");
decisionHandler(WKPolicyDecisionAllow);
}
- (void)browsingContextController:(WKBrowsingContextController *)browsingContext decidePolicyForResponseAction:(NSDictionary *)actionInformation decisionHandler:(WKPolicyDecisionHandler)decisionHandler
{
decisionHandler(WKPolicyDecisionAllow);
}
@end
#endif // WK_API_ENABLED
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment