Changeset 159876 in webkit


Ignore:
Timestamp:
Nov 29, 2013 3:21:08 PM (10 years ago)
Author:
mitz@apple.com
Message:

[Cocoa] Add a way to recover from load errors
https://bugs.webkit.org/show_bug.cgi?id=125020

Reviewed by Sam Weinig.

  • UIProcess/API/Cocoa/WKBrowsingContextController.mm:

(createErrorWithRecoveryAttempter): Added this helper function. It creates an NSError from
the given error, adding two keys to the user info dictionary: the context controller under
the recovery attempter key, and the frame under a private key.
(didFailProvisionalLoadWithErrorForFrame): Changed to use createErrorWithRecoveryAttempter.
(didFailLoadWithErrorForFrame): Ditto.
(-[WKBrowsingContextController attemptRecoveryFromError:]): Implemented this
WKErrorRecoveryAttempting protocol method by loading the failing URL from the error into the
frame from the error.

  • UIProcess/API/Cocoa/WKErrorRecoveryAttempting.h: Added. Defines a protocol for attempting

recovery from errors and declares the error user info dictionary key under which an object
conforming to this protocol may be stored.

  • UIProcess/API/Cocoa/WKErrorRecoveryAttempting.m: Added. Defines

WKRecoveryAttempterErrorKey.

  • UIProcess/WebFrameProxy.cpp:

(WebKit::WebFrameProxy::loadURL): Added. Sends the LoadURLInFrame message to the page.

  • UIProcess/WebFrameProxy.h:
  • WebKit2.xcodeproj/project.pbxproj: Added references to new files.
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::loadURLInFrame): Added. Loads the URL in the given frame.

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in: Added LoadURLInFrame.
Location:
trunk/Source/WebKit2
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r159875 r159876  
     12013-11-29  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Add a way to recover from load errors
     4        https://bugs.webkit.org/show_bug.cgi?id=125020
     5
     6        Reviewed by Sam Weinig.
     7
     8        * UIProcess/API/Cocoa/WKBrowsingContextController.mm:
     9        (createErrorWithRecoveryAttempter): Added this helper function. It creates an NSError from
     10        the given error, adding two keys to the user info dictionary: the context controller under
     11        the recovery attempter key, and the frame under a private key.
     12        (didFailProvisionalLoadWithErrorForFrame): Changed to use createErrorWithRecoveryAttempter.
     13        (didFailLoadWithErrorForFrame): Ditto.
     14        (-[WKBrowsingContextController attemptRecoveryFromError:]): Implemented this
     15        WKErrorRecoveryAttempting protocol method by loading the failing URL from the error into the
     16        frame from the error.
     17
     18        * UIProcess/API/Cocoa/WKErrorRecoveryAttempting.h: Added. Defines a protocol for attempting
     19        recovery from errors and declares the error user info dictionary key under which an object
     20        conforming to this protocol may be stored.
     21        * UIProcess/API/Cocoa/WKErrorRecoveryAttempting.m: Added. Defines
     22        WKRecoveryAttempterErrorKey.
     23
     24        * UIProcess/WebFrameProxy.cpp:
     25        (WebKit::WebFrameProxy::loadURL): Added. Sends the LoadURLInFrame message to the page.
     26        * UIProcess/WebFrameProxy.h:
     27
     28        * WebKit2.xcodeproj/project.pbxproj: Added references to new files.
     29
     30        * WebProcess/WebPage/WebPage.cpp:
     31        (WebKit::WebPage::loadURLInFrame): Added. Loads the URL in the given frame.
     32        * WebProcess/WebPage/WebPage.h:
     33        * WebProcess/WebPage/WebPage.messages.in: Added LoadURLInFrame.
     34
    1352013-11-29  Dan Bernstein  <mitz@apple.com>
    236
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm

    r159875 r159876  
    3333#import "WKBackForwardListItemInternal.h"
    3434#import "WKErrorCF.h"
     35#import "WKErrorRecoveryAttempting.h"
    3536#import "WKFrame.h"
    3637#import "WKFramePolicyListener.h"
    3738#import "WKNSArray.h"
     39#import "WKNSError.h"
    3840#import "WKNSURLExtras.h"
    3941#import "WKPagePrivate.h"
     
    102104NSString * const WKActionCanShowMIMETypeKey = @"WKActionCanShowMIMETypeKey";
    103105
     106static NSString * const frameErrorKey = @"WKBrowsingContextFrameErrorKey";
     107
     108@interface WKBrowsingContextController () <WKErrorRecoveryAttempting>
     109@end
     110
    104111@implementation WKBrowsingContextController {
    105112    // Underlying WKPageRef.
     
    374381}
    375382
     383static NSError *createErrorWithRecoveryAttempter(WKErrorRef wkError, WKFrameRef frame, WKBrowsingContextController *browsingContext)
     384{
     385    NSError *error = wrapper(*toImpl(wkError));
     386    NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
     387        browsingContext, WKRecoveryAttempterErrorKey,
     388        toImpl(frame)->wrapper(), frameErrorKey,
     389    nil];
     390
     391    if (NSDictionary *originalUserInfo = error.userInfo)
     392        [userInfo addEntriesFromDictionary:originalUserInfo];
     393
     394    return [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:userInfo];
     395}
     396
    376397static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
    377398{
     
    401422    WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo;
    402423    if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidFailProvisionalLoad:withError:)]) {
    403         RetainPtr<CFErrorRef> cfError = adoptCF(WKErrorCopyCFError(kCFAllocatorDefault, error));
    404         [browsingContext.loadDelegate browsingContextControllerDidFailProvisionalLoad:browsingContext withError:(NSError *)cfError.get()];
     424        RetainPtr<NSError> nsError = adoptNS(createErrorWithRecoveryAttempter(error, frame, browsingContext));
     425        [browsingContext.loadDelegate browsingContextControllerDidFailProvisionalLoad:browsingContext withError:nsError.get()];
    405426    }
    406427}
     
    433454    WKBrowsingContextController *browsingContext = (WKBrowsingContextController *)clientInfo;
    434455    if ([browsingContext.loadDelegate respondsToSelector:@selector(browsingContextControllerDidFailLoad:withError:)]) {
    435         RetainPtr<CFErrorRef> cfError = adoptCF(WKErrorCopyCFError(kCFAllocatorDefault, error));
    436         [browsingContext.loadDelegate browsingContextControllerDidFailLoad:browsingContext withError:(NSError *)cfError.get()];
     456        RetainPtr<NSError> nsError = adoptNS(createErrorWithRecoveryAttempter(error, frame, browsingContext));
     457        [browsingContext.loadDelegate browsingContextControllerDidFailLoad:browsingContext withError:nsError.get()];
    437458    }
    438459}
     
    611632    return customSchemes;
    612633}
    613  
     634
     635#pragma mark WKErrorRecoveryAttempting
     636
     637- (BOOL)attemptRecoveryFromError:(NSError *)error
     638{
     639    NSDictionary *userInfo = error.userInfo;
     640
     641    NSString *failingURLString = userInfo[NSURLErrorFailingURLStringErrorKey];
     642    if (!failingURLString)
     643        return NO;
     644
     645    NSObject <WKObject> *frame = userInfo[frameErrorKey];
     646    if (![frame conformsToProtocol:@protocol(WKObject)])
     647        return NO;
     648
     649    if (frame._apiObject.type() != API::Object::Type::Frame)
     650        return NO;
     651
     652    WebFrameProxy& webFrame = *static_cast<WebFrameProxy*>(&frame._apiObject);
     653    webFrame.loadURL(failingURLString);
     654
     655    return YES;
     656}
     657
    614658@end
    615659
  • trunk/Source/WebKit2/UIProcess/WebFrameProxy.cpp

    r159647 r159876  
    7474}
    7575
     76void WebFrameProxy::loadURL(const String& url)
     77{
     78    if (!m_page)
     79        return;
     80
     81    m_page->process()->send(Messages::WebPage::LoadURLInFrame(url, m_frameID), m_page->pageID());
     82}
     83
    7684void WebFrameProxy::stopLoading() const
    7785{
  • trunk/Source/WebKit2/UIProcess/WebFrameProxy.h

    r159647 r159876  
    7272    FrameLoadState& frameLoadState() { return m_frameLoadState; }
    7373
     74    void loadURL(const String&);
    7475    void stopLoading() const;
    7576
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r159874 r159876  
    454454                37C4C0951814B9E6003688B9 /* WKBackForwardListInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C08E1814AF3A003688B9 /* WKBackForwardListInternal.h */; };
    455455                37C4E9F6131C6E7E0029BD5A /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = B396EA5512E0ED2D00F4FEB7 /* config.h */; };
     456                37D0B5C61845218400F6CE7D /* WKErrorRecoveryAttempting.h in Headers */ = {isa = PBXBuildFile; fileRef = 37D0B5C51845218400F6CE7D /* WKErrorRecoveryAttempting.h */; settings = {ATTRIBUTES = (Public, ); }; };
     457                37D0B5C81845232700F6CE7D /* WKErrorRecoveryAttempting.m in Sources */ = {isa = PBXBuildFile; fileRef = 37D0B5C71845232700F6CE7D /* WKErrorRecoveryAttempting.m */; };
    456458                37DFA7001810BB92001F4A9F /* WKFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 37DFA6FF1810BB92001F4A9F /* WKFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
    457459                37F623B812A57B6200E3FDF6 /* WKFindOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 37F623B712A57B6200E3FDF6 /* WKFindOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    19781980                37C4C0911814B3AF003688B9 /* WKNSArray.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSArray.mm; sourceTree = "<group>"; };
    19791981                37C4C0921814B3AF003688B9 /* WKNSArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSArray.h; sourceTree = "<group>"; };
     1982                37D0B5C51845218400F6CE7D /* WKErrorRecoveryAttempting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKErrorRecoveryAttempting.h; sourceTree = "<group>"; };
     1983                37D0B5C71845232700F6CE7D /* WKErrorRecoveryAttempting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WKErrorRecoveryAttempting.m; sourceTree = "<group>"; };
    19801984                37DFA6FF1810BB92001F4A9F /* WKFoundation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFoundation.h; sourceTree = "<group>"; };
    19811985                37F623B712A57B6200E3FDF6 /* WKFindOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFindOptions.h; sourceTree = "<group>"; };
     
    37593763                                BCA284D41492F2C7001F9042 /* WKConnection.mm */,
    37603764                                BC5C75C614954DA600BC4775 /* WKConnectionInternal.h */,
     3765                                37D0B5C51845218400F6CE7D /* WKErrorRecoveryAttempting.h */,
     3766                                37D0B5C71845232700F6CE7D /* WKErrorRecoveryAttempting.m */,
    37613767                                370F34A11829BE1E009027C8 /* WKNavigationData.h */,
    37623768                                370F34A01829BE1E009027C8 /* WKNavigationData.mm */,
     
    59285934                                D3B9484911FF4B6500032B39 /* WebSearchPopupMenu.h in Headers */,
    59295935                                F634445612A885C8000612D8 /* WebSecurityOrigin.h in Headers */,
     5936                                37D0B5C61845218400F6CE7D /* WKErrorRecoveryAttempting.h in Headers */,
    59305937                                BCC5715B115ADAEF001CCAF9 /* WebSystemInterface.h in Headers */,
    59315938                                1A594ABB112A1FB6009DE7C7 /* WebUIClient.h in Headers */,
     
    69266933                                E1EE53E711F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp in Sources */,
    69276934                                BC14E109120B905E00826C0C /* InjectedBundlePageFormClient.cpp in Sources */,
     6935                                37D0B5C81845232700F6CE7D /* WKErrorRecoveryAttempting.m in Sources */,
    69286936                                CD5C66A0134B9D38004FE2A8 /* InjectedBundlePageFullScreenClient.cpp in Sources */,
    69296937                                755422CB180650020046F6A8 /* WebOriginDataManager.cpp in Sources */,
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r159765 r159876  
    854854}
    855855
     856void WebPage::loadURLInFrame(const String& url, uint64_t frameID)
     857{
     858    WebFrame* frame = WebProcess::shared().webFrame(frameID);
     859    if (!frame)
     860        return;
     861
     862    frame->coreFrame()->loader().load(FrameLoadRequest(frame->coreFrame(), ResourceRequest(URL(URL(), url))));
     863}
     864
    856865void WebPage::loadURLRequest(const ResourceRequest& request, const SandboxExtension::Handle& sandboxExtensionHandle, CoreIPC::MessageDecoder& decoder)
    857866{
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r159724 r159876  
    739739    static bool logicalScroll(WebCore::Page*, WebCore::ScrollLogicalDirection, WebCore::ScrollGranularity);
    740740
     741    void loadURLInFrame(const String&, uint64_t frameID);
     742
    741743    uint64_t restoreSession(const SessionState&);
    742744    void restoreSessionAndNavigateToCurrentItem(const SessionState&);
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r159724 r159876  
    7373
    7474    LoadURL(WTF::String url, WebKit::SandboxExtension::Handle sandboxExtensionHandle, WebKit::WebContextUserMessageEncoder userData) Variadic
     75    LoadURLInFrame(WTF::String url, uint64_t frameID)
    7576    LoadURLRequest(WebCore::ResourceRequest request, WebKit::SandboxExtension::Handle sandboxExtensionHandle, WebKit::WebContextUserMessageEncoder userData) Variadic
    7677    LoadData(CoreIPC::DataReference data, WTF::String MIMEType, WTF::String encoding, WTF::String baseURL, WebKit::WebContextUserMessageEncoder userData) Variadic
Note: See TracChangeset for help on using the changeset viewer.