Changeset 130948 in webkit


Ignore:
Timestamp:
Oct 10, 2012, 1:28:30 PM (13 years ago)
Author:
aestes@apple.com
Message:

[WebKit2] Create an API for adding and removing user stylesheets from a page group
https://bugs.webkit.org/show_bug.cgi?id=98432

Reviewed by Sam Weinig.

Source/WebKit2:

This patch adds the following API to WKBrowsingContextGroup:

  • (void)addUserStyleSheet:(NSString *)source baseURL:(NSURL *)baseURL whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist mainFrameOnly:(BOOL)mainFrameOnly;
  • (void)removeAllUserStyleSheets;

Sheets added via this API are sent to all processes that contain a page
in the given page group. Sheets are also cached in the UI process in a
new object called UserContentContainer, which is a property of each
group's WebPageGroupData and is sent to new web processes during page
initialization.

This is less than ideal, since new pages added to a pre-existing
process / page group combination will send redundant user stylesheet
strings over the wire. To avoid this we'd have to keep track track of
the groups that currently exist in each process and only send user
content during page creation if it is the first time a process has seen
the page's group. I decided to not add this complexity for the time
being, but we might need to consider it if we find that the current
approach impacts performance for clients that heavily utilize user
content.

  • Shared/API/c/WKArray.cpp:

(WKArrayCreateAdoptingValues): Add a WKArray creation function that
adopts the incoming WKTypeRefs rather than refing them.

  • Shared/API/c/WKArray.h:
  • Shared/API/c/WKBase.h: Move WKUserContentInjectedFrames out of

WKBundlePrivate.h so it can be used in WKPageGroup, too.

  • Shared/API/c/cf/WKURLCF.cpp:

(WKURLCreateWithCFURL): Return 0 for null CFURLRefs instead of crashing
inside CFURLGetString().

  • Shared/ImmutableArray.cpp:

(WebKit::ImmutableArray::ImmutableArray): Add a tag to differentiate
between the adopting and refing ctors.

  • Shared/ImmutableArray.h:

(WebKit::ImmutableArray::create): Call the refing ctor.
(WebKit::ImmutableArray::adopt): Call the adopting ctor.

  • Shared/UserContentContainer.cpp: Added.

(UserContentItemMessageEncoder): Create a UserMessageEncoder for
serializing UserContentContainer::Item's APIObjects.
(WebKit::UserContentItemMessageEncoder::UserContentItemMessageEncoder):
(WebKit::UserContentItemMessageEncoder::encode):
(UserContentItemMessageDecoder): Create a UserMessageEncoder for
deserializing UserContentContainer::Item's APIObjects.
(WebKit::UserContentItemMessageDecoder::UserContentItemMessageDecoder):
(WebKit::UserContentItemMessageDecoder::decode):
(WebKit::UserContentContainer::Item::Item):
(WebKit::encodeStringArray): Add a helper function for encoding
ImmutableArrays of WebStrings.
(WebKit::UserContentContainer::Item::encode): Encode the item's
properties using UserContentItemMessageEncoder.
(WebKit::decodeStringArray): Add a helper function for decoding
ImmutableArrays of WebStrings.
(WebKit::UserContentContainer::Item::decode): Decode the item's
properties using UserContentItemMessageDecoder.
(WebKit::toStringVector): Add a helper function for converting an
ImmutableArray of WebStrings to a Vector of Strings.
(WebKit::UserContentContainer::Item::whitelist): Use toStringVector().
(WebKit::UserContentContainer::Item::blacklist): Ditto.
(WebKit::UserContentContainer::encode): Encode the Vector of UserContentContainer::Items.
(WebKit::UserContentContainer::decode): Decode the Vector of UserContentContainer::Items.

  • Shared/UserContentContainer.h: Added.
  • Shared/WebPageGroupData.cpp:

(WebKit::WebPageGroupData::encode): Include userStyleSheets when encoding.
(WebKit::WebPageGroupData::decode): Include userStyleSheets when decoding.

  • Shared/WebPageGroupData.h:

(WebPageGroupData): Add a UserContentContainer called userStyleSheets
to WebPageGroupData.

  • UIProcess/API/C/WKPageGroup.cpp: Add the C SPI version of the Objective-C API.

(WKPageGroupAddUserStyleSheet):
(WKPageGroupRemoveAllUserStyleSheets):

  • UIProcess/API/C/WKPageGroup.h:
  • UIProcess/API/mac/WKBrowsingContextGroup.h: Add the Objective-C API.
  • UIProcess/API/mac/WKBrowsingContextGroup.mm:

(createWKArray): Add a helper function that converts an NSArray of NSStrings to a WKArray of WKStrings.
(-[WKBrowsingContextGroup addUserStyleSheet:baseURL:whitelist:blacklist:mainFrameOnly:]):
Implement the Objective-C API in terms of the C SPI.
(-[WKBrowsingContextGroup removeAllUserStyleSheets]): Ditto.

  • UIProcess/WebPageGroup.cpp:

(WebKit::WebPageGroup::addUserStyleSheet): Add the new sheet to the
group's WebPageGroupData, which ensures that the group's sheets are
sent to new web processes.
(WebKit::WebPageGroup::removeAllUserStyleSheets): Ditto for removal.

  • UIProcess/WebPageGroup.h:

(WebKit::WebPageGroup::sendToAllProcessesInGroup): Add a helper message
that sends a message to all processes that have a page in the current
group. This is used to add new user sheets to already-initialized page
groups in the UI processes.

  • WebKit2.xcodeproj/project.pbxproj:
  • WebProcess/InjectedBundle/API/c/WKBundlePrivate.h: Moved

WKUserContentInjectedFrames from here to WKBase.h.

  • WebProcess/WebPage/WebPageGroupProxy.cpp:

(WebKit::WebPageGroupProxy::WebPageGroupProxy): Add each sheet in the
WebPageGroupData to WebCore's page group.
(WebKit::WebPageGroupProxy::addUserStyleSheet): Add the sheet received
from the UI process to WebCore's page group.
(WebKit::WebPageGroupProxy::removeAllUserStyleSheets): Remove all
sheets from WebCore's page group.

  • WebProcess/WebPage/WebPageGroupProxy.h:
  • WebProcess/WebPage/WebPageGroupProxy.messages.in: Define

AddUserStyleSheet and RemoveAllUserStyleSheets, two messages sent from
the UI process to a web process's WebPageGroupProxy.

Tools:

Add three new API tests:

  • Test adding a user stylesheet before a page is created. This tests

the code path where the sheet is sent to the web process as part of
the new page's WebPageCreationParameters.

  • Test adding a user stylesheet after a page is created. This tests the

code patch where the sheet is sent as a separate message to all
processes containing the given page group.

  • Test removing all user stylesheets.
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit2ObjC/UserContentTest.mm: Added.

(-[UserContentTestLoadDelegate initWithBlockToRunOnLoad:]):
(-[UserContentTestLoadDelegate browsingContextControllerDidFinishLoad:]):
(expectScriptValue):

  • TestWebKitAPI/Tests/WebKit2ObjC/WKBrowsingContextGroupTest.mm:
Location:
trunk
Files:
3 added
26 edited

Legend:

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

    r130316 r130948  
    153153    Shared/SurfaceUpdateInfo.cpp
    154154    Shared/UpdateInfo.cpp
     155    Shared/UserContentContainer.cpp
    155156    Shared/VisitedLinkTable.cpp
    156157    Shared/WebBackForwardListItem.cpp
  • trunk/Source/WebKit2/ChangeLog

    r130939 r130948  
     12012-10-04  Andy Estes  <aestes@apple.com>
     2
     3        [WebKit2] Create an API for adding and removing user stylesheets from a page group
     4        https://bugs.webkit.org/show_bug.cgi?id=98432
     5
     6        Reviewed by Sam Weinig.
     7
     8        This patch adds the following API to WKBrowsingContextGroup:
     9
     10        - (void)addUserStyleSheet:(NSString *)source baseURL:(NSURL *)baseURL whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist mainFrameOnly:(BOOL)mainFrameOnly;
     11        - (void)removeAllUserStyleSheets;
     12
     13        Sheets added via this API are sent to all processes that contain a page
     14        in the given page group. Sheets are also cached in the UI process in a
     15        new object called UserContentContainer, which is a property of each
     16        group's WebPageGroupData and is sent to new web processes during page
     17        initialization.
     18
     19        This is less than ideal, since new pages added to a pre-existing
     20        process / page group combination will send redundant user stylesheet
     21        strings over the wire. To avoid this we'd have to keep track track of
     22        the groups that currently exist in each process and only send user
     23        content during page creation if it is the first time a process has seen
     24        the page's group. I decided to not add this complexity for the time
     25        being, but we might need to consider it if we find that the current
     26        approach impacts performance for clients that heavily utilize user
     27        content.
     28
     29        * Shared/API/c/WKArray.cpp:
     30        (WKArrayCreateAdoptingValues): Add a WKArray creation function that
     31        adopts the incoming WKTypeRefs rather than refing them.
     32        * Shared/API/c/WKArray.h:
     33        * Shared/API/c/WKBase.h: Move WKUserContentInjectedFrames out of
     34        WKBundlePrivate.h so it can be used in WKPageGroup, too.
     35        * Shared/API/c/cf/WKURLCF.cpp:
     36        (WKURLCreateWithCFURL): Return 0 for null CFURLRefs instead of crashing
     37        inside CFURLGetString().
     38        * Shared/ImmutableArray.cpp:
     39        (WebKit::ImmutableArray::ImmutableArray): Add a tag to differentiate
     40        between the adopting and refing ctors.
     41        * Shared/ImmutableArray.h:
     42        (WebKit::ImmutableArray::create): Call the refing ctor.
     43        (WebKit::ImmutableArray::adopt): Call the adopting ctor.
     44        * Shared/UserContentContainer.cpp: Added.
     45        (UserContentItemMessageEncoder): Create a UserMessageEncoder for
     46        serializing UserContentContainer::Item's APIObjects.
     47        (WebKit::UserContentItemMessageEncoder::UserContentItemMessageEncoder):
     48        (WebKit::UserContentItemMessageEncoder::encode):
     49        (UserContentItemMessageDecoder): Create a UserMessageEncoder for
     50        deserializing UserContentContainer::Item's APIObjects.
     51        (WebKit::UserContentItemMessageDecoder::UserContentItemMessageDecoder):
     52        (WebKit::UserContentItemMessageDecoder::decode):
     53        (WebKit::UserContentContainer::Item::Item):
     54        (WebKit::encodeStringArray): Add a helper function for encoding
     55        ImmutableArrays of WebStrings.
     56        (WebKit::UserContentContainer::Item::encode): Encode the item's
     57        properties using UserContentItemMessageEncoder.
     58        (WebKit::decodeStringArray): Add a helper function for decoding
     59        ImmutableArrays of WebStrings.
     60        (WebKit::UserContentContainer::Item::decode): Decode the item's
     61        properties using UserContentItemMessageDecoder.
     62        (WebKit::toStringVector): Add a helper function for converting an
     63        ImmutableArray of WebStrings to a Vector of Strings.
     64        (WebKit::UserContentContainer::Item::whitelist): Use toStringVector().
     65        (WebKit::UserContentContainer::Item::blacklist): Ditto.
     66        (WebKit::UserContentContainer::encode): Encode the Vector of UserContentContainer::Items.
     67        (WebKit::UserContentContainer::decode): Decode the Vector of UserContentContainer::Items.
     68        * Shared/UserContentContainer.h: Added.
     69        * Shared/WebPageGroupData.cpp:
     70        (WebKit::WebPageGroupData::encode): Include userStyleSheets when encoding.
     71        (WebKit::WebPageGroupData::decode): Include userStyleSheets when decoding.
     72        * Shared/WebPageGroupData.h:
     73        (WebPageGroupData): Add a UserContentContainer called userStyleSheets
     74        to WebPageGroupData.
     75        * UIProcess/API/C/WKPageGroup.cpp: Add the C SPI version of the Objective-C API.
     76        (WKPageGroupAddUserStyleSheet):
     77        (WKPageGroupRemoveAllUserStyleSheets):
     78        * UIProcess/API/C/WKPageGroup.h:
     79        * UIProcess/API/mac/WKBrowsingContextGroup.h: Add the Objective-C API.
     80        * UIProcess/API/mac/WKBrowsingContextGroup.mm:
     81        (createWKArray): Add a helper function that converts an NSArray of NSStrings to a WKArray of WKStrings.
     82        (-[WKBrowsingContextGroup addUserStyleSheet:baseURL:whitelist:blacklist:mainFrameOnly:]):
     83        Implement the Objective-C API in terms of the C SPI.
     84        (-[WKBrowsingContextGroup removeAllUserStyleSheets]): Ditto.
     85        * UIProcess/WebPageGroup.cpp:
     86        (WebKit::WebPageGroup::addUserStyleSheet): Add the new sheet to the
     87        group's WebPageGroupData, which ensures that the group's sheets are
     88        sent to new web processes.
     89        (WebKit::WebPageGroup::removeAllUserStyleSheets): Ditto for removal.
     90        * UIProcess/WebPageGroup.h:
     91        (WebKit::WebPageGroup::sendToAllProcessesInGroup): Add a helper message
     92        that sends a message to all processes that have a page in the current
     93        group. This is used to add new user sheets to already-initialized page
     94        groups in the UI processes.
     95        * WebKit2.xcodeproj/project.pbxproj:
     96        * WebProcess/InjectedBundle/API/c/WKBundlePrivate.h: Moved
     97        WKUserContentInjectedFrames from here to WKBase.h.
     98        * WebProcess/WebPage/WebPageGroupProxy.cpp:
     99        (WebKit::WebPageGroupProxy::WebPageGroupProxy): Add each sheet in the
     100        WebPageGroupData to WebCore's page group.
     101        (WebKit::WebPageGroupProxy::addUserStyleSheet): Add the sheet received
     102        from the UI process to WebCore's page group.
     103        (WebKit::WebPageGroupProxy::removeAllUserStyleSheets): Remove all
     104        sheets from WebCore's page group.
     105        * WebProcess/WebPage/WebPageGroupProxy.h:
     106        * WebProcess/WebPage/WebPageGroupProxy.messages.in: Define
     107        AddUserStyleSheet and RemoveAllUserStyleSheets, two messages sent from
     108        the UI process to a web process's WebPageGroupProxy.
     109
    11102012-10-10  Sam Weinig  <sam@webkit.org>
    2111
  • trunk/Source/WebKit2/GNUmakefile.list.am

    r130316 r130948  
    442442        Source/WebKit2/Shared/UpdateInfo.cpp \
    443443        Source/WebKit2/Shared/UpdateInfo.h \
     444        Source/WebKit2/Shared/UserContentContainer.cpp \
     445        Source/WebKit2/Shared/UserContentContainer.h \
    444446        Source/WebKit2/Shared/VisitedLinkTable.cpp \
    445447        Source/WebKit2/Shared/VisitedLinkTable.h \
  • trunk/Source/WebKit2/Shared/API/c/WKArray.cpp

    r99239 r130948  
    4343}
    4444
     45WKArrayRef WKArrayCreateAdoptingValues(WKTypeRef* values, size_t numberOfValues)
     46{
     47    RefPtr<ImmutableArray> array = ImmutableArray::adopt(reinterpret_cast<APIObject**>(const_cast<void**>(values)), numberOfValues);
     48    return toAPI(array.release().leakRef());
     49}
     50
    4551WKTypeRef WKArrayGetItemAtIndex(WKArrayRef arrayRef, size_t index)
    4652{
  • trunk/Source/WebKit2/Shared/API/c/WKArray.h

    r95901 r130948  
    3838
    3939WK_EXPORT WKArrayRef WKArrayCreate(WKTypeRef* values, size_t numberOfValues);
     40WK_EXPORT WKArrayRef WKArrayCreateAdoptingValues(WKTypeRef* values, size_t numberOfValues);
    4041
    4142WK_EXPORT WKTypeRef WKArrayGetItemAtIndex(WKArrayRef array, size_t index);
  • trunk/Source/WebKit2/Shared/API/c/WKBase.h

    r128553 r130948  
    7979typedef const struct OpaqueWKURLResponse* WKURLResponseRef;
    8080typedef const struct OpaqueWKUserContentURLPattern* WKUserContentURLPatternRef;
     81
     82enum WKUserContentInjectedFrames {
     83    kWKInjectInAllFrames,
     84    kWKInjectInTopFrameOnly
     85};
     86typedef enum WKUserContentInjectedFrames WKUserContentInjectedFrames;
    8187
    8288/* WebKit2 main API types */
  • trunk/Source/WebKit2/Shared/API/c/cf/WKURLCF.cpp

    r95901 r130948  
    3939WKURLRef WKURLCreateWithCFURL(CFURLRef cfURL)
    4040{
     41    if (!cfURL)
     42        return 0;
     43
    4144    String urlString(CFURLGetString(cfURL));
    4245    return toCopiedURLAPI(urlString);
  • trunk/Source/WebKit2/Shared/ImmutableArray.cpp

    r95901 r130948  
    3333}
    3434
     35ImmutableArray::ImmutableArray(AdoptTag, APIObject** entries, size_t size)
     36    : m_entries(size)
     37{
     38    for (size_t i = 0; i < size; ++i)
     39        m_entries[i] = adoptRef(entries[i]);
     40}
     41
    3542ImmutableArray::ImmutableArray(APIObject** entries, size_t size)
    3643    : m_entries(size)
  • trunk/Source/WebKit2/Shared/ImmutableArray.h

    r95901 r130948  
    3939public:
    4040    static const Type APIType = TypeArray;
     41    enum AdoptTag { Adopt };
    4142
    4243    static PassRefPtr<ImmutableArray> create()
     
    4748    {
    4849        return adoptRef(new ImmutableArray(entries, size));
     50    }
     51    static PassRefPtr<ImmutableArray> adopt(APIObject** entries, size_t size)
     52    {
     53        return adoptRef(new ImmutableArray(Adopt, entries, size));
    4954    }
    5055    static PassRefPtr<ImmutableArray> adopt(Vector<RefPtr<APIObject> >& entries)
     
    6570protected:
    6671    ImmutableArray();
    67     ImmutableArray(APIObject** entries, size_t size);
     72    ImmutableArray(AdoptTag, APIObject** entries, size_t);
     73    ImmutableArray(APIObject** entries, size_t);
    6874    ImmutableArray(Vector<RefPtr<APIObject> >& entries);
    6975
  • trunk/Source/WebKit2/Shared/WebPageGroupData.cpp

    r95901 r130948  
    3434void WebPageGroupData::encode(CoreIPC::ArgumentEncoder* encoder) const
    3535{
    36     return encoder->encode(CoreIPC::In(identifer, pageGroupID, visibleToInjectedBundle, visibleToHistoryClient));
     36    return encoder->encode(CoreIPC::In(identifer, pageGroupID, visibleToInjectedBundle, visibleToHistoryClient, userStyleSheets));
    3737}
    3838
    3939bool WebPageGroupData::decode(CoreIPC::ArgumentDecoder* decoder, WebPageGroupData& data)
    4040{
    41     return decoder->decode(CoreIPC::Out(data.identifer, data.pageGroupID, data.visibleToInjectedBundle, data.visibleToHistoryClient));
     41    return decoder->decode(CoreIPC::Out(data.identifer, data.pageGroupID, data.visibleToInjectedBundle, data.visibleToHistoryClient, data.userStyleSheets));
    4242}
    4343
  • trunk/Source/WebKit2/Shared/WebPageGroupData.h

    r95901 r130948  
    2727#define WebPageGroupData_h
    2828
     29#include "UserContentContainer.h"
     30#include <wtf/Vector.h>
    2931#include <wtf/text/WTFString.h>
    3032
     
    4446    bool visibleToInjectedBundle;
    4547    bool visibleToHistoryClient;
     48    UserContentContainer userStyleSheets;
    4649};
    4750
  • trunk/Source/WebKit2/Target.pri

    r130207 r130948  
    9797    Shared/SurfaceUpdateInfo.h \
    9898    Shared/UpdateInfo.h \
     99    Shared/UserContentContainer.h \
    99100    Shared/UserMessageCoders.h \
    100101    Shared/VisitedLinkTable.h \
     
    453454    Shared/SurfaceUpdateInfo.cpp \
    454455    Shared/UpdateInfo.cpp \
     456    Shared/UserContentContainer.cpp \
    455457    Shared/VisitedLinkTable.cpp \
    456458    Shared/WebBackForwardListItem.cpp \
  • trunk/Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp

    r95901 r130948  
    5858    return toAPI(toImpl(pageGroupRef)->preferences());
    5959}
     60
     61void WKPageGroupAddUserStyleSheet(WKPageGroupRef pageGroupRef, WKStringRef sourceRef, WKURLRef baseURL, WKArrayRef whitelist, WKArrayRef blacklist, WKUserContentInjectedFrames injectedFrames)
     62{
     63    if (!sourceRef)
     64        return;
     65
     66    toImpl(pageGroupRef)->addUserStyleSheet(UserContentContainer::Item(toImpl(sourceRef), toImpl(baseURL), toImpl(whitelist), toImpl(blacklist), static_cast<UserContentContainer::Item::InjectedFrames>(injectedFrames), UserContentContainer::Item::TypeStylesheet));
     67}
     68
     69void WKPageGroupRemoveAllUserStyleSheets(WKPageGroupRef pageGroupRef)
     70{
     71    toImpl(pageGroupRef)->removeAllUserStyleSheets();
     72}
  • trunk/Source/WebKit2/UIProcess/API/C/WKPageGroup.h

    r95901 r130948  
    4141WK_EXPORT void WKPageGroupSetPreferences(WKPageGroupRef pageGroup, WKPreferencesRef preferences);
    4242WK_EXPORT WKPreferencesRef WKPageGroupGetPreferences(WKPageGroupRef pageGroup);
     43   
     44WK_EXPORT void WKPageGroupAddUserStyleSheet(WKPageGroupRef pageGroup, WKStringRef source, WKURLRef baseURL, WKArrayRef whitelist, WKArrayRef blacklist, WKUserContentInjectedFrames);
     45WK_EXPORT void WKPageGroupRemoveAllUserStyleSheets(WKPageGroupRef pageGroup);
    4346
    4447#ifdef __cplusplus
  • trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.h

    r98622 r130948  
    3737- (id)initWithIdentifier:(NSString *)identifier;
    3838
     39/* User Content */
     40
     41- (void)addUserStyleSheet:(NSString *)source baseURL:(NSURL *)baseURL whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist mainFrameOnly:(BOOL)mainFrameOnly;
     42- (void)removeAllUserStyleSheets;
     43
    3944
    4045/* Settings */
  • trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.mm

    r102633 r130948  
    2828#import "WKBrowsingContextGroupInternal.h"
    2929
     30#import "WKArray.h"
    3031#import "WKPageGroup.h"
    3132#import "WKPreferences.h"
    3233#import "WKRetainPtr.h"
    3334#import "WKStringCF.h"
     35#import "WKURL.h"
     36#import "WKURLCF.h"
     37#import <wtf/Vector.h>
    3438
    3539@interface WKBrowsingContextGroupData : NSObject {
     
    8286}
    8387
     88static WKArrayRef createWKArray(NSArray *array)
     89{
     90    NSUInteger count = [array count];
     91    if (count == 0)
     92        return WKArrayRef();
     93
     94    Vector<WKTypeRef> stringVector;
     95    stringVector.reserveInitialCapacity(count);
     96    for (NSUInteger i = 0; i < count; ++i) {
     97        id entry = [array objectAtIndex:i];
     98        if ([entry isKindOfClass:[NSString class]])
     99            stringVector.uncheckedAppend(WKStringCreateWithCFString((CFStringRef)entry));
     100           
     101    }
     102
     103    return WKArrayCreateAdoptingValues(stringVector.data(), stringVector.size());
     104}
     105
     106-(void)addUserStyleSheet:(NSString *)source baseURL:(NSURL *)baseURL whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist mainFrameOnly:(BOOL)mainFrameOnly
     107{
     108    if (!source)
     109        return;
     110
     111    WKRetainPtr<WKStringRef> wkSource = adoptWK(WKStringCreateWithCFString((CFStringRef)source));
     112    WKRetainPtr<WKURLRef> wkBaseURL = adoptWK(WKURLCreateWithCFURL((CFURLRef)baseURL));
     113    WKRetainPtr<WKArrayRef> wkWhitelist = adoptWK(createWKArray(whitelist));
     114    WKRetainPtr<WKArrayRef> wkBlacklist = adoptWK(createWKArray(blacklist));
     115    WKUserContentInjectedFrames injectedFrames = mainFrameOnly ? kWKInjectInTopFrameOnly : kWKInjectInAllFrames;
     116
     117    WKPageGroupAddUserStyleSheet(self._pageGroupRef, wkSource.get(), wkBaseURL.get(), wkWhitelist.get(), wkBlacklist.get(), injectedFrames);
     118}
     119
     120- (void)removeAllUserStyleSheets
     121{
     122    WKPageGroupRemoveAllUserStyleSheets(self._pageGroupRef);
     123}
     124
    84125@end
    85126
  • trunk/Source/WebKit2/UIProcess/WebPageGroup.cpp

    r95901 r130948  
    2727#include "WebPageGroup.h"
    2828
     29#include "WebPageGroupProxyMessages.h"
    2930#include "WebPageProxy.h"
    3031#include "WebPreferences.h"
     
    128129    }
    129130}
     131   
     132void WebPageGroup::addUserStyleSheet(const UserContentContainer::Item& styleSheet)
     133{
     134    m_data.userStyleSheets.addItem(styleSheet);
     135    sendToAllProcessesInGroup(Messages::WebPageGroupProxy::AddUserStyleSheet(styleSheet), m_data.pageGroupID);
     136}
     137
     138void WebPageGroup::removeAllUserStyleSheets()
     139{
     140    m_data.userStyleSheets.removeAllItems();
     141    sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveAllUserStyleSheets(), m_data.pageGroupID);
     142}
    130143
    131144} // namespace WebKit
  • trunk/Source/WebKit2/UIProcess/WebPageGroup.h

    r95901 r130948  
    2929#include "APIObject.h"
    3030#include "WebPageGroupData.h"
     31#include "WebPageProxy.h"
     32#include "WebProcessProxy.h"
    3133#include <wtf/Forward.h>
    3234#include <wtf/HashSet.h>
     
    5759    WebPreferences* preferences() const;
    5860    void preferencesDidChange();
     61   
     62    void addUserStyleSheet(const UserContentContainer::Item& styleSheet);
     63    void removeAllUserStyleSheets();
    5964
    6065private:
     
    6267
    6368    virtual Type type() const { return APIType; }
     69   
     70    template<typename MessageType> void sendToAllProcessesInGroup(const MessageType&, uint64_t destinationID);
    6471
    6572    WebPageGroupData m_data;
     
    6774    HashSet<WebPageProxy*> m_pages;
    6875};
     76   
     77template<typename MessageType> inline void WebPageGroup::sendToAllProcessesInGroup(const MessageType& message, uint64_t destinationID)
     78{
     79    HashSet<WebProcessProxy*> processesSeen;
     80    for (HashSet<WebPageProxy*>::const_iterator it = m_pages.begin(), end = m_pages.end(); it != end; ++it) {
     81        WebProcessProxy* webProcessProxy = (*it)->process();
     82        ASSERT(webProcessProxy);
     83        if (!processesSeen.add(webProcessProxy).isNewEntry)
     84            continue;
     85        if (webProcessProxy->canSendMessage())
     86            webProcessProxy->send(message, destinationID);
     87    }
     88}
    6989
    7090} // namespace WebKit
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r130316 r130948  
    251251                1CA8B946127C882A00576C2B /* WebInspectorProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CA8B944127C882A00576C2B /* WebInspectorProxyMessages.h */; };
    252252                1CA8B954127C891500576C2B /* WebInspectorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C8E2DAD1278C5B200BC7BD0 /* WebInspectorMac.mm */; };
     253                29121707161CE7360057D451 /* UserContentContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29121705161CE7360057D451 /* UserContentContainer.cpp */; };
     254                29121708161CE7360057D451 /* UserContentContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 29121706161CE7360057D451 /* UserContentContainer.h */; };
    253255                296BD85D15019BC30071F424 /* StringUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BD85B15019BC30071F424 /* StringUtilities.h */; };
    254256                296BD85E15019BC30071F424 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 296BD85C15019BC30071F424 /* StringUtilities.mm */; };
     
    13121314                1CA8B943127C882A00576C2B /* WebInspectorProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebInspectorProxyMessageReceiver.cpp; sourceTree = "<group>"; };
    13131315                1CA8B944127C882A00576C2B /* WebInspectorProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebInspectorProxyMessages.h; sourceTree = "<group>"; };
     1316                29121705161CE7360057D451 /* UserContentContainer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserContentContainer.cpp; sourceTree = "<group>"; };
     1317                29121706161CE7360057D451 /* UserContentContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserContentContainer.h; sourceTree = "<group>"; };
    13141318                296BD85B15019BC30071F424 /* StringUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtilities.h; sourceTree = "<group>"; };
    13151319                296BD85C15019BC30071F424 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = "<group>"; };
     
    13171321                29CD55A9128E294F00133C85 /* WKAccessibilityWebPageObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKAccessibilityWebPageObject.mm; sourceTree = "<group>"; };
    13181322                29D55DEE161BF8780031A2E3 /* WebPageGroupProxy.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebPageGroupProxy.messages.in; sourceTree = "<group>"; };
    1319                 29D55DEF161BF9F10031A2E3 /* WebPageGroupProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebPageGroupProxyMessageReceiver.cpp; path = WebPageGroupProxyMessageReceiver.cpp; sourceTree = "<group>"; };
    1320                 29D55DF0161BF9F10031A2E3 /* WebPageGroupProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebPageGroupProxyMessages.h; path = WebPageGroupProxyMessages.h; sourceTree = "<group>"; };
     1323                29D55DEF161BF9F10031A2E3 /* WebPageGroupProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPageGroupProxyMessageReceiver.cpp; sourceTree = "<group>"; };
     1324                29D55DF0161BF9F10031A2E3 /* WebPageGroupProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPageGroupProxyMessages.h; sourceTree = "<group>"; };
    13211325                31099968146C71F50029DEB9 /* WebNotificationClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebNotificationClient.h; sourceTree = "<group>"; };
    13221326                31099971146C759B0029DEB9 /* WebNotificationClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebNotificationClient.cpp; sourceTree = "<group>"; };
     
    25552559                                F6113E24126CE1820057D0A7 /* WebUserContentURLPattern.h */,
    25562560                                C0337DD0127A2980008FF4F4 /* WebWheelEvent.cpp */,
     2561                                29121705161CE7360057D451 /* UserContentContainer.cpp */,
     2562                                29121706161CE7360057D451 /* UserContentContainer.h */,
    25572563                        );
    25582564                        path = Shared;
     
    43394345                                1A3EED12161A53D600AEB4F5 /* MessageReceiver.h in Headers */,
    43404346                                29D55DF2161BF9F10031A2E3 /* WebPageGroupProxyMessages.h in Headers */,
     4347                                29121708161CE7360057D451 /* UserContentContainer.h in Headers */,
    43414348                        );
    43424349                        runOnlyForDeploymentPostprocessing = 0;
     
    51985205                                1A3EED0E161A535400AEB4F5 /* MessageReceiverMap.cpp in Sources */,
    51995206                                29D55DF1161BF9F10031A2E3 /* WebPageGroupProxyMessageReceiver.cpp in Sources */,
     5207                                29121707161CE7360057D451 /* UserContentContainer.cpp in Sources */,
    52005208                        );
    52015209                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h

    r130662 r130948  
    4242};
    4343typedef enum WKUserScriptInjectionTime WKUserScriptInjectionTime;
    44 
    45 enum WKUserContentInjectedFrames {
    46     kWKInjectInAllFrames,
    47     kWKInjectInTopFrameOnly
    48 };
    49 typedef enum WKUserContentInjectedFrames WKUserContentInjectedFrames;
    5044
    5145// TestRunner only SPI
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPageGroupProxy.cpp

    r130316 r130948  
    2929#include "WebProcess.h"
    3030#include "InjectedBundle.h"
     31#include <WebCore/DOMWrapperWorld.h>
     32#include <WebCore/PageGroup.h>
    3133
    3234namespace WebKit {
     
    5052    didReceiveWebPageGroupProxyMessage(connection, messageID, arguments);
    5153}
     54   
     55WebPageGroupProxy::WebPageGroupProxy(const WebPageGroupData& data)
     56    : m_data(data)
     57    , m_pageGroup(WebCore::PageGroup::pageGroup(m_data.identifer))
     58{
     59    for (size_t i = 0; i < data.userStyleSheets.size(); ++i)
     60        addUserStyleSheet(data.userStyleSheets.at(i));
     61}
    5262
    53 void WebPageGroupProxy::didReceiveWebPageGroupProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*)
     63void WebPageGroupProxy::addUserStyleSheet(const UserContentContainer::Item& styleSheet)
    5464{
    55     // FIXME: Remove this once WebPageGroupProxy.messages.in contains messages,
    56     // in which case this method will be auto-generated.
     65    m_pageGroup->addUserStyleSheetToWorld(WebCore::mainThreadNormalWorld(), styleSheet.source(), styleSheet.url(), styleSheet.whitelist(), styleSheet.blacklist(), static_cast<WebCore::UserContentInjectedFrames>(styleSheet.injectedFrames()));
     66}
     67
     68void WebPageGroupProxy::removeAllUserStyleSheets()
     69{
     70    m_pageGroup->removeUserStyleSheetsFromWorld(WebCore::mainThreadNormalWorld());
    5771}
    5872
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPageGroupProxy.h

    r130316 r130948  
    3737}
    3838
     39namespace WebCore {
     40class PageGroup;
     41}
     42
    3943namespace WebKit {
    4044
     
    5458
    5559private:
    56     WebPageGroupProxy(const WebPageGroupData& data)
    57         : m_data(data)
    58     {
    59     }
     60    WebPageGroupProxy(const WebPageGroupData&);
    6061
    6162    virtual Type type() const { return APIType; }
    6263   
    6364    void didReceiveWebPageGroupProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
     65   
     66    void addUserStyleSheet(const UserContentContainer::Item& styleSheet);
     67    void removeAllUserStyleSheets();
    6468
    6569    WebPageGroupData m_data;
     70    WebCore::PageGroup* m_pageGroup;
    6671};
    6772
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPageGroupProxy.messages.in

    r130316 r130948  
    2222
    2323messages -> WebPageGroupProxy {
     24    AddUserStyleSheet(WebKit::UserContentContainer::Item styleSheet);
     25    RemoveAllUserStyleSheets();
    2426}
  • trunk/Source/WebKit2/win/WebKit2.vcproj

    r130316 r130948  
    588588                        </File>
    589589                        <File
     590                                RelativePath="..\Shared\UserContentContainer.cpp"
     591                                >
     592                        </File>
     593                        <File
     594                                RelativePath="..\Shared\UserContentContainer.h"
     595                                >
     596                        </File>
     597                        <File
    590598                                RelativePath="..\Shared\UserMessageCoders.h"
    591599                                >
  • trunk/Tools/ChangeLog

    r130924 r130948  
     12012-10-04  Andy Estes  <aestes@apple.com>
     2
     3        [WebKit2] Create an API for adding and removing user stylesheets from a page group
     4        https://bugs.webkit.org/show_bug.cgi?id=98432
     5
     6        Reviewed by Sam Weinig.
     7
     8        Add three new API tests:
     9
     10        - Test adding a user stylesheet before a page is created. This tests
     11        the code path where the sheet is sent to the web process as part of
     12        the new page's WebPageCreationParameters.
     13        - Test adding a user stylesheet after a page is created. This tests the
     14        code patch where the sheet is sent as a separate message to all
     15        processes containing the given page group.
     16        - Test removing all user stylesheets.
     17
     18        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     19        * TestWebKitAPI/Tests/WebKit2ObjC/UserContentTest.mm: Added.
     20        (-[UserContentTestLoadDelegate initWithBlockToRunOnLoad:]):
     21        (-[UserContentTestLoadDelegate browsingContextControllerDidFinishLoad:]):
     22        (expectScriptValue):
     23        * TestWebKitAPI/Tests/WebKit2ObjC/WKBrowsingContextGroupTest.mm:
     24
    1252012-10-10  Dan Bernstein  <mitz@apple.com>
    226
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r129545 r130948  
    3232                26F1B44415CA434F00D1E4BF /* AtomicString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F1B44215CA434F00D1E4BF /* AtomicString.cpp */; };
    3333                26F1B44515CA434F00D1E4BF /* StringImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F1B44315CA434F00D1E4BF /* StringImpl.cpp */; };
     34                2943BE86161DFEB800999E3D /* UserContentTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2943BE84161DFEB800999E3D /* UserContentTest.mm */; };
    3435                333B9CE21277F23100FEFCE3 /* PreventEmptyUserAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */; };
    3536                33BE5AF5137B5A6C00705813 /* MouseMoveAfterCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */; };
     
    267268                26F1B44215CA434F00D1E4BF /* AtomicString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AtomicString.cpp; path = WTF/AtomicString.cpp; sourceTree = "<group>"; };
    268269                26F1B44315CA434F00D1E4BF /* StringImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringImpl.cpp; path = WTF/StringImpl.cpp; sourceTree = "<group>"; };
     270                2943BE84161DFEB800999E3D /* UserContentTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = UserContentTest.mm; path = WebKit2ObjC/UserContentTest.mm; sourceTree = "<group>"; };
    269271                333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; };
    270272                33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; };
     
    530532                        isa = PBXGroup;
    531533                        children = (
     534                                2943BE84161DFEB800999E3D /* UserContentTest.mm */,
    532535                                BC3C4C7D14587AA60025FB62 /* WKBrowsingContextGroupTest.mm */,
    533536                                BC3C4C7014575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm */,
     
    988991                                265AF55015D1E48A00B0CB4A /* WTFString.cpp in Sources */,
    989992                                9318778915EEC57700A9CCE3 /* NewFirstVisuallyNonEmptyLayoutForImages.cpp in Sources */,
     993                                2943BE86161DFEB800999E3D /* UserContentTest.mm in Sources */,
    990994                        );
    991995                        runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset for help on using the changeset viewer.