[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75

mitz at apple.com mitz at apple.com
Thu Oct 29 20:31:17 UTC 2009


The following commit has been merged in the webkit-1.1 branch:
commit 85c072cc324ba20a988ccba5f813e3720de1e617
Author: mitz at apple.com <mitz at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Sep 21 18:01:10 2009 +0000

    <rdar://problem/4137135> iFrame with PDF not being handled correctly on
    usps.com
    https://bugs.webkit.org/show_bug.cgi?id=4151
    
    Reviewed by Anders Carlsson.
    
    WebKit:
    
    * WebKit.xcodeproj/project.pbxproj: Added WebPDFDocumentExtras.{h,mm}
    and WebJSPDFDoc.{h,mm} and changed WebPDFRepresentation to
    Objective-C++.
    
    WebKit/mac:
    
    * WebView/WebJSPDFDoc.h: Added.
    * WebView/WebJSPDFDoc.mm: Added.
    (jsPDFDocInitialize): Retains the WebDataSource.
    (jsPDFDocFinalize): Releases the WebDataSource.
    (jsPDFDocPrint): Call the WebUIDelegate method -webView:printFrameView:
    with the PDF document's view.
    (makeJSPDFDoc): Makes and returns a JavaScript Doc instance that wraps
    the WebDataSource.
    * WebView/WebPDFDocumentExtras.h: Added.
    * WebView/WebPDFDocumentExtras.mm: Added.
    (appendValuesInPDFNameSubtreeToArray): Traverses a subtree of a PDF name
    tree and adds all values in the subtree to an array.
    (allValuesInPDFNameTree): Returns an array with all of the values in a
    PDF name tree.
    (web_PDFDocumentAllScripts): This is the implementation of -[PDFDocument
    _web_allScripts]. It gets all values in the document-level "JavaScript"
    name tree, which are action dictionaries, and returns an array of the
    actions' scripts.
    (addWebPDFDocumentExtras): Adds the -_web_allScripts method to
    PDFDocument.
    * WebView/WebPDFRepresentation.h:
    * WebView/WebPDFRepresentation.m: Removed.
    * WebView/WebPDFRepresentation.mm: Copied from WebKit/mac/WebView/WebPDFRepresentation.m.
    (+[WebPDFRepresentation initialize]): Added. Calls
    addWebPDFDocumentExtras().
    (-[WebPDFRepresentation finishedLoadingWithDataSource:]): Get the
    scripts from the PDF document, create a JavaScript Doc object for the
    document, and a JavaScript execution context, then execute every script
    in the context, with the Doc object as "this".
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48586 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index a870e74..bf50c9b 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,15 @@
+2009-09-21  Dan Bernstein  <mitz at apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/4137135> iFrame with PDF not being handled correctly on
+        usps.com
+        https://bugs.webkit.org/show_bug.cgi?id=4151
+
+        * WebKit.xcodeproj/project.pbxproj: Added WebPDFDocumentExtras.{h,mm}
+        and WebJSPDFDoc.{h,mm} and changed WebPDFRepresentation to
+        Objective-C++.
+
 2009-09-07  Steve Block  <steveblock at google.com>
 
         Reviewed by Adam Barth.
diff --git a/WebKit/WebKit.xcodeproj/project.pbxproj b/WebKit/WebKit.xcodeproj/project.pbxproj
index 477217e..402c1f6 100644
--- a/WebKit/WebKit.xcodeproj/project.pbxproj
+++ b/WebKit/WebKit.xcodeproj/project.pbxproj
@@ -71,6 +71,10 @@
 		226E9E6A09D0AA8200F3A2BC /* WebNetscapeDeprecatedFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 226E9E6809D0AA8200F3A2BC /* WebNetscapeDeprecatedFunctions.h */; };
 		226E9E6B09D0AA8200F3A2BC /* WebNetscapeDeprecatedFunctions.c in Sources */ = {isa = PBXBuildFile; fileRef = 226E9E6909D0AA8200F3A2BC /* WebNetscapeDeprecatedFunctions.c */; settings = {COMPILER_FLAGS = "-Wno-deprecated-declarations"; }; };
 		22F219CC08D236730030E078 /* WebBackForwardListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 22F219CB08D236730030E078 /* WebBackForwardListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		37B6FB4E1063530C000FDB3B /* WebPDFDocumentExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 37B6FB4C1063530C000FDB3B /* WebPDFDocumentExtras.h */; };
+		37B6FB4F1063530C000FDB3B /* WebPDFDocumentExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37B6FB4D1063530C000FDB3B /* WebPDFDocumentExtras.mm */; };
+		37D1DCA81065928C0068F7EF /* WebJSPDFDoc.h in Headers */ = {isa = PBXBuildFile; fileRef = 37D1DCA61065928C0068F7EF /* WebJSPDFDoc.h */; };
+		37D1DCA91065928C0068F7EF /* WebJSPDFDoc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37D1DCA71065928C0068F7EF /* WebJSPDFDoc.mm */; };
 		41F4484F10338E8C0030E55E /* WebWorkersPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 41F4484D10338E8C0030E55E /* WebWorkersPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		41F4485010338E8C0030E55E /* WebWorkersPrivate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41F4484E10338E8C0030E55E /* WebWorkersPrivate.mm */; };
 		441793A60E34EE150055E1AE /* WebHTMLRepresentationInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 441793A50E34EE150055E1AE /* WebHTMLRepresentationInternal.h */; };
@@ -291,7 +295,7 @@
 		9398111C0824BF01008DF038 /* WebDOMOperations.mm in Sources */ = {isa = PBXBuildFile; fileRef = 846171FA0624AE5B0071A4A3 /* WebDOMOperations.mm */; };
 		9398111D0824BF01008DF038 /* WebArchive.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8373435B0624EE0D00F3B289 /* WebArchive.mm */; };
 		9398111E0824BF01008DF038 /* WebPDFView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E94C3506C0321200A9B09E /* WebPDFView.mm */; };
-		9398111F0824BF01008DF038 /* WebPDFRepresentation.m in Sources */ = {isa = PBXBuildFile; fileRef = 51E94C6906C0347500A9B09E /* WebPDFRepresentation.m */; };
+		9398111F0824BF01008DF038 /* WebPDFRepresentation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E94C6906C0347500A9B09E /* WebPDFRepresentation.mm */; };
 		939811260824BF01008DF038 /* WebPluginContainerCheck.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65E1150407EFFEBF009B8BF7 /* WebPluginContainerCheck.mm */; };
 		939811290824BF01008DF038 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5C2869402846DCD018635CA /* Carbon.framework */; };
 		9398112A0824BF01008DF038 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5C2869502846DCD018635CA /* Cocoa.framework */; };
@@ -409,6 +413,10 @@
 		35081D9502B6D4D80ACA2ACA /* WebHTMLView.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebHTMLView.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		35081D9602B6D4D80ACA2ACA /* WebHTMLViewPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebHTMLViewPrivate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		35081DAE02B6D4F50ACA2ACA /* WebDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebDocument.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+		37B6FB4C1063530C000FDB3B /* WebPDFDocumentExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPDFDocumentExtras.h; sourceTree = "<group>"; };
+		37B6FB4D1063530C000FDB3B /* WebPDFDocumentExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPDFDocumentExtras.mm; sourceTree = "<group>"; };
+		37D1DCA61065928C0068F7EF /* WebJSPDFDoc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebJSPDFDoc.h; sourceTree = "<group>"; };
+		37D1DCA71065928C0068F7EF /* WebJSPDFDoc.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = WebJSPDFDoc.mm; sourceTree = "<group>"; };
 		3944606B020F50ED0ECA1767 /* WebDynamicScrollBarsView.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebDynamicScrollBarsView.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		3944606C020F50ED0ECA1767 /* WebDynamicScrollBarsView.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; indentWidth = 4; path = WebDynamicScrollBarsView.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		3944606E020F50ED0ECA1767 /* WebPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebPreferences.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
@@ -464,7 +472,7 @@
 		51E94C3406C0321200A9B09E /* WebPDFView.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebPDFView.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		51E94C3506C0321200A9B09E /* WebPDFView.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPDFView.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		51E94C6806C0347500A9B09E /* WebPDFRepresentation.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebPDFRepresentation.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
-		51E94C6906C0347500A9B09E /* WebPDFRepresentation.m */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebPDFRepresentation.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+		51E94C6906C0347500A9B09E /* WebPDFRepresentation.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPDFRepresentation.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		51FDC4D20B0AF5C100F84EB3 /* WebHistoryItemPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebHistoryItemPrivate.h; sourceTree = "<group>"; };
 		5241ADF30B1BC48A004012BD /* WebCache.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebCache.h; sourceTree = "<group>"; };
 		5241ADF40B1BC48A004012BD /* WebCache.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCache.mm; sourceTree = "<group>"; };
@@ -960,8 +968,12 @@
 		51E94C0706C02CA300A9B09E /* PDF */ = {
 			isa = PBXGroup;
 			children = (
+				37D1DCA61065928C0068F7EF /* WebJSPDFDoc.h */,
+				37D1DCA71065928C0068F7EF /* WebJSPDFDoc.mm */,
+				37B6FB4C1063530C000FDB3B /* WebPDFDocumentExtras.h */,
+				37B6FB4D1063530C000FDB3B /* WebPDFDocumentExtras.mm */,
 				51E94C6806C0347500A9B09E /* WebPDFRepresentation.h */,
-				51E94C6906C0347500A9B09E /* WebPDFRepresentation.m */,
+				51E94C6906C0347500A9B09E /* WebPDFRepresentation.mm */,
 				51E94C3406C0321200A9B09E /* WebPDFView.h */,
 				51E94C3506C0321200A9B09E /* WebPDFView.mm */,
 			);
@@ -1453,6 +1465,8 @@
 				939810710824BF01008DF038 /* WebViewPrivate.h in Headers */,
 				41F4484F10338E8C0030E55E /* WebWorkersPrivate.h in Headers */,
 				59C77F4B105471E700506104 /* WebGeolocationMockPrivate.h in Headers */,
+				37B6FB4E1063530C000FDB3B /* WebPDFDocumentExtras.h in Headers */,
+				37D1DCA81065928C0068F7EF /* WebJSPDFDoc.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -1759,7 +1773,7 @@
 				939810D90824BF01008DF038 /* WebNullPluginView.mm in Sources */,
 				939810D00824BF01008DF038 /* WebPanelAuthenticationHandler.m in Sources */,
 				A7D3C5BD0B5773C5002CA450 /* WebPasteboardHelper.mm in Sources */,
-				9398111F0824BF01008DF038 /* WebPDFRepresentation.m in Sources */,
+				9398111F0824BF01008DF038 /* WebPDFRepresentation.mm in Sources */,
 				9398111E0824BF01008DF038 /* WebPDFView.mm in Sources */,
 				939811260824BF01008DF038 /* WebPluginContainerCheck.mm in Sources */,
 				939810DA0824BF01008DF038 /* WebPluginController.mm in Sources */,
@@ -1785,6 +1799,8 @@
 				939810E80824BF01008DF038 /* WebViewFactory.mm in Sources */,
 				41F4485010338E8C0030E55E /* WebWorkersPrivate.mm in Sources */,
 				59C77F3510545F7E00506104 /* WebGeolocationMock.mm in Sources */,
+				37B6FB4F1063530C000FDB3B /* WebPDFDocumentExtras.mm in Sources */,
+				37D1DCA91065928C0068F7EF /* WebJSPDFDoc.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/WebKit/mac/ChangeLog b/WebKit/mac/ChangeLog
index 3bb926f..c55079b 100644
--- a/WebKit/mac/ChangeLog
+++ b/WebKit/mac/ChangeLog
@@ -1,3 +1,41 @@
+2009-09-21  Dan Bernstein  <mitz at apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        <rdar://problem/4137135> iFrame with PDF not being handled correctly on
+        usps.com
+        https://bugs.webkit.org/show_bug.cgi?id=4151
+
+        * WebView/WebJSPDFDoc.h: Added.
+        * WebView/WebJSPDFDoc.mm: Added.
+        (jsPDFDocInitialize): Retains the WebDataSource.
+        (jsPDFDocFinalize): Releases the WebDataSource.
+        (jsPDFDocPrint): Call the WebUIDelegate method -webView:printFrameView:
+        with the PDF document's view.
+        (makeJSPDFDoc): Makes and returns a JavaScript Doc instance that wraps
+        the WebDataSource.
+        * WebView/WebPDFDocumentExtras.h: Added.
+        * WebView/WebPDFDocumentExtras.mm: Added.
+        (appendValuesInPDFNameSubtreeToArray): Traverses a subtree of a PDF name
+        tree and adds all values in the subtree to an array.
+        (allValuesInPDFNameTree): Returns an array with all of the values in a
+        PDF name tree.
+        (web_PDFDocumentAllScripts): This is the implementation of -[PDFDocument
+        _web_allScripts]. It gets all values in the document-level "JavaScript"
+        name tree, which are action dictionaries, and returns an array of the
+        actions' scripts.
+        (addWebPDFDocumentExtras): Adds the -_web_allScripts method to
+        PDFDocument.
+        * WebView/WebPDFRepresentation.h:
+        * WebView/WebPDFRepresentation.m: Removed.
+        * WebView/WebPDFRepresentation.mm: Copied from WebKit/mac/WebView/WebPDFRepresentation.m.
+        (+[WebPDFRepresentation initialize]): Added. Calls
+        addWebPDFDocumentExtras().
+        (-[WebPDFRepresentation finishedLoadingWithDataSource:]): Get the
+        scripts from the PDF document, create a JavaScript Doc object for the
+        document, and a JavaScript execution context, then execute every script
+        in the context, with the Doc object as "this".
+
 2009-09-17  Simon Fraser  <simon.fraser at apple.com>
 
         Reviewed by Dave Hyatt.
diff --git a/WebKit/mac/WebView/WebJSPDFDoc.h b/WebKit/mac/WebView/WebJSPDFDoc.h
new file mode 100644
index 0000000..d3e756c
--- /dev/null
+++ b/WebKit/mac/WebView/WebJSPDFDoc.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2009 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 <JavaScriptCore/JSBase.h>
+
+ at class WebDataSource;
+
+JSObjectRef makeJSPDFDoc(JSContextRef, WebDataSource *);
diff --git a/WebKit/mac/WebView/WebJSPDFDoc.mm b/WebKit/mac/WebView/WebJSPDFDoc.mm
new file mode 100644
index 0000000..24169fe
--- /dev/null
+++ b/WebKit/mac/WebView/WebJSPDFDoc.mm
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2009 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 "WebJSPDFDoc.h"
+
+#import "WebDataSource.h"
+#import "WebDelegateImplementationCaching.h"
+#import "WebFrame.h"
+#import "WebView.h"
+#import <JavaScriptCore/JSObjectRef.h>
+
+static void jsPDFDocInitialize(JSContextRef ctx, JSObjectRef object)
+{
+    WebDataSource *dataSource = (WebDataSource *)JSObjectGetPrivate(object);
+    CFRetain(dataSource);
+}
+
+static void jsPDFDocFinalize(JSObjectRef object)
+{
+    WebDataSource *dataSource = (WebDataSource *)JSObjectGetPrivate(object);
+    CFRelease(dataSource);
+}
+
+static JSValueRef jsPDFDocPrint(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    WebDataSource *dataSource = (WebDataSource *)JSObjectGetPrivate(thisObject);
+
+    WebView *webView = [[dataSource webFrame] webView];
+    CallUIDelegate(webView, @selector(webView:printFrameView:), [[dataSource webFrame] frameView]);
+
+    return JSValueMakeUndefined(ctx);
+}
+
+static JSStaticFunction jsPDFDocStaticFunctions[] = {
+    { "print", jsPDFDocPrint, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+    { 0, 0, 0 },
+};
+
+static JSClassDefinition jsPDFDocClassDefinition = {
+    0,
+    kJSClassAttributeNone,
+    "Doc",
+    0,
+    0,
+    jsPDFDocStaticFunctions,
+    jsPDFDocInitialize, jsPDFDocFinalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+JSObjectRef makeJSPDFDoc(JSContextRef ctx, WebDataSource *dataSource)
+{
+    static JSClassRef jsPDFDocClass = JSClassCreate(&jsPDFDocClassDefinition);
+
+    return JSObjectMake(ctx, jsPDFDocClass, dataSource);
+}
diff --git a/WebKit/mac/WebView/WebPDFDocumentExtras.h b/WebKit/mac/WebView/WebPDFDocumentExtras.h
new file mode 100644
index 0000000..5a33ccf
--- /dev/null
+++ b/WebKit/mac/WebView/WebPDFDocumentExtras.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2009 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 <PDFKit/PDFDocument.h>
+
+ at interface PDFDocument (WebPDFDocumentExtras)
+- (NSArray *)_web_allScripts;
+ at end
+
+void addWebPDFDocumentExtras(Class);
diff --git a/WebKit/mac/WebView/WebPDFDocumentExtras.mm b/WebKit/mac/WebView/WebPDFDocumentExtras.mm
new file mode 100644
index 0000000..0a1cdaf
--- /dev/null
+++ b/WebKit/mac/WebView/WebPDFDocumentExtras.mm
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2009 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 "WebPDFDocumentExtras.h"
+
+#import <JavaScriptCore/RetainPtr.h>
+#import <PDFKit/PDFKit.h>
+#import <objc/objc-runtime.h>
+
+static void appendValuesInPDFNameSubtreeToArray(CGPDFDictionaryRef subtree, NSMutableArray *values)
+{
+    CGPDFArrayRef names;
+    if (CGPDFDictionaryGetArray(subtree, "Names", &names)) {
+        size_t nameCount = CGPDFArrayGetCount(names) / 2;
+        for (size_t i = 0; i < nameCount; ++i) {
+            CGPDFObjectRef object;
+            CGPDFArrayGetObject(names, 2 * i + 1, &object);
+            [values addObject:(id)object];
+        }
+        return;
+    }
+
+    CGPDFArrayRef kids;
+    if (!CGPDFDictionaryGetArray(subtree, "Kids", &kids))
+        return;
+
+    size_t kidCount = CGPDFArrayGetCount(kids);
+    for (size_t i = 0; i < kidCount; ++i) {
+        CGPDFDictionaryRef kid;
+        if (!CGPDFArrayGetDictionary(kids, i, &kid))
+            continue;
+        appendValuesInPDFNameSubtreeToArray(kid, values);
+    }
+}
+
+static NSArray *allValuesInPDFNameTree(CGPDFDictionaryRef tree)
+{
+    NSMutableArray *allValues = [[NSMutableArray alloc] init];
+    appendValuesInPDFNameSubtreeToArray(tree, allValues);
+    return [allValues autorelease];
+}
+
+static NSArray *web_PDFDocumentAllScripts(id self, SEL _cmd)
+{
+    NSMutableArray *scripts = [NSMutableArray array];
+    CGPDFDocumentRef pdfDocument = [self documentRef];
+    if (!pdfDocument)
+        return scripts;
+
+    CGPDFDictionaryRef pdfCatalog = CGPDFDocumentGetCatalog(pdfDocument);
+    if (!pdfCatalog)
+        return scripts;
+
+    // Get the dictionary of all document-level name trees.
+    CGPDFDictionaryRef namesDictionary;
+    if (!CGPDFDictionaryGetDictionary(pdfCatalog, "Names", &namesDictionary))
+        return scripts;
+
+    // Get the document-level "JavaScript" name tree.
+    CGPDFDictionaryRef javaScriptNameTree;
+    if (!CGPDFDictionaryGetDictionary(namesDictionary, "JavaScript", &javaScriptNameTree))
+        return scripts;
+
+    // The names are aribtrary. We are only interested in the values.
+    NSArray *objects = allValuesInPDFNameTree(javaScriptNameTree);
+    NSUInteger objectCount = [objects count];
+
+    for (NSUInteger i = 0; i < objectCount; ++i) {
+        CGPDFDictionaryRef javaScriptAction;
+        if (!CGPDFObjectGetValue(reinterpret_cast<CGPDFObjectRef>([objects objectAtIndex:i]), kCGPDFObjectTypeDictionary, &javaScriptAction))
+            continue;
+
+        // A JavaScript action must have an action type of "JavaScript".
+        const char* actionType;
+        if (!CGPDFDictionaryGetName(javaScriptAction, "S", &actionType) || strcmp(actionType, "JavaScript"))
+            continue;
+
+        const UInt8* bytes = 0;
+        CFIndex length;
+        CGPDFStreamRef stream;
+        CGPDFStringRef string;
+        RetainPtr<CFDataRef> data;
+        if (CGPDFDictionaryGetStream(javaScriptAction, "JS", &stream)) {
+            CGPDFDataFormat format;
+            data.adoptCF(CGPDFStreamCopyData(stream, &format));
+            bytes = CFDataGetBytePtr(data.get());
+            length = CFDataGetLength(data.get());
+        } else if (CGPDFDictionaryGetString(javaScriptAction, "JS", &string)) {
+            bytes = CGPDFStringGetBytePtr(string);
+            length = CGPDFStringGetLength(string);
+        }
+        if (!bytes)
+            continue;
+
+        NSStringEncoding encoding = (length > 1 && bytes[0] == 0xFE && bytes[1] == 0xFF) ? NSUTF16StringEncoding : NSUTF8StringEncoding;
+        NSString *script = [[NSString alloc] initWithBytes:bytes length:length encoding:encoding];
+        [scripts addObject:script];
+        [script release];
+    }
+
+    return scripts;
+}
+
+void addWebPDFDocumentExtras(Class pdfDocumentClass)
+{
+#ifndef BUILDING_ON_TIGER
+    class_addMethod(pdfDocumentClass, @selector(_web_allScripts), (IMP)web_PDFDocumentAllScripts, "@@:");
+#else
+    struct objc_method_list methodList = { 0, 1, { @selector(_web_allScripts), (IMP)web_PDFDocumentAllScripts, "@@:" } };
+    class_addMethods(pdfDocumentClass, &methodList);
+#endif
+}
diff --git a/WebKit/mac/WebView/WebPDFRepresentation.h b/WebKit/mac/WebView/WebPDFRepresentation.h
index 6b60d4c..be40ae1 100644
--- a/WebKit/mac/WebView/WebPDFRepresentation.h
+++ b/WebKit/mac/WebView/WebPDFRepresentation.h
@@ -26,7 +26,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#import <Foundation/Foundation.h>
+#import "WebDocument.h"
 
 @protocol WebDocumentRepresentation;
 
diff --git a/WebKit/mac/WebView/WebPDFRepresentation.m b/WebKit/mac/WebView/WebPDFRepresentation.m
deleted file mode 100644
index 7eae380..0000000
--- a/WebKit/mac/WebView/WebPDFRepresentation.m
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 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/WebDataSourcePrivate.h>
-#import <WebKit/WebFrame.h>
-#import <WebKit/WebFrameView.h>
-#import <WebKit/WebNSObjectExtras.h>
-#import <WebKit/WebPDFRepresentation.h>
-#import <WebKit/WebPDFView.h>
-#import <wtf/Assertions.h>
-
-#import <PDFKit/PDFDocument.h>
-
- at implementation WebPDFRepresentation
-
-+ (NSArray *)postScriptMIMETypes
-{
-    return [NSArray arrayWithObjects:
-        @"application/postscript",
-        nil];
-}
-
-+ (NSArray *)supportedMIMETypes
-{
-    return [[[self class] postScriptMIMETypes] arrayByAddingObjectsFromArray:
-        [NSArray arrayWithObjects:
-            @"text/pdf",
-            @"application/pdf",
-            nil]];
-}
-
-+ (Class)PDFDocumentClass
-{
-    static Class PDFDocumentClass = nil;
-    if (PDFDocumentClass == nil) {
-        PDFDocumentClass = [[WebPDFView PDFKitBundle] classNamed:@"PDFDocument"];
-        if (PDFDocumentClass == nil) {
-            LOG_ERROR("Couldn't find PDFDocument class in PDFKit.framework");
-        }
-    }
-    return PDFDocumentClass;
-}
-
-- (void)setDataSource:(WebDataSource *)dataSource;
-{
-}
-
-- (void)receivedData:(NSData *)data withDataSource:(WebDataSource *)dataSource;
-{
-}
-
-- (void)receivedError:(NSError *)error withDataSource:(WebDataSource *)dataSource;
-{
-}
-
-- (NSData *)convertPostScriptDataSourceToPDF:(NSData *)data
-{
-    // Convert PostScript to PDF using Quartz 2D API
-    // http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_ps_convert/chapter_16_section_1.html
-
-    CGPSConverterCallbacks callbacks = { 0, 0, 0, 0, 0, 0, 0, 0 };    
-    CGPSConverterRef converter = CGPSConverterCreate(0, &callbacks, 0);
-    ASSERT(converter);
-
-    CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data);
-    ASSERT(provider);
-
-    CFMutableDataRef result = CFDataCreateMutable(kCFAllocatorDefault, 0);
-    ASSERT(result);
-
-    CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData(result);
-    ASSERT(consumer);
-
-    // Error handled by detecting zero-length 'result' in caller
-    CGPSConverterConvert(converter, provider, consumer, 0);
-
-    CFRelease(converter);
-    CFRelease(provider);
-    CFRelease(consumer);
-
-    return WebCFAutorelease(result);
-}
-
-- (void)finishedLoadingWithDataSource:(WebDataSource *)dataSource
-{
-    NSData *data = [dataSource data];
-
-    NSArray *postScriptMIMETypes = [[self class] postScriptMIMETypes];
-    NSString *mimeType = [dataSource _responseMIMEType];
-    if ([postScriptMIMETypes containsObject:mimeType]) {
-        data = [self convertPostScriptDataSourceToPDF:data];
-        if ([data length] == 0)
-            return;
-    }
-
-    WebPDFView *view = (WebPDFView *)[[[dataSource webFrame] frameView] documentView];
-    PDFDocument *doc = [[[[self class] PDFDocumentClass] alloc] initWithData:data];
-    [view setPDFDocument:doc];
-    [doc release];
-}
-
-
-- (BOOL)canProvideDocumentSource
-{
-    return NO;
-}
-
-
-- (NSString *)documentSource
-{
-    return nil;
-}
-
-
-- (NSString *)title
-{
-    return nil;
-}
-
- at end
diff --git a/WebKit/mac/WebView/WebPDFRepresentation.mm b/WebKit/mac/WebView/WebPDFRepresentation.mm
new file mode 100644
index 0000000..df8ea9c
--- /dev/null
+++ b/WebKit/mac/WebView/WebPDFRepresentation.mm
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2005, 2006 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 "WebPDFRepresentation.h"
+
+#import "WebDataSourcePrivate.h"
+#import "WebFrame.h"
+#import "WebJSPDFDoc.h"
+#import "WebNSObjectExtras.h"
+#import "WebPDFDocumentExtras.h"
+#import "WebPDFView.h"
+#import <JavaScriptCore/Assertions.h>
+#import <JavaScriptCore/JSContextRef.h>
+#import <JavaScriptCore/JSStringRef.h>
+#import <JavaScriptCore/JSStringRefCF.h>
+
+ at implementation WebPDFRepresentation
+
++ (NSArray *)postScriptMIMETypes
+{
+    return [NSArray arrayWithObjects:
+        @"application/postscript",
+        nil];
+}
+
++ (NSArray *)supportedMIMETypes
+{
+    return [[[self class] postScriptMIMETypes] arrayByAddingObjectsFromArray:
+        [NSArray arrayWithObjects:
+            @"text/pdf",
+            @"application/pdf",
+            nil]];
+}
+
++ (Class)PDFDocumentClass
+{
+    static Class PDFDocumentClass = nil;
+    if (PDFDocumentClass == nil) {
+        PDFDocumentClass = [[WebPDFView PDFKitBundle] classNamed:@"PDFDocument"];
+        if (PDFDocumentClass == nil) {
+            LOG_ERROR("Couldn't find PDFDocument class in PDFKit.framework");
+        }
+    }
+    return PDFDocumentClass;
+}
+
++ (void)initialize
+{
+    if (self != [WebPDFRepresentation class])
+        return;
+
+    Class pdfDocumentClass = [self PDFDocumentClass];
+    if (pdfDocumentClass)
+        addWebPDFDocumentExtras(pdfDocumentClass);
+}
+
+- (void)setDataSource:(WebDataSource *)dataSource;
+{
+}
+
+- (void)receivedData:(NSData *)data withDataSource:(WebDataSource *)dataSource;
+{
+}
+
+- (void)receivedError:(NSError *)error withDataSource:(WebDataSource *)dataSource;
+{
+}
+
+- (NSData *)convertPostScriptDataSourceToPDF:(NSData *)data
+{
+    // Convert PostScript to PDF using Quartz 2D API
+    // http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_ps_convert/chapter_16_section_1.html
+
+    CGPSConverterCallbacks callbacks = { 0, 0, 0, 0, 0, 0, 0, 0 };    
+    CGPSConverterRef converter = CGPSConverterCreate(0, &callbacks, 0);
+    ASSERT(converter);
+
+    CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data);
+    ASSERT(provider);
+
+    CFMutableDataRef result = CFDataCreateMutable(kCFAllocatorDefault, 0);
+    ASSERT(result);
+
+    CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData(result);
+    ASSERT(consumer);
+
+    // Error handled by detecting zero-length 'result' in caller
+    CGPSConverterConvert(converter, provider, consumer, 0);
+
+    CFRelease(converter);
+    CFRelease(provider);
+    CFRelease(consumer);
+
+    return WebCFAutorelease(result);
+}
+
+- (void)finishedLoadingWithDataSource:(WebDataSource *)dataSource
+{
+    NSData *data = [dataSource data];
+
+    NSArray *postScriptMIMETypes = [[self class] postScriptMIMETypes];
+    NSString *mimeType = [dataSource _responseMIMEType];
+    if ([postScriptMIMETypes containsObject:mimeType]) {
+        data = [self convertPostScriptDataSourceToPDF:data];
+        if ([data length] == 0)
+            return;
+    }
+
+    WebPDFView *view = (WebPDFView *)[[[dataSource webFrame] frameView] documentView];
+    PDFDocument *doc = [[[[self class] PDFDocumentClass] alloc] initWithData:data];
+    [view setPDFDocument:doc];
+
+    NSArray *scripts = [doc _web_allScripts];
+    [doc release];
+    doc = nil;
+
+    NSUInteger scriptCount = [scripts count];
+    if (!scriptCount)
+        return;
+
+    JSGlobalContextRef ctx = JSGlobalContextCreate(0);
+    JSObjectRef jsPDFDoc = makeJSPDFDoc(ctx, dataSource);
+
+    for (NSUInteger i = 0; i < scriptCount; ++i) {
+        JSStringRef script = JSStringCreateWithCFString((CFStringRef)[scripts objectAtIndex:i]);
+        JSEvaluateScript(ctx, script, jsPDFDoc, 0, 0, 0);
+        JSStringRelease(script);
+    }
+
+    JSGlobalContextRelease(ctx);
+}
+
+- (BOOL)canProvideDocumentSource
+{
+    return NO;
+}
+
+
+- (NSString *)documentSource
+{
+    return nil;
+}
+
+
+- (NSString *)title
+{
+    return nil;
+}
+
+ at end

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list