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

Changeset 176542 in webkit


Ignore:
Timestamp:
Nov 25, 2014, 8:16:15 AM (12 years ago)
Author:
andersca@apple.com
Message:

Add a user content controller to WebViewGroup and use it for user content
https://bugs.webkit.org/show_bug.cgi?id=139043

Reviewed by Antti Koivisto.

Source/WebCore:

  • WebCore.exp.in:

Export symbols.

  • page/Page.cpp:

(WebCore::Page::setUserContentController):
Invalidate the injected style cache when setting a new user content controller.

Source/WebKit/mac:

This is another tiny step towards getting rid of user content handling inside PageGroup.

  • WebCoreSupport/WebViewGroup.h:

(WebViewGroup::userContentController):
Add a UserContentController member and getter.

  • WebCoreSupport/WebViewGroup.mm:

(WebViewGroup::get):
Helper function that returns a WebViewGroup by its name (or null if it doesn't exist).

(WebViewGroup::WebViewGroup):
Create a user content controller.

  • WebView/WebView.mm:

(-[WebView _commonInitializationWithFrameName:groupName:]):
Instead of calling -[WebView setGroupName:], create a WebViewGroup before creating the page, that way we can
set its user content controller in the PageConfiguration.

(-[WebView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]):
Ditto.

(+[WebView _addUserScriptToGroup:world:source:url:whitelist:blacklist:injectionTime:injectedFrames:]):
(+[WebView _addUserStyleSheetToGroup:world:source:url:whitelist:blacklist:injectedFrames:]):
(+[WebView _removeUserScriptFromGroup:world:url:]):
(+[WebView _removeUserStyleSheetFromGroup:world:url:]):
(+[WebView _removeUserScriptsFromGroup:world:]):
(+[WebView _removeUserStyleSheetsFromGroup:world:]):
(+[WebView _removeAllUserContentFromGroup:]):
Instead of calling into the PageGroup, get the WebViewGroup's user content controller and call into that.

(-[WebView setGroupName:]):
Set the user content controller to the new WebViewGroup's user content controller.

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r176541 r176542  
     12014-11-25  Anders Carlsson  <andersca@apple.com>
     2
     3        Add a user content controller to WebViewGroup and use it for user content
     4        https://bugs.webkit.org/show_bug.cgi?id=139043
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * WebCore.exp.in:
     9        Export symbols.
     10
     11        * page/Page.cpp:
     12        (WebCore::Page::setUserContentController):
     13        Invalidate the injected style cache when setting a new user content controller.
     14
    1152014-11-25  Philippe Normand  <pnormand@igalia.com>
    216
  • trunk/Source/WebCore/WebCore.exp.in

    r176509 r176542  
    958958__ZN7WebCore21URLByRemovingUserInfoEP5NSURL
    959959__ZN7WebCore21UserContentController13addUserScriptERNS_15DOMWrapperWorldENSt3__110unique_ptrINS_10UserScriptENS3_14default_deleteIS5_EEEE
     960__ZN7WebCore21UserContentController16removeUserScriptERNS_15DOMWrapperWorldERKNS_3URLE
    960961__ZN7WebCore21UserContentController17addUserStyleSheetERNS_15DOMWrapperWorldENSt3__110unique_ptrINS_14UserStyleSheetENS3_14default_deleteIS5_EEEENS_22UserStyleInjectionTimeE
    961962__ZN7WebCore21UserContentController17removeUserScriptsERNS_15DOMWrapperWorldE
     963__ZN7WebCore21UserContentController20removeAllUserContentEv
     964__ZN7WebCore21UserContentController20removeUserStyleSheetERNS_15DOMWrapperWorldERKNS_3URLE
    962965__ZN7WebCore21UserContentController21removeUserStyleSheetsERNS_15DOMWrapperWorldE
    963966__ZN7WebCore21UserContentController31addUserMessageHandlerDescriptorERNS_28UserMessageHandlerDescriptorE
     
    11661169__ZN7WebCore4Page24resumeScriptedAnimationsEv
    11671170__ZN7WebCore4Page24scrollingStateTreeAsTextEv
     1171__ZN7WebCore4Page24setUserContentControllerEPNS_21UserContentControllerE
    11681172__ZN7WebCore4Page25suspendScriptedAnimationsEv
    11691173__ZN7WebCore4Page27enableLegacyPrivateBrowsingEb
  • trunk/Source/WebCore/page/Page.cpp

    r176499 r176542  
    16211621    if (m_userContentController)
    16221622        m_userContentController->addPage(*this);
     1623
     1624    for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
     1625        if (Document *document = frame->document()) {
     1626            document->styleSheetCollection().invalidateInjectedStyleSheetCache();
     1627            document->styleResolverChanged(DeferRecalcStyle);
     1628        }
     1629    }
    16231630}
    16241631
  • trunk/Source/WebKit/mac/ChangeLog

    r176499 r176542  
     12014-11-25  Anders Carlsson  <andersca@apple.com>
     2
     3        Add a user content controller to WebViewGroup and use it for user content
     4        https://bugs.webkit.org/show_bug.cgi?id=139043
     5
     6        Reviewed by Antti Koivisto.
     7
     8        This is another tiny step towards getting rid of user content handling inside PageGroup.
     9
     10        * WebCoreSupport/WebViewGroup.h:
     11        (WebViewGroup::userContentController):
     12        Add a UserContentController member and getter.
     13
     14        * WebCoreSupport/WebViewGroup.mm:
     15        (WebViewGroup::get):
     16        Helper function that returns a WebViewGroup by its name (or null if it doesn't exist).
     17
     18        (WebViewGroup::WebViewGroup):
     19        Create a user content controller.
     20
     21        * WebView/WebView.mm:
     22        (-[WebView _commonInitializationWithFrameName:groupName:]):
     23        Instead of calling -[WebView setGroupName:], create a WebViewGroup before creating the page, that way we can
     24        set its user content controller in the PageConfiguration.
     25
     26        (-[WebView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]):
     27        Ditto.
     28
     29        (+[WebView _addUserScriptToGroup:world:source:url:whitelist:blacklist:injectionTime:injectedFrames:]):
     30        (+[WebView _addUserStyleSheetToGroup:world:source:url:whitelist:blacklist:injectedFrames:]):
     31        (+[WebView _removeUserScriptFromGroup:world:url:]):
     32        (+[WebView _removeUserStyleSheetFromGroup:world:url:]):
     33        (+[WebView _removeUserScriptsFromGroup:world:]):
     34        (+[WebView _removeUserStyleSheetsFromGroup:world:]):
     35        (+[WebView _removeAllUserContentFromGroup:]):
     36        Instead of calling into the PageGroup, get the WebViewGroup's user content controller and call into that.
     37
     38        (-[WebView setGroupName:]):
     39        Set the user content controller to the new WebViewGroup's user content controller.
     40
    1412014-11-21  Jer Noble  <jer.noble@apple.com>
    242
  • trunk/Source/WebKit/mac/WebCoreSupport/WebViewGroup.h

    r164618 r176542  
    2424 */
    2525
    26 #import <wtf/HashSet.h>
    27 #import <wtf/RefCounted.h>
    28 #import <wtf/PassRefPtr.h>
    29 #import <wtf/text/WTFString.h>
     26#import <WebCore/UserContentController.h>
    3027
    3128@class WebView;
     
    3633    ~WebViewGroup();
    3734
     35    static WebViewGroup* get(const String& name);
     36
    3837    void addWebView(WebView *);
    3938    void removeWebView(WebView *);
    40    
     39
     40    WebCore::UserContentController& userContentController() { return m_userContentController.get(); }
     41
    4142private:
    4243    WebViewGroup(const String& name);
     
    4445    String m_name;
    4546    HashSet<WebView *> m_webViews;
     47
     48    Ref<WebCore::UserContentController> m_userContentController;
    4649};
  • trunk/Source/WebKit/mac/WebCoreSupport/WebViewGroup.mm

    r164618 r176542  
    2727
    2828#import "WebView.h"
    29 #import <wtf/HashMap.h>
    3029#import <wtf/NeverDestroyed.h>
    31 #import <wtf/RefPtr.h>
    3230#import <wtf/text/StringHash.h>
     31
     32using namespace WebCore;
    3333
    3434// Any named groups will live for the lifetime of the process, thanks to the reference held by the RefPtr.
     
    5252}
    5353
     54WebViewGroup* WebViewGroup::get(const String& name)
     55{
     56    ASSERT(!name.isEmpty());
     57
     58    return webViewGroups().get(name);
     59}
     60
    5461WebViewGroup::WebViewGroup(const String& name)
    5562    : m_name(name)
     63    , m_userContentController(*UserContentController::create())
    5664{
    5765}
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r176499 r176542  
    177177#import <WebCore/ThreadCheck.h>
    178178#import <WebCore/UserAgent.h>
     179#import <WebCore/UserContentController.h>
    179180#import <WebCore/WebCoreObjCExtras.h>
    180181#import <WebCore/WebCoreView.h>
     
    920921    }
    921922
     923    _private->group = WebViewGroup::getOrCreate(groupName);
     924    _private->group->addWebView(self);
     925
    922926    PageConfiguration pageConfiguration;
    923927#if !PLATFORM(IOS)
     
    936940    pageConfiguration.loaderClientForMainFrame = new WebFrameLoaderClient;
    937941    pageConfiguration.progressTrackerClient = new WebProgressTrackerClient(self);
     942    pageConfiguration.userContentController = &_private->group->userContentController();
    938943    _private->page = new Page(pageConfiguration);
     944
     945    _private->page->setGroupName(groupName);
     946
    939947#if ENABLE(GEOLOCATION)
    940948    WebCore::provideGeolocationTo(_private->page, new WebGeolocationClient(self));
     
    9931001
    9941002    [self _addToAllWebViewsSet];
    995     [self setGroupName:groupName];
    9961003   
    9971004    // If there's already a next key view (e.g., from a nib), wire it up to our
     
    11561163    [frameView release];
    11571164
    1158    
     1165    _private->group = WebViewGroup::getOrCreate(groupName);
     1166    _private->group->addWebView(self);
     1167
    11591168    PageConfiguration pageConfiguration;
    11601169    pageConfiguration.chromeClient = new WebChromeClientIOS(self);
     
    11661175    pageConfiguration.loaderClientForMainFrame = new WebFrameLoaderClient;
    11671176    pageConfiguration.progressTrackerClient = new WebProgressTrackerClient(self);
     1177    pageConfiguration.userContentController = &_private->group->userContentController();
     1178
    11681179    _private->page = new Page(pageConfiguration);
    11691180   
     
    11931204    _private->page->settings().setMinimumFontSize([_private->preferences minimumFontSize]);
    11941205
    1195     [self setGroupName:groupName];
     1206    _private->page->setGroupName(groupName);
    11961207
    11971208#if ENABLE(REMOTE_INSPECTOR)
     
    39964007    if (group.isEmpty())
    39974008        return;
    3998    
    3999     PageGroup* pageGroup = PageGroup::pageGroup(group);
    4000     if (!pageGroup)
     4009
     4010    auto* viewGroup = WebViewGroup::get(group);
     4011    if (!viewGroup)
    40014012        return;
    40024013
     
    40044015        return;
    40054016
    4006     pageGroup->addUserScriptToWorld(*core(world), source, url, toStringVector(whitelist), toStringVector(blacklist),
    4007                                     injectionTime == WebInjectAtDocumentStart ? InjectAtDocumentStart : InjectAtDocumentEnd,
    4008                                     injectedFrames == WebInjectInAllFrames ? InjectInAllFrames : InjectInTopFrameOnly);
     4017    auto userScript = std::make_unique<UserScript>(source, url, toStringVector(whitelist), toStringVector(blacklist), injectionTime == WebInjectAtDocumentStart ? InjectAtDocumentStart : InjectAtDocumentEnd, injectedFrames == WebInjectInAllFrames ? InjectInAllFrames : InjectInTopFrameOnly);
     4018    viewGroup->userContentController().addUserScript(*core(world), WTF::move(userScript));
    40094019}
    40104020
     
    40224032    if (group.isEmpty())
    40234033        return;
    4024    
    4025     PageGroup* pageGroup = PageGroup::pageGroup(group);
    4026     if (!pageGroup)
     4034
     4035    auto* viewGroup = WebViewGroup::get(group);
     4036    if (!viewGroup)
    40274037        return;
    40284038
     
    40304040        return;
    40314041
    4032     pageGroup->addUserStyleSheetToWorld(*core(world), source, url, toStringVector(whitelist), toStringVector(blacklist), injectedFrames == WebInjectInAllFrames ? InjectInAllFrames : InjectInTopFrameOnly);
     4042    auto styleSheet = std::make_unique<UserStyleSheet>(source, url, toStringVector(whitelist), toStringVector(blacklist), injectedFrames == WebInjectInAllFrames ? InjectInAllFrames : InjectInTopFrameOnly, UserStyleUserLevel);
     4043    viewGroup->userContentController().addUserStyleSheet(*core(world), WTF::move(styleSheet), InjectInExistingDocuments);
    40334044}
    40344045
     
    40384049    if (group.isEmpty())
    40394050        return;
    4040    
    4041     PageGroup* pageGroup = PageGroup::pageGroup(group);
    4042     if (!pageGroup)
     4051
     4052    auto* viewGroup = WebViewGroup::get(group);
     4053    if (!viewGroup)
    40434054        return;
    40444055
     
    40464057        return;
    40474058
    4048     pageGroup->removeUserScriptFromWorld(*core(world), url);
     4059    viewGroup->userContentController().removeUserScript(*core(world), url);
    40494060}
    40504061
     
    40544065    if (group.isEmpty())
    40554066        return;
    4056    
    4057     PageGroup* pageGroup = PageGroup::pageGroup(group);
    4058     if (!pageGroup)
     4067
     4068    auto* viewGroup = WebViewGroup::get(group);
     4069    if (!viewGroup)
    40594070        return;
    40604071
     
    40624073        return;
    40634074
    4064     pageGroup->removeUserStyleSheetFromWorld(*core(world), url);
     4075    viewGroup->userContentController().removeUserStyleSheet(*core(world), url);
    40654076}
    40664077
     
    40704081    if (group.isEmpty())
    40714082        return;
    4072    
    4073     PageGroup* pageGroup = PageGroup::pageGroup(group);
    4074     if (!pageGroup)
     4083
     4084    auto* viewGroup = WebViewGroup::get(group);
     4085    if (!viewGroup)
    40754086        return;
    40764087
     
    40784089        return;
    40794090
    4080     pageGroup->removeUserScriptsFromWorld(*core(world));
     4091    viewGroup->userContentController().removeUserScripts(*core(world));
    40814092}
    40824093
     
    40864097    if (group.isEmpty())
    40874098        return;
    4088    
    4089     PageGroup* pageGroup = PageGroup::pageGroup(group);
    4090     if (!pageGroup)
     4099
     4100    auto* viewGroup = WebViewGroup::get(group);
     4101    if (!viewGroup)
    40914102        return;
    40924103
     
    40944105        return;
    40954106
    4096     pageGroup->removeUserStyleSheetsFromWorld(*core(world));
     4107    viewGroup->userContentController().removeUserStyleSheets(*core(world));
    40974108}
    40984109
     
    41024113    if (group.isEmpty())
    41034114        return;
    4104    
    4105     PageGroup* pageGroup = PageGroup::pageGroup(group);
    4106     if (!pageGroup)
    4107         return;
    4108    
    4109     pageGroup->removeAllUserContent();
     4115
     4116    auto* viewGroup = WebViewGroup::get(group);
     4117    if (!viewGroup)
     4118        return;
     4119
     4120    viewGroup->userContentController().removeAllUserContent();
    41104121}
    41114122
     
    61036114    if (!_private->page)
    61046115        return;
     6116
     6117    _private->page->setUserContentController(&_private->group->userContentController());
    61056118    _private->page->setGroupName(groupName);
    61066119}
Note: See TracChangeset for help on using the changeset viewer.