2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #import "ResourceError.h"
29 #import "BlockExceptions.h"
31 #import <Foundation/Foundation.h>
33 @interface NSError (WebExtras)
34 - (NSString *)_web_localizedDescription;
39 void ResourceError::platformLazyInit()
44 m_domain = [m_platformError.get() domain];
45 m_errorCode = [m_platformError.get() code];
47 NSString* failingURLString = [[m_platformError.get() userInfo] valueForKey:@"NSErrorFailingURLStringKey"];
48 if (!failingURLString)
49 failingURLString = [[[m_platformError.get() userInfo] valueForKey:@"NSErrorFailingURLKey"] absoluteString];
50 m_failingURL = failingURLString;
51 // Workaround for <rdar://problem/6554067>
52 m_localizedDescription = m_failingURL;
53 BEGIN_BLOCK_OBJC_EXCEPTIONS;
54 m_localizedDescription = [m_platformError.get() _web_localizedDescription];
55 END_BLOCK_OBJC_EXCEPTIONS;
57 m_dataIsUpToDate = true;
60 bool ResourceError::platformCompare(const ResourceError& a, const ResourceError& b)
62 return (NSError*)a == (NSError*)b;
65 ResourceError::operator NSError*() const
68 ASSERT(!m_platformError);
72 if (!m_platformError) {
73 RetainPtr<NSMutableDictionary> userInfo(AdoptNS, [[NSMutableDictionary alloc] init]);
75 if (!m_localizedDescription.isEmpty())
76 [userInfo.get() setValue:m_localizedDescription forKey:NSLocalizedDescriptionKey];
78 if (!m_failingURL.isEmpty()) {
79 NSURL *cocoaURL = KURL(ParsedURLString, m_failingURL);
80 [userInfo.get() setValue:m_failingURL forKey:@"NSErrorFailingURLStringKey"];
81 [userInfo.get() setValue:cocoaURL forKey:@"NSErrorFailingURLKey"];
84 m_platformError.adoptNS([[NSError alloc] initWithDomain:m_domain code:m_errorCode userInfo:userInfo.get()]);
87 return m_platformError.get();
90 } // namespace WebCore