Changeset 103860 in webkit


Ignore:
Timestamp:
Dec 31, 2011 12:58:39 PM (12 years ago)
Author:
mitz@apple.com
Message:

Source/WebCore: WebCore change for <rdar://problem/10463059> Cannot print USPS shipping labels
http://webkit.org/b/72801

Reviewed by Anders Carlsson and Alexey Proskuryakov.

  • WebCore.exp.in: Exported Chrome::print().

Source/WebKit2: <rdar://problem/10463059> Cannot print USPS shipping labels
http://webkit.org/b/72801

Reviewed by Anders Carlsson and Alexey Proskuryakov.

  • WebProcess/Plugins/PDF/BuiltInPDFView.cpp:

(appendValuesInPDFNameSubtreeToVector): Copied from WebKit/mac/WebView/WebPDFDocumentExtras.mm.
(getAllValuesInPDFNameTree): Ditto.
(getAllScriptsInPDFDocument): Copied allScriptsInPDFDocument() from WebPDFDocumentExtras.mm
and changed it to append to a Vector<RetainPtr<CFStringRef> >.
(WebKit::BuiltInPDFView::create): Changed to take a WebFrame* rather than a Page*.
(WebKit::BuiltInPDFView::BuiltInPDFView): Ditto. Updated initializer accordingly.
(WebKit::BuiltInPDFView::pdfDocumentDidLoad): Copied and adapted code from
-[WebPDFRepresentation finishedLoadingWithDataSource:] to run scripts from the PDF with a
Doc object as the this object.
(WebKit::BuiltInPDFView::initialize): Adapted for the change from having a Page* to having
a WebFrame*.
(WebKit::BuiltInPDFView::destroy): Ditto.
(WebKit::BuiltInPDFView::isActive): Ditto.
(WebKit::jsPDFDocInitialize): Added. Refs the BuiltInPDFView which is the private object for
this Doc.
(WebKit::jsPDFDocFinalize): Added. Derefs the BuiltInPDFView for this Doc.
(WebKit::BuiltInPDFView::jsPDFDocPrint): Added. Calls WebCore::Chrome::print().
(WebKit::BuiltInPDFView::makeJSPDFDoc): Copied from WebKit/mac/WebView/WebJSPDFDoc.mm and
modified to use this BuiltInPDFView as the private object of the Doc being made.

  • WebProcess/Plugins/PDF/BuiltInPDFView.h:

(WebKit::BuiltInPDFView::disconnectFromPage): Adapted for the change from having a Page* to
having a WebFrame*.

  • WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:

(WebKit::WebFrameLoaderClient::createPlugin): Pass the WebFrame to WebPage::createPlugin().

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::createPlugin): Added a WebFrame* parameter, which is used when creating
a BuiltInPDFView.

  • WebProcess/WebPage/WebPage.h:
Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r103858 r103860  
     12011-12-31  Dan Bernstein  <mitz@apple.com>
     2
     3        WebCore change for <rdar://problem/10463059> Cannot print USPS shipping labels
     4        http://webkit.org/b/72801
     5
     6        Reviewed by Anders Carlsson and Alexey Proskuryakov.
     7
     8        * WebCore.exp.in: Exported Chrome::print().
     9
    1102011-12-31  Dan Bernstein  <mitz@apple.com>
    211
  • trunk/Source/WebCore/WebCore.exp.in

    r103858 r103860  
    814814__ZN7WebCore5RangeD1Ev
    815815__ZN7WebCore6Chrome16setStatusbarTextEPNS_5FrameERKN3WTF6StringE
     816__ZN7WebCore6Chrome5printEPNS_5FrameE
    816817__ZN7WebCore6Cursor8fromTypeENS0_4TypeE
    817818__ZN7WebCore6CursorC1EPNS_5ImageERKNS_8IntPointE
  • trunk/Source/WebKit2/ChangeLog

    r103859 r103860  
     12011-12-31  Dan Bernstein  <mitz@apple.com>
     2
     3        <rdar://problem/10463059> Cannot print USPS shipping labels
     4        http://webkit.org/b/72801
     5
     6        Reviewed by Anders Carlsson and Alexey Proskuryakov.
     7
     8        * WebProcess/Plugins/PDF/BuiltInPDFView.cpp:
     9        (appendValuesInPDFNameSubtreeToVector): Copied from WebKit/mac/WebView/WebPDFDocumentExtras.mm.
     10        (getAllValuesInPDFNameTree): Ditto.
     11        (getAllScriptsInPDFDocument): Copied allScriptsInPDFDocument() from WebPDFDocumentExtras.mm
     12        and changed it to append to a Vector<RetainPtr<CFStringRef> >.
     13        (WebKit::BuiltInPDFView::create): Changed to take a WebFrame* rather than a Page*.
     14        (WebKit::BuiltInPDFView::BuiltInPDFView): Ditto. Updated initializer accordingly.
     15        (WebKit::BuiltInPDFView::pdfDocumentDidLoad): Copied and adapted code from
     16        -[WebPDFRepresentation finishedLoadingWithDataSource:] to run scripts from the PDF with a
     17        Doc object as the this object.
     18        (WebKit::BuiltInPDFView::initialize): Adapted for the change from having a Page* to having
     19        a WebFrame*.
     20        (WebKit::BuiltInPDFView::destroy): Ditto.
     21        (WebKit::BuiltInPDFView::isActive): Ditto.
     22        (WebKit::jsPDFDocInitialize): Added. Refs the BuiltInPDFView which is the private object for
     23        this Doc.
     24        (WebKit::jsPDFDocFinalize): Added. Derefs the BuiltInPDFView for this Doc.
     25        (WebKit::BuiltInPDFView::jsPDFDocPrint): Added. Calls WebCore::Chrome::print().
     26        (WebKit::BuiltInPDFView::makeJSPDFDoc): Copied from WebKit/mac/WebView/WebJSPDFDoc.mm and
     27        modified to use this BuiltInPDFView as the private object of the Doc being made.
     28        * WebProcess/Plugins/PDF/BuiltInPDFView.h:
     29        (WebKit::BuiltInPDFView::disconnectFromPage): Adapted for the change from having a Page* to
     30        having a WebFrame*.
     31        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
     32        (WebKit::WebFrameLoaderClient::createPlugin): Pass the WebFrame to WebPage::createPlugin().
     33        * WebProcess/WebPage/WebPage.cpp:
     34        (WebKit::WebPage::createPlugin): Added a WebFrame* parameter, which is used when creating
     35        a BuiltInPDFView.
     36        * WebProcess/WebPage/WebPage.h:
     37
    1382011-12-31  Dan Bernstein  <mitz@apple.com>
    239
  • trunk/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.cpp

    r103362 r103860  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3131#include "WebEvent.h"
    3232#include "WebEventConversion.h"
     33#include <JavaScriptCore/JSContextRef.h>
     34#include <JavaScriptCore/JSObjectRef.h>
     35#include <JavaScriptCore/JSStringRef.h>
     36#include <JavaScriptCore/JSStringRefCF.h>
    3337#include <WebCore/ArchiveResource.h>
     38#include <WebCore/Chrome.h>
    3439#include <WebCore/DocumentLoader.h>
    3540#include <WebCore/FocusController.h>
     
    4853using namespace std;
    4954
     55static void appendValuesInPDFNameSubtreeToVector(CGPDFDictionaryRef subtree, Vector<CGPDFObjectRef>& values)
     56{
     57    CGPDFArrayRef names;
     58    if (CGPDFDictionaryGetArray(subtree, "Names", &names)) {
     59        size_t nameCount = CGPDFArrayGetCount(names) / 2;
     60        for (size_t i = 0; i < nameCount; ++i) {
     61            CGPDFObjectRef object;
     62            CGPDFArrayGetObject(names, 2 * i + 1, &object);
     63            values.append(object);
     64        }
     65        return;
     66    }
     67
     68    CGPDFArrayRef kids;
     69    if (!CGPDFDictionaryGetArray(subtree, "Kids", &kids))
     70        return;
     71
     72    size_t kidCount = CGPDFArrayGetCount(kids);
     73    for (size_t i = 0; i < kidCount; ++i) {
     74        CGPDFDictionaryRef kid;
     75        if (!CGPDFArrayGetDictionary(kids, i, &kid))
     76            continue;
     77        appendValuesInPDFNameSubtreeToVector(kid, values);
     78    }
     79}
     80
     81static void getAllValuesInPDFNameTree(CGPDFDictionaryRef tree, Vector<CGPDFObjectRef>& allValues)
     82{
     83    appendValuesInPDFNameSubtreeToVector(tree, allValues);
     84}
     85
     86static void getAllScriptsInPDFDocument(CGPDFDocumentRef pdfDocument, Vector<RetainPtr<CFStringRef> >& scripts)
     87{
     88    if (!pdfDocument)
     89        return;
     90
     91    CGPDFDictionaryRef pdfCatalog = CGPDFDocumentGetCatalog(pdfDocument);
     92    if (!pdfCatalog)
     93        return;
     94
     95    // Get the dictionary of all document-level name trees.
     96    CGPDFDictionaryRef namesDictionary;
     97    if (!CGPDFDictionaryGetDictionary(pdfCatalog, "Names", &namesDictionary))
     98        return;
     99
     100    // Get the document-level "JavaScript" name tree.
     101    CGPDFDictionaryRef javaScriptNameTree;
     102    if (!CGPDFDictionaryGetDictionary(namesDictionary, "JavaScript", &javaScriptNameTree))
     103        return;
     104
     105    // The names are arbitrary. We are only interested in the values.
     106    Vector<CGPDFObjectRef> objects;
     107    getAllValuesInPDFNameTree(javaScriptNameTree, objects);
     108    size_t objectCount = objects.size();
     109
     110    for (size_t i = 0; i < objectCount; ++i) {
     111        CGPDFDictionaryRef javaScriptAction;
     112        if (!CGPDFObjectGetValue(reinterpret_cast<CGPDFObjectRef>(objects[i]), kCGPDFObjectTypeDictionary, &javaScriptAction))
     113            continue;
     114
     115        // A JavaScript action must have an action type of "JavaScript".
     116        const char* actionType;
     117        if (!CGPDFDictionaryGetName(javaScriptAction, "S", &actionType) || strcmp(actionType, "JavaScript"))
     118            continue;
     119
     120        const UInt8* bytes = 0;
     121        CFIndex length;
     122        CGPDFStreamRef stream;
     123        CGPDFStringRef string;
     124        RetainPtr<CFDataRef> data;
     125        if (CGPDFDictionaryGetStream(javaScriptAction, "JS", &stream)) {
     126            CGPDFDataFormat format;
     127            data.adoptCF(CGPDFStreamCopyData(stream, &format));
     128            if (!data)
     129                continue;
     130            bytes = CFDataGetBytePtr(data.get());
     131            length = CFDataGetLength(data.get());
     132        } else if (CGPDFDictionaryGetString(javaScriptAction, "JS", &string)) {
     133            bytes = CGPDFStringGetBytePtr(string);
     134            length = CGPDFStringGetLength(string);
     135        }
     136        if (!bytes)
     137            continue;
     138
     139        CFStringEncoding encoding = (length > 1 && bytes[0] == 0xFE && bytes[1] == 0xFF) ? kCFStringEncodingUnicode : kCFStringEncodingUTF8;
     140        RetainPtr<CFStringRef> script(AdoptCF, CFStringCreateWithBytes(kCFAllocatorDefault, bytes, length, encoding, true));
     141        if (!script)
     142            continue;
     143
     144        scripts.append(script);
     145    }
     146}
     147
    50148namespace WebKit {
    51149
     
    57155const int shadowSize = 7;
    58156
    59 PassRefPtr<BuiltInPDFView> BuiltInPDFView::create(Page* page)
    60 {
    61     return adoptRef(new BuiltInPDFView(page));
    62 }
    63 
    64 BuiltInPDFView::BuiltInPDFView(Page* page)
    65     : m_page(page)
     157PassRefPtr<BuiltInPDFView> BuiltInPDFView::create(WebFrame* frame)
     158{
     159    return adoptRef(new BuiltInPDFView(frame));
     160}
     161
     162BuiltInPDFView::BuiltInPDFView(WebFrame* frame)
     163    : m_frame(frame)
    66164{
    67165}
     
    212310
    213311    controller()->invalidate(IntRect(0, 0, m_pluginSize.width(), m_pluginSize.height()));
     312
     313    Vector<RetainPtr<CFStringRef> > scripts;
     314    getAllScriptsInPDFDocument(m_pdfDocument.get(), scripts);
     315
     316    size_t scriptCount = scripts.size();
     317    if (!scriptCount)
     318        return;
     319
     320    JSGlobalContextRef ctx = JSGlobalContextCreate(0);
     321    JSObjectRef jsPDFDoc = makeJSPDFDoc(ctx);
     322
     323    for (size_t i = 0; i < scriptCount; ++i) {
     324        JSStringRef script = JSStringCreateWithCFString(scripts[i].get());
     325        JSEvaluateScript(ctx, script, jsPDFDoc, 0, 0, 0);
     326        JSStringRelease(script);
     327    }
     328
     329    JSGlobalContextRelease(ctx);
    214330}
    215331
     
    233349bool BuiltInPDFView::initialize(const Parameters& parameters)
    234350{
    235     m_page->addScrollableArea(this);
     351    m_frame->coreFrame()->page()->addScrollableArea(this);
    236352
    237353    // Load the src URL if needed.
     
    245361void BuiltInPDFView::destroy()
    246362{
    247     if (m_page)
    248         m_page->removeScrollableArea(this);
     363    if (m_frame) {
     364        if (Page* page = m_frame->coreFrame()->page())
     365            page->removeScrollableArea(this);
     366    }
    249367
    250368    destroyScrollbar(HorizontalScrollbar);
     
    602720bool BuiltInPDFView::isActive() const
    603721{
    604     return m_page->focusController()->isActive();
     722    if (Frame* coreFrame = m_frame->coreFrame()) {
     723        if (Page* page = coreFrame->page())
     724            return page->focusController()->isActive();
     725    }
     726
     727    return false;
    605728}
    606729
     
    696819}
    697820
     821static void jsPDFDocInitialize(JSContextRef ctx, JSObjectRef object)
     822{
     823    BuiltInPDFView* pdfView = static_cast<BuiltInPDFView*>(JSObjectGetPrivate(object));
     824    pdfView->ref();
     825}
     826
     827static void jsPDFDocFinalize(JSObjectRef object)
     828{
     829    BuiltInPDFView* pdfView = static_cast<BuiltInPDFView*>(JSObjectGetPrivate(object));
     830    pdfView->deref();
     831}
     832
     833JSValueRef BuiltInPDFView::jsPDFDocPrint(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
     834{
     835    BuiltInPDFView* pdfView = static_cast<BuiltInPDFView*>(JSObjectGetPrivate(thisObject));
     836
     837    WebFrame* frame = pdfView->m_frame;
     838    if (!frame)
     839        return JSValueMakeUndefined(ctx);
     840
     841    Frame* coreFrame = frame->coreFrame();
     842    if (!coreFrame)
     843        return JSValueMakeUndefined(ctx);
     844
     845    Page* page = coreFrame->page();
     846    if (!page)
     847        return JSValueMakeUndefined(ctx);
     848
     849    page->chrome()->print(coreFrame);
     850
     851    return JSValueMakeUndefined(ctx);
     852}
     853
     854JSObjectRef BuiltInPDFView::makeJSPDFDoc(JSContextRef ctx)
     855{
     856    static JSStaticFunction jsPDFDocStaticFunctions[] = {
     857        { "print", jsPDFDocPrint, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
     858        { 0, 0, 0 },
     859    };
     860
     861    static JSClassDefinition jsPDFDocClassDefinition = {
     862        0,
     863        kJSClassAttributeNone,
     864        "Doc",
     865        0,
     866        0,
     867        jsPDFDocStaticFunctions,
     868        jsPDFDocInitialize, jsPDFDocFinalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
     869    };
     870
     871    static JSClassRef jsPDFDocClass = JSClassCreate(&jsPDFDocClassDefinition);
     872
     873    return JSObjectMake(ctx, jsPDFDocClass, this);
     874}
     875
    698876} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h

    r103858 r103860  
    3131#include <wtf/RetainPtr.h>
    3232
     33typedef const struct OpaqueJSContext* JSContextRef;
     34typedef struct OpaqueJSValue* JSObjectRef;
     35typedef const struct OpaqueJSValue* JSValueRef;
     36
    3337namespace WebCore {
    34     class Page;
    3538    struct PluginInfo;
    3639}
     
    3942
    4043class PluginView;
     44class WebFrame;
    4145
    4246class BuiltInPDFView : public Plugin, private WebCore::ScrollableArea {
    4347public:
    44     static PassRefPtr<BuiltInPDFView> create(WebCore::Page*);
     48    static PassRefPtr<BuiltInPDFView> create(WebFrame*);
    4549    ~BuiltInPDFView();
    4650
     
    4852
    4953private:
    50     explicit BuiltInPDFView(WebCore::Page*);
     54    explicit BuiltInPDFView(WebFrame*);
    5155
    5256    // Regular plug-ins don't need access to view, but we add scrollbars to embedding FrameView for proper event handling.
     
    135139    virtual WebCore::Scrollbar* verticalScrollbar() const { return m_verticalScrollbar.get(); }
    136140    virtual bool isOnActivePage() const;
    137     virtual void disconnectFromPage() { m_page = 0; }
     141    virtual void disconnectFromPage() { m_frame = 0; }
    138142    virtual bool shouldSuspendScrollAnimations() const { return false; } // If we return true, ScrollAnimatorMac will keep cycling a timer forever, waiting for a good time to animate.
    139143    virtual void scrollbarStyleChanged(int newStyle, bool forceUpdate);
     
    142146    // FIXME: Implement the other conversion functions; this one is enough to get scrollbar hit testing working.
    143147    virtual WebCore::IntPoint convertFromContainingViewToScrollbar(const WebCore::Scrollbar*, const WebCore::IntPoint& parentPoint) const;
     148
     149    JSObjectRef makeJSPDFDoc(JSContextRef);
     150    static JSValueRef jsPDFDocPrint(JSContextRef, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
    144151
    145152    WebCore::IntSize m_pluginSize;
     
    157164    RefPtr<WebCore::Scrollbar> m_verticalScrollbar;
    158165
    159     WebCore::Page* m_page; // Needed to register and unregister ScrollableArea.
     166    WebFrame* m_frame;
    160167
    161168    WebCore::IntSize m_scrollOffset;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

    r101838 r103860  
    12751275#endif
    12761276
    1277     RefPtr<Plugin> plugin = webPage->createPlugin(parameters);
     1277    RefPtr<Plugin> plugin = webPage->createPlugin(m_frame, parameters);
    12781278    if (!plugin)
    12791279        return 0;
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r103858 r103860  
    346346#endif
    347347
    348 PassRefPtr<Plugin> WebPage::createPlugin(const Plugin::Parameters& parameters)
     348PassRefPtr<Plugin> WebPage::createPlugin(WebFrame* frame, const Plugin::Parameters& parameters)
    349349{
    350350    String pluginPath;
     
    360360        if (parameters.mimeType == "application/pdf"
    361361            || (parameters.mimeType.isEmpty() && parameters.url.path().lower().endsWith(".pdf")))
    362             return BuiltInPDFView::create(m_page.get());
     362            return BuiltInPDFView::create(frame);
     363#else
     364        UNUSED_PARAM(frame);
    363365#endif
    364366        return 0;
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r103858 r103860  
    238238    WebCore::FrameView* mainFrameView() const; // May return 0.
    239239
    240     PassRefPtr<Plugin> createPlugin(const Plugin::Parameters&);
     240    PassRefPtr<Plugin> createPlugin(WebFrame*, const Plugin::Parameters&);
    241241
    242242    EditorState editorState() const;
Note: See TracChangeset for help on using the changeset viewer.