Changeset 103860 in webkit
- Timestamp:
- Dec 31, 2011 12:58:39 PM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r103858 r103860 1 2011-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 1 10 2011-12-31 Dan Bernstein <mitz@apple.com> 2 11 -
trunk/Source/WebCore/WebCore.exp.in
r103858 r103860 814 814 __ZN7WebCore5RangeD1Ev 815 815 __ZN7WebCore6Chrome16setStatusbarTextEPNS_5FrameERKN3WTF6StringE 816 __ZN7WebCore6Chrome5printEPNS_5FrameE 816 817 __ZN7WebCore6Cursor8fromTypeENS0_4TypeE 817 818 __ZN7WebCore6CursorC1EPNS_5ImageERKNS_8IntPointE -
trunk/Source/WebKit2/ChangeLog
r103859 r103860 1 2011-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 1 38 2011-12-31 Dan Bernstein <mitz@apple.com> 2 39 -
trunk/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.cpp
r103362 r103860 1 1 /* 2 * Copyright (C) 20 11 Apple Inc. All rights reserved.2 * Copyright (C) 2009, 2011 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 31 31 #include "WebEvent.h" 32 32 #include "WebEventConversion.h" 33 #include <JavaScriptCore/JSContextRef.h> 34 #include <JavaScriptCore/JSObjectRef.h> 35 #include <JavaScriptCore/JSStringRef.h> 36 #include <JavaScriptCore/JSStringRefCF.h> 33 37 #include <WebCore/ArchiveResource.h> 38 #include <WebCore/Chrome.h> 34 39 #include <WebCore/DocumentLoader.h> 35 40 #include <WebCore/FocusController.h> … … 48 53 using namespace std; 49 54 55 static 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 81 static void getAllValuesInPDFNameTree(CGPDFDictionaryRef tree, Vector<CGPDFObjectRef>& allValues) 82 { 83 appendValuesInPDFNameSubtreeToVector(tree, allValues); 84 } 85 86 static 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 50 148 namespace WebKit { 51 149 … … 57 155 const int shadowSize = 7; 58 156 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)157 PassRefPtr<BuiltInPDFView> BuiltInPDFView::create(WebFrame* frame) 158 { 159 return adoptRef(new BuiltInPDFView(frame)); 160 } 161 162 BuiltInPDFView::BuiltInPDFView(WebFrame* frame) 163 : m_frame(frame) 66 164 { 67 165 } … … 212 310 213 311 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); 214 330 } 215 331 … … 233 349 bool BuiltInPDFView::initialize(const Parameters& parameters) 234 350 { 235 m_ page->addScrollableArea(this);351 m_frame->coreFrame()->page()->addScrollableArea(this); 236 352 237 353 // Load the src URL if needed. … … 245 361 void BuiltInPDFView::destroy() 246 362 { 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 } 249 367 250 368 destroyScrollbar(HorizontalScrollbar); … … 602 720 bool BuiltInPDFView::isActive() const 603 721 { 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; 605 728 } 606 729 … … 696 819 } 697 820 821 static void jsPDFDocInitialize(JSContextRef ctx, JSObjectRef object) 822 { 823 BuiltInPDFView* pdfView = static_cast<BuiltInPDFView*>(JSObjectGetPrivate(object)); 824 pdfView->ref(); 825 } 826 827 static void jsPDFDocFinalize(JSObjectRef object) 828 { 829 BuiltInPDFView* pdfView = static_cast<BuiltInPDFView*>(JSObjectGetPrivate(object)); 830 pdfView->deref(); 831 } 832 833 JSValueRef 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 854 JSObjectRef 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 698 876 } // namespace WebKit -
trunk/Source/WebKit2/WebProcess/Plugins/PDF/BuiltInPDFView.h
r103858 r103860 31 31 #include <wtf/RetainPtr.h> 32 32 33 typedef const struct OpaqueJSContext* JSContextRef; 34 typedef struct OpaqueJSValue* JSObjectRef; 35 typedef const struct OpaqueJSValue* JSValueRef; 36 33 37 namespace WebCore { 34 class Page;35 38 struct PluginInfo; 36 39 } … … 39 42 40 43 class PluginView; 44 class WebFrame; 41 45 42 46 class BuiltInPDFView : public Plugin, private WebCore::ScrollableArea { 43 47 public: 44 static PassRefPtr<BuiltInPDFView> create(Web Core::Page*);48 static PassRefPtr<BuiltInPDFView> create(WebFrame*); 45 49 ~BuiltInPDFView(); 46 50 … … 48 52 49 53 private: 50 explicit BuiltInPDFView(Web Core::Page*);54 explicit BuiltInPDFView(WebFrame*); 51 55 52 56 // Regular plug-ins don't need access to view, but we add scrollbars to embedding FrameView for proper event handling. … … 135 139 virtual WebCore::Scrollbar* verticalScrollbar() const { return m_verticalScrollbar.get(); } 136 140 virtual bool isOnActivePage() const; 137 virtual void disconnectFromPage() { m_ page = 0; }141 virtual void disconnectFromPage() { m_frame = 0; } 138 142 virtual bool shouldSuspendScrollAnimations() const { return false; } // If we return true, ScrollAnimatorMac will keep cycling a timer forever, waiting for a good time to animate. 139 143 virtual void scrollbarStyleChanged(int newStyle, bool forceUpdate); … … 142 146 // FIXME: Implement the other conversion functions; this one is enough to get scrollbar hit testing working. 143 147 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); 144 151 145 152 WebCore::IntSize m_pluginSize; … … 157 164 RefPtr<WebCore::Scrollbar> m_verticalScrollbar; 158 165 159 Web Core::Page* m_page; // Needed to register and unregister ScrollableArea.166 WebFrame* m_frame; 160 167 161 168 WebCore::IntSize m_scrollOffset; -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
r101838 r103860 1275 1275 #endif 1276 1276 1277 RefPtr<Plugin> plugin = webPage->createPlugin( parameters);1277 RefPtr<Plugin> plugin = webPage->createPlugin(m_frame, parameters); 1278 1278 if (!plugin) 1279 1279 return 0; -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
r103858 r103860 346 346 #endif 347 347 348 PassRefPtr<Plugin> WebPage::createPlugin( const Plugin::Parameters& parameters)348 PassRefPtr<Plugin> WebPage::createPlugin(WebFrame* frame, const Plugin::Parameters& parameters) 349 349 { 350 350 String pluginPath; … … 360 360 if (parameters.mimeType == "application/pdf" 361 361 || (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); 363 365 #endif 364 366 return 0; -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h
r103858 r103860 238 238 WebCore::FrameView* mainFrameView() const; // May return 0. 239 239 240 PassRefPtr<Plugin> createPlugin( const Plugin::Parameters&);240 PassRefPtr<Plugin> createPlugin(WebFrame*, const Plugin::Parameters&); 241 241 242 242 EditorState editorState() const;
Note: See TracChangeset
for help on using the changeset viewer.