Changeset 202345 in webkit


Ignore:
Timestamp:
Jun 22, 2016 1:00:03 PM (8 years ago)
Author:
andersca@apple.com
Message:

Inline the last of the Apple Pay WebCore code
https://bugs.webkit.org/show_bug.cgi?id=159032

Reviewed by Tim Horton.

  • loader/EmptyClients.cpp:

(WebCore::fillWithEmptyClients):

  • page/MainFrame.cpp:

(WebCore::MainFrame::MainFrame):

  • page/MainFrame.h:
  • page/PageConfiguration.h:
  • platform/cocoa/ThemeCocoa.mm:

(WebCore::passKitBundle):
(WebCore::loadPassKitPDFPage):
(WebCore::applePayButtonLogoBlack):
(WebCore::applePayButtonLogoWhite):
(WebCore::drawApplePayButton):
(WebCore::ThemeCocoa::drawNamedImage):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r202337 r202345  
    66    "${WEBCORE_DIR}"
    77    "${WEBCORE_DIR}/Modules/airplay"
     8    "${WEBCORE_DIR}/Modules/applepay"
    89    "${WEBCORE_DIR}/Modules/battery"
    910    "${WEBCORE_DIR}/Modules/encryptedmedia"
  • trunk/Source/WebCore/ChangeLog

    r202342 r202345  
     12016-06-22  Anders Carlsson  <andersca@apple.com>
     2
     3        Inline the last of the Apple Pay WebCore code
     4        https://bugs.webkit.org/show_bug.cgi?id=159032
     5
     6        Reviewed by Tim Horton.
     7
     8        * loader/EmptyClients.cpp:
     9        (WebCore::fillWithEmptyClients):
     10        * page/MainFrame.cpp:
     11        (WebCore::MainFrame::MainFrame):
     12        * page/MainFrame.h:
     13        * page/PageConfiguration.h:
     14        * platform/cocoa/ThemeCocoa.mm:
     15        (WebCore::passKitBundle):
     16        (WebCore::loadPassKitPDFPage):
     17        (WebCore::applePayButtonLogoBlack):
     18        (WebCore::applePayButtonLogoWhite):
     19        (WebCore::drawApplePayButton):
     20        (WebCore::ThemeCocoa::drawNamedImage):
     21
    1222016-06-22  Anders Carlsson  <andersca@apple.com>
    223
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r202005 r202345  
    4242#include "Page.h"
    4343#include "PageConfiguration.h"
     44#include "PaymentCoordinatorClient.h"
    4445#include "StorageArea.h"
    4546#include "StorageNamespace.h"
     
    4849#include <wtf/NeverDestroyed.h>
    4950
    50 #if USE(APPLE_INTERNAL_SDK)
    51 #include <WebKitAdditions/EmptyClientsIncludes.h>
    52 #endif
    53 
    5451namespace WebCore {
     52
     53#if ENABLE(APPLE_PAY)
     54class EmptyPaymentCoordinatorClient final : public PaymentCoordinatorClient {
     55    bool supportsVersion(unsigned) override { return false; }
     56    bool canMakePayments() override { return false; }
     57    void canMakePaymentsWithActiveCard(const String&, const String&, std::function<void (bool)> completionHandler) override { callOnMainThread([completionHandler] { completionHandler(false); }); }
     58    void showPaymentUI(const URL&, const Vector<URL>&, const PaymentRequest&) override { }
     59    void completeMerchantValidation(const PaymentMerchantSession&) override { }
     60
     61    void completeShippingMethodSelection(PaymentAuthorizationStatus, Optional<PaymentRequest::TotalAndLineItems>) override { }
     62    void completeShippingContactSelection(PaymentAuthorizationStatus, const Vector<PaymentRequest::ShippingMethod>&, Optional<PaymentRequest::TotalAndLineItems>) override { }
     63    void completePaymentMethodSelection(Optional<WebCore::PaymentRequest::TotalAndLineItems>) override { }
     64    void completePaymentSession(PaymentAuthorizationStatus) override { }
     65    void abortPaymentSession() override { }
     66    void mainFrameDestroyed() override { }
     67};
     68#endif
    5569
    5670class EmptyDatabaseProvider final : public DatabaseProvider {
     
    121135    pageConfiguration.chromeClient = &dummyChromeClient.get();
    122136
     137#if ENABLE(APPLE_PAY)
     138    static NeverDestroyed<EmptyPaymentCoordinatorClient> dummyPaymentCoordinatorClient;
     139    pageConfiguration.paymentCoordinatorClient = &dummyPaymentCoordinatorClient.get();
     140#endif
     141
    123142#if ENABLE(CONTEXT_MENUS)
    124143    static NeverDestroyed<EmptyContextMenuClient> dummyContextMenuClient;
     
    147166    pageConfiguration.userContentProvider = adoptRef(new EmptyUserContentProvider);
    148167    pageConfiguration.visitedLinkStore = adoptRef(new EmptyVisitedLinkStore);
    149 
    150 #if USE(APPLE_INTERNAL_SDK)
    151 #include <WebKitAdditions/EmptyClientsFill.cpp>
    152 #endif
    153168}
    154169
  • trunk/Source/WebCore/page/MainFrame.cpp

    r199955 r202345  
    3131#include "PageConfiguration.h"
    3232#include "PageOverlayController.h"
     33#include "PaymentCoordinator.h"
    3334#include "ScrollLatchingState.h"
    3435#include "Settings.h"
     
    3839#if PLATFORM(MAC)
    3940#include "ServicesOverlayController.h"
    40 #endif /* PLATFORM(MAC) */
    41 
    42 #if USE(APPLE_INTERNAL_SDK)
    43 #include <WebKitAdditions/MainFrameIncludes.h>
    4441#endif
    4542
     
    4946    : Frame(page, nullptr, *configuration.loaderClientForMainFrame)
    5047    , m_selfOnlyRefCount(0)
    51 #if PLATFORM(MAC)
    52 #if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
     48#if PLATFORM(MAC) && (ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION))
    5349    , m_servicesOverlayController(std::make_unique<ServicesOverlayController>(*this))
    54 #endif
    5550#endif
    5651    , m_recentWheelEventDeltaFilter(WheelEventDeltaFilter::create())
    5752    , m_pageOverlayController(std::make_unique<PageOverlayController>(*this))
     53#if ENABLE(APPLE_PAY)
     54    , m_paymentCoordinator(std::make_unique<PaymentCoordinator>(*configuration.paymentCoordinatorClient))
     55#endif
    5856{
    59 #if USE(APPLE_INTERNAL_SDK)
    60 #include <WebKitAdditions/MainFrameInitialization.cpp>
    61 #endif
    6257}
    6358
  • trunk/Source/WebCore/page/MainFrame.h

    r202298 r202345  
    6464#endif // PLATFORM(MAC)
    6565
    66 #if USE(APPLE_INTERNAL_SDK)
    67 #include <WebKitAdditions/MainFrameMembers.h>
     66#if ENABLE(APPLE_PAY)
     67    PaymentCoordinator& paymentCoordinator() const { return *m_paymentCoordinator; }
    6868#endif
    6969
     
    8484    std::unique_ptr<WheelEventDeltaFilter> m_recentWheelEventDeltaFilter;
    8585    std::unique_ptr<PageOverlayController> m_pageOverlayController;
     86
     87#if ENABLE(APPLE_PAY)
     88    std::unique_ptr<PaymentCoordinator> m_paymentCoordinator;
     89#endif
    8690};
    8791
  • trunk/Source/WebCore/page/PageConfiguration.h

    r202005 r202345  
    3030#include <wtf/UniqueRef.h>
    3131
    32 #if USE(APPLE_INTERNAL_SDK)
    33 #include <WebKitAdditions/PageConfigurationIncludes.h>
    34 #endif
    35 
    3632namespace WebCore {
    3733
     
    4642class FrameLoaderClient;
    4743class InspectorClient;
     44class PaymentCoordinatorClient;
    4845class PlugInClient;
    4946class ProgressTrackerClient;
     
    7370    DragClient* dragClient { nullptr };
    7471    InspectorClient* inspectorClient { nullptr };
     72#if ENABLE(APPLE_PAY)
     73    PaymentCoordinatorClient* paymentCoordinatorClient { nullptr };
     74#endif
     75
    7576    PlugInClient* plugInClient { nullptr };
    7677    ProgressTrackerClient* progressTrackerClient { nullptr };
     
    7980    FrameLoaderClient* loaderClientForMainFrame { nullptr };
    8081    std::unique_ptr<DiagnosticLoggingClient> diagnosticLoggingClient { nullptr };
    81 
    82 #if USE(APPLE_INTERNAL_SDK)
    83 #include <WebKitAdditions/PageConfigurationMembers.h>
    84 #endif
    8582
    8683    RefPtr<ApplicationCacheStorage> applicationCacheStorage;
  • trunk/Source/WebCore/platform/cocoa/ThemeCocoa.mm

    r201241 r202345  
    5454}
    5555
     56#if ENABLE(APPLE_PAY)
     57static NSBundle *passKitBundle()
     58{
     59    static NSBundle *passKitBundle;
     60    static dispatch_once_t onceToken;
     61    dispatch_once(&onceToken, ^{
     62#if PLATFORM(MAC)
     63        passKitBundle = [NSBundle bundleWithURL:[NSURL fileURLWithPath:@"/System/Library/PrivateFrameworks/PassKit.framework"]];
     64#else
     65        dlopen("/System/Library/Frameworks/PassKit.framework/PassKit", RTLD_NOW);
     66        passKitBundle = [NSBundle bundleForClass:NSClassFromString(@"PKPaymentAuthorizationViewController")];
     67#endif
     68    });
     69
     70    return passKitBundle;
     71}
     72
     73static RetainPtr<CGPDFPageRef> loadPassKitPDFPage(NSString *imageName)
     74{
     75    NSURL *url = [passKitBundle() URLForResource:imageName withExtension:@"pdf"];
     76    if (!url)
     77        return nullptr;
     78
     79    auto document = adoptCF(CGPDFDocumentCreateWithURL((CFURLRef)url));
     80    if (!document)
     81        return nullptr;
     82
     83    if (!CGPDFDocumentGetNumberOfPages(document.get()))
     84        return nullptr;
     85
     86    return CGPDFDocumentGetPage(document.get(), 1);
     87};
     88
     89static CGPDFPageRef applePayButtonLogoBlack()
     90{
     91    static CGPDFPageRef logoPage;
     92    static dispatch_once_t onceToken;
     93    dispatch_once(&onceToken, ^{
     94        logoPage = loadPassKitPDFPage(@"PayButtonLogoBlack").leakRef();
     95    });
     96
     97    return logoPage;
     98};
     99
     100static CGPDFPageRef applePayButtonLogoWhite()
     101{
     102    static CGPDFPageRef logoPage;
     103    static dispatch_once_t onceToken;
     104    dispatch_once(&onceToken, ^{
     105        logoPage = loadPassKitPDFPage(@"PayButtonLogoWhite").leakRef();
     106    });
     107
     108    return logoPage;
     109};
     110
     111static void drawApplePayButton(GraphicsContext& context, CGPDFPageRef page, const FloatRect& rect)
     112{
     113    CGSize pdfSize = CGPDFPageGetBoxRect(page, kCGPDFMediaBox).size;
     114    GraphicsContextStateSaver stateSaver(context);
     115    fitContextToBox(context, FloatSize(pdfSize), rect.size());
     116
     117    CGContextTranslateCTM(context.platformContext(), 0, pdfSize.height);
     118    CGContextScaleCTM(context.platformContext(), 1, -1);
     119
     120    CGContextDrawPDFPage(context.platformContext(), page);
     121};
     122
     123#endif
     124
    56125void ThemeCocoa::drawNamedImage(const String& name, GraphicsContext& context, const FloatRect& rect) const
    57126{
    58     // We only handle one icon at the moment.
    59127    if (name == "wireless-playback") {
    60128        GraphicsContextStateSaver stateSaver(context);
     
    89157    }
    90158
    91 #if USE(APPLE_INTERNAL_SDK)
    92 #include <WebKitAdditions/ThemeCocoaDrawNamedImage.mm>
     159#if ENABLE(APPLE_PAY)
     160    if (name == "apple-pay-logo-black") {
     161        if (auto logo = applePayButtonLogoBlack()) {
     162            drawApplePayButton(context, logo, rect);
     163            return;
     164        }
     165    }
     166
     167    if (name == "apple-pay-logo-white") {
     168        if (auto logo = applePayButtonLogoWhite()) {
     169            drawApplePayButton(context, logo, rect);
     170            return;
     171        }
     172    }
    93173#endif
    94174
Note: See TracChangeset for help on using the changeset viewer.