⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 90162 in webkit


Ignore:
Timestamp:
Jun 30, 2011, 2:46:35 PM (15 years ago)
Author:
mrowe@apple.com
Message:

Teach APIClient to correctly handle multiple versions of a client interface.

Reviewed by Anders Carlsson.

If a client struct is not the current version then we can't copy it via assignment
since that will read past the end of the smaller, older struct. To deal with this
APIClient needs to be aware of the sizes of the older client version structs so that
it can copy only the appropriate amount of the struct.

  • Shared/APIClient.h:

(WebKit::APIClient::initialize): Assign through to our client if the new in client is the
latest version. If an older client version was passed then we zero out our client and memcpy
the appropriate number of bytes in to it. This ensures that any new members in the client
are initialized to 0.

  • Shared/APIClientTraits.cpp:
  • Shared/APIClientTraits.h: Client interfaces are the size of their struct unless otherwise stated.
  • WebKit2.xcodeproj/project.pbxproj:
  • WebProcess/InjectedBundle/API/c/WKBundlePage.h: Bump the version and add comments indicating

which components belong to which versions.

Location:
trunk/Source/WebKit2
Files:
7 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r90161 r90162  
     12011-06-30  Mark Rowe  <mrowe@apple.com>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        Teach APIClient to correctly handle multiple versions of a client interface.
     6
     7        If a client struct is not the current version then we can't copy it via assignment
     8        since that will read past the end of the smaller, older struct. To deal with this
     9        APIClient needs to be aware of the sizes of the older client version structs so that
     10        it can copy only the appropriate amount of the struct.
     11       
     12        * Shared/APIClient.h:
     13        (WebKit::APIClient::initialize): Assign through to our client if the new in client is the
     14        latest version. If an older client version was passed then we zero out our client and memcpy
     15        the appropriate number of bytes in to it. This ensures that any new members in the client
     16        are initialized to 0.
     17        * Shared/APIClientTraits.cpp:
     18        * Shared/APIClientTraits.h: Client interfaces are the size of their struct unless otherwise stated.
     19        * WebKit2.xcodeproj/project.pbxproj:
     20        * WebProcess/InjectedBundle/API/c/WKBundlePage.h: Bump the version and add comments indicating
     21        which components belong to which versions.
     22
    1232011-06-30  Mark Rowe  <mrowe@apple.com>
    224
  • trunk/Source/WebKit2/GNUmakefile.am

    r89426 r90162  
    127127        Source/WebKit2/PluginProcess/gtk/PluginProcessGtk.cpp \
    128128        Source/WebKit2/Shared/APIClient.h \
     129        Source/WebKit2/Shared/APIClientTraits.cpp \
     130        Source/WebKit2/Shared/APIClientTraits.h \
    129131        Source/WebKit2/Shared/API/c/cairo/WKImageCairo.cpp \
    130132        Source/WebKit2/Shared/API/c/cairo/WKImageCairo.h \
  • trunk/Source/WebKit2/Shared/APIClient.h

    r90161 r90162  
    2727#define APIClient_h
    2828
     29#include "APIClientTraits.h"
     30
    2931namespace WebKit {
    3032
    31 template<typename T, int> class APIClient {
     33template<typename ClientInterface, int currentVersion> class APIClient {
    3234public:
    3335    APIClient()
     
    3537        initialize(0);
    3638    }
     39   
     40    void initialize(const ClientInterface* client)
     41    {
     42        COMPILE_ASSERT(sizeof(APIClientTraits<ClientInterface>::interfaceSizesByVersion) / sizeof(size_t) == currentVersion + 1, size_of_some_interfaces_are_unknown);
    3743
    38     void initialize(const T* client)
    39     {
    40         if (client && !client->version)
     44        if (client && client->version == currentVersion) {
    4145            m_client = *client;
    42         else
    43             memset(&m_client, 0, sizeof(m_client));
     46            return;
     47        }
     48
     49        memset(&m_client, 0, sizeof(m_client));
     50
     51        if (client)
     52            memcpy(&m_client, client, APIClientTraits<ClientInterface>::interfaceSizesByVersion[client->version]);
    4453    }
    45 
     54   
    4655protected:
    47     T m_client;
     56    ClientInterface m_client;
    4857};
    4958
  • trunk/Source/WebKit2/Shared/APIClientTraits.cpp

    r90161 r90162  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #ifndef APIClient_h
    27 #define APIClient_h
     26#include "config.h"
     27#include "APIClientTraits.h"
     28
     29#include "WKBundlePage.h"
    2830
    2931namespace WebKit {
    3032
    31 template<typename T, int> class APIClient {
    32 public:
    33     APIClient()
    34     {
    35         initialize(0);
    36     }
    37 
    38     void initialize(const T* client)
    39     {
    40         if (client && !client->version)
    41             m_client = *client;
    42         else
    43             memset(&m_client, 0, sizeof(m_client));
    44     }
    45 
    46 protected:
    47     T m_client;
     33const size_t APIClientTraits<WKBundlePageLoaderClient>::interfaceSizesByVersion[] = {
     34    offsetof(WKBundlePageLoaderClient, didLayoutForFrame),
     35    sizeof(WKBundlePageLoaderClient)
    4836};
    4937
    5038} // namespace WebKit
    51 
    52 #endif // APIClient_h
  • trunk/Source/WebKit2/Shared/APIClientTraits.h

    r90161 r90162  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #ifndef APIClient_h
    27 #define APIClient_h
     26#ifndef APIClientTraits_h
     27#define APIClientTraits_h
     28
     29#include "WKBundlePage.h"
    2830
    2931namespace WebKit {
    3032
    31 template<typename T, int> class APIClient {
    32 public:
    33     APIClient()
    34     {
    35         initialize(0);
    36     }
     33template <typename ClientInterface> struct APIClientTraits
     34{
     35    static const size_t interfaceSizesByVersion[1];
     36};
     37template <typename ClientInterface> const size_t APIClientTraits<ClientInterface>::interfaceSizesByVersion[] = { sizeof(ClientInterface) };
    3738
    38     void initialize(const T* client)
    39     {
    40         if (client && !client->version)
    41             m_client = *client;
    42         else
    43             memset(&m_client, 0, sizeof(m_client));
    44     }
    45 
    46 protected:
    47     T m_client;
     39template<> struct APIClientTraits<WKBundlePageLoaderClient>
     40{
     41    static const size_t interfaceSizesByVersion[2];
    4842};
    4943
    5044} // namespace WebKit
    5145
    52 #endif // APIClient_h
     46#endif // APIClientTraits_h
  • trunk/Source/WebKit2/WebKit2.pro

    r89582 r90162  
    114114    PluginProcess/PluginProcess.h \
    115115    PluginProcess/WebProcessConnection.h \
     116    Shared/APIClientTraits.h \
    116117    Shared/ShareableBitmap.h \
    117118    Shared/CacheModel.h \
     
    328329    PluginProcess/qt/PluginControllerProxyQt.cpp \
    329330    PluginProcess/qt/PluginProcessQt.cpp \
     331    Shared/APIClientTraits.cpp \
    330332    Shared/Plugins/Netscape/NetscapePluginModule.cpp \
    331333    Shared/Plugins/Netscape/NetscapePluginModuleNone.cpp \
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r88967 r90162  
    391391                51D130561382EAC000351EDD /* SecItemResponseData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D130521382EAC000351EDD /* SecItemResponseData.h */; };
    392392                51D130581382F10500351EDD /* WebProcessProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51D130571382F10500351EDD /* WebProcessProxyMac.mm */; };
     393                5D51845513BCF9CC00C7FF4A /* APIClientTraits.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5D51845313BCF9CC00C7FF4A /* APIClientTraits.cpp */; };
     394                5D51845613BCF9CC00C7FF4A /* APIClientTraits.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D51845413BCF9CC00C7FF4A /* APIClientTraits.h */; };
    393395                6501BD1A12F1243400E9F248 /* WKBundleInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65B86F1712F11D7B00B7DD8A /* WKBundleInspector.cpp */; };
    394396                659C551E130006410025C0C2 /* InjectedBundlePageResourceLoadClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6546A82913000164000CEB1C /* InjectedBundlePageResourceLoadClient.cpp */; };
     
    13251327                51D130521382EAC000351EDD /* SecItemResponseData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecItemResponseData.h; sourceTree = "<group>"; };
    13261328                51D130571382F10500351EDD /* WebProcessProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessProxyMac.mm; sourceTree = "<group>"; };
     1329                5D51845313BCF9CC00C7FF4A /* APIClientTraits.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APIClientTraits.cpp; sourceTree = "<group>"; };
     1330                5D51845413BCF9CC00C7FF4A /* APIClientTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIClientTraits.h; sourceTree = "<group>"; };
    13271331                5DAD7294116FF70B00EE5396 /* WebProcess.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebProcess.xcconfig; sourceTree = "<group>"; };
    13281332                5DAD73F1116FF90C00EE5396 /* BaseTarget.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = BaseTarget.xcconfig; sourceTree = "<group>"; };
     
    21352139                                1AAE058C1279DCD400852418 /* Plugins */,
    21362140                                1A3DD205125E5A2F004515E6 /* APIClient.h */,
     2141                                5D51845313BCF9CC00C7FF4A /* APIClientTraits.cpp */,
     2142                                5D51845413BCF9CC00C7FF4A /* APIClientTraits.h */,
    21372143                                BCF04C8C11FF9B7D00F86A58 /* APIObject.h */,
    21382144                                BC3065F91259344E00E71278 /* CacheModel.h */,
     
    38253831                                93C01DAC139AC91700ED51D7 /* CoreIPCClientRunLoop.h in Headers */,
    38263832                                1A3D610213A7CC2A00F95D4E /* PluginModuleInfo.h in Headers */,
     3833                                5D51845613BCF9CC00C7FF4A /* APIClientTraits.h in Headers */,
    38273834                        );
    38283835                        runOnlyForDeploymentPostprocessing = 0;
     
    44944501                                1A3D610113A7CC2A00F95D4E /* PluginModuleInfo.cpp in Sources */,
    44954502                                1A3D610513A7F03A00F95D4E /* ArgumentCoders.cpp in Sources */,
     4503                                5D51845513BCF9CC00C7FF4A /* APIClientTraits.cpp in Sources */,
    44964504                        );
    44974505                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h

    r90160 r90162  
    104104    int                                                                 version;
    105105    const void *                                                        clientInfo;
     106
     107    // Version 0.
    106108    WKBundlePageDidStartProvisionalLoadForFrameCallback                 didStartProvisionalLoadForFrame;
    107109    WKBundlePageDidReceiveServerRedirectForProvisionalLoadForFrameCallback    didReceiveServerRedirectForProvisionalLoadForFrame;
     
    122124    WKBundlePageWillPerformClientRedirectForFrameCallback               willPerformClientRedirectForFrame;
    123125    WKBundlePageDidHandleOnloadEventsForFrameCallback                   didHandleOnloadEventsForFrame;
     126
     127    // Version 1.
    124128    WKBundlePageDidLayoutForFrameCallback                               didLayoutForFrame;
    125129};
    126130typedef struct WKBundlePageLoaderClient WKBundlePageLoaderClient;
    127131
    128 enum { kWKBundlePageLoaderClientCurrentVersion = 0 };
     132enum { kWKBundlePageLoaderClientCurrentVersion = 1 };
    129133
    130134enum {
  • trunk/Source/WebKit2/win/WebKit2.vcproj

    r89758 r90162  
    396396                        </File>
    397397                        <File
     398                                RelativePath="..\Shared\APIClientTraits.cpp"
     399                                >
     400                        </File>
     401                        <File
     402                                RelativePath="..\Shared\APIClientTraits.h"
     403                                >
     404                        </File>
     405                        <File
    398406                                RelativePath="..\Shared\APIObject.h"
    399407                                >
Note: See TracChangeset for help on using the changeset viewer.