+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
"/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"
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"
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
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)
- (BOOL)_pointIsInSelection:(NSPoint)point;
- (void)_receivedPDFKitLaunchNotification:(NSNotification *)notification;
- (NSAttributedString *)_scaledAttributedString:(NSAttributedString *)unscaledAttributedString;
+- (NSString *)_temporaryPDFDirectoryPath;
- (void)_trackFirstResponder;
@end;
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];
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]);