diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
commit | 1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch) | |
tree | 4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /WebKit/mac/Misc | |
parent | 9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff) | |
download | external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'WebKit/mac/Misc')
36 files changed, 651 insertions, 1024 deletions
diff --git a/WebKit/mac/Misc/EmptyProtocolDefinitions.h b/WebKit/mac/Misc/EmptyProtocolDefinitions.h new file mode 100644 index 0000000..c52d8ce --- /dev/null +++ b/WebKit/mac/Misc/EmptyProtocolDefinitions.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__OBJC__) + +#if defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD) +#define DELEGATES_DECLARED_AS_FORMAL_PROTOCOLS 0 +#else +#define DELEGATES_DECLARED_AS_FORMAL_PROTOCOLS 1 +#endif + +#if !DELEGATES_DECLARED_AS_FORMAL_PROTOCOLS + +#define EMPTY_PROTOCOL(NAME) \ +@protocol NAME <NSObject> \ +@end + +EMPTY_PROTOCOL(NSTableViewDataSource) +EMPTY_PROTOCOL(NSTableViewDelegate) +EMPTY_PROTOCOL(NSWindowDelegate) + +#undef EMPTY_PROTOCOL + +#endif /* !DELEGATES_DECLARED_AS_FORMAL_PROTOCOLS */ + +#endif /* defined(__OBJC__) */ diff --git a/WebKit/mac/Misc/WebCache.mm b/WebKit/mac/Misc/WebCache.mm index 1c1850b..d3dfbdb 100644 --- a/WebKit/mac/Misc/WebCache.mm +++ b/WebKit/mac/Misc/WebCache.mm @@ -28,6 +28,7 @@ #import "WebPreferences.h" #import "WebView.h" #import "WebViewInternal.h" +#import <WebCore/ApplicationCacheStorage.h> #import <WebCore/Cache.h> @implementation WebCache @@ -40,25 +41,41 @@ [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:s.images.count], @"Images", [NSNumber numberWithInt:s.cssStyleSheets.count], @"CSS", +#if ENABLE(XSLT) [NSNumber numberWithInt:s.xslStyleSheets.count], @"XSL", +#else + [NSNumber numberWithInt:0], @"XSL", +#endif [NSNumber numberWithInt:s.scripts.count], @"JavaScript", nil], [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:s.images.size], @"Images", [NSNumber numberWithInt:s.cssStyleSheets.size] ,@"CSS", +#if ENABLE(XSLT) [NSNumber numberWithInt:s.xslStyleSheets.size], @"XSL", +#else + [NSNumber numberWithInt:0], @"XSL", +#endif [NSNumber numberWithInt:s.scripts.size], @"JavaScript", nil], [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:s.images.liveSize], @"Images", [NSNumber numberWithInt:s.cssStyleSheets.liveSize] ,@"CSS", +#if ENABLE(XSLT) [NSNumber numberWithInt:s.xslStyleSheets.liveSize], @"XSL", +#else + [NSNumber numberWithInt:0], @"XSL", +#endif [NSNumber numberWithInt:s.scripts.liveSize], @"JavaScript", nil], [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:s.images.decodedSize], @"Images", [NSNumber numberWithInt:s.cssStyleSheets.decodedSize] ,@"CSS", +#if ENABLE(XSLT) [NSNumber numberWithInt:s.xslStyleSheets.decodedSize], @"XSL", +#else + [NSNumber numberWithInt:0], @"XSL", +#endif [NSNumber numberWithInt:s.scripts.decodedSize], @"JavaScript", nil], nil]; @@ -70,6 +87,9 @@ WebCacheModel cacheModel = [WebView _cacheModel]; [WebView _setCacheModel:WebCacheModelDocumentViewer]; [WebView _setCacheModel:cacheModel]; + + // Empty the application cache. + WebCore::cacheStorage().empty(); } + (void)setDisabled:(BOOL)disabled diff --git a/WebKit/mac/Misc/WebCoreStatistics.h b/WebKit/mac/Misc/WebCoreStatistics.h index 7585ec0..392f31b 100644 --- a/WebKit/mac/Misc/WebCoreStatistics.h +++ b/WebKit/mac/Misc/WebCoreStatistics.h @@ -50,6 +50,11 @@ + (size_t)iconRecordCount; + (size_t)iconsWithDataCount; ++ (size_t)cachedFontDataCount; ++ (size_t)cachedFontDataInactiveCount; ++ (void)purgeInactiveFontData; ++ (size_t)glyphPageCount; + + (BOOL)shouldPrintExceptions; + (void)setShouldPrintExceptions:(BOOL)print; diff --git a/WebKit/mac/Misc/WebCoreStatistics.mm b/WebKit/mac/Misc/WebCoreStatistics.mm index 1dc553f..ecbfe9d 100644 --- a/WebKit/mac/Misc/WebCoreStatistics.mm +++ b/WebKit/mac/Misc/WebCoreStatistics.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,15 +29,19 @@ #import "WebCoreStatistics.h" #import "WebCache.h" -#import <JavaScriptCore/collector.h> -#import <JavaScriptCore/interpreter.h> +#import "WebFrameInternal.h" +#import <runtime/JSLock.h> +#import <WebCore/Console.h> +#import <WebCore/FontCache.h> +#import <WebCore/Frame.h> #import <WebCore/GCController.h> +#import <WebCore/GlyphPageTreeNode.h> #import <WebCore/IconDatabase.h> -#import <WebCore/Node.h> -#import <WebKit/WebFrameBridge.h> -#import <WebKit/WebFrameInternal.h> +#import <WebCore/JSDOMWindow.h> +#import <WebCore/RenderTreeAsText.h> +#import <WebCore/RenderView.h> -using namespace KJS; +using namespace JSC; using namespace WebCore; @implementation WebCoreStatistics @@ -49,35 +53,35 @@ using namespace WebCore; + (size_t)javaScriptObjectsCount { - JSLock lock; - return Collector::size(); + JSLock lock(false); + return JSDOMWindow::commonJSGlobalData()->heap.size(); } + (size_t)javaScriptGlobalObjectsCount { - JSLock lock; - return Collector::globalObjectCount(); + JSLock lock(false); + return JSDOMWindow::commonJSGlobalData()->heap.globalObjectCount(); } + (size_t)javaScriptProtectedObjectsCount { - JSLock lock; - return Collector::protectedObjectCount(); + JSLock lock(false); + return JSDOMWindow::commonJSGlobalData()->heap.protectedObjectCount(); } + (size_t)javaScriptProtectedGlobalObjectsCount { - JSLock lock; - return Collector::protectedGlobalObjectCount(); + JSLock lock(false); + return JSDOMWindow::commonJSGlobalData()->heap.protectedGlobalObjectCount(); } + (NSCountedSet *)javaScriptProtectedObjectTypeCounts { - JSLock lock; + JSLock lock(false); NSCountedSet *result = [NSCountedSet set]; - OwnPtr<HashCountedSet<const char*> > counts(Collector::protectedObjectTypeCounts()); + OwnPtr<HashCountedSet<const char*> > counts(JSDOMWindow::commonJSGlobalData()->heap.protectedObjectTypeCounts()); HashCountedSet<const char*>::iterator end = counts->end(); for (HashCountedSet<const char*>::iterator it = counts->begin(); it != end; ++it) for (unsigned i = 0; i < it->second; ++i) @@ -116,16 +120,36 @@ using namespace WebCore; return iconDatabase()->iconRecordCountWithData(); } ++ (size_t)cachedFontDataCount +{ + return FontCache::fontDataCount(); +} + ++ (size_t)cachedFontDataInactiveCount +{ + return FontCache::inactiveFontDataCount(); +} + ++ (void)purgeInactiveFontData +{ + FontCache::purgeInactiveFontData(); +} + ++ (size_t)glyphPageCount +{ + return GlyphPageTreeNode::treeGlyphPageCount(); +} + + (BOOL)shouldPrintExceptions { - JSLock lock; - return Interpreter::shouldPrintExceptions(); + JSLock lock(false); + return Console::shouldPrintExceptions(); } + (void)setShouldPrintExceptions:(BOOL)print { - JSLock lock; - Interpreter::setShouldPrintExceptions(print); + JSLock lock(false); + Console::setShouldPrintExceptions(print); } + (void)emptyCache @@ -156,8 +180,8 @@ using namespace WebCore; + (size_t)javaScriptReferencedObjectsCount { - JSLock lock; - return Collector::protectedObjectCount(); + JSLock lock(false); + return JSDOMWindow::commonJSGlobalData()->heap.protectedObjectCount(); } + (NSSet *)javaScriptRootObjectClasses @@ -181,7 +205,7 @@ using namespace WebCore; - (NSString *)renderTreeAsExternalRepresentation { - return [[self _bridge] renderTreeAsExternalRepresentation]; + return externalRepresentation(_private->coreFrame->contentRenderer()); } @end diff --git a/WebKit/mac/Misc/WebDownload.m b/WebKit/mac/Misc/WebDownload.m index 50a5777..2c53c1b 100644 --- a/WebKit/mac/Misc/WebDownload.m +++ b/WebKit/mac/Misc/WebDownload.m @@ -30,8 +30,8 @@ #import <Foundation/NSURLAuthenticationChallenge.h> #import <Foundation/NSURLDownload.h> -#import <JavaScriptCore/Assertions.h> #import <WebKit/WebPanelAuthenticationHandler.h> +#import <wtf/Assertions.h> #import "WebTypesInternal.h" @@ -96,6 +96,9 @@ - (void)downloadDidBegin:(NSURLDownload *)download { +#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) + [[NSProcessInfo processInfo] disableSuddenTermination]; +#endif [realDelegate downloadDidBegin:download]; } @@ -154,11 +157,17 @@ - (void)downloadDidFinish:(NSURLDownload *)download { +#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) + [[NSProcessInfo processInfo] enableSuddenTermination]; +#endif [realDelegate downloadDidFinish:download]; } - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error { +#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) + [[NSProcessInfo processInfo] enableSuddenTermination]; +#endif [realDelegate download:download didFailWithError:error]; } diff --git a/WebKit/mac/Misc/WebElementDictionary.mm b/WebKit/mac/Misc/WebElementDictionary.mm index 25b0b99..b987525 100644 --- a/WebKit/mac/Misc/WebElementDictionary.mm +++ b/WebKit/mac/Misc/WebElementDictionary.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,19 +30,17 @@ #import "WebDOMOperations.h" #import "WebFrame.h" -#import "WebFrameBridge.h" #import "WebFrameInternal.h" #import "WebKitLogging.h" +#import "WebTypesInternal.h" #import "WebView.h" #import "WebViewPrivate.h" - -#import <WebKit/DOMCore.h> -#import <WebKit/DOMExtensions.h> #import <WebCore/Frame.h> #import <WebCore/HitTestResult.h> #import <WebCore/Image.h> -#import <WebCore/KURL.h> #import <WebCore/WebCoreObjCExtras.h> +#import <WebKit/DOMCore.h> +#import <WebKit/DOMExtensions.h> using namespace WebCore; @@ -102,6 +100,9 @@ static void cacheValueForKey(const void *key, const void *value, void *self) - (void)dealloc { + if (WebCoreObjCScheduleDeallocateOnMainThread([WebElementDictionary class], self)) + return; + delete _result; [_cache release]; [_nilValues release]; @@ -121,7 +122,7 @@ static void cacheValueForKey(const void *key, const void *value, void *self) _cacheComplete = YES; } -- (unsigned)count +- (NSUInteger)count { if (!_cacheComplete) [self _fillCache]; @@ -205,7 +206,7 @@ static NSString* NSStringOrNil(String coreString) - (NSURL *)_absoluteImageURL { - return _result->absoluteImageURL().getNSURL(); + return _result->absoluteImageURL(); } - (NSNumber *)_isSelected @@ -220,7 +221,7 @@ static NSString* NSStringOrNil(String coreString) - (NSURL *)_absoluteLinkURL { - return _result->absoluteLinkURL().getNSURL(); + return _result->absoluteLinkURL(); } - (WebFrame *)_targetWebFrame diff --git a/WebKit/mac/Misc/WebGraphicsExtras.c b/WebKit/mac/Misc/WebGraphicsExtras.c index 0832c6c..4d36b58 100644 --- a/WebKit/mac/Misc/WebGraphicsExtras.c +++ b/WebKit/mac/Misc/WebGraphicsExtras.c @@ -29,8 +29,8 @@ #import "WebGraphicsExtras.h" #import <Accelerate/Accelerate.h> -#import <JavaScriptCore/Assertions.h> #import <dlfcn.h> +#import <wtf/Assertions.h> unsigned WebConvertBGRAToARGB(unsigned char *offscreenBuffer, int rowBytes, int x, int y, int width, int height) { diff --git a/WebKit/mac/Misc/WebIconDatabase.mm b/WebKit/mac/Misc/WebIconDatabase.mm index 39dbcac..d911f0c 100644 --- a/WebKit/mac/Misc/WebIconDatabase.mm +++ b/WebKit/mac/Misc/WebIconDatabase.mm @@ -32,6 +32,7 @@ #import "WebIconDatabaseDelegate.h" #import "WebKitLogging.h" #import "WebKitNSStringExtras.h" +#import "WebNSFileManagerExtras.h" #import "WebNSNotificationCenterExtras.h" #import "WebNSURLExtras.h" #import "WebPreferences.h" @@ -624,8 +625,8 @@ bool importToWebCoreFormat() // After we're done importing old style icons over to webcore icons, we delete the entire directory hierarchy // for the old icon DB (skipping the new iconDB if it is in the same directory) NSFileManager *fileManager = [NSFileManager defaultManager]; - enumerator = [[fileManager directoryContentsAtPath:databaseDirectory] objectEnumerator]; - + enumerator = [[fileManager contentsOfDirectoryAtPath:databaseDirectory error:NULL] objectEnumerator]; + NSString *databaseFilename = iconDatabase()->defaultDatabaseFilename(); BOOL foundIconDB = NO; @@ -636,7 +637,7 @@ bool importToWebCoreFormat() continue; } NSString *filePath = [databaseDirectory stringByAppendingPathComponent:file]; - if (![fileManager removeFileAtPath:filePath handler:nil]) + if (![fileManager removeItemAtPath:filePath error:NULL]) LOG_ERROR("Failed to delete %@ from old icon directory", filePath); } diff --git a/WebKit/mac/Misc/WebIconFetcher.h b/WebKit/mac/Misc/WebIconFetcher.h new file mode 100644 index 0000000..d27ad94 --- /dev/null +++ b/WebKit/mac/Misc/WebIconFetcher.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <Cocoa/Cocoa.h> + +@class WebIconFetcherPrivate; + +@interface WebIconFetcher : NSObject { + WebIconFetcherPrivate *_private; +} + +- (void)cancel; + +@end diff --git a/WebKit/mac/Misc/WebIconFetcher.mm b/WebKit/mac/Misc/WebIconFetcher.mm new file mode 100644 index 0000000..bec7c12 --- /dev/null +++ b/WebKit/mac/Misc/WebIconFetcher.mm @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "WebIconFetcher.h" + +#import "WebFrameInternal.h" +#import "WebIconFetcherInternal.h" + +#import <WebCore/Frame.h> +#import <WebCore/IconFetcher.h> +#import <WebCore/SharedBuffer.h> +#import <wtf/PassRefPtr.h> + +using namespace WebCore; + +class WebIconFetcherClient : public IconFetcherClient { +public: + WebIconFetcherClient(id target, SEL selector) + : m_target(target) + , m_selector(selector) + { + } + + virtual void finishedFetchingIcon(PassRefPtr<SharedBuffer> iconData) + { + RetainPtr<NSData> data; + if (iconData) + data = iconData->createNSData(); + + [m_target performSelector:m_selector withObject:m_fetcher.get() withObject:data.get()]; + + delete this; + } + + void setFetcher(WebIconFetcher *fetcher) { m_fetcher = fetcher; } + +private: + RetainPtr<WebIconFetcher> m_fetcher; + id m_target; + SEL m_selector; +}; + +@implementation WebIconFetcher + +- (id)init +{ + return nil; +} + +- (void)dealloc +{ + reinterpret_cast<IconFetcher*>(_private)->deref(); + + [super dealloc]; +} + +- (void)finalize +{ + reinterpret_cast<IconFetcher*>(_private)->deref(); + + [super finalize]; +} + +- (void)cancel +{ + reinterpret_cast<IconFetcher*>(_private)->cancel(); +} + +@end + +@implementation WebIconFetcher (WebInternal) + +- (id)_initWithIconFetcher:(PassRefPtr<IconFetcher>)iconFetcher client:(WebIconFetcherClient *)client +{ + ASSERT(iconFetcher); + + self = [super init]; + if (!self) + return nil; + + client->setFetcher(self); + _private = reinterpret_cast<WebIconFetcherPrivate*>(iconFetcher.releaseRef()); + + return self; +} + ++ (WebIconFetcher *)_fetchApplicationIconForFrame:(WebFrame *)webFrame + target:(id)target + selector:(SEL)selector +{ + Frame* frame = core(webFrame); + + WebIconFetcherClient* client = new WebIconFetcherClient(target, selector); + + RefPtr<IconFetcher> fetcher = IconFetcher::create(frame, client); + + if (!fetcher) + return nil; + + return [[[WebIconFetcher alloc] _initWithIconFetcher:fetcher.release() client:client] autorelease]; +} + +@end + diff --git a/WebKit/mac/Misc/WebIconFetcherInternal.h b/WebKit/mac/Misc/WebIconFetcherInternal.h new file mode 100644 index 0000000..5951ef9 --- /dev/null +++ b/WebKit/mac/Misc/WebIconFetcherInternal.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import <WebKit/WebIconFetcher.h> +#import <wtf/Forward.h> + +namespace WebCore { + class IconFetcher; +} + +@class WebFrame; + +@interface WebIconFetcher (WebInternal) + ++ (WebIconFetcher *)_fetchApplicationIconForFrame:(WebFrame *)webFrame + target:(id)target + selector:(SEL)selector; + +@end + diff --git a/WebKit/mac/Misc/WebKitErrors.m b/WebKit/mac/Misc/WebKitErrors.m index 59561f3..fc739ba 100644 --- a/WebKit/mac/Misc/WebKitErrors.m +++ b/WebKit/mac/Misc/WebKitErrors.m @@ -108,7 +108,11 @@ static NSMutableDictionary *descriptions = nil; NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init]; if (contentURL) { [userInfo setObject:contentURL forKey:@"NSErrorFailingURLKey"]; +#if defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD) [userInfo setObject:[contentURL _web_userVisibleString] forKey:NSErrorFailingURLStringKey]; +#else + [userInfo setObject:[contentURL _web_userVisibleString] forKey:NSURLErrorFailingURLStringErrorKey]; +#endif } if (pluginPageURL) { [userInfo setObject:[pluginPageURL _web_userVisibleString] forKey:WebKitErrorPlugInPageURLStringKey]; diff --git a/WebKit/mac/Misc/WebKitLogging.h b/WebKit/mac/Misc/WebKitLogging.h index 0bf791c..dc37dbf 100644 --- a/WebKit/mac/Misc/WebKitLogging.h +++ b/WebKit/mac/Misc/WebKitLogging.h @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import <JavaScriptCore/Assertions.h> +#import <wtf/Assertions.h> #ifndef LOG_CHANNEL_PREFIX #define LOG_CHANNEL_PREFIX WebKitLog diff --git a/WebKit/mac/Misc/WebKitNSStringExtras.h b/WebKit/mac/Misc/WebKitNSStringExtras.h index d7fe47c..47056c6 100644 --- a/WebKit/mac/Misc/WebKitNSStringExtras.h +++ b/WebKit/mac/Misc/WebKitNSStringExtras.h @@ -54,4 +54,6 @@ - (NSString *)_webkit_stringByCollapsingWhitespaceCharacters; - (NSString *)_webkit_fixedCarbonPOSIXPath; ++ (NSString *)_webkit_localCacheDirectoryWithBundleIdentifier:(NSString*)bundleIdentifier; + @end diff --git a/WebKit/mac/Misc/WebKitNSStringExtras.m b/WebKit/mac/Misc/WebKitNSStringExtras.m index 940e63c..157069a 100644 --- a/WebKit/mac/Misc/WebKitNSStringExtras.m +++ b/WebKit/mac/Misc/WebKitNSStringExtras.m @@ -35,6 +35,7 @@ #import <WebCore/WebCoreTextRenderer.h> #import <unicode/uchar.h> +#import <sys/param.h> @implementation NSString (WebKitExtras) @@ -322,22 +323,38 @@ static BOOL canUseFastRenderer(const UniChar *buffer, unsigned length) if ([[fileManager _webkit_startupVolumeName] isEqualToString:volumeName]) { // Startup volume name is included in path, remove it. [pathComponents removeObjectAtIndex:1]; - } else if ([[fileManager directoryContentsAtPath:@"/Volumes"] containsObject:volumeName]) { + } else if ([[fileManager contentsOfDirectoryAtPath:@"/Volumes" error:NULL] containsObject:volumeName]) { // Path starts with other volume name, prepend "/Volumes". [pathComponents insertObject:@"Volumes" atIndex:1]; - } else { + } else // It's valid. return self; - } NSString *path = [NSString pathWithComponents:pathComponents]; - if (![fileManager fileExistsAtPath:path]) { + if (![fileManager fileExistsAtPath:path]) // File at canonicalized path doesn't exist, return original. return self; - } return path; } ++ (NSString *)_webkit_localCacheDirectoryWithBundleIdentifier:(NSString*)bundleIdentifier +{ + NSString* cacheDir = nil; + +#ifdef BUILDING_ON_TIGER + cacheDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"]; +#else + char cacheDirectory[MAXPATHLEN]; + size_t cacheDirectoryLen = confstr(_CS_DARWIN_USER_CACHE_DIR, cacheDirectory, MAXPATHLEN); + + if (cacheDirectoryLen) + cacheDir = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:cacheDirectory length:cacheDirectoryLen - 1]; +#endif + + return [cacheDir stringByAppendingPathComponent:bundleIdentifier]; +} + + @end diff --git a/WebKit/mac/Misc/WebKitStatistics.m b/WebKit/mac/Misc/WebKitStatistics.m index 9b4cd4f..3e40324 100644 --- a/WebKit/mac/Misc/WebKitStatistics.m +++ b/WebKit/mac/Misc/WebKitStatistics.m @@ -30,7 +30,6 @@ #import "WebKitStatisticsPrivate.h" -int WebBridgeCount; int WebViewCount; int WebDataSourceCount; int WebFrameCount; @@ -61,7 +60,8 @@ int WebFrameViewCount; + (int)bridgeCount { - return WebBridgeCount; + // No such thing as a bridge any more. Just return 0. + return 0; } + (int)HTMLRepresentationCount diff --git a/WebKit/mac/Misc/WebKitStatisticsPrivate.h b/WebKit/mac/Misc/WebKitStatisticsPrivate.h index ed8ce6a..e69bc51 100644 --- a/WebKit/mac/Misc/WebKitStatisticsPrivate.h +++ b/WebKit/mac/Misc/WebKitStatisticsPrivate.h @@ -26,7 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -extern int WebBridgeCount; extern int WebViewCount; extern int WebDataSourceCount; extern int WebFrameCount; diff --git a/WebKit/mac/Misc/WebKitSystemBits.h b/WebKit/mac/Misc/WebKitSystemBits.h index 99370e0..fe627ee 100644 --- a/WebKit/mac/Misc/WebKitSystemBits.h +++ b/WebKit/mac/Misc/WebKitSystemBits.h @@ -32,7 +32,7 @@ extern "C" { #endif -vm_size_t WebMemorySize(void); +uint64_t WebMemorySize(void); unsigned long long WebVolumeFreeSize(NSString *path); int WebNumberOfCPUs(void); diff --git a/WebKit/mac/Misc/WebKitSystemBits.m b/WebKit/mac/Misc/WebKitSystemBits.m index afa54f2..d64f2de 100644 --- a/WebKit/mac/Misc/WebKitSystemBits.m +++ b/WebKit/mac/Misc/WebKitSystemBits.m @@ -26,16 +26,15 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import <WebKit/WebKitSystemBits.h> +#import "WebKitSystemBits.h" -#import <JavaScriptCore/Assertions.h> - -#include <mach/mach.h> -#include <mach/host_info.h> -#include <mach/mach_error.h> - -#include <sys/types.h> -#include <sys/sysctl.h> +#import "WebNSFileManagerExtras.h" +#import <mach/host_info.h> +#import <mach/mach.h> +#import <mach/mach_error.h> +#import <sys/sysctl.h> +#import <sys/types.h> +#import <wtf/Assertions.h> static host_basic_info_data_t gHostBasicInfo; static pthread_once_t initControl = PTHREAD_ONCE_INIT; @@ -56,10 +55,10 @@ static void initCapabilities(void) } } -vm_size_t WebMemorySize(void) +uint64_t WebMemorySize(void) { pthread_once(&initControl, initCapabilities); - return gHostBasicInfo.memory_size; + return gHostBasicInfo.max_mem; } int WebNumberOfCPUs(void) @@ -80,6 +79,6 @@ int WebNumberOfCPUs(void) unsigned long long WebVolumeFreeSize(NSString *path) { - NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] fileSystemAttributesAtPath:path]; + NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error:NULL]; return [[fileSystemAttributesDictionary objectForKey:NSFileSystemFreeSize] unsignedLongLongValue]; } diff --git a/WebKit/mac/Misc/WebKitVersionChecks.h b/WebKit/mac/Misc/WebKitVersionChecks.h index 793dc73..33dc38b 100644 --- a/WebKit/mac/Misc/WebKitVersionChecks.h +++ b/WebKit/mac/Misc/WebKitVersionChecks.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008 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,13 +26,15 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* Version numbers are based on the 'current library version' specified in the WebKit build rules. - All of these methods return or take version numbers with each part shifted to the left 2 bytes. - For example the version 1.2.3 is returned as 0x00010203 and version 200.3.5 is returned as 0x00C80305 - A version of -1 is returned if the main executable did not link against WebKit (should never happen). */ +/* + Version numbers are based on the 'current library version' specified in the WebKit build rules. + All of these methods return or take version numbers with each part shifted to the left 2 bytes. + For example the version 1.2.3 is returned as 0x00010203 and version 200.3.5 is returned as 0x00C80305 + A version of -1 is returned if the main executable did not link against WebKit (should never happen). -/* Please use the current WebKit version number, available in WebKit/Configurations/Version.xcconfig, - when adding a new version constant. */ + Please use the current WebKit version number, available in WebKit/Configurations/Version.xcconfig, + when adding a new version constant. +*/ #define WEBKIT_FIRST_VERSION_WITH_3_0_CONTEXT_MENU_TAGS 0x020A0000 // 522.0.0 #define WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION 0x020A0000 // 522.0.0 @@ -44,6 +46,8 @@ #define WEBKIT_FIRST_VERSION_WITH_CACHE_MODEL_API 0x020B0500 // 523.5.0 #define WEBKIT_FIRST_VERSION_WITHOUT_JAVASCRIPT_RETURN_QUIRK 0x020D0100 // 525.1.0 #define WEBKIT_FIRST_VERSION_WITH_IE_COMPATIBLE_KEYBOARD_EVENT_DISPATCH 0x020D0100 // 525.1.0 +#define WEBKIT_FIRST_VERSION_WITH_LOADING_DURING_COMMON_RUNLOOP_MODES 0x020E0000 // 526.0.0 +#define WEBKIT_FIRST_VERSION_WITH_MORE_STRICT_LOCAL_RESOURCE_SECURITY_RESTRICTION 0x02100200 // 528.2.0 #ifdef __cplusplus extern "C" { diff --git a/WebKit/mac/Misc/WebLocalizableStrings.m b/WebKit/mac/Misc/WebLocalizableStrings.m index 6e95be1..0babfbc 100644 --- a/WebKit/mac/Misc/WebLocalizableStrings.m +++ b/WebKit/mac/Misc/WebLocalizableStrings.m @@ -28,7 +28,7 @@ #import <WebKit/WebLocalizableStrings.h> -#import <JavaScriptCore/Assertions.h> +#import <wtf/Assertions.h> WebLocalizableStringsBundle WebKitLocalizableStringsBundle = { "com.apple.WebKit", 0 }; diff --git a/WebKit/mac/Misc/WebNSArrayExtras.m b/WebKit/mac/Misc/WebNSArrayExtras.m index efc655e..b8b9af3 100644 --- a/WebKit/mac/Misc/WebNSArrayExtras.m +++ b/WebKit/mac/Misc/WebNSArrayExtras.m @@ -28,7 +28,7 @@ #import "WebNSArrayExtras.h" -#import <JavaScriptCore/Assertions.h> +#import <wtf/Assertions.h> @implementation NSMutableArray (WebExtras) diff --git a/WebKit/mac/Misc/WebNSAttributedStringExtras.mm b/WebKit/mac/Misc/WebNSAttributedStringExtras.mm index 04d9075..ef472aa 100644 --- a/WebKit/mac/Misc/WebNSAttributedStringExtras.mm +++ b/WebKit/mac/Misc/WebNSAttributedStringExtras.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,8 +31,8 @@ #import "DOMRangeInternal.h" #import "WebDataSourcePrivate.h" #import "WebFrame.h" -#import "WebFrameBridge.h" #import "WebFrameInternal.h" +#import "WebTypesInternal.h" #import <WebCore/BlockExceptions.h> #import <WebCore/ColorMac.h> #import <WebCore/CSSHelper.h> @@ -43,7 +43,6 @@ #import <WebCore/HTMLNames.h> #import <WebCore/Image.h> #import <WebCore/InlineTextBox.h> -#import <WebCore/KURL.h> #import <WebCore/Range.h> #import <WebCore/RenderImage.h> #import <WebCore/RenderListItem.h> @@ -52,6 +51,7 @@ #import <WebCore/RenderText.h> #import <WebCore/SimpleFontData.h> #import <WebCore/Text.h> +#import <WebCore/TextIterator.h> using namespace WebCore; using namespace HTMLNames; @@ -61,32 +61,6 @@ struct ListItemInfo { unsigned end; }; -static Element* listParent(Element* item) -{ - while (!item->hasTagName(ulTag) && !item->hasTagName(olTag)) { - item = static_cast<Element*>(item->parentNode()); - if (!item) - break; - } - return item; -} - -static Node* isTextFirstInListItem(Node* e) -{ - if (!e->isTextNode()) - return 0; - Node* par = e->parentNode(); - while (par) { - if (par->firstChild() != e) - return 0; - if (par->hasTagName(liTag)) - return par; - e = par; - par = par->parentNode(); - } - return 0; -} - static NSFileWrapper *fileWrapperForElement(Element* e) { NSFileWrapper *wrapper = nil; @@ -94,7 +68,7 @@ static NSFileWrapper *fileWrapperForElement(Element* e) const AtomicString& attr = e->getAttribute(srcAttr); if (!attr.isEmpty()) { - NSURL *URL = KURL(e->document()->completeURL(attr.deprecatedString())).getNSURL(); + NSURL *URL = e->document()->completeURL(attr); wrapper = [[kit(e->document()->frame()) _dataSource] _fileWrapperForURL:URL]; } if (!wrapper) { @@ -145,417 +119,57 @@ static NSFileWrapper *fileWrapperForElement(Element* e) return self; } -// FIXME: Use WebCore::TextIterator to iterate text runs. - + (NSAttributedString *)_web_attributedStringFromRange:(Range*)range { - ListItemInfo info; - ExceptionCode ec = 0; // dummy variable -- we ignore DOM exceptions - NSMutableAttributedString *result; - BEGIN_BLOCK_OBJC_EXCEPTIONS; - - if (!range || !range->boundaryPointsValid()) - return nil; - - Node* firstNode = range->startNode(); - if (!firstNode) - return nil; - Node* pastEndNode = range->pastEndNode(); - - int startOffset = range->startOffset(ec); - int endOffset = range->endOffset(ec); - Node* endNode = range->endContainer(ec); - - result = [[[NSMutableAttributedString alloc] init] autorelease]; - - bool hasNewLine = true; - bool addedSpace = true; - NSAttributedString *pendingStyledSpace = nil; - bool hasParagraphBreak = true; - const Element *linkStartNode = 0; - unsigned linkStartLocation = 0; - Vector<Element*> listItems; - Vector<ListItemInfo> listItemLocations; - float maxMarkerWidth = 0; - - Node *currentNode = firstNode; - - // If the first item is the entire text of a list item, use the list item node as the start of the - // selection, not the text node. The user's intent was probably to select the list. - if (currentNode->isTextNode() && startOffset == 0) { - Node *startListNode = isTextFirstInListItem(firstNode); - if (startListNode){ - firstNode = startListNode; - currentNode = firstNode; - } - } - - while (currentNode && currentNode != pastEndNode) { - RenderObject *renderer = currentNode->renderer(); - if (renderer) { - RenderStyle *style = renderer->style(); - NSFont *font = style->font().primaryFont()->getNSFont(); - bool needSpace = pendingStyledSpace != nil; - if (currentNode->isTextNode()) { - if (hasNewLine) { - addedSpace = true; - needSpace = false; - [pendingStyledSpace release]; - pendingStyledSpace = nil; - hasNewLine = false; - } - DeprecatedString text; - DeprecatedString str = currentNode->nodeValue().deprecatedString(); - int start = (currentNode == firstNode) ? startOffset : -1; - int end = (currentNode == endNode) ? endOffset : -1; - if (renderer->isText()) { - if (!style->collapseWhiteSpace()) { - if (needSpace && !addedSpace) { - if (text.isEmpty() && linkStartLocation == [result length]) - ++linkStartLocation; - [result appendAttributedString:pendingStyledSpace]; - } - int runStart = (start == -1) ? 0 : start; - int runEnd = (end == -1) ? str.length() : end; - text += str.mid(runStart, runEnd-runStart); - [pendingStyledSpace release]; - pendingStyledSpace = nil; - addedSpace = u_charDirection(str[runEnd - 1].unicode()) == U_WHITE_SPACE_NEUTRAL; - } - else { - RenderText* textObj = static_cast<RenderText*>(renderer); - if (!textObj->firstTextBox() && str.length() > 0 && !addedSpace) { - // We have no runs, but we do have a length. This means we must be - // whitespace that collapsed away at the end of a line. - text += ' '; - addedSpace = true; - } - else { - addedSpace = false; - for (InlineTextBox* box = textObj->firstTextBox(); box; box = box->nextTextBox()) { - int runStart = (start == -1) ? box->m_start : start; - int runEnd = (end == -1) ? box->m_start + box->m_len : end; - if (runEnd > box->m_start + box->m_len) - runEnd = box->m_start + box->m_len; - if (runStart >= box->m_start && - runStart < box->m_start + box->m_len) { - if (box == textObj->firstTextBox() && box->m_start == runStart && runStart > 0) - needSpace = true; // collapsed space at the start - if (needSpace && !addedSpace) { - if (pendingStyledSpace != nil) { - if (text.isEmpty() && linkStartLocation == [result length]) - ++linkStartLocation; - [result appendAttributedString:pendingStyledSpace]; - } else - text += ' '; - } - DeprecatedString runText = str.mid(runStart, runEnd - runStart); - runText.replace('\n', ' '); - text += runText; - int nextRunStart = box->nextTextBox() ? box->nextTextBox()->m_start : str.length(); // collapsed space between runs or at the end - needSpace = nextRunStart > runEnd; - [pendingStyledSpace release]; - pendingStyledSpace = nil; - addedSpace = u_charDirection(str[runEnd - 1].unicode()) == U_WHITE_SPACE_NEUTRAL; - start = -1; - } - if (end != -1 && runEnd >= end) - break; - } - } - } - } - - text.replace('\\', renderer->backslashAsCurrencySymbol()); - - if (text.length() > 0 || needSpace) { - NSMutableDictionary *attrs = [[NSMutableDictionary alloc] init]; - [attrs setObject:font forKey:NSFontAttributeName]; - if (style && style->color().isValid() && style->color().alpha() != 0) - [attrs setObject:nsColor(style->color()) forKey:NSForegroundColorAttributeName]; - if (style && style->backgroundColor().isValid() && style->backgroundColor().alpha() != 0) - [attrs setObject:nsColor(style->backgroundColor()) forKey:NSBackgroundColorAttributeName]; - - if (text.length() > 0) { - hasParagraphBreak = false; - NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text.getNSString() attributes:attrs]; - [result appendAttributedString: partialString]; - [partialString release]; - } - - if (needSpace) { - [pendingStyledSpace release]; - pendingStyledSpace = [[NSAttributedString alloc] initWithString:@" " attributes:attrs]; - } - - [attrs release]; - } - } else { - // This is our simple HTML -> ASCII transformation: - DeprecatedString text; - if (currentNode->hasTagName(aTag)) { - // Note the start of the <a> element. We will add the NSLinkAttributeName - // attribute to the attributed string when navigating to the next sibling - // of this node. - linkStartLocation = [result length]; - linkStartNode = static_cast<Element*>(currentNode); - } else if (currentNode->hasTagName(brTag)) { - text += "\n"; - hasNewLine = true; - } else if (currentNode->hasTagName(liTag)) { - DeprecatedString listText; - Element *itemParent = listParent(static_cast<Element*>(currentNode)); - - if (!hasNewLine) - listText += '\n'; - hasNewLine = true; - - listItems.append(static_cast<Element*>(currentNode)); - info.start = [result length]; - info.end = 0; - listItemLocations.append (info); - - listText += '\t'; - if (itemParent && renderer->isListItem()) { - RenderListItem* listRenderer = static_cast<RenderListItem*>(renderer); - - maxMarkerWidth = MAX([font pointSize], maxMarkerWidth); - - String marker = listRenderer->markerText(); - if (!marker.isEmpty()) { - listText += marker.deprecatedString(); - // Use AppKit metrics, since this will be rendered by AppKit. - NSString *markerNSString = marker; - float markerWidth = [markerNSString sizeWithAttributes:[NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]].width; - maxMarkerWidth = MAX(markerWidth, maxMarkerWidth); - } - - listText += ' '; - listText += '\t'; - - NSMutableDictionary *attrs = [[NSMutableDictionary alloc] init]; - [attrs setObject:font forKey:NSFontAttributeName]; - if (style && style->color().isValid()) - [attrs setObject:nsColor(style->color()) forKey:NSForegroundColorAttributeName]; - if (style && style->backgroundColor().isValid()) - [attrs setObject:nsColor(style->backgroundColor()) forKey:NSBackgroundColorAttributeName]; - - NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:listText.getNSString() attributes:attrs]; - [attrs release]; - [result appendAttributedString: partialString]; - [partialString release]; - } - } else if (currentNode->hasTagName(olTag) || currentNode->hasTagName(ulTag)) { - if (!hasNewLine) - text += "\n"; - hasNewLine = true; - } else if (currentNode->hasTagName(blockquoteTag) - || currentNode->hasTagName(ddTag) - || currentNode->hasTagName(divTag) - || currentNode->hasTagName(dlTag) - || currentNode->hasTagName(dtTag) - || currentNode->hasTagName(hrTag) - || currentNode->hasTagName(listingTag) - || currentNode->hasTagName(preTag) - || currentNode->hasTagName(tdTag) - || currentNode->hasTagName(thTag)) { - if (!hasNewLine) - text += '\n'; - hasNewLine = true; - } else if (currentNode->hasTagName(h1Tag) - || currentNode->hasTagName(h2Tag) - || currentNode->hasTagName(h3Tag) - || currentNode->hasTagName(h4Tag) - || currentNode->hasTagName(h5Tag) - || currentNode->hasTagName(h6Tag) - || currentNode->hasTagName(pTag) - || currentNode->hasTagName(trTag)) { - if (!hasNewLine) - text += '\n'; - - // In certain cases, emit a paragraph break. - int bottomMargin = renderer->collapsedMarginBottom(); - int fontSize = style->fontDescription().computedPixelSize(); - if (bottomMargin * 2 >= fontSize) { - if (!hasParagraphBreak) { - text += '\n'; - hasParagraphBreak = true; - } - } - - hasNewLine = true; - } - else if (currentNode->hasTagName(imgTag)) { - if (pendingStyledSpace != nil) { - if (linkStartLocation == [result length]) - ++linkStartLocation; - [result appendAttributedString:pendingStyledSpace]; - [pendingStyledSpace release]; - pendingStyledSpace = nil; - } - NSFileWrapper *fileWrapper = fileWrapperForElement(static_cast<Element*>(currentNode)); - NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper]; - NSAttributedString *iString = [NSAttributedString attributedStringWithAttachment:attachment]; - [result appendAttributedString: iString]; - [attachment release]; - } - - NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text.getNSString()]; - [result appendAttributedString: partialString]; - [partialString release]; - } - } - - Node *nextNode = currentNode->firstChild(); - if (!nextNode) - nextNode = currentNode->nextSibling(); - - while (!nextNode && currentNode->parentNode()) { - DeprecatedString text; - currentNode = currentNode->parentNode(); - if (currentNode == pastEndNode) - break; - nextNode = currentNode->nextSibling(); - - if (currentNode->hasTagName(aTag)) { - // End of a <a> element. Create an attributed string NSLinkAttributeName attribute - // for the range of the link. Note that we create the attributed string from the DOM, which - // will have corrected any illegally nested <a> elements. - if (linkStartNode && currentNode == linkStartNode) { - String href = parseURL(linkStartNode->getAttribute(hrefAttr)); - KURL kURL = linkStartNode->document()->frame()->loader()->completeURL(href.deprecatedString()); - - NSURL *URL = kURL.getNSURL(); - NSRange tempRange = { linkStartLocation, [result length]-linkStartLocation }; // workaround for 4213314 - [result addAttribute:NSLinkAttributeName value:URL range:tempRange]; - linkStartNode = 0; - } - } - else if (currentNode->hasTagName(olTag) || currentNode->hasTagName(ulTag)) { - if (!hasNewLine) - text += '\n'; - hasNewLine = true; - } else if (currentNode->hasTagName(liTag)) { - - int i, count = listItems.size(); - for (i = 0; i < count; i++){ - if (listItems[i] == currentNode){ - listItemLocations[i].end = [result length]; - break; - } - } - if (!hasNewLine) - text += '\n'; - hasNewLine = true; - } else if (currentNode->hasTagName(blockquoteTag) || - currentNode->hasTagName(ddTag) || - currentNode->hasTagName(divTag) || - currentNode->hasTagName(dlTag) || - currentNode->hasTagName(dtTag) || - currentNode->hasTagName(hrTag) || - currentNode->hasTagName(listingTag) || - currentNode->hasTagName(preTag) || - currentNode->hasTagName(tdTag) || - currentNode->hasTagName(thTag)) { - if (!hasNewLine) - text += '\n'; - hasNewLine = true; - } else if (currentNode->hasTagName(pTag) || - currentNode->hasTagName(trTag) || - currentNode->hasTagName(h1Tag) || - currentNode->hasTagName(h2Tag) || - currentNode->hasTagName(h3Tag) || - currentNode->hasTagName(h4Tag) || - currentNode->hasTagName(h5Tag) || - currentNode->hasTagName(h6Tag)) { - if (!hasNewLine) - text += '\n'; - // An extra newline is needed at the start, not the end, of these types of tags, - // so don't add another here. - hasNewLine = true; - } - - NSAttributedString *partialString = [[NSAttributedString alloc] initWithString:text.getNSString()]; - [result appendAttributedString:partialString]; - [partialString release]; - } - - currentNode = nextNode; - } - - [pendingStyledSpace release]; - - // Apply paragraph styles from outside in. This ensures that nested lists correctly - // override their parent's paragraph style. - { - unsigned i, count = listItems.size(); - Element *e; - -#ifdef POSITION_LIST - Node *containingBlock; - int containingBlockX, containingBlockY; + NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init]; + NSUInteger stringLength = 0; + RetainPtr<NSMutableDictionary> attrs(AdoptNS, [[NSMutableDictionary alloc] init]); + + for (TextIterator it(range); !it.atEnd(); it.advance()) { + RefPtr<Range> currentTextRange = it.range(); + ExceptionCode ec = 0; + Node* startContainer = currentTextRange->startContainer(ec); + Node* endContainer = currentTextRange->endContainer(ec); + int startOffset = currentTextRange->startOffset(ec); + int endOffset = currentTextRange->endOffset(ec); - // Determine the position of the outermost containing block. All paragraph - // styles and tabs should be relative to this position. So, the horizontal position of - // each item in the list (in the resulting attributed string) will be relative to position - // of the outermost containing block. - if (count > 0){ - containingBlock = firstNode; - while (containingBlock->renderer()->isInline()){ - containingBlock = containingBlock->parentNode(); + if (startContainer == endContainer && (startOffset == endOffset - 1)) { + Node* node = startContainer->childNode(startOffset); + if (node && node->hasTagName(imgTag)) { + NSFileWrapper *fileWrapper = fileWrapperForElement(static_cast<Element*>(node)); + NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper]; + [string appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]]; + [attachment release]; } - containingBlock->renderer()->absolutePosition(containingBlockX, containingBlockY); } -#endif - - for (i = 0; i < count; i++){ - e = listItems[i]; - info = listItemLocations[i]; - - if (info.end < info.start) - info.end = [result length]; - - RenderObject *r = e->renderer(); - RenderStyle *style = r->style(); - - int rx; - NSFont *font = style->font().primaryFont()->getNSFont(); - float pointSize = [font pointSize]; -#ifdef POSITION_LIST - int ry; - r->absolutePosition(rx, ry); - rx -= containingBlockX; - - // Ensure that the text is indented at least enough to allow for the markers. - rx = MAX(rx, (int)maxMarkerWidth); -#else - rx = (int)MAX(maxMarkerWidth, pointSize); -#endif - - // The bullet text will be right aligned at the first tab marker, followed - // by a space, followed by the list item text. The space is arbitrarily - // picked as pointSize*2/3. The space on the first line of the text item - // is established by a left aligned tab, on subsequent lines it's established - // by the head indent. - NSMutableParagraphStyle *mps = [[NSMutableParagraphStyle alloc] init]; - [mps setFirstLineHeadIndent: 0]; - [mps setHeadIndent: rx]; - [mps setTabStops:[NSArray arrayWithObjects: - [[[NSTextTab alloc] initWithType:NSRightTabStopType location:rx-(pointSize*2/3)] autorelease], - [[[NSTextTab alloc] initWithType:NSLeftTabStopType location:rx] autorelease], - nil]]; - NSRange tempRange = { info.start, info.end-info.start }; // workaround for 4213314 - [result addAttribute:NSParagraphStyleAttributeName value:mps range:tempRange]; - [mps release]; - } + int currentTextLength = it.length(); + if (!currentTextLength) + continue; + + RenderObject* renderer = startContainer->renderer(); + ASSERT(renderer); + if (!renderer) + continue; + RenderStyle* style = renderer->style(); + NSFont *font = style->font().primaryFont()->getNSFont(); + [attrs.get() setObject:font forKey:NSFontAttributeName]; + if (style->color().isValid()) + [attrs.get() setObject:nsColor(style->color()) forKey:NSForegroundColorAttributeName]; + else + [attrs.get() removeObjectForKey:NSForegroundColorAttributeName]; + if (style->backgroundColor().isValid()) + [attrs.get() setObject:nsColor(style->backgroundColor()) forKey:NSBackgroundColorAttributeName]; + else + [attrs.get() removeObjectForKey:NSBackgroundColorAttributeName]; + + RetainPtr<NSString> substring(AdoptNS, [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(it.characters()) length:currentTextLength freeWhenDone:NO]); + [string replaceCharactersInRange:NSMakeRange(stringLength, 0) withString:substring.get()]; + [string setAttributes:attrs.get() range:NSMakeRange(stringLength, currentTextLength)]; + stringLength += currentTextLength; } - return result; - - END_BLOCK_OBJC_EXCEPTIONS; - - return nil; + return [string autorelease]; } @end diff --git a/WebKit/mac/Misc/WebNSControlExtras.m b/WebKit/mac/Misc/WebNSControlExtras.m index 733269b..b666131 100644 --- a/WebKit/mac/Misc/WebNSControlExtras.m +++ b/WebKit/mac/Misc/WebNSControlExtras.m @@ -42,9 +42,10 @@ frame.origin.y -= heightDelta; [self setFrame:frame]; - NSRect windowFrame = [[self window] frame]; - windowFrame.size.height += heightDelta; - [[self window] setFrame:windowFrame display:NO]; + NSWindow *window = [self window]; + NSRect windowFrame = [window frame]; + windowFrame.size.height += heightDelta * [window userSpaceScaleFactor]; + [window setFrame:windowFrame display:NO]; } @end diff --git a/WebKit/mac/Misc/WebNSDataExtras.m b/WebKit/mac/Misc/WebNSDataExtras.m index a10efcd..0bd4555 100644 --- a/WebKit/mac/Misc/WebNSDataExtras.m +++ b/WebKit/mac/Misc/WebNSDataExtras.m @@ -29,7 +29,7 @@ #import <WebKit/WebNSDataExtras.h> #import <WebKit/WebNSDataExtrasPrivate.h> -#import <JavaScriptCore/Assertions.h> +#import <wtf/Assertions.h> @interface NSString (WebNSDataExtrasInternal) - (NSString *)_web_capitalizeRFC822HeaderFieldName; diff --git a/WebKit/mac/Misc/WebNSDictionaryExtras.m b/WebKit/mac/Misc/WebNSDictionaryExtras.m index 86df63a..665db22 100644 --- a/WebKit/mac/Misc/WebNSDictionaryExtras.m +++ b/WebKit/mac/Misc/WebNSDictionaryExtras.m @@ -28,7 +28,7 @@ #import <WebKit/WebNSDataExtras.h> -#import <JavaScriptCore/Assertions.h> +#import <wtf/Assertions.h> @implementation NSDictionary (WebNSDictionaryExtras) -(NSNumber *)_webkit_numberForKey:(id)key diff --git a/WebKit/mac/Misc/WebNSFileManagerExtras.h b/WebKit/mac/Misc/WebNSFileManagerExtras.h index aaaf0a7..d6e26ee 100644 --- a/WebKit/mac/Misc/WebNSFileManagerExtras.h +++ b/WebKit/mac/Misc/WebNSFileManagerExtras.h @@ -34,8 +34,6 @@ @interface NSFileManager (WebNSFileManagerExtras) -- (BOOL)_webkit_createDirectoryAtPathWithIntermediateDirectories:(NSString *)path attributes:(NSDictionary *)attributes; -- (BOOL)_webkit_createFileAtPathWithIntermediateDirectories:(NSString *)path contents:(NSData *)contents attributes:(NSDictionary *)attributes directoryAttributes:(NSDictionary *)directoryAttributes; - (void)_webkit_backgroundRemoveFileAtPath:(NSString *)path; - (void)_webkit_backgroundRemoveLeftoverFiles:(NSString *)path; - (BOOL)_webkit_removeFileOnlyAtPath:(NSString *)path; @@ -45,3 +43,12 @@ @end + +#ifdef BUILDING_ON_TIGER +@interface NSFileManager (WebNSFileManagerTigerForwardCompatibility) +- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error; +- (BOOL)moveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error; +- (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error; +- (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error; +@end +#endif diff --git a/WebKit/mac/Misc/WebNSFileManagerExtras.m b/WebKit/mac/Misc/WebNSFileManagerExtras.m index ae45afe..0c10725 100644 --- a/WebKit/mac/Misc/WebNSFileManagerExtras.m +++ b/WebKit/mac/Misc/WebNSFileManagerExtras.m @@ -28,161 +28,14 @@ #import <WebKit/WebNSFileManagerExtras.h> -#import <JavaScriptCore/Assertions.h> #import <WebKit/WebKitNSStringExtras.h> #import <WebKitSystemInterface.h> +#import <wtf/Assertions.h> #import <sys/mount.h> @implementation NSFileManager (WebNSFileManagerExtras) -- (BOOL)_webkit_fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory traverseLink:(BOOL)flag -{ - BOOL result; - NSDictionary *attributes; - - result = NO; - if (isDirectory) { - *isDirectory = NO; - } - - attributes = [self fileAttributesAtPath:path traverseLink:flag]; - - if (attributes) { - result = YES; - if ([[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeDirectory]) { - if (isDirectory) { - *isDirectory = YES; - } - } - } - - return result; -} - -- (BOOL)_webkit_createIntermediateDirectoriesForPath:(NSString *)path attributes:(NSDictionary *)attributes -{ - BOOL result; - NSArray *pathComponents; - BOOL isDir; - unsigned count; - unsigned i; - NSString *checkPath; - NSMutableString *subpath; - - if (!path || [path length] == 0 || ![path isAbsolutePath]) { - return NO; - } - - result = NO; - - // check to see if the path to the file already exists - if ([self _webkit_fileExistsAtPath:[path stringByDeletingLastPathComponent] isDirectory:&isDir traverseLink:YES]) { - if (isDir) { - result = YES; - } - else { - result = NO; - } - } - else { - // create the path to the file - result = YES; - - // assume that most of the path exists, look backwards until we find an existing subpath - checkPath = path; - while (![checkPath isEqualToString:@"/"]) { - checkPath = [checkPath stringByDeletingLastPathComponent]; - if ([self _webkit_fileExistsAtPath:checkPath isDirectory:&isDir traverseLink:YES]) { - if (isDir) { - break; - } - else { - // found a leaf node, can't continue - result = NO; - break; - } - } - } - - if (result) { - // now build up the path to the point where we found existing paths - subpath = [[NSMutableString alloc] initWithCapacity:[path length]]; - pathComponents = [path componentsSeparatedByString:@"/"]; - count = [pathComponents count]; - i = 0; - while (i < count - 1 && ![subpath isEqualToString:checkPath]) { - if (i > 0) { - [subpath appendString:@"/"]; - } - [subpath appendString:[pathComponents objectAtIndex:i]]; - i++; - } - - // now create the parts of the path that did not yet exist - while (i < count - 1) { - if ([(NSString *)[pathComponents objectAtIndex:i] length] == 0) { - continue; - } - if (i > 0) { - [subpath appendString:@"/"]; - } - [subpath appendString:[pathComponents objectAtIndex:i]]; - - // does this directory exist? - if ([self _webkit_fileExistsAtPath:subpath isDirectory:&isDir traverseLink:YES]) { - if (!isDir) { - // ran into a leaf node of some sort - result = NO; - break; - } - } - else { - // subpath does not exist - create it - if (![self createDirectoryAtPath:subpath attributes:attributes]) { - // failed to create subpath - result = NO; - break; - } - } - i++; - } - - [subpath release]; - } - - } - - return result; -} - -- (BOOL)_webkit_createDirectoryAtPathWithIntermediateDirectories:(NSString *)path attributes:(NSDictionary *)attributes -{ - // Be really optimistic - assume that in the common case, the directory exists. - BOOL isDirectory; - if ([self fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory) { - return YES; - } - - // Assume the next most common case is that the parent directory already exists - if ([self createDirectoryAtPath:path attributes:attributes]) { - return YES; - } - - // Do it the hard way - return [self _webkit_createIntermediateDirectoriesForPath:path attributes:attributes] && [self createDirectoryAtPath:path attributes:attributes]; -} - -- (BOOL)_webkit_createFileAtPathWithIntermediateDirectories:(NSString *)path contents:(NSData *)contents attributes:(NSDictionary *)attributes directoryAttributes:(NSDictionary *)directoryAttributes -{ - // Be optimistic - try just creating the file first, assuming intermediate directories exist. - if ([self createFileAtPath:path contents:contents attributes:attributes]) { - return YES; - } - - return ([self _webkit_createIntermediateDirectoriesForPath:path attributes:directoryAttributes] && [self createFileAtPath:path contents:contents attributes:attributes]); -} - - (BOOL)_webkit_removeFileOnlyAtPath:(NSString *)path { struct statfs buf; @@ -218,10 +71,8 @@ i++; } while ([manager fileExistsAtPath:moveToPath]); - if ([manager movePath:path toPath:moveToPath handler:nil]) { + if ([manager moveItemAtPath:path toPath:moveToPath error:NULL]) [NSThread detachNewThreadSelector:@selector(_performRemoveFileAtPath:) toTarget:self withObject:moveToPath]; - } - } - (void)_webkit_backgroundRemoveLeftoverFiles:(NSString *)path @@ -344,3 +195,44 @@ } @end + + +#ifdef BUILDING_ON_TIGER +@implementation NSFileManager (WebNSFileManagerTigerForwardCompatibility) + +- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error +{ + // We don't report errors via the NSError* output parameter, so ensure that the caller does not expect us to do so. + ASSERT_ARG(error, !error); + + return [self directoryContentsAtPath:path]; +} + +- (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error +{ + // We don't report errors via the NSError* output parameter, so ensure that the caller does not expect us to do so. + ASSERT_ARG(error, !error); + + return [self fileSystemAttributesAtPath:path]; +} + +- (BOOL)moveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error +{ + // The implementation of moveItemAtPath:toPath:error: interacts with the NSFileManager's delegate. + // We are not matching that behaviour at the moment, but it should not be a problem as any client + // expecting that would need to call setDelegate: first which will generate a compile-time warning, + // as that method is not available on Tiger. + return [self movePath:srcPath toPath:dstPath handler:nil]; +} + +- (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error +{ + // The implementation of removeItemAtPath:error: interacts with the NSFileManager's delegate. + // We are not matching that behaviour at the moment, but it should not be a problem as any client + // expecting that would need to call setDelegate: first which will generate a compile-time warning, + // as that method is not available on Tiger. + return [self removeFileAtPath:path handler:nil]; +} + +@end +#endif diff --git a/WebKit/mac/Misc/WebNSPasteboardExtras.mm b/WebKit/mac/Misc/WebNSPasteboardExtras.mm index cdf47cc..b84542a 100644 --- a/WebKit/mac/Misc/WebNSPasteboardExtras.mm +++ b/WebKit/mac/Misc/WebNSPasteboardExtras.mm @@ -29,19 +29,18 @@ #import "WebNSPasteboardExtras.h" #import "WebArchive.h" -#import "WebFrameBridge.h" #import "WebFrameInternal.h" #import "WebHTMLViewInternal.h" #import "WebNSURLExtras.h" #import "WebResourcePrivate.h" #import "WebURLsWithTitles.h" #import "WebViewPrivate.h" -#import <JavaScriptCore/Assertions.h> #import <WebCore/Element.h> #import <WebCore/MIMETypeRegistry.h> #import <WebCore/RenderImage.h> #import <WebKit/DOMExtensions.h> #import <WebKit/DOMPrivate.h> +#import <wtf/Assertions.h> #import <wtf/RetainPtr.h> #import <WebKitSystemInterface.h> diff --git a/WebKit/mac/Misc/WebNSURLExtras.mm b/WebKit/mac/Misc/WebNSURLExtras.mm index c9efe1d..b388c22 100644 --- a/WebKit/mac/Misc/WebNSURLExtras.mm +++ b/WebKit/mac/Misc/WebNSURLExtras.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved. * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) * * Redistribution and use in source and binary forms, with or without @@ -35,10 +35,10 @@ #import "WebNSObjectExtras.h" #import "WebSystemInterface.h" #import <Foundation/NSURLRequest.h> -#import <JavaScriptCore/Assertions.h> #import <WebCore/KURL.h> #import <WebCore/LoaderNSURLExtras.h> #import <WebKitSystemInterface.h> +#import <wtf/Assertions.h> #import <unicode/uchar.h> #import <unicode/uidna.h> #import <unicode/uscript.h> @@ -411,22 +411,96 @@ static NSString *mapHostNames(NSString *string, BOOL encode) + (NSURL *)_web_URLWithData:(NSData *)data { - return urlWithData(data); + return [NSURL _web_URLWithData:data relativeToURL:nil]; } + (NSURL *)_web_URLWithData:(NSData *)data relativeToURL:(NSURL *)baseURL { - return urlWithDataRelativeToURL(data, baseURL); + if (data == nil) + return nil; + + NSURL *result = nil; + size_t length = [data length]; + if (length > 0) { + // work around <rdar://4470771>: CFURLCreateAbsoluteURLWithBytes(.., TRUE) doesn't remove non-path components. + baseURL = [baseURL _webkit_URLByRemovingResourceSpecifier]; + + const UInt8 *bytes = static_cast<const UInt8*>([data bytes]); + // NOTE: We use UTF-8 here since this encoding is used when computing strings when returning URL components + // (e.g calls to NSURL -path). However, this function is not tolerant of illegal UTF-8 sequences, which + // could either be a malformed string or bytes in a different encoding, like shift-jis, so we fall back + // onto using ISO Latin 1 in those cases. + result = WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingUTF8, (CFURLRef)baseURL, YES)); + if (!result) + result = WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES)); + } else + result = [NSURL URLWithString:@""]; + + return result; } - (NSData *)_web_originalData { - return urlOriginalData(self); + UInt8 *buffer = (UInt8 *)malloc(URL_BYTES_BUFFER_LENGTH); + CFIndex bytesFilled = CFURLGetBytes((CFURLRef)self, buffer, URL_BYTES_BUFFER_LENGTH); + if (bytesFilled == -1) { + CFIndex bytesToAllocate = CFURLGetBytes((CFURLRef)self, NULL, 0); + buffer = (UInt8 *)realloc(buffer, bytesToAllocate); + bytesFilled = CFURLGetBytes((CFURLRef)self, buffer, bytesToAllocate); + ASSERT(bytesFilled == bytesToAllocate); + } + + // buffer is adopted by the NSData + NSData *data = [NSData dataWithBytesNoCopy:buffer length:bytesFilled freeWhenDone:YES]; + + NSURL *baseURL = (NSURL *)CFURLGetBaseURL((CFURLRef)self); + if (baseURL) + return [[NSURL _web_URLWithData:data relativeToURL:baseURL] _web_originalData]; + return data; } - (NSString *)_web_originalDataAsString { - return urlOriginalDataAsString(self); + return [[[NSString alloc] initWithData:[self _web_originalData] encoding:NSISOLatin1StringEncoding] autorelease]; +} + +static CFStringRef createStringWithEscapedUnsafeCharacters(CFStringRef string) +{ + CFIndex length = CFStringGetLength(string); + Vector<UChar, 2048> sourceBuffer(length); + CFStringGetCharacters(string, CFRangeMake(0, length), sourceBuffer.data()); + + Vector<UChar, 2048> outBuffer; + + CFIndex i = 0; + while (i < length) { + UChar32 c; + U16_NEXT(sourceBuffer, i, length, c) + + if (isLookalikeCharacter(c)) { + uint8_t utf8Buffer[4]; + CFIndex offset = 0; + UBool failure = false; + U8_APPEND(utf8Buffer, offset, 4, c, failure) + ASSERT(!failure); + + for (CFIndex j = 0; j < offset; ++j) { + outBuffer.append('%'); + outBuffer.append(hexDigit(utf8Buffer[j] >> 4)); + outBuffer.append(hexDigit(utf8Buffer[j] & 0xf)); + } + } else { + UChar utf16Buffer[2]; + CFIndex offset = 0; + UBool failure = false; + U16_APPEND(utf16Buffer, offset, 2, c, failure) + ASSERT(!failure); + for (CFIndex j = 0; j < offset; ++j) + outBuffer.append(utf16Buffer[j]); + } + } + + return CFStringCreateWithCharacters(NULL, outBuffer.data(), outBuffer.size()); } - (NSString *)_web_userVisibleString @@ -444,28 +518,20 @@ static NSString *mapHostNames(NSString *string, BOOL encode) int i; for (i = 0; i < length; i++) { unsigned char c = p[i]; - // escape control characters, space, and delete - if (c <= 0x20 || c == 0x7f) { - *q++ = '%'; - *q++ = hexDigit(c >> 4); - *q++ = hexDigit(c & 0xf); - } // unescape escape sequences that indicate bytes greater than 0x7f - else if (c == '%' && (i + 1 < length && isHexDigit(p[i + 1])) && i + 2 < length && isHexDigit(p[i + 2])) { + if (c == '%' && (i + 1 < length && isHexDigit(p[i + 1])) && i + 2 < length && isHexDigit(p[i + 2])) { unsigned char u = (hexDigitValue(p[i + 1]) << 4) | hexDigitValue(p[i + 2]); if (u > 0x7f) { // unescape *q++ = u; - } - else { + } else { // do not unescape *q++ = p[i]; *q++ = p[i + 1]; *q++ = p[i + 2]; } i += 2; - } - else { + } else { *q++ = c; // Check for "xn--" in an efficient, non-case-sensitive, way. @@ -493,8 +559,7 @@ static NSString *mapHostNames(NSString *string, BOOL encode) *q++ = '%'; *q++ = hexDigit(c >> 4); *q++ = hexDigit(c & 0xf); - } - else { + } else { *q++ = *p; } p++; @@ -504,14 +569,16 @@ static NSString *mapHostNames(NSString *string, BOOL encode) } free(after); - - // As an optimization, only do host name decoding if we have "xn--" somewhere. - return needsHostNameDecoding ? mapHostNames(result, NO) : result; + + result = mapHostNames(result, !needsHostNameDecoding); + return WebCFAutorelease(createStringWithEscapedUnsafeCharacters((CFStringRef)result)); } - (BOOL)_web_isEmpty { - return urlIsEmpty(self); + if (!CFURLGetBaseURL((CFURLRef)self)) + return CFURLGetBytes((CFURLRef)self, NULL, 0) == 0; + return [[self _web_originalData] length] == 0; } - (const char *)_web_URLCString @@ -523,9 +590,24 @@ static NSString *mapHostNames(NSString *string, BOOL encode) } - (NSURL *)_webkit_canonicalize -{ - InitWebCoreSystemInterface(); - return canonicalURL(self); +{ + NSURLRequest *request = [[NSURLRequest alloc] initWithURL:self]; + Class concreteClass = WKNSURLProtocolClassForRequest(request); + if (!concreteClass) { + [request release]; + return self; + } + + // This applies NSURL's concept of canonicalization, but not KURL's concept. It would + // make sense to apply both, but when we tried that it caused a performance degradation + // (see 5315926). It might make sense to apply only the KURL concept and not the NSURL + // concept, but it's too risky to make that change for WebKit 3.0. + NSURLRequest *newRequest = [concreteClass canonicalRequestForRequest:request]; + NSURL *newURL = [newRequest URL]; + NSURL *result = [[newURL retain] autorelease]; + [request release]; + + return result; } typedef struct { @@ -539,21 +621,38 @@ typedef struct { NSString *fragment; } WebKitURLComponents; - - - (NSURL *)_webkit_URLByRemovingComponent:(CFURLComponentType)component { - return urlByRemovingComponent(self, component); + CFRange fragRg = CFURLGetByteRangeForComponent((CFURLRef)self, component, NULL); + // Check to see if a fragment exists before decomposing the URL. + if (fragRg.location == kCFNotFound) + return self; + + UInt8 *urlBytes, buffer[2048]; + CFIndex numBytes = CFURLGetBytes((CFURLRef)self, buffer, 2048); + if (numBytes == -1) { + numBytes = CFURLGetBytes((CFURLRef)self, NULL, 0); + urlBytes = static_cast<UInt8*>(malloc(numBytes)); + CFURLGetBytes((CFURLRef)self, urlBytes, numBytes); + } else + urlBytes = buffer; + + NSURL *result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, fragRg.location - 1, kCFStringEncodingUTF8, NULL)); + if (!result) + result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, fragRg.location - 1, kCFStringEncodingISOLatin1, NULL)); + + if (urlBytes != buffer) free(urlBytes); + return result ? [result autorelease] : self; } - (NSURL *)_webkit_URLByRemovingFragment { - return urlByRemovingFragment(self); + return [self _webkit_URLByRemovingComponent:kCFURLComponentFragment]; } - (NSURL *)_webkit_URLByRemovingResourceSpecifier { - return urlByRemovingResourceSpecifier(self); + return [self _webkit_URLByRemovingComponent:kCFURLComponentResourceSpecifier]; } - (BOOL)_webkit_isJavaScriptURL @@ -567,8 +666,8 @@ typedef struct { } - (BOOL)_webkit_isFileURL -{ - return urlIsFileURL(self); +{ + return [[self _web_originalDataAsString] _webkit_isFileURL]; } - (BOOL)_webkit_isFTPDirectoryURL @@ -797,13 +896,12 @@ typedef struct { - (BOOL)_webkit_isFileURL { - return stringIsFileURL(self); + return [self rangeOfString:@"file:" options:(NSCaseInsensitiveSearch | NSAnchoredSearch)].location != NSNotFound; } - (NSString *)_webkit_stringByReplacingValidPercentEscapes { - DeprecatedString s = KURL::decode_string(DeprecatedString::fromNSString(self)); - return s.getNSString(); + return decodeURLEscapeSequences(self); } - (NSString *)_webkit_scriptIfJavaScriptURL diff --git a/WebKit/mac/Misc/WebNSUserDefaultsExtras.m b/WebKit/mac/Misc/WebNSUserDefaultsExtras.m index b7d297a..383d202 100644 --- a/WebKit/mac/Misc/WebNSUserDefaultsExtras.m +++ b/WebKit/mac/Misc/WebNSUserDefaultsExtras.m @@ -26,10 +26,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import <WebKit/WebNSUserDefaultsExtras.h> +#import "WebNSUserDefaultsExtras.h" -#import <JavaScriptCore/Assertions.h> +#import "WebNSObjectExtras.h" #import <WebKitSystemInterface.h> +#import <wtf/Assertions.h> @implementation NSString (WebNSUserDefaultsPrivate) @@ -37,7 +38,7 @@ { // Look up the language code using CFBundle. NSString *languageCode = self; - NSString *preferredLanguageCode = [(id)WKCopyCFLocalizationPreferredName((CFStringRef)self) autorelease]; + NSString *preferredLanguageCode = WebCFAutorelease(WKCopyCFLocalizationPreferredName((CFStringRef)self)); if (preferredLanguageCode) languageCode = preferredLanguageCode; diff --git a/WebKit/mac/Misc/WebNSViewExtras.m b/WebKit/mac/Misc/WebNSViewExtras.m index 189a3bc..70ff68a 100644 --- a/WebKit/mac/Misc/WebNSViewExtras.m +++ b/WebKit/mac/Misc/WebNSViewExtras.m @@ -36,7 +36,6 @@ #import <WebKit/WebNSPasteboardExtras.h> #import <WebKit/WebNSURLExtras.h> #import <WebKit/WebView.h> -#import <WebKitSystemInterface.h> #define WebDragStartHysteresisX 5.0f #define WebDragStartHysteresisY 5.0f @@ -47,22 +46,6 @@ @implementation NSView (WebExtras) -// FIXME: Safari 2.0 is the only client of _web_superviewOfClass:stoppingAtClass: -// remove this method once Open Source users have a new version to use with TOT WebKit. -- (NSView *)_web_superviewOfClass:(Class)class stoppingAtClass:(Class)limitClass -{ - NSView *view = self; - while ((view = [view superview]) != nil) { - if ([view isKindOfClass:class]) { - return view; - } else if (limitClass && [view isKindOfClass:limitClass]) { - break; - } - } - - return nil; -} - - (NSView *)_web_superviewOfClass:(Class)class { NSView *view = [self superview]; diff --git a/WebKit/mac/Misc/WebNSWindowExtras.m b/WebKit/mac/Misc/WebNSWindowExtras.m index 49bf006..ef27b13 100644 --- a/WebKit/mac/Misc/WebNSWindowExtras.m +++ b/WebKit/mac/Misc/WebNSWindowExtras.m @@ -49,9 +49,4 @@ [self setFrameOrigin:origin]; } -+ (void)_webkit_displayThrottledWindows -{ - // this is needed only to keep PLT working on Safari 2.0.4 -} - @end diff --git a/WebKit/mac/Misc/WebSearchableTextView.h b/WebKit/mac/Misc/WebSearchableTextView.h deleted file mode 100644 index fda38ee..0000000 --- a/WebKit/mac/Misc/WebSearchableTextView.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import <WebKit/WebDocumentPrivate.h> - -@interface WebSearchableTextView : NSTextView <WebDocumentSearching, WebDocumentSelection> -@end diff --git a/WebKit/mac/Misc/WebSearchableTextView.m b/WebKit/mac/Misc/WebSearchableTextView.m deleted file mode 100644 index 5f80b46..0000000 --- a/WebKit/mac/Misc/WebSearchableTextView.m +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "WebSearchableTextView.h" -#import "WebDocumentPrivate.h" -#import "WebTypesInternal.h" - -@interface NSString (_Web_StringTextFinding) -- (NSRange)findString:(NSString *)string selectedRange:(NSRange)selectedRange options:(unsigned)mask wrap:(BOOL)wrapFlag; -@end - -@implementation WebSearchableTextView - -- (BOOL)searchFor: (NSString *)string direction: (BOOL)forward caseSensitive: (BOOL)caseFlag wrap: (BOOL)wrapFlag; -{ - if (![string length]) - return NO; - - BOOL lastFindWasSuccessful = NO; - NSString *textContents = [self string]; - unsigned textLength; - - if (textContents && (textLength = [textContents length])) { - NSRange range; - unsigned options = 0; - - if (!forward) - options |= NSBackwardsSearch; - - if (!caseFlag) - options |= NSCaseInsensitiveSearch; - - range = [textContents findString:string selectedRange:[self selectedRange] options:options wrap:wrapFlag]; - if (range.length) { - [self setSelectedRange:range]; - [self scrollRangeToVisible:range]; - lastFindWasSuccessful = YES; - } - } - - return lastFindWasSuccessful; -} - -- (void)copy:(id)sender -{ - if ([self isRichText]) { - [super copy:sender]; - }else{ - //Convert CRLF to LF to workaround: 3105538 - Carbon doesn't convert text with CRLF to LF - NSMutableString *string = [[[self string] substringWithRange:[self selectedRange]] mutableCopy]; - [string replaceOccurrencesOfString:@"\r\n" withString:@"\n" options:0 range:NSMakeRange(0, [string length])]; - - NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; - [pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self]; - [pasteboard setString:string forType:NSStringPboardType]; - } -} - -- (NSRect)selectionRect -{ - // Note that this method would work for any NSTextView; some day we might want to use it - // for an NSTextView that isn't a WebTextView. - NSRect result = NSZeroRect; - - // iterate over multiple selected ranges - NSEnumerator *rangeEnumerator = [[self selectedRanges] objectEnumerator]; - NSValue *rangeAsValue; - while ((rangeAsValue = [rangeEnumerator nextObject]) != nil) { - NSRange range = [rangeAsValue rangeValue]; - NSUInteger rectCount; - NSRectArray rectArray = [[self layoutManager] rectArrayForCharacterRange:range - withinSelectedCharacterRange:range - inTextContainer:[self textContainer] - rectCount:&rectCount]; - unsigned i; - // iterate over multiple rects in each selected range - for (i = 0; i < rectCount; ++i) { - NSRect rect = rectArray[i]; - if (NSEqualRects(result, NSZeroRect)) { - result = rect; - } else { - result = NSUnionRect(result, rect); - } - } - } - - return result; -} - -- (NSImage *)selectionImageForcingBlackText:(BOOL)forceBlackText -{ - // This is here to complete the <WebDocumentSelection> protocol, but it was introduced after this - // class was deprecated so there's no implementation. - return nil; -} - -- (NSImage *)selectionImageForcingWhiteText:(BOOL)forceWhiteText -{ - // This is here to complete the <WebDocumentSelection> protocol, but it was introduced after this - // class was deprecated so there's no implementation. - return nil; -} - -- (NSRect)selectionImageRect -{ - // This is here to complete the <WebDocumentSelection> protocol, but it was introduced after this - // class was deprecated so there's no implementation. - return NSZeroRect; -} - -- (NSArray *)selectionTextRects -{ - // This is here to complete the <WebDocumentSelection> protocol, but it was introduced after this - // class was deprecated so there's no implementation. - return nil; -} - -- (NSView *)selectionView -{ - return self; -} - -- (NSArray *)pasteboardTypesForSelection -{ - return [self writablePasteboardTypes]; -} - -- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard -{ - [self writeSelectionToPasteboard:pasteboard types:types]; -} - -- (BOOL)supportsTextEncoding -{ - return YES; -} - -- (NSString *)string -{ - return [super string]; -} - -- (NSAttributedString *)attributedString -{ - return [self attributedSubstringFromRange:NSMakeRange(0, [[self string] length])]; -} - -- (NSString *)selectedString -{ - return [[self string] substringWithRange:[self selectedRange]]; -} - -- (NSAttributedString *)selectedAttributedString -{ - return [self attributedSubstringFromRange:[self selectedRange]]; -} - -- (void)selectAll -{ - [self setSelectedRange:NSMakeRange(0, [[self string] length])]; -} - -- (void)deselectAll -{ - [self setSelectedRange:NSMakeRange(0,0)]; -} - -@end - -@implementation NSString (_Web_StringTextFinding) - -- (NSRange)findString:(NSString *)string selectedRange:(NSRange)selectedRange options:(unsigned)options wrap:(BOOL)wrap -{ - BOOL forwards = (options & NSBackwardsSearch) == 0; - unsigned length = [self length]; - NSRange searchRange, range; - - // Our search algorithm, used in WebCore also, is to search in the selection first. If the found text is the - // entire selection, then we search again from just past the selection. - - if (forwards) { - // FIXME: If selectedRange has length of 0, we ignore it, which is appropriate for non-editable text (since - // a zero-length selection in non-editable is invisible). We might want to change this someday to only ignore the - // selection if its location is NSNotFound when the text is editable (and similarly for the backwards case). - searchRange.location = selectedRange.length > 0 ? selectedRange.location : 0; - searchRange.length = length - searchRange.location; - range = [self rangeOfString:string options:options range:searchRange]; - - // If found range matches (non-empty) selection, search again from just past selection - if (range.location != NSNotFound && NSEqualRanges(range, selectedRange)) { - searchRange.location = NSMaxRange(selectedRange); - searchRange.length = length - searchRange.location; - range = [self rangeOfString:string options:options range:searchRange]; - } - - // If not found, search again from the beginning. Make search range large enough that - // we'll find a match even if it partially overlapped the existing selection (including the - // case where it exactly matches the existing selection). - if ((range.length == 0) && wrap) { - searchRange.location = 0; - searchRange.length = selectedRange.location + selectedRange.length + [string length]; - if (searchRange.length > length) { - searchRange.length = length; - } - range = [self rangeOfString:string options:options range:searchRange]; - } - } else { - searchRange.location = 0; - searchRange.length = selectedRange.length > 0 ? NSMaxRange(selectedRange) : length; - range = [self rangeOfString:string options:options range:searchRange]; - - // If found range matches (non-empty) selection, search again from just before selection - if (range.location != NSNotFound && NSEqualRanges(range, selectedRange)) { - searchRange.location = 0; - searchRange.length = selectedRange.location; - range = [self rangeOfString:string options:options range:searchRange]; - } - - // If not found, search again from the end. Make search range large enough that - // we'll find a match even if it partially overlapped the existing selection (including the - // case where it exactly matches the existing selection). - if ((range.length == 0) && wrap) { - unsigned stringLength = [string length]; - if (selectedRange.location > stringLength) { - searchRange.location = selectedRange.location - stringLength; - } else { - searchRange.location = 0; - } - searchRange.length = length - searchRange.location; - range = [self rangeOfString:string options:options range:searchRange]; - } -} -return range; -} - -@end diff --git a/WebKit/mac/Misc/WebTypesInternal.h b/WebKit/mac/Misc/WebTypesInternal.h index 33bdf81..4b97ab3 100644 --- a/WebKit/mac/Misc/WebTypesInternal.h +++ b/WebKit/mac/Misc/WebTypesInternal.h @@ -31,11 +31,4 @@ typedef int NSInteger; typedef unsigned int NSUInteger; #endif -#ifndef CGFLOAT_DEFINED -#ifdef __LP64__ -typedef double CGFloat; -#else -typedef float CGFloat; -#endif -#define CGFLOAT_DEFINED 1 -#endif + |