Changeset 160231 in webkit


Ignore:
Timestamp:
Dec 6, 2013 11:02:05 AM (10 years ago)
Author:
mitz@apple.com
Message:

[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.

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r160230 r160231  
     12013-12-06  Dan Bernstein  <mitz@apple.com>
     2
     3        [Mac] Transition MiniBrowser to the Cocoa API: load delegate
     4        https://bugs.webkit.org/show_bug.cgi?id=125334
     5
     6        Reviewed by Darin Adler.
     7
     8        * MiniBrowser/mac/WK2BrowserWindowController.m:
     9        (-[WK2BrowserWindowController dealloc]): Nil out the load delegate and stop observing the
     10        title property.
     11        (-[WK2BrowserWindowController isPaginated]): Changed to use Cocoa SPI.
     12        (-[WK2BrowserWindowController togglePaginationMode:]): Ditto.
     13        (-[WK2BrowserWindowController observeValueForKeyPath:ofObject:change:context:]): Update the
     14        window title with the title property changes.
     15        (-[WK2BrowserWindowController awakeFromNib]): Start observing the title property. Changed to
     16        set the load delegate instead of the load client.
     17        (-[WK2BrowserWindowController updateTextFieldFromURL:]): Changed to use Cocoa types.
     18        (-[WK2BrowserWindowController updateProvisionalURL]): Removed frame parameter.
     19        (-[WK2BrowserWindowController updateCommittedURL]): Ditto.
     20        (-[WK2BrowserWindowController browsingContextControllerDidStartProvisionalLoad:]):
     21        Implemented this load delegate method.
     22        (-[WK2BrowserWindowController browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:]):
     23        Ditto.
     24        (-[WK2BrowserWindowController browsingContextController:didFailProvisionalLoadWithError:]): Ditto.
     25        (-[WK2BrowserWindowController browsingContextControllerDidCommitLoad:]): Ditto.
     26        (-[WK2BrowserWindowController browsingContextControllerDidFinishLoad:]): Ditto.
     27        (-[WK2BrowserWindowController browsingContextController:didFailLoadWithError:]): Ditto.
     28        (-[WK2BrowserWindowController browsingContextControllerDidChangeBackForwardList:addedItem:removedItems:]):
     29        Ditto.
     30        (-[WK2BrowserWindowController browsingContextController:canAuthenticateAgainstProtectionSpace:]):
     31        Ditto.
     32        (-[WK2BrowserWindowController browsingContextController:didReceiveAuthenticationChallenge:]): Ditto.
     33
    1342013-12-06  Tamas Gergely  <tgergely.u-szeged@partner.samsung.com>
    235
  • trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m

    r160137 r160231  
    2929
    3030#import "AppDelegate.h"
    31 #import <WebKit2/WKBrowsingContextController.h>
     31#import <WebKit2/WKBrowsingContextControllerPrivate.h>
     32#import <WebKit2/WKBrowsingContextLoadDelegatePrivate.h>
    3233#import <WebKit2/WKBrowsingContextPolicyDelegate.h>
    3334#import <WebKit2/WKPagePrivate.h>
     
    3637#import <WebKit2/WKViewPrivate.h>
    3738
    38 @interface WK2BrowserWindowController () <WKBrowsingContextPolicyDelegate>
    39 - (void)didStartProvisionalLoadForFrame:(WKFrameRef)frame;
    40 - (void)didCommitLoadForFrame:(WKFrameRef)frame;
    41 - (void)didReceiveServerRedirectForProvisionalLoadForFrame:(WKFrameRef)frame;
    42 - (void)didFailProvisionalLoadWithErrorForFrame:(WKFrameRef)frame;
    43 - (void)didFailLoadWithErrorForFrame:(WKFrameRef)frame;
    44 - (void)didSameDocumentNavigationForFrame:(WKFrameRef)frame;
    45 - (BOOL)isPaginated;
     39@interface WK2BrowserWindowController () <WKBrowsingContextLoadDelegatePrivate, WKBrowsingContextPolicyDelegate>
    4640@end
    4741
     
    7064    WKRelease(_context);
    7165    WKRelease(_pageGroup);
     66    [_webView.browsingContextController removeObserver:self forKeyPath:@"title" context:[WK2BrowserWindowController self]];
     67    _webView.browsingContextController.loadDelegate = nil;
    7268    _webView.browsingContextController.policyDelegate = nil;
    7369    [_webView release];
     
    264260- (BOOL)isPaginated
    265261{
    266     return WKPageGetPaginationMode(_webView.pageRef) != kWKPaginationModeUnpaginated;
     262    return _webView.browsingContextController.paginationMode != WKPaginationModeUnpaginated;
    267263}
    268264
     
    270266{
    271267    if ([self isPaginated])
    272         WKPageSetPaginationMode(_webView.pageRef, kWKPaginationModeUnpaginated);
     268        _webView.browsingContextController.paginationMode = WKPaginationModeUnpaginated;
    273269    else {
    274         WKPageSetPaginationMode(_webView.pageRef, kWKPaginationModeLeftToRight);
    275         WKPageSetPageLength(_webView.pageRef, _webView.bounds.size.width / 2);
    276         WKPageSetGapBetweenPages(_webView.pageRef, 10);
     270        _webView.browsingContextController.paginationMode = WKPaginationModeLeftToRight;
     271        _webView.browsingContextController.pageLength = _webView.bounds.size.width / 2;
     272        _webView.browsingContextController.gapBetweenPages = 10;
    277273    }
    278274}
     
    304300}
    305301
    306 // MARK: Loader Client Callbacks
    307 
    308 static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    309 {
    310     [(WK2BrowserWindowController *)clientInfo didStartProvisionalLoadForFrame:frame];
    311 }
    312 
    313 static void didReceiveServerRedirectForProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    314 {
    315     [(WK2BrowserWindowController *)clientInfo didReceiveServerRedirectForProvisionalLoadForFrame:frame];
    316 }
    317 
    318 static void didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void *clientInfo)
    319 {
    320     [(WK2BrowserWindowController *)clientInfo didFailProvisionalLoadWithErrorForFrame:frame];
    321 }
    322 
    323 static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    324 {
    325     [(WK2BrowserWindowController *)clientInfo didCommitLoadForFrame:frame];
    326 }
    327 
    328 static void didFinishDocumentLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    329 {
    330     LOG(@"didFinishDocumentLoadForFrame");
    331 }
    332 
    333 static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    334 {
    335     LOG(@"didFinishLoadForFrame");
    336 }
    337 
    338 static void didFailLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void *clientInfo)
    339 {
    340     [(WK2BrowserWindowController *)clientInfo didFailLoadWithErrorForFrame:frame];
    341 }
    342 
    343 static void didSameDocumentNavigationForFrame(WKPageRef page, WKFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef userData, const void *clientInfo)
    344 {
    345     [(WK2BrowserWindowController *)clientInfo didSameDocumentNavigationForFrame:frame];
    346 }
    347 
    348 static void didReceiveTitleForFrame(WKPageRef page, WKStringRef title, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    349 {
    350     if (!WKFrameIsMainFrame(frame))
    351         return;
    352 
    353     WK2BrowserWindowController* controller = (WK2BrowserWindowController*)clientInfo;
    354     CFStringRef cfTitle = WKStringCopyCFString(0, title);
    355     [[controller window] setTitle:[(NSString *)cfTitle stringByAppendingString:@" [WK2]"]];
    356     CFRelease(cfTitle);
    357 }
    358 
    359 static void didFirstLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    360 {
    361     LOG(@"didFirstLayoutForFrame");
    362 }
    363 
    364 static void didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    365 {
    366     LOG(@"didFirstVisuallyNonEmptyLayoutForFrame");
    367 }
    368 
    369 static void didRemoveFrameFromHierarchy(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    370 {
    371     LOG(@"didRemoveFrameFromHierarchy");
    372 }
    373 
    374 static void didDisplayInsecureContentForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    375 {
    376     LOG(@"didDisplayInsecureContentForFrame");
    377 }
    378 
    379 static void didRunInsecureContentForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    380 {
    381     LOG(@"didRunInsecureContentForFrame");
    382 }
    383 
    384 static void didDetectXSSForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
    385 {
    386     LOG(@"didDetectXSSForFrame");
    387 }
    388  
    389 static void didBecomeUnresponsive(WKPageRef page, const void *clientInfo)
    390 {
    391     LOG(@"didBecomeUnresponsive");
    392 }
    393 
    394 static void didBecomeResponsive(WKPageRef page, const void *clientInfo)
    395 {
    396     LOG(@"didBecomeResponsive");
    397 }
    398 
    399 static void processDidExit(WKPageRef page, const void *clientInfo)
    400 {
    401     LOG(@"processDidExit");
    402 }
    403 
    404 static void didChangeBackForwardList(WKPageRef page, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void *clientInfo)
    405 {
    406     [(WK2BrowserWindowController *)clientInfo validateToolbar];
     302- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
     303{
     304    if (context != [WK2BrowserWindowController self] || object != _webView.browsingContextController)
     305        return;
     306
     307    if ([keyPath isEqualToString:@"title"])
     308        self.window.title = [_webView.browsingContextController.title stringByAppendingString:@" [WK2]"];
    407309}
    408310
     
    604506    [progressIndicator bind:NSValueBinding toObject:_webView.browsingContextController withKeyPath:@"estimatedProgress" options:nil];
    605507
    606     WKPageLoaderClientV3 loadClient = {
    607         { 3, self },
    608         didStartProvisionalLoadForFrame,
    609         didReceiveServerRedirectForProvisionalLoadForFrame,
    610         didFailProvisionalLoadWithErrorForFrame,
    611         didCommitLoadForFrame,
    612         didFinishDocumentLoadForFrame,
    613         didFinishLoadForFrame,
    614         didFailLoadWithErrorForFrame,
    615         didSameDocumentNavigationForFrame,
    616         didReceiveTitleForFrame,
    617         didFirstLayoutForFrame,
    618         didFirstVisuallyNonEmptyLayoutForFrame,
    619         didRemoveFrameFromHierarchy,
    620         didDisplayInsecureContentForFrame,
    621         didRunInsecureContentForFrame,
    622         0, // canAuthenticateAgainstProtectionSpaceInFrame
    623         0, // didReceiveAuthenticationChallengeInFrame
    624         0, // didStartProgress,
    625         0, // didChangeProgress,
    626         0, // didFinishProgress,
    627         didBecomeUnresponsive,
    628         didBecomeResponsive,
    629         processDidExit,
    630         didChangeBackForwardList,
    631         0, // shouldGoToBackForwardItem
    632         0, // didFailToInitializePlugin
    633         didDetectXSSForFrame,
    634         0, // didNewFirstVisuallyNonEmptyLayout_unavailable
    635         0, // willGoToBackForwardListItem
    636         0, // interactionOccurredWhileProcessUnresponsive
    637         0, // pluginDidFail_deprecatedForUseWithV1
    638         0, // didReceiveIntentForFrame
    639         0, // registerIntentServiceForFrame
    640         0, // didLayout
    641         0, // pluginLoadPolicy_deprecatedForUseWithV2
    642         0, // pluginDidFail
    643         0, // pluginLoadPolicy
    644     };
    645     WKPageSetPageLoaderClient(_webView.pageRef, &loadClient.base);
     508    [_webView.browsingContextController addObserver:self forKeyPath:@"title" options:0 context:[WK2BrowserWindowController self]];
     509
     510    _webView.browsingContextController.loadDelegate = self;
    646511
    647512    _webView.browsingContextController.policyDelegate = self;
     
    699564}
    700565
    701 - (void)updateTextFieldFromURL:(WKURLRef)URLRef
    702 {
    703     if (!URLRef)
    704         return;
    705 
    706     static WKURLRef emptyURL = 0;
    707     if (!emptyURL)
    708         emptyURL = WKURLCreateWithUTF8CString("");
    709 
    710     if (WKURLIsEqual(URLRef, emptyURL))
    711         return;
    712 
    713     CFURLRef cfSourceURL = WKURLCopyCFURL(0, URLRef);
    714     [urlText setStringValue:(NSString*)CFURLGetString(cfSourceURL)];
    715     CFRelease(cfSourceURL);
    716 }
    717 
    718 - (void)updateProvisionalURLForFrame:(WKFrameRef)frame
    719 {
    720     WKURLRef url = WKFrameCopyProvisionalURL(frame);
     566- (void)updateTextFieldFromURL:(NSURL *)URL
     567{
     568    if (!URL)
     569        return;
     570
     571    if (!URL.absoluteString.length)
     572        return;
     573
     574    urlText.stringValue = (NSString *)CFURLGetString((CFURLRef)URL);
     575}
     576
     577- (void)updateProvisionalURL
     578{
     579    NSURL *url = _webView.browsingContextController.provisionalURL;
    721580    if (!url)
    722581        return;
    723582    [self updateTextFieldFromURL:url];
    724     WKRelease(url);
    725 }
    726 
    727 - (void)updateCommittedURLForFrame:(WKFrameRef)frame
    728 {
    729     WKURLRef url = WKFrameCopyURL(frame);
     583}
     584
     585- (void)updateCommittedURL
     586{
     587    NSURL *url = _webView.browsingContextController.committedURL;
    730588    if (!url)
    731589        return;
    732590    [self updateTextFieldFromURL:url];
    733     WKRelease(url);
    734 }
    735 
    736 - (void)didStartProvisionalLoadForFrame:(WKFrameRef)frame
    737 {
    738     if (!WKFrameIsMainFrame(frame))
    739         return;
    740 
    741     [self updateProvisionalURLForFrame:frame];
    742 }
    743 
    744 - (void)didReceiveServerRedirectForProvisionalLoadForFrame:(WKFrameRef)frame
    745 {
    746     if (!WKFrameIsMainFrame(frame))
    747         return;
    748 
    749     [self updateProvisionalURLForFrame:frame];
    750 }
    751 
    752 - (void)didFailProvisionalLoadWithErrorForFrame:(WKFrameRef)frame
    753 {
    754     if (!WKFrameIsMainFrame(frame))
    755         return;
    756 
    757     [self updateProvisionalURLForFrame:frame];
    758 }
    759 
    760 - (void)didFailLoadWithErrorForFrame:(WKFrameRef)frame
    761 {
    762     if (!WKFrameIsMainFrame(frame))
    763         return;
    764 
    765     [self updateProvisionalURLForFrame:frame];
    766 }
    767 
    768 - (void)didSameDocumentNavigationForFrame:(WKFrameRef)frame
    769 {
    770 }
    771 
    772 - (void)didCommitLoadForFrame:(WKFrameRef)frame
    773 {
    774     if (!WKFrameIsMainFrame(frame))
    775         return;
    776 
    777     [self updateCommittedURLForFrame:frame];
    778591}
    779592
     
    797610}
    798611
     612#pragma mark WKBrowsingContextLoadDelegate
     613
     614- (void)browsingContextControllerDidStartProvisionalLoad:(WKBrowsingContextController *)sender
     615{
     616    [self updateProvisionalURL];
     617}
     618
     619- (void)browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:(WKBrowsingContextController *)sender
     620{
     621    [self updateProvisionalURL];
     622}
     623
     624- (void)browsingContextController:(WKBrowsingContextController *)sender didFailProvisionalLoadWithError:(NSError *)error
     625{
     626    [self updateProvisionalURL];
     627}
     628
     629- (void)browsingContextControllerDidCommitLoad:(WKBrowsingContextController *)sender
     630{
     631    [self updateCommittedURL];
     632}
     633
     634- (void)browsingContextControllerDidFinishLoad:(WKBrowsingContextController *)sender
     635{
     636    LOG(@"didFinishLoad");
     637}
     638
     639- (void)browsingContextController:(WKBrowsingContextController *)sender didFailLoadWithError:(NSError *)error
     640{
     641    [self updateProvisionalURL];
     642}
     643
     644- (void)browsingContextControllerDidChangeBackForwardList:(WKBrowsingContextController *)sender addedItem:(WKBackForwardListItem *)addedItem removedItems:(NSArray *)removedItems
     645{
     646    [self validateToolbar];
     647}
     648
     649#pragma mark WKBrowsingContextLoadDelegatePrivate
     650
     651- (BOOL)browsingContextController:(WKBrowsingContextController *)sender canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
     652{
     653    LOG(@"canAuthenticateAgainstProtectionSpace: %@", protectionSpace);
     654    return YES;
     655}
     656
     657- (void)browsingContextController:(WKBrowsingContextController *)sender didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
     658{
     659    LOG(@"didReceiveAuthenticationChallenge: %@", challenge);
     660    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
     661}
     662
    799663#pragma mark WKBrowsingContextPolicyDelegate
    800664
Note: See TracChangeset for help on using the changeset viewer.