Commit 3944ae26 authored by mitz@apple.com's avatar mitz@apple.com

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

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

Reviewed by Darin Adler.

* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController dealloc]): Nil out the load delegate and stop observing the
title property.
(-[WK2BrowserWindowController isPaginated]): Changed to use Cocoa SPI.
(-[WK2BrowserWindowController togglePaginationMode:]): Ditto.
(-[WK2BrowserWindowController observeValueForKeyPath:ofObject:change:context:]): Update the
window title with the title property changes.
(-[WK2BrowserWindowController awakeFromNib]): Start observing the title property. Changed to
set the load delegate instead of the load client.
(-[WK2BrowserWindowController updateTextFieldFromURL:]): Changed to use Cocoa types.
(-[WK2BrowserWindowController updateProvisionalURL]): Removed frame parameter.
(-[WK2BrowserWindowController updateCommittedURL]): Ditto.
(-[WK2BrowserWindowController browsingContextControllerDidStartProvisionalLoad:]):
Implemented this load delegate method.
(-[WK2BrowserWindowController browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:]):
Ditto.
(-[WK2BrowserWindowController browsingContextController:didFailProvisionalLoadWithError:]): Ditto.
(-[WK2BrowserWindowController browsingContextControllerDidCommitLoad:]): Ditto.
(-[WK2BrowserWindowController browsingContextControllerDidFinishLoad:]): Ditto.
(-[WK2BrowserWindowController browsingContextController:didFailLoadWithError:]): Ditto.
(-[WK2BrowserWindowController browsingContextControllerDidChangeBackForwardList:addedItem:removedItems:]):
Ditto.
(-[WK2BrowserWindowController browsingContextController:canAuthenticateAgainstProtectionSpace:]):
Ditto.
(-[WK2BrowserWindowController browsingContextController:didReceiveAuthenticationChallenge:]): Ditto.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160231 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d436eeb1
2013-12-06 Dan Bernstein <mitz@apple.com>
[Mac] Transition MiniBrowser to the Cocoa API: load delegate
https://bugs.webkit.org/show_bug.cgi?id=125334
Reviewed by Darin Adler.
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController dealloc]): Nil out the load delegate and stop observing the
title property.
(-[WK2BrowserWindowController isPaginated]): Changed to use Cocoa SPI.
(-[WK2BrowserWindowController togglePaginationMode:]): Ditto.
(-[WK2BrowserWindowController observeValueForKeyPath:ofObject:change:context:]): Update the
window title with the title property changes.
(-[WK2BrowserWindowController awakeFromNib]): Start observing the title property. Changed to
set the load delegate instead of the load client.
(-[WK2BrowserWindowController updateTextFieldFromURL:]): Changed to use Cocoa types.
(-[WK2BrowserWindowController updateProvisionalURL]): Removed frame parameter.
(-[WK2BrowserWindowController updateCommittedURL]): Ditto.
(-[WK2BrowserWindowController browsingContextControllerDidStartProvisionalLoad:]):
Implemented this load delegate method.
(-[WK2BrowserWindowController browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:]):
Ditto.
(-[WK2BrowserWindowController browsingContextController:didFailProvisionalLoadWithError:]): Ditto.
(-[WK2BrowserWindowController browsingContextControllerDidCommitLoad:]): Ditto.
(-[WK2BrowserWindowController browsingContextControllerDidFinishLoad:]): Ditto.
(-[WK2BrowserWindowController browsingContextController:didFailLoadWithError:]): Ditto.
(-[WK2BrowserWindowController browsingContextControllerDidChangeBackForwardList:addedItem:removedItems:]):
Ditto.
(-[WK2BrowserWindowController browsingContextController:canAuthenticateAgainstProtectionSpace:]):
Ditto.
(-[WK2BrowserWindowController browsingContextController:didReceiveAuthenticationChallenge:]): Ditto.
2013-12-06 Tamas Gergely <tgergely.u-szeged@partner.samsung.com>
Remove function from style/checkers/cpp.py.
......
......@@ -28,21 +28,15 @@
#if WK_API_ENABLED
#import "AppDelegate.h"
#import <WebKit2/WKBrowsingContextController.h>
#import <WebKit2/WKBrowsingContextControllerPrivate.h>
#import <WebKit2/WKBrowsingContextLoadDelegatePrivate.h>
#import <WebKit2/WKBrowsingContextPolicyDelegate.h>
#import <WebKit2/WKPagePrivate.h>
#import <WebKit2/WKStringCF.h>
#import <WebKit2/WKURLCF.h>
#import <WebKit2/WKViewPrivate.h>
@interface WK2BrowserWindowController () <WKBrowsingContextPolicyDelegate>
- (void)didStartProvisionalLoadForFrame:(WKFrameRef)frame;
- (void)didCommitLoadForFrame:(WKFrameRef)frame;
- (void)didReceiveServerRedirectForProvisionalLoadForFrame:(WKFrameRef)frame;
- (void)didFailProvisionalLoadWithErrorForFrame:(WKFrameRef)frame;
- (void)didFailLoadWithErrorForFrame:(WKFrameRef)frame;
- (void)didSameDocumentNavigationForFrame:(WKFrameRef)frame;
- (BOOL)isPaginated;
@interface WK2BrowserWindowController () <WKBrowsingContextLoadDelegatePrivate, WKBrowsingContextPolicyDelegate>
@end
@implementation WK2BrowserWindowController {
......@@ -69,6 +63,8 @@ - (void)dealloc
WKRelease(_context);
WKRelease(_pageGroup);
[_webView.browsingContextController removeObserver:self forKeyPath:@"title" context:[WK2BrowserWindowController self]];
_webView.browsingContextController.loadDelegate = nil;
_webView.browsingContextController.policyDelegate = nil;
[_webView release];
......@@ -263,17 +259,17 @@ - (IBAction)toggleZoomMode:(id)sender
- (BOOL)isPaginated
{
return WKPageGetPaginationMode(_webView.pageRef) != kWKPaginationModeUnpaginated;
return _webView.browsingContextController.paginationMode != WKPaginationModeUnpaginated;
}
- (IBAction)togglePaginationMode:(id)sender
{
if ([self isPaginated])
WKPageSetPaginationMode(_webView.pageRef, kWKPaginationModeUnpaginated);
_webView.browsingContextController.paginationMode = WKPaginationModeUnpaginated;
else {
WKPageSetPaginationMode(_webView.pageRef, kWKPaginationModeLeftToRight);
WKPageSetPageLength(_webView.pageRef, _webView.bounds.size.width / 2);
WKPageSetGapBetweenPages(_webView.pageRef, 10);
_webView.browsingContextController.paginationMode = WKPaginationModeLeftToRight;
_webView.browsingContextController.pageLength = _webView.bounds.size.width / 2;
_webView.browsingContextController.gapBetweenPages = 10;
}
}
......@@ -303,107 +299,13 @@ - (IBAction)dumpSourceToConsole:(id)sender
WKPageGetSourceForFrame(_webView.pageRef, WKPageGetMainFrame(_webView.pageRef), NULL, dumpSource);
}
// MARK: Loader Client Callbacks
static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
[(WK2BrowserWindowController *)clientInfo didStartProvisionalLoadForFrame:frame];
}
static void didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
[(WK2BrowserWindowController *)clientInfo didReceiveServerRedirectForProvisionalLoadForFrame:frame];
}
static void didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void *clientInfo)
{
[(WK2BrowserWindowController *)clientInfo didFailProvisionalLoadWithErrorForFrame:frame];
}
static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
[(WK2BrowserWindowController *)clientInfo didCommitLoadForFrame:frame];
}
static void didFinishDocumentLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
LOG(@"didFinishDocumentLoadForFrame");
}
static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
LOG(@"didFinishLoadForFrame");
}
static void didFailLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void *clientInfo)
{
[(WK2BrowserWindowController *)clientInfo didFailLoadWithErrorForFrame:frame];
}
static void didSameDocumentNavigationForFrame(WKPageRef page, WKFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef userData, const void *clientInfo)
{
[(WK2BrowserWindowController *)clientInfo didSameDocumentNavigationForFrame:frame];
}
static void didReceiveTitleForFrame(WKPageRef page, WKStringRef title, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (!WKFrameIsMainFrame(frame))
if (context != [WK2BrowserWindowController self] || object != _webView.browsingContextController)
return;
WK2BrowserWindowController* controller = (WK2BrowserWindowController*)clientInfo;
CFStringRef cfTitle = WKStringCopyCFString(0, title);
[[controller window] setTitle:[(NSString *)cfTitle stringByAppendingString:@" [WK2]"]];
CFRelease(cfTitle);
}
static void didFirstLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
LOG(@"didFirstLayoutForFrame");
}
static void didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
LOG(@"didFirstVisuallyNonEmptyLayoutForFrame");
}
static void didRemoveFrameFromHierarchy(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
LOG(@"didRemoveFrameFromHierarchy");
}
static void didDisplayInsecureContentForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
LOG(@"didDisplayInsecureContentForFrame");
}
static void didRunInsecureContentForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
LOG(@"didRunInsecureContentForFrame");
}
static void didDetectXSSForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
{
LOG(@"didDetectXSSForFrame");
}
static void didBecomeUnresponsive(WKPageRef page, const void *clientInfo)
{
LOG(@"didBecomeUnresponsive");
}
static void didBecomeResponsive(WKPageRef page, const void *clientInfo)
{
LOG(@"didBecomeResponsive");
}
static void processDidExit(WKPageRef page, const void *clientInfo)
{
LOG(@"processDidExit");
}
static void didChangeBackForwardList(WKPageRef page, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void *clientInfo)
{
[(WK2BrowserWindowController *)clientInfo validateToolbar];
if ([keyPath isEqualToString:@"title"])
self.window.title = [_webView.browsingContextController.title stringByAppendingString:@" [WK2]"];
}
// MARK: UI Client Callbacks
......@@ -603,46 +505,9 @@ - (void)awakeFromNib
[progressIndicator bind:NSHiddenBinding toObject:_webView.browsingContextController withKeyPath:@"loading" options:@{ NSValueTransformerNameBindingOption : NSNegateBooleanTransformerName }];
[progressIndicator bind:NSValueBinding toObject:_webView.browsingContextController withKeyPath:@"estimatedProgress" options:nil];
WKPageLoaderClientV3 loadClient = {
{ 3, self },
didStartProvisionalLoadForFrame,
didReceiveServerRedirectForProvisionalLoadForFrame,
didFailProvisionalLoadWithErrorForFrame,
didCommitLoadForFrame,
didFinishDocumentLoadForFrame,
didFinishLoadForFrame,
didFailLoadWithErrorForFrame,
didSameDocumentNavigationForFrame,
didReceiveTitleForFrame,
didFirstLayoutForFrame,
didFirstVisuallyNonEmptyLayoutForFrame,
didRemoveFrameFromHierarchy,
didDisplayInsecureContentForFrame,
didRunInsecureContentForFrame,
0, // canAuthenticateAgainstProtectionSpaceInFrame
0, // didReceiveAuthenticationChallengeInFrame
0, // didStartProgress,
0, // didChangeProgress,
0, // didFinishProgress,
didBecomeUnresponsive,
didBecomeResponsive,
processDidExit,
didChangeBackForwardList,
0, // shouldGoToBackForwardItem
0, // didFailToInitializePlugin
didDetectXSSForFrame,
0, // didNewFirstVisuallyNonEmptyLayout_unavailable
0, // willGoToBackForwardListItem
0, // interactionOccurredWhileProcessUnresponsive
0, // pluginDidFail_deprecatedForUseWithV1
0, // didReceiveIntentForFrame
0, // registerIntentServiceForFrame
0, // didLayout
0, // pluginLoadPolicy_deprecatedForUseWithV2
0, // pluginDidFail
0, // pluginLoadPolicy
};
WKPageSetPageLoaderClient(_webView.pageRef, &loadClient.base);
[_webView.browsingContextController addObserver:self forKeyPath:@"title" options:0 context:[WK2BrowserWindowController self]];
_webView.browsingContextController.loadDelegate = self;
_webView.browsingContextController.policyDelegate = self;
......@@ -698,102 +563,101 @@ - (void)awakeFromNib
WKPageSetPageUIClient(_webView.pageRef, &uiClient.base);
}
- (void)updateTextFieldFromURL:(WKURLRef)URLRef
- (void)updateTextFieldFromURL:(NSURL *)URL
{
if (!URLRef)
if (!URL)
return;
static WKURLRef emptyURL = 0;
if (!emptyURL)
emptyURL = WKURLCreateWithUTF8CString("");
if (WKURLIsEqual(URLRef, emptyURL))
if (!URL.absoluteString.length)
return;
CFURLRef cfSourceURL = WKURLCopyCFURL(0, URLRef);
[urlText setStringValue:(NSString*)CFURLGetString(cfSourceURL)];
CFRelease(cfSourceURL);
urlText.stringValue = (NSString *)CFURLGetString((CFURLRef)URL);
}
- (void)updateProvisionalURLForFrame:(WKFrameRef)frame
- (void)updateProvisionalURL
{
WKURLRef url = WKFrameCopyProvisionalURL(frame);
NSURL *url = _webView.browsingContextController.provisionalURL;
if (!url)
return;
[self updateTextFieldFromURL:url];
WKRelease(url);
}
- (void)updateCommittedURLForFrame:(WKFrameRef)frame
- (void)updateCommittedURL
{
WKURLRef url = WKFrameCopyURL(frame);
NSURL *url = _webView.browsingContextController.committedURL;
if (!url)
return;
[self updateTextFieldFromURL:url];
WKRelease(url);
}
- (void)didStartProvisionalLoadForFrame:(WKFrameRef)frame
- (void)loadURLString:(NSString *)urlString
{
if (!WKFrameIsMainFrame(frame))
return;
[self updateProvisionalURLForFrame:frame];
// FIXME: We shouldn't have to set the url text here.
[urlText setStringValue:urlString];
[self fetch:nil];
}
- (void)didReceiveServerRedirectForProvisionalLoadForFrame:(WKFrameRef)frame
- (IBAction)performFindPanelAction:(id)sender
{
if (!WKFrameIsMainFrame(frame))
return;
[self updateProvisionalURLForFrame:frame];
[findPanelWindow makeKeyAndOrderFront:sender];
}
- (void)didFailProvisionalLoadWithErrorForFrame:(WKFrameRef)frame
- (IBAction)find:(id)sender
{
if (!WKFrameIsMainFrame(frame))
return;
WKStringRef string = WKStringCreateWithCFString((CFStringRef)[sender stringValue]);
[self updateProvisionalURLForFrame:frame];
WKPageFindString(_webView.pageRef, string, kWKFindOptionsCaseInsensitive | kWKFindOptionsWrapAround | kWKFindOptionsShowFindIndicator | kWKFindOptionsShowOverlay, 100);
}
- (void)didFailLoadWithErrorForFrame:(WKFrameRef)frame
#pragma mark WKBrowsingContextLoadDelegate
- (void)browsingContextControllerDidStartProvisionalLoad:(WKBrowsingContextController *)sender
{
if (!WKFrameIsMainFrame(frame))
return;
[self updateProvisionalURL];
}
[self updateProvisionalURLForFrame:frame];
- (void)browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:(WKBrowsingContextController *)sender
{
[self updateProvisionalURL];
}
- (void)didSameDocumentNavigationForFrame:(WKFrameRef)frame
- (void)browsingContextController:(WKBrowsingContextController *)sender didFailProvisionalLoadWithError:(NSError *)error
{
[self updateProvisionalURL];
}
- (void)didCommitLoadForFrame:(WKFrameRef)frame
- (void)browsingContextControllerDidCommitLoad:(WKBrowsingContextController *)sender
{
if (!WKFrameIsMainFrame(frame))
return;
[self updateCommittedURL];
}
[self updateCommittedURLForFrame:frame];
- (void)browsingContextControllerDidFinishLoad:(WKBrowsingContextController *)sender
{
LOG(@"didFinishLoad");
}
- (void)loadURLString:(NSString *)urlString
- (void)browsingContextController:(WKBrowsingContextController *)sender didFailLoadWithError:(NSError *)error
{
// FIXME: We shouldn't have to set the url text here.
[urlText setStringValue:urlString];
[self fetch:nil];
[self updateProvisionalURL];
}
- (IBAction)performFindPanelAction:(id)sender
- (void)browsingContextControllerDidChangeBackForwardList:(WKBrowsingContextController *)sender addedItem:(WKBackForwardListItem *)addedItem removedItems:(NSArray *)removedItems
{
[findPanelWindow makeKeyAndOrderFront:sender];
[self validateToolbar];
}
- (IBAction)find:(id)sender
#pragma mark WKBrowsingContextLoadDelegatePrivate
- (BOOL)browsingContextController:(WKBrowsingContextController *)sender canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
WKStringRef string = WKStringCreateWithCFString((CFStringRef)[sender stringValue]);
LOG(@"canAuthenticateAgainstProtectionSpace: %@", protectionSpace);
return YES;
}
WKPageFindString(_webView.pageRef, string, kWKFindOptionsCaseInsensitive | kWKFindOptionsWrapAround | kWKFindOptionsShowFindIndicator | kWKFindOptionsShowOverlay, 100);
- (void)browsingContextController:(WKBrowsingContextController *)sender didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
LOG(@"didReceiveAuthenticationChallenge: %@", challenge);
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
#pragma mark WKBrowsingContextPolicyDelegate
......
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