Title: [93931] trunk/Source/WebKit2
Revision
93931
Author
[email protected]
Date
2011-08-26 18:05:51 -0700 (Fri, 26 Aug 2011)

Log Message

Stop using custom NSErrors for WebKit2 WebErrors
https://bugs.webkit.org/show_bug.cgi?id=67075

Reviewed by Anders Carlsson.

* WebProcess/WebCoreSupport/WebErrors.h:
* WebProcess/WebCoreSupport/mac/WebErrorsMac.mm:
(WebKit::createNSError):
(WebKit::cancelledError):
(WebKit::fileDoesNotExistError):
(WebKit::blockedError):
(WebKit::cannotShowURLError):
(WebKit::interruptedForPolicyChangeError):
(WebKit::cannotShowMIMETypeError):
(WebKit::pluginWillHandleLoadError):
There is no reason to use custom registered NSErrors anymore, so don't.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (93930 => 93931)


--- trunk/Source/WebKit2/ChangeLog	2011-08-27 01:05:13 UTC (rev 93930)
+++ trunk/Source/WebKit2/ChangeLog	2011-08-27 01:05:51 UTC (rev 93931)
@@ -1,3 +1,22 @@
+2011-08-26  Sam Weinig  <[email protected]>
+
+        Stop using custom NSErrors for WebKit2 WebErrors
+        https://bugs.webkit.org/show_bug.cgi?id=67075
+
+        Reviewed by Anders Carlsson.
+
+        * WebProcess/WebCoreSupport/WebErrors.h:
+        * WebProcess/WebCoreSupport/mac/WebErrorsMac.mm:
+        (WebKit::createNSError):
+        (WebKit::cancelledError):
+        (WebKit::fileDoesNotExistError):
+        (WebKit::blockedError):
+        (WebKit::cannotShowURLError):
+        (WebKit::interruptedForPolicyChangeError):
+        (WebKit::cannotShowMIMETypeError):
+        (WebKit::pluginWillHandleLoadError):
+        There is no reason to use custom registered NSErrors anymore, so don't.
+
 2011-08-26  Anders Carlsson  <[email protected]>
 
         Fix build.

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebErrors.h (93930 => 93931)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebErrors.h	2011-08-27 01:05:13 UTC (rev 93930)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebErrors.h	2011-08-27 01:05:51 UTC (rev 93931)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,9 +26,11 @@
 #ifndef WebErrors_h
 #define WebErrors_h
 
-#include <WebCore/ResourceError.h>
-#include <WebCore/ResourceRequest.h>
-#include <WebCore/ResourceResponse.h>
+namespace WebCore {
+    class ResourceError;
+    class ResourceRequest;
+    class ResourceResponse;
+}
 
 namespace WebKit {
 

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebErrorsMac.mm (93930 => 93931)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebErrorsMac.mm	2011-08-27 01:05:13 UTC (rev 93930)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebErrorsMac.mm	2011-08-27 01:05:51 UTC (rev 93931)
@@ -26,148 +26,65 @@
 #import "config.h"
 #import "WebErrors.h"
 
-#import "WKError.h"
 #import "WebError.h"
+#import "WKError.h"
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/ResourceRequest.h>
 #import <WebCore/ResourceResponse.h>
-#import <pthread.h>
 
 using namespace WebCore;
 using namespace WebKit;
 
-// FIXME: We probably don't need to use NSErrors here.
+namespace WebKit {
 
-static NSString * const WebKitErrorMIMETypeKey =               @"WebKitErrorMIMETypeKey";
-static NSString * const WebKitErrorPlugInNameKey =             @"WebKitErrorPlugInNameKey";
-static NSString * const WebKitErrorPlugInPageURLStringKey =    @"WebKitErrorPlugInPageURLStringKey";
-
-// Policy errors
-#define WebKitErrorDescriptionCannotShowMIMEType WEB_UI_STRING("Content with specified MIME type can’t be shown", "WebKitErrorCannotShowMIMEType description")
-#define WebKitErrorDescriptionCannotShowURL WEB_UI_STRING("The URL can’t be shown", "WebKitErrorCannotShowURL description")
-#define WebKitErrorDescriptionFrameLoadInterruptedByPolicyChange WEB_UI_STRING("Frame load interrupted", "WebKitErrorFrameLoadInterruptedByPolicyChange description")
-#define WebKitErrorDescriptionCannotUseRestrictedPort WEB_UI_STRING("Not allowed to use restricted network port", "WebKitErrorCannotUseRestrictedPort description")
-
-// Plug-in and java errors
-#define WebKitErrorDescriptionCannotFindPlugin WEB_UI_STRING("The plug-in can’t be found", "WebKitErrorCannotFindPlugin description")
-#define WebKitErrorDescriptionCannotLoadPlugin WEB_UI_STRING("The plug-in can’t be loaded", "WebKitErrorCannotLoadPlugin description")
-#define WebKitErrorDescriptionJavaUnavailable WEB_UI_STRING("Java is unavailable", "WebKitErrorJavaUnavailable description")
-#define WebKitErrorDescriptionPlugInCancelledConnection WEB_UI_STRING("Plug-in cancelled", "WebKitErrorPlugInCancelledConnection description")
-#define WebKitErrorDescriptionPlugInWillHandleLoad WEB_UI_STRING("Plug-in handled load", "WebKitErrorPlugInWillHandleLoad description")
-
-static pthread_once_t registerErrorsControl = PTHREAD_ONCE_INIT;
-static void registerErrors(void);
-
-@interface NSError (WebKitExtras)
-+ (NSError *)_webKitErrorWithDomain:(NSString *)domain code:(int)code URL:(NSURL *)URL;
-@end
-
-@implementation NSError (WebKitExtras)
-
-static NSMutableDictionary *descriptions = nil;
-
-+ (void)_registerWebKitErrors
+static RetainPtr<NSError> createNSError(NSString* domain, int code, NSURL *URL)
 {
-    pthread_once(&registerErrorsControl, registerErrors);
-}
-
-+(id)_webkit_errorWithDomain:(NSString *)domain code:(int)code URL:(NSURL *)URL
-{
-    NSDictionary *descriptionsDict;
-    NSString *localizedDesc;
-    NSDictionary *dict;
-    // insert a localized string here for those folks not savvy to our category methods
-    descriptionsDict = [descriptions objectForKey:domain];
-    localizedDesc = descriptionsDict ? [descriptionsDict objectForKey:[NSNumber numberWithInt:code]] : nil;
-    dict = [NSDictionary dictionaryWithObjectsAndKeys:
+    NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
         URL, @"NSErrorFailingURLKey",
         [URL absoluteString], @"NSErrorFailingURLStringKey",
-        localizedDesc, NSLocalizedDescriptionKey,
         nil];
 
-    return [[[self alloc] initWithDomain:domain code:code userInfo:dict] autorelease];
+    return RetainPtr<NSError>(AdoptNS, [[NSError alloc] initWithDomain:domain code:code userInfo:userInfo]);
 }
 
-+ (NSError *)_webKitErrorWithDomain:(NSString *)domain code:(int)code URL:(NSURL *)URL
-{
-    [self _registerWebKitErrors];
-    return [self _webkit_errorWithDomain:domain code:code URL:URL];
-}
+// Use NSError's if available.
 
-+ (NSError *)_webKitErrorWithCode:(int)code failingURL:(NSString *)URLString
+ResourceError cancelledError(const ResourceRequest& request)
 {
-    return [self _webKitErrorWithDomain:WebError::webKitErrorDomain() code:code URL:[NSURL URLWithString:URLString]];
+    return ResourceError(createNSError(NSURLErrorDomain, NSURLErrorCancelled, request.url()).get());
 }
 
-+ (void)_webkit_addErrorsWithCodesAndDescriptions:(NSDictionary *)dictionary inDomain:(NSString *)domain
+ResourceError fileDoesNotExistError(const ResourceResponse& response)
 {
-    if (!descriptions)
-        descriptions = [[NSMutableDictionary alloc] init];
-
-    [descriptions setObject:dictionary forKey:domain];
+    return ResourceError(createNSError(NSURLErrorDomain, NSURLErrorFileDoesNotExist, response.url()).get());
 }
 
-static void registerErrors()
-{
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
-    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
-        // Policy errors
-        (NSString *)WebKitErrorDescriptionCannotShowMIMEType,                   [NSNumber numberWithInt: kWKErrorCodeCannotShowMIMEType],
-        (NSString *)WebKitErrorDescriptionCannotShowURL,                        [NSNumber numberWithInt: kWKErrorCodeCannotShowURL],
-        (NSString *)WebKitErrorDescriptionFrameLoadInterruptedByPolicyChange,   [NSNumber numberWithInt: kWKErrorCodeFrameLoadInterruptedByPolicyChange],
-        (NSString *)WebKitErrorDescriptionCannotUseRestrictedPort,              [NSNumber numberWithInt: kWKErrorCodeCannotUseRestrictedPort],
-        
-        // Plug-in and java errors
-        (NSString *)WebKitErrorDescriptionCannotFindPlugin,                     [NSNumber numberWithInt: kWKErrorCodeCannotFindPlugIn],
-        (NSString *)WebKitErrorDescriptionCannotLoadPlugin,                     [NSNumber numberWithInt: kWKErrorCodeCannotLoadPlugIn],
-        (NSString *)WebKitErrorDescriptionJavaUnavailable,                      [NSNumber numberWithInt: kWKErrorCodeJavaUnavailable],
-        (NSString *)WebKitErrorDescriptionPlugInCancelledConnection,            [NSNumber numberWithInt: kWKErrorCodePlugInCancelledConnection],
-        (NSString *)WebKitErrorDescriptionPlugInWillHandleLoad,                 [NSNumber numberWithInt: kWKErrorCodePlugInWillHandleLoad],
-        nil];
+// Otherwise, fallback to our own errors.
 
-    [NSError _webkit_addErrorsWithCodesAndDescriptions:dict inDomain:WebError::webKitErrorDomain()];
-
-    [pool drain];
-}
-
-@end
-
-namespace WebKit {
-
-ResourceError cancelledError(const ResourceRequest& request)
-{
-    return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled URL:request.url()];
-}
-
 ResourceError blockedError(const ResourceRequest& request)
 {
-    return [NSError _webKitErrorWithDomain:WebError::webKitErrorDomain() code:kWKErrorCodeCannotUseRestrictedPort URL:request.url()];
+    return ResourceError(WebError::webKitErrorDomain(), kWKErrorCodeCannotUseRestrictedPort, request.url(), WEB_UI_STRING("Not allowed to use restricted network port", "WebKitErrorCannotUseRestrictedPort description"));
 }
 
 ResourceError cannotShowURLError(const ResourceRequest& request)
 {
-    return [NSError _webKitErrorWithDomain:WebError::webKitErrorDomain() code:kWKErrorCodeCannotShowURL URL:request.url()];
+    return ResourceError(WebError::webKitErrorDomain(), kWKErrorCodeCannotShowURL, request.url(), WEB_UI_STRING("The URL can’t be shown", "WebKitErrorCannotShowURL description"));
 }
 
 ResourceError interruptedForPolicyChangeError(const ResourceRequest& request)
 {
-    return [NSError _webKitErrorWithDomain:WebError::webKitErrorDomain() code:kWKErrorCodeFrameLoadInterruptedByPolicyChange URL:request.url()];
+    return ResourceError(WebError::webKitErrorDomain(), kWKErrorCodeFrameLoadInterruptedByPolicyChange, request.url(), WEB_UI_STRING("Frame load interrupted", "WebKitErrorFrameLoadInterruptedByPolicyChange description"));
 }
 
 ResourceError cannotShowMIMETypeError(const ResourceResponse& response)
 {
-    return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:kWKErrorCodeCannotShowMIMEType URL:response.url()];
+    return ResourceError(WebError::webKitErrorDomain(), kWKErrorCodeCannotShowMIMEType, response.url(), WEB_UI_STRING("Content with specified MIME type can’t be shown", "WebKitErrorCannotShowMIMEType description"));
 }
 
-ResourceError fileDoesNotExistError(const ResourceResponse& response)
-{
-    return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist URL:response.url()];    
-}
-
 ResourceError pluginWillHandleLoadError(const ResourceResponse& response)
 {
-    return [NSError _webKitErrorWithDomain:WebError::webKitErrorDomain() code:kWKErrorCodePlugInWillHandleLoad URL:response.url()];
+    return ResourceError(WebError::webKitErrorDomain(), kWKErrorCodePlugInWillHandleLoad, response.url(), WEB_UI_STRING("Plug-in handled load", "WebKitErrorPlugInWillHandleLoad description"));
 }
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to