Changeset 48586 in webkit


Ignore:
Timestamp:
Sep 21, 2009, 11:01:10 AM (15 years ago)
Author:
mitz@apple.com
Message:

<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".

Location:
trunk/WebKit
Files:
4 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/ChangeLog

    r48144 r48586  
     12009-09-21  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        <rdar://problem/4137135> iFrame with PDF not being handled correctly on
     6        usps.com
     7        https://bugs.webkit.org/show_bug.cgi?id=4151
     8
     9        * WebKit.xcodeproj/project.pbxproj: Added WebPDFDocumentExtras.{h,mm}
     10        and WebJSPDFDoc.{h,mm} and changed WebPDFRepresentation to
     11        Objective-C++.
     12
    1132009-09-07  Steve Block  <steveblock@google.com>
    214
  • trunk/WebKit/WebKit.xcodeproj/project.pbxproj

    r48144 r48586  
    7272                226E9E6B09D0AA8200F3A2BC /* WebNetscapeDeprecatedFunctions.c in Sources */ = {isa = PBXBuildFile; fileRef = 226E9E6909D0AA8200F3A2BC /* WebNetscapeDeprecatedFunctions.c */; settings = {COMPILER_FLAGS = "-Wno-deprecated-declarations"; }; };
    7373                22F219CC08D236730030E078 /* WebBackForwardListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 22F219CB08D236730030E078 /* WebBackForwardListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
     74                37B6FB4E1063530C000FDB3B /* WebPDFDocumentExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 37B6FB4C1063530C000FDB3B /* WebPDFDocumentExtras.h */; };
     75                37B6FB4F1063530C000FDB3B /* WebPDFDocumentExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37B6FB4D1063530C000FDB3B /* WebPDFDocumentExtras.mm */; };
     76                37D1DCA81065928C0068F7EF /* WebJSPDFDoc.h in Headers */ = {isa = PBXBuildFile; fileRef = 37D1DCA61065928C0068F7EF /* WebJSPDFDoc.h */; };
     77                37D1DCA91065928C0068F7EF /* WebJSPDFDoc.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37D1DCA71065928C0068F7EF /* WebJSPDFDoc.mm */; };
    7478                41F4484F10338E8C0030E55E /* WebWorkersPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 41F4484D10338E8C0030E55E /* WebWorkersPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
    7579                41F4485010338E8C0030E55E /* WebWorkersPrivate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41F4484E10338E8C0030E55E /* WebWorkersPrivate.mm */; };
     
    292296                9398111D0824BF01008DF038 /* WebArchive.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8373435B0624EE0D00F3B289 /* WebArchive.mm */; };
    293297                9398111E0824BF01008DF038 /* WebPDFView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E94C3506C0321200A9B09E /* WebPDFView.mm */; };
    294                 9398111F0824BF01008DF038 /* WebPDFRepresentation.m in Sources */ = {isa = PBXBuildFile; fileRef = 51E94C6906C0347500A9B09E /* WebPDFRepresentation.m */; };
     298                9398111F0824BF01008DF038 /* WebPDFRepresentation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E94C6906C0347500A9B09E /* WebPDFRepresentation.mm */; };
    295299                939811260824BF01008DF038 /* WebPluginContainerCheck.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65E1150407EFFEBF009B8BF7 /* WebPluginContainerCheck.mm */; };
    296300                939811290824BF01008DF038 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5C2869402846DCD018635CA /* Carbon.framework */; };
     
    410414                35081D9602B6D4D80ACA2ACA /* WebHTMLViewPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebHTMLViewPrivate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    411415                35081DAE02B6D4F50ACA2ACA /* WebDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebDocument.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
     416                37B6FB4C1063530C000FDB3B /* WebPDFDocumentExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPDFDocumentExtras.h; sourceTree = "<group>"; };
     417                37B6FB4D1063530C000FDB3B /* WebPDFDocumentExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPDFDocumentExtras.mm; sourceTree = "<group>"; };
     418                37D1DCA61065928C0068F7EF /* WebJSPDFDoc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebJSPDFDoc.h; sourceTree = "<group>"; };
     419                37D1DCA71065928C0068F7EF /* WebJSPDFDoc.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = WebJSPDFDoc.mm; sourceTree = "<group>"; };
    412420                3944606B020F50ED0ECA1767 /* WebDynamicScrollBarsView.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebDynamicScrollBarsView.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    413421                3944606C020F50ED0ECA1767 /* WebDynamicScrollBarsView.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; indentWidth = 4; path = WebDynamicScrollBarsView.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
     
    465473                51E94C3506C0321200A9B09E /* WebPDFView.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPDFView.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    466474                51E94C6806C0347500A9B09E /* WebPDFRepresentation.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebPDFRepresentation.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    467                 51E94C6906C0347500A9B09E /* WebPDFRepresentation.m */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebPDFRepresentation.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
     475                51E94C6906C0347500A9B09E /* WebPDFRepresentation.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPDFRepresentation.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    468476                51FDC4D20B0AF5C100F84EB3 /* WebHistoryItemPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebHistoryItemPrivate.h; sourceTree = "<group>"; };
    469477                5241ADF30B1BC48A004012BD /* WebCache.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebCache.h; sourceTree = "<group>"; };
     
    961969                        isa = PBXGroup;
    962970                        children = (
     971                                37D1DCA61065928C0068F7EF /* WebJSPDFDoc.h */,
     972                                37D1DCA71065928C0068F7EF /* WebJSPDFDoc.mm */,
     973                                37B6FB4C1063530C000FDB3B /* WebPDFDocumentExtras.h */,
     974                                37B6FB4D1063530C000FDB3B /* WebPDFDocumentExtras.mm */,
    963975                                51E94C6806C0347500A9B09E /* WebPDFRepresentation.h */,
    964                                 51E94C6906C0347500A9B09E /* WebPDFRepresentation.m */,
     976                                51E94C6906C0347500A9B09E /* WebPDFRepresentation.mm */,
    965977                                51E94C3406C0321200A9B09E /* WebPDFView.h */,
    966978                                51E94C3506C0321200A9B09E /* WebPDFView.mm */,
     
    14541466                                41F4484F10338E8C0030E55E /* WebWorkersPrivate.h in Headers */,
    14551467                                59C77F4B105471E700506104 /* WebGeolocationMockPrivate.h in Headers */,
     1468                                37B6FB4E1063530C000FDB3B /* WebPDFDocumentExtras.h in Headers */,
     1469                                37D1DCA81065928C0068F7EF /* WebJSPDFDoc.h in Headers */,
    14561470                        );
    14571471                        runOnlyForDeploymentPostprocessing = 0;
     
    17601774                                939810D00824BF01008DF038 /* WebPanelAuthenticationHandler.m in Sources */,
    17611775                                A7D3C5BD0B5773C5002CA450 /* WebPasteboardHelper.mm in Sources */,
    1762                                 9398111F0824BF01008DF038 /* WebPDFRepresentation.m in Sources */,
     1776                                9398111F0824BF01008DF038 /* WebPDFRepresentation.mm in Sources */,
    17631777                                9398111E0824BF01008DF038 /* WebPDFView.mm in Sources */,
    17641778                                939811260824BF01008DF038 /* WebPluginContainerCheck.mm in Sources */,
     
    17861800                                41F4485010338E8C0030E55E /* WebWorkersPrivate.mm in Sources */,
    17871801                                59C77F3510545F7E00506104 /* WebGeolocationMock.mm in Sources */,
     1802                                37B6FB4F1063530C000FDB3B /* WebPDFDocumentExtras.mm in Sources */,
     1803                                37D1DCA91065928C0068F7EF /* WebJSPDFDoc.mm in Sources */,
    17881804                        );
    17891805                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebKit/mac/ChangeLog

    r48526 r48586  
     12009-09-21  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        <rdar://problem/4137135> iFrame with PDF not being handled correctly on
     6        usps.com
     7        https://bugs.webkit.org/show_bug.cgi?id=4151
     8
     9        * WebView/WebJSPDFDoc.h: Added.
     10        * WebView/WebJSPDFDoc.mm: Added.
     11        (jsPDFDocInitialize): Retains the WebDataSource.
     12        (jsPDFDocFinalize): Releases the WebDataSource.
     13        (jsPDFDocPrint): Call the WebUIDelegate method -webView:printFrameView:
     14        with the PDF document's view.
     15        (makeJSPDFDoc): Makes and returns a JavaScript Doc instance that wraps
     16        the WebDataSource.
     17        * WebView/WebPDFDocumentExtras.h: Added.
     18        * WebView/WebPDFDocumentExtras.mm: Added.
     19        (appendValuesInPDFNameSubtreeToArray): Traverses a subtree of a PDF name
     20        tree and adds all values in the subtree to an array.
     21        (allValuesInPDFNameTree): Returns an array with all of the values in a
     22        PDF name tree.
     23        (web_PDFDocumentAllScripts): This is the implementation of -[PDFDocument
     24        _web_allScripts]. It gets all values in the document-level "JavaScript"
     25        name tree, which are action dictionaries, and returns an array of the
     26        actions' scripts.
     27        (addWebPDFDocumentExtras): Adds the -_web_allScripts method to
     28        PDFDocument.
     29        * WebView/WebPDFRepresentation.h:
     30        * WebView/WebPDFRepresentation.m: Removed.
     31        * WebView/WebPDFRepresentation.mm: Copied from WebKit/mac/WebView/WebPDFRepresentation.m.
     32        (+[WebPDFRepresentation initialize]): Added. Calls
     33        addWebPDFDocumentExtras().
     34        (-[WebPDFRepresentation finishedLoadingWithDataSource:]): Get the
     35        scripts from the PDF document, create a JavaScript Doc object for the
     36        document, and a JavaScript execution context, then execute every script
     37        in the context, with the Doc object as "this".
     38
    1392009-09-17  Simon Fraser  <simon.fraser@apple.com>
    240
  • trunk/WebKit/mac/WebView/WebPDFRepresentation.h

    r11962 r48586  
    2727 */
    2828
    29 #import <Foundation/Foundation.h>
     29#import "WebDocument.h"
    3030
    3131@protocol WebDocumentRepresentation;
  • trunk/WebKit/mac/WebView/WebPDFRepresentation.mm

    r48585 r48586  
    2727 */
    2828
    29 #import <WebKit/WebDataSourcePrivate.h>
    30 #import <WebKit/WebFrame.h>
    31 #import <WebKit/WebFrameView.h>
    32 #import <WebKit/WebNSObjectExtras.h>
    33 #import <WebKit/WebPDFRepresentation.h>
    34 #import <WebKit/WebPDFView.h>
    35 #import <wtf/Assertions.h>
     29#import "WebPDFRepresentation.h"
    3630
    37 #import <PDFKit/PDFDocument.h>
     31#import "WebDataSourcePrivate.h"
     32#import "WebFrame.h"
     33#import "WebJSPDFDoc.h"
     34#import "WebNSObjectExtras.h"
     35#import "WebPDFDocumentExtras.h"
     36#import "WebPDFView.h"
     37#import <JavaScriptCore/Assertions.h>
     38#import <JavaScriptCore/JSContextRef.h>
     39#import <JavaScriptCore/JSStringRef.h>
     40#import <JavaScriptCore/JSStringRefCF.h>
    3841
    3942@implementation WebPDFRepresentation
     
    6568    }
    6669    return PDFDocumentClass;
     70}
     71
     72+ (void)initialize
     73{
     74    if (self != [WebPDFRepresentation class])
     75        return;
     76
     77    Class pdfDocumentClass = [self PDFDocumentClass];
     78    if (pdfDocumentClass)
     79        addWebPDFDocumentExtras(pdfDocumentClass);
    6780}
    6881
     
    122135    PDFDocument *doc = [[[[self class] PDFDocumentClass] alloc] initWithData:data];
    123136    [view setPDFDocument:doc];
     137
     138    NSArray *scripts = [doc _web_allScripts];
    124139    [doc release];
     140    doc = nil;
     141
     142    NSUInteger scriptCount = [scripts count];
     143    if (!scriptCount)
     144        return;
     145
     146    JSGlobalContextRef ctx = JSGlobalContextCreate(0);
     147    JSObjectRef jsPDFDoc = makeJSPDFDoc(ctx, dataSource);
     148
     149    for (NSUInteger i = 0; i < scriptCount; ++i) {
     150        JSStringRef script = JSStringCreateWithCFString((CFStringRef)[scripts objectAtIndex:i]);
     151        JSEvaluateScript(ctx, script, jsPDFDoc, 0, 0, 0);
     152        JSStringRelease(script);
     153    }
     154
     155    JSGlobalContextRelease(ctx);
    125156}
    126 
    127157
    128158- (BOOL)canProvideDocumentSource
Note: See TracChangeset for help on using the changeset viewer.