Reviewed by Kevin, Geoff, Brady, and Darin
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Jan 2007 14:20:16 +0000 (14:20 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Jan 2007 14:20:16 +0000 (14:20 +0000)
        - fixed <rdar://problem/4918446> Safari's temp files (PDF's) should be in a sub-folder when calling Preview

        * WebView/WebPDFView.mm:
        (-[WebPDFView _path]):
        use _temporaryPDFDirectoryPath method instead of #defines for hardwiring strings; stop bad practice
        of modifying the const char* returned by fileSystemRepresentation
        (-[WebPDFView _temporaryPDFDirectoryPath]):
        new method, lazily creates and returns a secure temporary directory created with NSTemporaryDirectory()
        and mkdtemp

        * English.lproj/StringsNotToBeLocalized.txt:
        Updated for these and other recent changes

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@19119 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/English.lproj/StringsNotToBeLocalized.txt
WebKit/WebView/WebPDFView.mm

index 168ea79efef2923fa8ac37ac6087b30f22276101..2f015441b0b5bfbb3e93953e2f03fe6c8868d748 100644 (file)
@@ -1,3 +1,20 @@
+2007-01-25  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Kevin, Geoff, Brady, and Darin
+        
+        - fixed <rdar://problem/4918446> Safari's temp files (PDF's) should be in a sub-folder when calling Preview
+        
+        * WebView/WebPDFView.mm:
+        (-[WebPDFView _path]):
+        use _temporaryPDFDirectoryPath method instead of #defines for hardwiring strings; stop bad practice
+        of modifying the const char* returned by fileSystemRepresentation
+        (-[WebPDFView _temporaryPDFDirectoryPath]):
+        new method, lazily creates and returns a secure temporary directory created with NSTemporaryDirectory()
+        and mkdtemp
+
+        * English.lproj/StringsNotToBeLocalized.txt:
+        Updated for these and other recent changes
+
 2007-01-24  Oliver Hunt  <oliver@apple.com>
 
         Build fix 
index 869cef1317e057f0b21259164c11dd427e9a0061..4b67ccc3583457a846dce74fbaea23ecb1328398 100644 (file)
@@ -39,9 +39,7 @@
 "/Volumes"
 "/image.pict"
 "/image.tiff"
-"/tmp/"
 "/tmp/WebKitPlugInStreamXXXXXX"
-"/tmp/XXXXXX-"
 "/tmp/XXXXXX.tiff"
 "0"
 "1"
 "Library/Internet Plug-Ins"
 "Look Up in Dictionary menu title."
 "MenuCommands"
+"MoveBackward"
+"MoveBackwardAndModifySelection"
+"MoveDown"
+"MoveDownAndModifySelection"
+"MoveForward"
+"MoveForwardAndModifySelection"
+"MoveLeft"
+"MoveLeftAndModifySelection"
+"MoveParagraphBackwardAndModifySelection"
+"MoveParagraphForwardAndModifySelection"
+"MoveRight"
+"MoveRightAndModifySelection"
+"MoveToBeginningOfDocument"
+"MoveToBeginningOfDocumentAndModifySelection"
+"MoveToBeginningOfLine"
+"MoveToBeginningOfLineAndModifySelection"
+"MoveToBeginningOfParagraph"
+"MoveToBeginningOfParagraphAndModifySelection"
+"MoveToBeginningOfSentence"
+"MoveToBeginningOfSentenceAndModifySelection"
+"MoveToEndOfDocument"
+"MoveToEndOfDocumentAndModifySelection"
+"MoveToEndOfLine"
+"MoveToEndOfLineAndModifySelection"
+"MoveToEndOfParagraph"
+"MoveToEndOfParagraphAndModifySelection"
+"MoveToEndOfSentence"
+"MoveToEndOfSentenceAndModifySelection"
+"MoveUp"
+"MoveUpAndModifySelection"
+"MoveWordBackward"
+"MoveWordBackwardAndModifySelection"
+"MoveWordForward"
+"MoveWordForwardAndModifySelection"
+"MoveWordLeft"
+"MoveWordLeftAndModifySelection"
+"MoveWordRight"
+"MoveWordRightAndModifySelection"
 "Mozilla/5.0 (Macintosh; U; "
 "NP_GetEntryPoints"
 "NP_Initialize"
 "Search in Google menu title."
 "Search in Spotlight menu title."
 "Times"
+"ToggleBold"
+"ToggleItalic"
+"U+000009"
 "UTF-8"
 "UseBackForwardList"
 "Volumes"
 "WebElementImageAltString"
 "WebElementImageRect"
 "WebElementImageURL"
+"WebElementIsContentEditableKey"
 "WebElementIsSelected"
+"WebElementLinkIsLive"
 "WebElementLinkLabel"
 "WebElementLinkTitle"
 "WebElementLinkURL"
+"WebElementSpellingToolTip"
 "WebElementTargetFrame"
 "WebElementTitle"
 "WebHistoryAllItemsRemovedNotification"
 "WebIconNotificationUserInfoURLKey"
 "WebJavaScriptTextInputPanel"
 "WebKitDeveloperExtras"
-"WebKitDisplayThrottleRunLoopMode"
 "WebKitErrorDomain"
 "WebKitErrorMIMETypeKey"
 "WebKitErrorPlugInNameKey"
 "WebKitHistoryAgeInDaysLimit"
 "WebKitHistoryItemLimit"
 "WebKitOmitPDFSupport"
+"WebKitPDFs-XXXXXX"
 "WebKitScriptDebuggerEnabled"
 "WebLoginWindowDidSwitchFromUserNotification"
 "WebLoginWindowDidSwitchToUserNotification"
 "WebViewDidChangeSelectionNotification"
 "WebViewDidChangeTypingStyleNotification"
 "WebViewDidEndEditingNotification"
-"WebViewEditingContextMenu"
-"WebViewEditingContextMenuOld"
+"XXXXXX-"
 "\"@?"
 "\"\\"
 "\0"
 "\t"
 "\xFF\xD8\xFF\xE0"
 "_DCMDictionaryServiceWindowShow"
-"_DCSDictionaryServiceWindowShow"
+"_DCSShowDictionaryServiceWindow"
 "_top"
 "a"
 "about:"
 "com.apple.Safari"
 "com.apple.WebKit"
 "com.apple.hiview"
+"com.apple.mail"
 "com.apple.quicktime.webplugin"
 "com.apple.universalaccess"
 "com.microsoft.WMP.defaultplugin"
 "html"
 "http"
 "https"
+"image.tiff"
 "image/jpeg"
 "image/pict"
 "image/tiff"
@@ -344,9 +387,10 @@ DefaultDelegates/WebDefaultContextMenuDelegate.mm:"Look Up in Dictionary"
 DefaultDelegates/WebDefaultContextMenuDelegate.mm:"Search in Google"
 DefaultDelegates/WebDefaultContextMenuDelegate.mm:"Search in Spotlight"
 DefaultDelegates/WebScriptDebugServer.m
-History/WebHistoryItem.m:" in \"%@\""
-History/WebHistoryItem.m:"children"
-History/WebHistoryItem.m:"title"
+History/WebHistoryItem.mm:" in \"%@\""
+History/WebHistoryItem.mm:"children"
+History/WebHistoryItem.mm:"title"
+Misc/WebCache.mm
 Misc/WebKitLogging.m
 Misc/WebKitVersionChecks.m
 Misc/WebNSURLExtras.m:"IDNScriptWhiteList"
@@ -359,6 +403,7 @@ Plugins/WebBasePluginPackage.m:"Java Applet Plugin Enabler"
 Plugins/WebBasePluginPackage.m:"name: %@\npath: %@\nmimeTypes:\n%@\npluginDescription:%@"
 Plugins/WebNetscapePluginPackage.m:"RealPlayer Plugin"
 Plugins/WebNetscapePluginPackage.m:"main"
+WebCoreSupport/WebChromeClient.mm
 WebCoreSupport/WebFrameBridge.mm:"height"
 WebCoreSupport/WebFrameBridge.mm:"width"
 WebInspector/WebInspector.m
index da14b5e60eedecdec8d33511abe825303e84e0f1..298146fe1c68b79afd665c2c8aaf62a581edc2e3 100644 (file)
@@ -56,8 +56,6 @@
 using namespace WebCore;
 using namespace EventNames;
 
-#define TEMP_PREFIX "/tmp/XXXXXX-"
-
 #define PDFKitLaunchNotification @"PDFPreviewLaunchPreview"
 
 // QuartzPrivate.h doesn't include the PDFKit private headers, so we can't get at PDFViewPriv.h. (3957971)
@@ -76,6 +74,7 @@ using namespace EventNames;
 - (BOOL)_pointIsInSelection:(NSPoint)point;
 - (void)_receivedPDFKitLaunchNotification:(NSNotification *)notification;
 - (NSAttributedString *)_scaledAttributedString:(NSAttributedString *)unscaledAttributedString;
+- (NSString *)_temporaryPDFDirectoryPath;
 - (void)_trackFirstResponder;
 @end;
 
@@ -1049,22 +1048,31 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
         return path;
     
     NSString *filename = [[dataSource response] suggestedFilename];
-    NSFileManager *manager = [NSFileManager defaultManager];    
+    NSFileManager *manager = [NSFileManager defaultManager]; 
+    NSString *temporaryPDFDirectoryPath = [self _temporaryPDFDirectoryPath];
+    
+    if (!temporaryPDFDirectoryPath) {
+        // This should never happen; if it does we'll fail silently on non-debug builds.
+        ASSERT_NOT_REACHED();
+        return nil;
+    }
     
-    path = [@"/tmp/" stringByAppendingPathComponent:filename];
+    path = [temporaryPDFDirectoryPath stringByAppendingPathComponent:filename];
     if ([manager fileExistsAtPath:path]) {
-        path = [@"" TEMP_PREFIX stringByAppendingString:filename];
-        // FIXME: Bad style to modify the path returned by fileSystemRepresentation!
-        char *cpath = (char *)[path fileSystemRepresentation];
-        int fd = mkstemps(cpath, strlen(cpath) - strlen(TEMP_PREFIX) + 1);
+        NSString *pathTemplatePrefix = [temporaryPDFDirectoryPath stringByAppendingPathComponent:@"XXXXXX-"];
+        NSString *pathTemplate = [pathTemplatePrefix stringByAppendingString:filename];
+        // fileSystemRepresentation returns a const char *; copy it into a char * so we can modify it safely
+        char *cPath = strdup([pathTemplate fileSystemRepresentation]);
+        int fd = mkstemps(cPath, strlen(cPath) - strlen([pathTemplatePrefix fileSystemRepresentation]) + 1);
         if (fd < 0) {
-            // Couldn't create a temporary file! Should never happen.
-            // Do we need an alert here?
+            // Couldn't create a temporary file! Should never happen; if it does we'll fail silently on non-debug builds.
+            ASSERT_NOT_REACHED();
             path = nil;
         } else {
             close(fd);
-            path = [manager stringWithFileSystemRepresentation:cpath length:strlen(cpath)];
+            path = [manager stringWithFileSystemRepresentation:cPath length:strlen(cPath)];
         }
+        free(cPath);
     }
     
     [path retain];
@@ -1119,6 +1127,31 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
     return result;
 }
 
+- (NSString *)_temporaryPDFDirectoryPath
+{
+    // Returns nil if the temporary PDF directory didn't exist and couldn't be created
+    
+    static NSString *_temporaryPDFDirectoryPath = nil;
+    
+    if (!_temporaryPDFDirectoryPath) {
+        NSString *temporaryDirectoryTemplate = [NSTemporaryDirectory() stringByAppendingPathComponent:@"WebKitPDFs-XXXXXX"];
+        char *cTemplate = strdup([temporaryDirectoryTemplate fileSystemRepresentation]);
+        
+        if (!mkdtemp(cTemplate)) {
+            // This should never happen; if it does we'll fail silently on non-debug builds.
+            ASSERT_NOT_REACHED();
+        } else {
+            // cTemplate has now been modified to be the just-created directory name. This directory has 700 permissions,
+            // so only the current user can add to it or view its contents.
+            _temporaryPDFDirectoryPath = [[[NSFileManager defaultManager] stringWithFileSystemRepresentation:cTemplate length:strlen(cTemplate)] retain];
+        }
+        
+        free(cTemplate);
+    }
+    
+    return _temporaryPDFDirectoryPath;
+}
+
 - (void)_trackFirstResponder
 {
     ASSERT([self window]);