Changeset 169422 in webkit


Ignore:
Timestamp:
May 28, 2014 7:28:56 AM (10 years ago)
Author:
mitz@apple.com
Message:

[Cocoa] Can't use bundle-defined classes for bundle parameters
https://bugs.webkit.org/show_bug.cgi?id=133339

Reviewed by Anders Carlsson.

Ensure that bundle parameters are decoded only after the injected bundle is loaded.

  • WebProcess/InjectedBundle/InjectedBundle.cpp:

(WebKit::InjectedBundle::create): Moved the definition from the header to here, added the
lagacy initializationUserData as a parameter, and made this function set the sandbox
extension and load the bundle.
(WebKit::InjectedBundle::InjectedBundle): Removed call to platformInitialize.

  • WebProcess/InjectedBundle/InjectedBundle.h:

(WebKit::InjectedBundle::setSandboxExtension): Deleted.

  • WebProcess/InjectedBundle/mac/InjectedBundleMac.mm:

(WebKit::InjectedBundle::initialize): Renamed the load function to this, and added the
creation parameters as a parameter. Moved code to initialize the bundle paramters from
platformInitialize to here. Changed the class passed to -decodeObjectOfClass:forKey: to
NSObject, to allow arbitrary types in the values, and added an assertion that the
top-level object is a dictionary.
(WebKit::InjectedBundle::platformInitialize): Deleted.

  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::initializeWebProcess): Changed to pass the legacy initialization user
data to InjectedBundle::create() and removed code to separately set the sandbox extension
and load the bundle, which is now done by create().

Location:
trunk/Source/WebKit2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r169421 r169422  
     12014-05-28  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Can't use bundle-defined classes for bundle parameters
     4        https://bugs.webkit.org/show_bug.cgi?id=133339
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Ensure that bundle parameters are decoded only after the injected bundle is loaded.
     9
     10        * WebProcess/InjectedBundle/InjectedBundle.cpp:
     11        (WebKit::InjectedBundle::create): Moved the definition from the header to here, added the
     12        lagacy initializationUserData as a parameter, and made this function set the sandbox
     13        extension and load the bundle.
     14        (WebKit::InjectedBundle::InjectedBundle): Removed call to platformInitialize.
     15        * WebProcess/InjectedBundle/InjectedBundle.h:
     16        (WebKit::InjectedBundle::setSandboxExtension): Deleted.
     17        * WebProcess/InjectedBundle/mac/InjectedBundleMac.mm:
     18        (WebKit::InjectedBundle::initialize): Renamed the load function to this, and added the
     19        creation parameters as a parameter. Moved code to initialize the bundle paramters from
     20        platformInitialize to here. Changed the class passed to -decodeObjectOfClass:forKey: to
     21        NSObject, to allow arbitrary types in the values, and added an assertion that the
     22        top-level object is a dictionary.
     23        (WebKit::InjectedBundle::platformInitialize): Deleted.
     24        * WebProcess/WebProcess.cpp:
     25        (WebKit::WebProcess::initializeWebProcess): Changed to pass the legacy initialization user
     26        data to InjectedBundle::create() and removed code to separately set the sandbox extension
     27        and load the bundle, which is now done by create().
     28
    1292014-05-28  Alberto Garcia  <berto@igalia.com>
    230
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp

    r169394 r169422  
    8686namespace WebKit {
    8787
     88PassRefPtr<InjectedBundle> InjectedBundle::create(const WebProcessCreationParameters& parameters, API::Object* initializationUserData)
     89{
     90    RefPtr<InjectedBundle> bundle = adoptRef(new InjectedBundle(parameters));
     91
     92    bundle->m_sandboxExtension = SandboxExtension::create(parameters.injectedBundlePathExtensionHandle);
     93    if (!bundle->initialize(parameters, initializationUserData))
     94        return nullptr;
     95
     96    return bundle.release();
     97}
     98
    8899InjectedBundle::InjectedBundle(const WebProcessCreationParameters& parameters)
    89100    : m_path(parameters.injectedBundlePath)
    90101    , m_platformBundle(0)
    91102{
    92     platformInitialize(parameters);
    93103}
    94104
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h

    r168123 r169422  
    8282class InjectedBundle : public API::ObjectImpl<API::Object::Type::Bundle> {
    8383public:
    84     static PassRefPtr<InjectedBundle> create(const WebProcessCreationParameters& parameters)
    85     {
    86         return adoptRef(new InjectedBundle(parameters));
    87     }
     84    static PassRefPtr<InjectedBundle> create(const WebProcessCreationParameters&, API::Object* initializationUserData);
     85
    8886    ~InjectedBundle();
    8987
    90     bool load(API::Object* initializationUserData);
    91     void setSandboxExtension(PassRefPtr<SandboxExtension> sandboxExtension) { m_sandboxExtension = sandboxExtension; }
     88    bool initialize(const WebProcessCreationParameters&, API::Object* initializationUserData);
    9289
    9390    void setBundleParameter(const String& key, const IPC::DataReference&);
     
    182179    explicit InjectedBundle(const WebProcessCreationParameters&);
    183180
    184     void platformInitialize(const WebProcessCreationParameters&);
    185 
    186181    String m_path;
    187182    PlatformBundle m_platformBundle; // This is leaked right now, since we never unload the bundle/module.
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/efl/InjectedBundleEfl.cpp

    r165801 r169422  
    3535namespace WebKit {
    3636
    37 bool InjectedBundle::load(API::Object* initializationUserData)
     37bool InjectedBundle::initialize(const WebProcessCreationParameters&, API::Object* initializationUserData)
    3838{
    3939    m_platformBundle = eina_module_new(m_path.utf8().data());
     
    6767}
    6868
    69 void InjectedBundle::platformInitialize(const WebProcessCreationParameters&)
    70 {
    71 }
    72 
    7369} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/gtk/InjectedBundleGtk.cpp

    r165802 r169422  
    3737namespace WebKit {
    3838
    39 bool InjectedBundle::load(API::Object* initializationUserData)
     39bool InjectedBundle::initialize(const WebProcessCreationParameters&, API::Object* initializationUserData)
    4040{
    4141    m_platformBundle = g_module_open(fileSystemRepresentation(m_path).data(), G_MODULE_BIND_LOCAL);
     
    5959}
    6060
    61 void InjectedBundle::platformInitialize(const WebProcessCreationParameters&)
    62 {
    63 }
    64 
    6561void InjectedBundle::setBundleParameter(WTF::String const&, IPC::DataReference const&)
    6662{
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.mm

    r167865 r169422  
    4848namespace WebKit {
    4949
    50 bool InjectedBundle::load(API::Object* initializationUserData)
     50bool InjectedBundle::initialize(const WebProcessCreationParameters& parameters, API::Object* initializationUserData)
    5151{
    5252    if (m_sandboxExtension) {
     
    9090   
    9191#if WK_API_ENABLED
     92    if (parameters.bundleParameterData) {
     93        auto bundleParameterData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(parameters.bundleParameterData->bytes())) length:parameters.bundleParameterData->size() freeWhenDone:NO]);
     94
     95        auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingWithData:bundleParameterData.get()]);
     96        [unarchiver setRequiresSecureCoding:YES];
     97
     98        NSDictionary *dictionary = nil;
     99        @try {
     100            dictionary = [unarchiver.get() decodeObjectOfClass:[NSObject class] forKey:@"parameters"];
     101            ASSERT([dictionary isKindOfClass:[NSDictionary class]]);
     102        } @catch (NSException *exception) {
     103            LOG_ERROR("Failed to decode bundle parameters: %@", exception);
     104        }
     105
     106        m_bundleParameters = adoptNS([[WKWebProcessBundleParameters alloc] initWithDictionary:dictionary]);
     107    }
     108
    92109    // Otherwise, look to see if the bundle has a principal class
    93110    Class principalClass = [m_platformBundle principalClass];
     
    163180}
    164181
    165 
    166 void InjectedBundle::platformInitialize(const WebProcessCreationParameters& parameters)
    167 {
    168 #if WK_API_ENABLED
    169     if (!parameters.bundleParameterData)
    170         return;
    171 
    172     auto bundleParameterData = adoptNS([[NSData alloc] initWithBytesNoCopy:const_cast<void*>(static_cast<const void*>(parameters.bundleParameterData->bytes())) length:parameters.bundleParameterData->size() freeWhenDone:NO]);
    173 
    174     auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingWithData:bundleParameterData.get()]);
    175     [unarchiver setRequiresSecureCoding:YES];
    176 
    177     NSDictionary *dictionary = nil;
    178     @try {
    179         dictionary = [unarchiver.get() decodeObjectOfClass:[NSDictionary class] forKey:@"parameters"];
    180     } @catch (NSException *exception) {
    181         LOG_ERROR("Failed to decode bundle parameters: %@", exception);
    182     }
    183 
    184     m_bundleParameters = adoptNS([[WKWebProcessBundleParameters alloc] initWithDictionary:dictionary]);
    185 #endif
    186 }
    187 
    188182} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r169394 r169422  
    278278        return;
    279279
    280     if (!parameters.injectedBundlePath.isEmpty()) {
    281         m_injectedBundle = InjectedBundle::create(parameters);
    282         m_injectedBundle->setSandboxExtension(SandboxExtension::create(parameters.injectedBundlePathExtensionHandle));
    283 
    284         if (!m_injectedBundle->load(injectedBundleInitializationUserData.get())) {
    285             // Don't keep around the InjectedBundle reference if the load fails.
    286             m_injectedBundle.clear();
    287         }
    288     }
     280    if (!parameters.injectedBundlePath.isEmpty())
     281        m_injectedBundle = InjectedBundle::create(parameters, injectedBundleInitializationUserData.get());
    289282
    290283    WebProcessSupplementMap::const_iterator it = m_supplements.begin();
Note: See TracChangeset for help on using the changeset viewer.