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

Changeset 197831 in webkit


Ignore:
Timestamp:
Mar 8, 2016, 8:39:49 PM (11 years ago)
Author:
weinig@apple.com
Message:

Stop using the UserContentController for injecting the override style sheet from CaptionUserPreferences
​https://bugs.webkit.org/show_bug.cgi?id=155211

Reviewed by Dan Bernstein.

The UserContentController is going to become read only from WebCore's perspective. The CaptionUserPreferences
was relying on being able to set a UserStyleSheet on it, but this was really unnecessary complexity. Simplify
things by storing the style sheet's source directly on the Page and teaching ExtensionStyleSheets about it
explicitly.

  • dom/ExtensionStyleSheets.cpp:

(WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache):
If there is a captionUserPreferencesStyleSheet on the page, inject it.

  • page/CaptionUserPreferences.cpp:

(WebCore::CaptionUserPreferences::updateCaptionStyleSheetOveride):
Greatly simplify the code. Now, all this does is set the style sheet on each page.

  • page/Page.cpp:

(WebCore::Page::invalidateInjectedStyleSheetCacheInAllFrames):
Extract this out from UserContentController.

(WebCore::Page::setUserContentController):
Call the newly extracted invalidateInjectedStyleSheetCacheInAllFrames().

(WebCore::Page::captionUserPreferencesStyleSheet):
(WebCore::Page::setCaptionUserPreferencesStyleSheet):
Add getter/setter. When setting, invalidate the style sheet cache.

  • page/Page.h:

Add new members and functions.

  • page/UserContentController.cpp:

(WebCore::UserContentController::addUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheet):
(WebCore::UserContentController::removeUserStyleSheets):
(WebCore::UserContentController::removeAllUserContent):
Switch to calling invalidateInjectedStyleSheetCacheInAllFramesInAllPages().

(WebCore::UserContentController::invalidateInjectedStyleSheetCacheInAllFramesInAllPages):
Rename and implement in terms of Page::invalidateInjectedStyleSheetCacheInAllFrames().

  • page/UserContentController.h:

Rename function.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r197827 r197831  
     12016-03-08  Sam Weinig  <sam@webkit.org>
     2
     3        Stop using the UserContentController for injecting the override style sheet from CaptionUserPreferences
     4        https://bugs.webkit.org/show_bug.cgi?id=155211
     5
     6        Reviewed by Dan Bernstein.
     7
     8        The UserContentController is going to become read only from WebCore's perspective. The CaptionUserPreferences
     9        was relying on being able to set a UserStyleSheet on it, but this was really unnecessary complexity. Simplify
     10        things by storing the style sheet's source directly on the Page and teaching ExtensionStyleSheets about it
     11        explicitly.
     12
     13        * dom/ExtensionStyleSheets.cpp:
     14        (WebCore::ExtensionStyleSheets::updateInjectedStyleSheetCache):
     15        If there is a captionUserPreferencesStyleSheet on the page, inject it.
     16
     17        * page/CaptionUserPreferences.cpp:
     18        (WebCore::CaptionUserPreferences::updateCaptionStyleSheetOveride):
     19        Greatly simplify the code. Now, all this does is set the style sheet on each page.
     20
     21        * page/Page.cpp:
     22        (WebCore::Page::invalidateInjectedStyleSheetCacheInAllFrames):
     23        Extract this out from UserContentController.
     24
     25        (WebCore::Page::setUserContentController):
     26        Call the newly extracted invalidateInjectedStyleSheetCacheInAllFrames().
     27
     28        (WebCore::Page::captionUserPreferencesStyleSheet):
     29        (WebCore::Page::setCaptionUserPreferencesStyleSheet):
     30        Add getter/setter. When setting, invalidate the style sheet cache.
     31
     32        * page/Page.h:
     33        Add new members and functions.
     34
     35        * page/UserContentController.cpp:
     36        (WebCore::UserContentController::addUserStyleSheet):
     37        (WebCore::UserContentController::removeUserStyleSheet):
     38        (WebCore::UserContentController::removeUserStyleSheets):
     39        (WebCore::UserContentController::removeAllUserContent):
     40        Switch to calling invalidateInjectedStyleSheetCacheInAllFramesInAllPages().
     41
     42        (WebCore::UserContentController::invalidateInjectedStyleSheetCacheInAllFramesInAllPages):
     43        Rename and implement in terms of Page::invalidateInjectedStyleSheetCacheInAllFrames().
     44
     45        * page/UserContentController.h:
     46        Rename function.
     47
    1482016-03-08  Joseph Pecoraro  <pecoraro@apple.com>
    249
  • trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp

    r195088 r197831  
    118118        return;
    119119
     120    if (!owningPage->captionUserPreferencesStyleSheet().isEmpty()) {
     121        // Identify our override style sheet with a unique URL - a new scheme and a UUID.
     122        static NeverDestroyed<URL> captionsStyleSheetURL(ParsedURLString, "user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23");
     123
     124        RefPtr<CSSStyleSheet> sheet = CSSStyleSheet::createInline(const_cast<Document&>(m_document), captionsStyleSheetURL.get());
     125        m_injectedAuthorStyleSheets.append(sheet);
     126
     127        sheet->contents().setIsUserStyleSheet(false);
     128        sheet->contents().parseString(owningPage->captionUserPreferencesStyleSheet());
     129    }
     130
    120131    const auto* userContentController = owningPage->userContentController();
    121132    if (!userContentController)
  • trunk/Source/WebCore/page/CaptionUserPreferences.cpp

    r196010 r197831  
    299299void CaptionUserPreferences::updateCaptionStyleSheetOveride()
    300300{
    301     // Identify our override style sheet with a unique URL - a new scheme and a UUID.
    302     static NeverDestroyed<URL> captionsStyleSheetURL(ParsedURLString, "user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23");
    303 
    304     auto& pages = m_pageGroup.pages();
    305     for (auto& page : pages) {
    306         if (auto* pageUserContentController = page->userContentController())
    307             pageUserContentController->removeUserStyleSheet(mainThreadNormalWorld(), captionsStyleSheetURL);
    308     }
    309 
    310301    String captionsOverrideStyleSheet = captionsStyleSheetOverride();
    311     if (captionsOverrideStyleSheet.isEmpty())
    312         return;
    313 
    314     for (auto& page : pages) {
    315         if (auto* pageUserContentController = page->userContentController()) {
    316             auto userStyleSheet = std::make_unique<UserStyleSheet>(captionsOverrideStyleSheet, captionsStyleSheetURL, Vector<String>(), Vector<String>(), InjectInAllFrames, UserStyleAuthorLevel);
    317             pageUserContentController->addUserStyleSheet(mainThreadNormalWorld(), WTFMove(userStyleSheet), InjectInExistingDocuments);
    318         }
    319     }
     302    for (auto& page : m_pageGroup.pages())
     303        page->setCaptionUserPreferencesStyleSheet(captionsOverrideStyleSheet);
    320304}
    321305
  • trunk/Source/WebCore/page/Page.cpp

    r197728 r197831  
    11271127}
    11281128
     1129void Page::invalidateInjectedStyleSheetCacheInAllFrames()
     1130{
     1131    for (Frame* frame = m_mainFrame.get(); frame; frame = frame->tree().traverseNext()) {
     1132        Document* document = frame->document();
     1133        if (!document)
     1134            continue;
     1135        document->extensionStyleSheets().invalidateInjectedStyleSheetCache();
     1136        document->styleResolverChanged(DeferRecalcStyle);
     1137    }
     1138}
     1139
    11291140void Page::setDebugger(JSC::Debugger* debugger)
    11301141{
    … …  
    18191830        m_userContentController->addPage(*this);
    18201831
    1821     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
    1822         if (Document *document = frame->document()) {
    1823             document->extensionStyleSheets().invalidateInjectedStyleSheetCache();
    1824             document->styleResolverChanged(DeferRecalcStyle);
    1825         }
    1826     }
     1832    invalidateInjectedStyleSheetCacheInAllFrames();
    18271833}
    18281834
    … …  
    20092015}
    20102016
     2017String Page::captionUserPreferencesStyleSheet()
     2018{
     2019    return m_captionUserPreferencesStyleSheet;
     2020}
     2021
     2022void Page::setCaptionUserPreferencesStyleSheet(const String& styleSheet)
     2023{
     2024    if (m_captionUserPreferencesStyleSheet == styleSheet)
     2025        return;
     2026
     2027    m_captionUserPreferencesStyleSheet = styleSheet;
     2028   
     2029    invalidateInjectedStyleSheetCacheInAllFrames();
     2030}
     2031
    20112032} // namespace WebCore
  • trunk/Source/WebCore/page/Page.h

    r197728 r197831  
    358358    WEBCORE_EXPORT void invalidateStylesForLink(LinkHash);
    359359
     360    void invalidateInjectedStyleSheetCacheInAllFrames();
     361
    360362    StorageNamespace* sessionStorage(bool optionalCreate = true);
    361363    void setSessionStorage(RefPtr<StorageNamespace>&&);
    … …  
    510512    bool isAlwaysOnLoggingAllowed() const;
    511513
     514    String captionUserPreferencesStyleSheet();
     515    void setCaptionUserPreferencesStyleSheet(const String&);
     516
    512517private:
    513518    WEBCORE_EXPORT void initGroup();
    … …  
    609614    mutable bool m_didLoadUserStyleSheet;
    610615    mutable time_t m_userStyleSheetModificationTime;
     616
     617    String m_captionUserPreferencesStyleSheet;
    611618
    612619    std::unique_ptr<PageGroup> m_singlePageGroup;
  • trunk/Source/WebCore/page/UserContentController.cpp

    r194496 r197831  
    124124
    125125    if (injectionTime == InjectInExistingDocuments)
    126         invalidateInjectedStyleSheetCacheInAllFrames();
     126        invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
    127127}
    128128
    … …  
    152152        m_userStyleSheets->remove(it);
    153153
    154     invalidateInjectedStyleSheetCacheInAllFrames();
     154    invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
    155155}
    156156
    … …  
    163163        return;
    164164
    165     invalidateInjectedStyleSheetCacheInAllFrames();
     165    invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
    166166}
    167167
    … …  
    250250    if (m_userStyleSheets) {
    251251        m_userStyleSheets = nullptr;
    252         invalidateInjectedStyleSheetCacheInAllFrames();
    253     }
    254 }
    255 
    256 void UserContentController::invalidateInjectedStyleSheetCacheInAllFrames()
    257 {
    258     for (auto& page : m_pages) {
    259         for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
    260             frame->document()->extensionStyleSheets().invalidateInjectedStyleSheetCache();
    261             frame->document()->styleResolverChanged(DeferRecalcStyle);
    262         }
    263     }
     252        invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
     253    }
     254}
     255
     256void UserContentController::invalidateInjectedStyleSheetCacheInAllFramesInAllPages()
     257{
     258    for (auto& page : m_pages)
     259        page->invalidateInjectedStyleSheetCacheInAllFrames();
    264260}
    265261
  • trunk/Source/WebCore/page/UserContentController.h

    r191266 r197831  
    104104    UserContentController();
    105105
    106     void invalidateInjectedStyleSheetCacheInAllFrames();
     106    void invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
    107107
    108108    HashSet<Page*> m_pages;
Note: See TracChangeset for help on using the changeset viewer.