1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#import "config.h" 27#import "WebErrors.h" 28 29#import "APIError.h" 30#import "WKErrorRef.h" 31#import <WebCore/LocalizedStrings.h> 32#import <WebCore/ResourceRequest.h> 33#import <WebCore/ResourceResponse.h> 34 35using namespace WebCore; 36using namespace WebKit; 37 38namespace WebKit { 39 40static RetainPtr<NSError> createNSError(NSString* domain, int code, NSURL *URL) 41{ 42 NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: 43 URL, @"NSErrorFailingURLKey", 44 [URL absoluteString], @"NSErrorFailingURLStringKey", 45 nil]; 46 47 return adoptNS([[NSError alloc] initWithDomain:domain code:code userInfo:userInfo]); 48} 49 50// Use NSError's if available. 51 52ResourceError cancelledError(const ResourceRequest& request) 53{ 54 return ResourceError(createNSError(NSURLErrorDomain, NSURLErrorCancelled, request.url()).get()); 55} 56 57ResourceError fileDoesNotExistError(const ResourceResponse& response) 58{ 59 return ResourceError(createNSError(NSURLErrorDomain, NSURLErrorFileDoesNotExist, response.url()).get()); 60} 61 62 63// Otherwise, fallback to our own errors. 64 65ResourceError blockedError(const ResourceRequest& request) 66{ 67 return ResourceError(API::Error::webKitErrorDomain(), kWKErrorCodeCannotUseRestrictedPort, request.url(), WEB_UI_STRING("Not allowed to use restricted network port", "WebKitErrorCannotUseRestrictedPort description")); 68} 69 70ResourceError cannotShowURLError(const ResourceRequest& request) 71{ 72 return ResourceError(API::Error::webKitErrorDomain(), kWKErrorCodeCannotShowURL, request.url(), WEB_UI_STRING("The URL can’t be shown", "WebKitErrorCannotShowURL description")); 73} 74 75ResourceError interruptedForPolicyChangeError(const ResourceRequest& request) 76{ 77 return ResourceError(API::Error::webKitErrorDomain(), kWKErrorCodeFrameLoadInterruptedByPolicyChange, request.url(), WEB_UI_STRING("Frame load interrupted", "WebKitErrorFrameLoadInterruptedByPolicyChange description")); 78} 79 80ResourceError cannotShowMIMETypeError(const ResourceResponse& response) 81{ 82 return ResourceError(API::Error::webKitErrorDomain(), kWKErrorCodeCannotShowMIMEType, response.url(), WEB_UI_STRING("Content with specified MIME type can’t be shown", "WebKitErrorCannotShowMIMEType description")); 83} 84 85ResourceError pluginWillHandleLoadError(const ResourceResponse& response) 86{ 87 return ResourceError(API::Error::webKitErrorDomain(), kWKErrorCodePlugInWillHandleLoad, response.url(), WEB_UI_STRING("Plug-in handled load", "WebKitErrorPlugInWillHandleLoad description")); 88} 89 90ResourceError internalError(const URL& url) 91{ 92 return ResourceError(API::Error::webKitErrorDomain(), kWKErrorInternal, url, WEB_UI_STRING("WebKit encountered an internal error", "WebKitErrorInternal description")); 93} 94 95} // namespace WebKit 96