Changeset 25312 in webkit


Ignore:
Timestamp:
Aug 29, 2007 5:45:52 PM (17 years ago)
Author:
darin
Message:

Reviewed by Tim Hatcher.

  • Misc/WebNSPasteboardExtras.h: Got rid of the global data objects and replaced them with global functions.
  • Misc/WebNSPasteboardExtras.mm: (initializePasteboardTypes): Changed the initialize method to be this function. (WebURLPasteboardType): Added, calls the initialize function and then returns the value of the global. (WebURLNamePasteboardType): Ditto. (+[NSPasteboard _web_writableTypesForURL]): Changed to call the new function instead of getting at the global directly. (+[NSPasteboard _web_dragTypesForURL]): Ditto. (-[NSPasteboard _web_writeURL:andTitle:types:]): Ditto.
  • WebCoreSupport/WebPasteboardHelper.mm: (WebPasteboardHelper::urlFromPasteboard): Ditto.
  • WebView/WebHTMLView.mm: (-[WebHTMLView _documentFragmentFromPasteboard:forType:inContext:subresources:]): Ditto.
  • WebView/WebView.mm: (+[WebView initialize]): Added a call to one of the functions to take advantage of the side effect that initializes the globals; this is to help out old versions of Safari. (+[WebView URLTitleFromPasteboard:]): Changed to call the new function instead of getting at the global directly.
  • WebKit.exp: Add exports of the new functions.
Location:
trunk/WebKit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/ChangeLog

    r25307 r25312  
     12007-08-29  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Tim Hatcher.
     4
     5        - fix <rdar://problem/4582212> WebKit inappropriately adds +initialize to
     6          NSPasteboard via a category, prevents AppKit initialize
     7          http://bugs.webkit.org/show_bug.cgi?id=9417
     8
     9        * Misc/WebNSPasteboardExtras.h: Got rid of the global data objects and replaced
     10        them with global functions.
     11
     12        * Misc/WebNSPasteboardExtras.mm:
     13        (initializePasteboardTypes): Changed the initialize method to be this function.
     14        (WebURLPasteboardType): Added, calls the initialize function and then returns
     15        the value of the global.
     16        (WebURLNamePasteboardType): Ditto.
     17        (+[NSPasteboard _web_writableTypesForURL]): Changed to call the new function instead
     18        of getting at the global directly.
     19        (+[NSPasteboard _web_dragTypesForURL]): Ditto.
     20        (-[NSPasteboard _web_writeURL:andTitle:types:]): Ditto.
     21        * WebCoreSupport/WebPasteboardHelper.mm:
     22        (WebPasteboardHelper::urlFromPasteboard): Ditto.
     23        * WebView/WebHTMLView.mm:
     24        (-[WebHTMLView _documentFragmentFromPasteboard:forType:inContext:subresources:]): Ditto.
     25
     26        * WebView/WebView.mm:
     27        (+[WebView initialize]): Added a call to one of the functions to take advantage
     28        of the side effect that initializes the globals; this is to help out old versions
     29        of Safari.
     30        (+[WebView URLTitleFromPasteboard:]): Changed to call the new function instead
     31        of getting at the global directly.
     32
     33        * WebKit.exp: Add exports of the new functions.
     34
    1352007-08-29  Adele Peterson  <adele@apple.com>
    236
  • trunk/WebKit/Misc/WebNSPasteboardExtras.h

    r21533 r25312  
    11/*
    2  * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3333@class WebHTMLView;
    3434
    35 extern NSString *WebURLPboardType;
    36 extern NSString *WebURLNamePboardType;
     35#ifdef __cplusplus
     36extern "C" {
     37#endif
     38
     39NSString *WebURLPasteboardType(void);
     40NSString *WebURLNamePasteboardType(void);
    3741
    3842@interface NSPasteboard (WebExtras)
     
    8084
    8185@end
     86
     87#ifdef __cplusplus
     88}
     89#endif
  • trunk/WebKit/Misc/WebNSPasteboardExtras.mm

    r24417 r25312  
    4646#import <WebKitSystemInterface.h>
    4747
    48 using namespace WebCore;
    49 
    50 NSString *WebURLPboardType = nil;
    51 NSString *WebURLNamePboardType = nil;
     48// These are needed for compatibility with old versions of Safari. Once we don't need
     49// to support Safari 2 or the first Safari 3 public beta, we can remove them.
     50extern "C" NSString *WebURLPboardType;
     51extern "C" NSString *WebURLNamePboardType;
    5252
    5353@interface NSFilePromiseDragSource : NSObject
     
    5656@end
    5757
    58 @implementation NSPasteboard (WebExtras)
    59 
    60 + (void)initialize
    61 {
    62     // FIXME  The code below addresses 3446192.  It was awaiting a fix for 3446669. Now that bug has been fixed,
    63     // but this code still does not work; UTTypeCopyPreferredTagWithClass returns nil, which caused 4145214. Some
    64     // day we'll need to investigate why this code is still not working.
     58using namespace WebCore;
     59
     60NSString *WebURLPboardType = nil;
     61NSString *WebURLNamePboardType = nil;
     62
     63static void initializePasteboardTypes()
     64{
     65    if (WebURLPboardType)
     66        return;
     67
     68    // FIXME: We'd like to use UTI_PB_API code, but we can't yet. The reasons are in Radar bug 3446192.
    6569#ifdef UTI_PB_API
    6670    CFStringRef osTypeString = UTCreateStringForOSType('url ');
    67     CFStringRef utiTypeString = UTTypeCreatePreferredIdentifierForTag( kUTTagClassOSType, osTypeString, NULL );
    68     WebURLPboardType = (NSString *)UTTypeCopyPreferredTagWithClass( kUTTagClassNSPboardType, utiTypeString );
    69     if (osTypeString != NULL) {
     71    CFStringRef utiTypeString = UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, osTypeString, NULL);
     72    WebURLPboardType = (NSString *)UTTypeCopyPreferredTagWithClass(kUTTagClassNSPboardType, utiTypeString);
     73    if (osTypeString != NULL)
    7074        CFRelease(osTypeString);
    71     }
    72     if (utiTypeString != NULL) {
     75    if (utiTypeString != NULL)
    7376        CFRelease(utiTypeString);
    74     }
    7577   
    7678    osTypeString = UTCreateStringForOSType('urln');
    77     utiTypeString = UTTypeCreatePreferredIdentifierForTag( kUTTagClassOSType, osTypeString, NULL );
    78     WebURLNamePboardType = (NSString *)UTTypeCopyPreferredTagWithClass( kUTTagClassNSPboardType, utiTypeString );
    79     if (osTypeString != NULL) {
     79    utiTypeString = UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, osTypeString, NULL);
     80    WebURLNamePboardType = (NSString *)UTTypeCopyPreferredTagWithClass(kUTTagClassNSPboardType, utiTypeString);
     81    if (osTypeString != NULL)
    8082        CFRelease(osTypeString);
    81     }
    82     if (utiTypeString != NULL) {
     83    if (utiTypeString != NULL)
    8384        CFRelease(utiTypeString);
    84     }
    8585#else
    8686    WebURLPboardType = WKCreateURLPasteboardFlavorTypeName();
     
    8888#endif
    8989}
     90
     91NSString *WebURLPasteboardType()
     92{
     93    initializePasteboardTypes();
     94    return WebURLPboardType;
     95}
     96
     97NSString *WebURLNamePasteboardType()
     98{
     99    initializePasteboardTypes();
     100    return WebURLNamePboardType;
     101}
     102
     103#define WebURLPboardType DO_NOT_USE_WebURLPboardType_IN_THIS_FILE
     104#define WebURLNamePboardType DO_NOT_USE_WebURLNamePboardType_IN_THIS_FILE
     105
     106@implementation NSPasteboard (WebExtras)
    90107
    91108+ (NSArray *)_web_writableTypesForURL
     
    96113            WebURLsWithTitlesPboardType,
    97114            NSURLPboardType,
    98             WebURLPboardType,
    99             WebURLNamePboardType,
     115            WebURLPasteboardType(),
     116            WebURLNamePasteboardType(),
    100117            NSStringPboardType,
    101118            nil];
     
    137154        WebURLsWithTitlesPboardType,
    138155        NSURLPboardType,
    139         WebURLPboardType,
    140         WebURLNamePboardType,
     156        WebURLPasteboardType(),
     157        WebURLNamePasteboardType(),
    141158        NSStringPboardType,
    142159        NSFilenamesPboardType,
     
    183200{
    184201    ASSERT(URL);
    185    
     202
    186203    if ([title length] == 0) {
    187204        title = [[URL path] lastPathComponent];
    188         if ([title length] == 0) {
     205        if ([title length] == 0)
    189206            title = [URL _web_userVisibleString];
    190         }
    191     }
    192    
    193     if ([types containsObject:NSURLPboardType]) {
     207    }
     208   
     209    if ([types containsObject:NSURLPboardType])
    194210        [URL writeToPasteboard:self];
    195     }
    196     if ([types containsObject:WebURLPboardType]) {
    197         [self setString:[URL _web_originalDataAsString] forType:WebURLPboardType];
    198     }
    199     if ([types containsObject:WebURLNamePboardType]) {
    200         [self setString:title forType:WebURLNamePboardType];
    201     }
    202     if ([types containsObject:NSStringPboardType]) {
     211    if ([types containsObject:WebURLPasteboardType()])
     212        [self setString:[URL _web_originalDataAsString] forType:WebURLPasteboardType()];
     213    if ([types containsObject:WebURLNamePasteboardType()])
     214        [self setString:title forType:WebURLNamePasteboardType()];
     215    if ([types containsObject:NSStringPboardType])
    203216        [self setString:[URL _web_userVisibleString] forType:NSStringPboardType];
    204     }
    205     if ([types containsObject:WebURLsWithTitlesPboardType]) {
     217    if ([types containsObject:WebURLsWithTitlesPboardType])
    206218        [WebURLsWithTitles writeURLs:[NSArray arrayWithObject:URL] andTitles:[NSArray arrayWithObject:title] toPasteboard:self];
    207     }
    208219}
    209220
  • trunk/WebKit/WebCoreSupport/WebPasteboardHelper.mm

    r20863 r25312  
    11/*
    2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4040{
    4141    NSURL *URL = [pasteboard _web_bestURL];
    42     if (title)
    43         if (NSString *URLTitleString = [pasteboard stringForType:WebURLNamePboardType])
     42    if (title) {
     43        if (NSString *URLTitleString = [pasteboard stringForType:WebURLNamePasteboardType()])
    4444            *title = URLTitleString;
     45    }
    4546
    4647    return [URL _web_originalDataAsString];
  • trunk/WebKit/WebKit.exp

    r23682 r25312  
    9494_WebScriptErrorDomain
    9595_WebScriptErrorLineNumberKey
     96_WebURLNamePasteboardType
    9697_WebURLNamePboardType
     98_WebURLPasteboardType
    9799_WebURLPboardType
    98100_WebViewDidBeginEditingNotification
  • trunk/WebKit/WebView/WebHTMLView.mm

    r25304 r25312  
    19261926        if ([URLString length] == 0)
    19271927            return nil;
    1928         NSString *URLTitleString = [pasteboard stringForType:WebURLNamePboardType];
     1928        NSString *URLTitleString = [pasteboard stringForType:WebURLNamePasteboardType()];
    19291929        DOMText *text = [document createTextNode:URLTitleString];
    19301930        [anchor setHref:URLString];
  • trunk/WebKit/WebView/WebView.mm

    r25307 r25312  
    16511651+ (void)initialize
    16521652{
    1653     static BOOL tooLate = NO;
    1654     if (!tooLate) {
     1653    static BOOL initialized = NO;
     1654    if (initialized)
     1655        return;
     1656    initialized = YES;
     1657
    16551658#ifdef REMOVE_SAFARI_DOM_TREE_DEBUG_ITEM
    1656         // this prevents open source users from crashing when using the Show DOM Tree menu item in Safari 2
    1657         // FIXME: remove this when we no longer need to support Safari 2
    1658         if ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.Safari"] && [[NSUserDefaults standardUserDefaults] boolForKey:@"IncludeDebugMenu"])
    1659             [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_finishedLaunching) name:NSApplicationDidFinishLaunchingNotification object:NSApp];
     1659    // This prevents open source users from crashing when using the Show DOM Tree menu item in Safari 2.
     1660    // FIXME: remove this when we no longer need to support Safari 2.
     1661    if ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.Safari"] && [[NSUserDefaults standardUserDefaults] boolForKey:@"IncludeDebugMenu"])
     1662        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_finishedLaunching) name:NSApplicationDidFinishLaunchingNotification object:NSApp];
    16601663#endif
    1661         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate) name:NSApplicationWillTerminateNotification object:NSApp];
    1662         tooLate = YES;
    1663     }
     1664
     1665    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate) name:NSApplicationWillTerminateNotification object:NSApp];
     1666
     1667    // Older versions of Safari use the pasteboard types without initializing them.
     1668    // But they create a WebView beforehand, so if we initialize here that should be fine.
     1669    WebURLPasteboardType();
    16641670}
    16651671
     
    17751781+ (NSString *)URLTitleFromPasteboard:(NSPasteboard *)pasteboard
    17761782{
    1777     return [pasteboard stringForType:WebURLNamePboardType];
     1783    return [pasteboard stringForType:WebURLNamePasteboardType()];
    17781784}
    17791785
Note: See TracChangeset for help on using the changeset viewer.