Title: [197831] trunk/Source/WebCore
Revision
197831
Author
[email protected]
Date
2016-03-08 20:39:49 -0800 (Tue, 08 Mar 2016)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (197830 => 197831)


--- trunk/Source/WebCore/ChangeLog	2016-03-09 02:50:22 UTC (rev 197830)
+++ trunk/Source/WebCore/ChangeLog	2016-03-09 04:39:49 UTC (rev 197831)
@@ -1,3 +1,50 @@
+2016-03-08  Sam Weinig  <[email protected]>
+
+        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.
+
 2016-03-08  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Memory Timeline should show MemoryPressure events

Modified: trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp (197830 => 197831)


--- trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp	2016-03-09 02:50:22 UTC (rev 197830)
+++ trunk/Source/WebCore/dom/ExtensionStyleSheets.cpp	2016-03-09 04:39:49 UTC (rev 197831)
@@ -117,6 +117,17 @@
     if (!owningPage)
         return;
 
+    if (!owningPage->captionUserPreferencesStyleSheet().isEmpty()) {
+        // Identify our override style sheet with a unique URL - a new scheme and a UUID.
+        static NeverDestroyed<URL> captionsStyleSheetURL(ParsedURLString, "user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23");
+
+        RefPtr<CSSStyleSheet> sheet = CSSStyleSheet::createInline(const_cast<Document&>(m_document), captionsStyleSheetURL.get());
+        m_injectedAuthorStyleSheets.append(sheet);
+
+        sheet->contents().setIsUserStyleSheet(false);
+        sheet->contents().parseString(owningPage->captionUserPreferencesStyleSheet());
+    }
+
     const auto* userContentController = owningPage->userContentController();
     if (!userContentController)
         return;

Modified: trunk/Source/WebCore/page/CaptionUserPreferences.cpp (197830 => 197831)


--- trunk/Source/WebCore/page/CaptionUserPreferences.cpp	2016-03-09 02:50:22 UTC (rev 197830)
+++ trunk/Source/WebCore/page/CaptionUserPreferences.cpp	2016-03-09 04:39:49 UTC (rev 197831)
@@ -298,25 +298,9 @@
 
 void CaptionUserPreferences::updateCaptionStyleSheetOveride()
 {
-    // Identify our override style sheet with a unique URL - a new scheme and a UUID.
-    static NeverDestroyed<URL> captionsStyleSheetURL(ParsedURLString, "user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23");
-
-    auto& pages = m_pageGroup.pages();
-    for (auto& page : pages) {
-        if (auto* pageUserContentController = page->userContentController())
-            pageUserContentController->removeUserStyleSheet(mainThreadNormalWorld(), captionsStyleSheetURL);
-    }
-
     String captionsOverrideStyleSheet = captionsStyleSheetOverride();
-    if (captionsOverrideStyleSheet.isEmpty())
-        return;
-
-    for (auto& page : pages) {
-        if (auto* pageUserContentController = page->userContentController()) {
-            auto userStyleSheet = std::make_unique<UserStyleSheet>(captionsOverrideStyleSheet, captionsStyleSheetURL, Vector<String>(), Vector<String>(), InjectInAllFrames, UserStyleAuthorLevel);
-            pageUserContentController->addUserStyleSheet(mainThreadNormalWorld(), WTFMove(userStyleSheet), InjectInExistingDocuments);
-        }
-    }
+    for (auto& page : m_pageGroup.pages())
+        page->setCaptionUserPreferencesStyleSheet(captionsOverrideStyleSheet);
 }
 
 String CaptionUserPreferences::primaryAudioTrackLanguageOverride() const

Modified: trunk/Source/WebCore/page/Page.cpp (197830 => 197831)


--- trunk/Source/WebCore/page/Page.cpp	2016-03-09 02:50:22 UTC (rev 197830)
+++ trunk/Source/WebCore/page/Page.cpp	2016-03-09 04:39:49 UTC (rev 197831)
@@ -1126,6 +1126,17 @@
     }
 }
 
+void Page::invalidateInjectedStyleSheetCacheInAllFrames()
+{
+    for (Frame* frame = m_mainFrame.get(); frame; frame = frame->tree().traverseNext()) {
+        Document* document = frame->document();
+        if (!document)
+            continue;
+        document->extensionStyleSheets().invalidateInjectedStyleSheetCache();
+        document->styleResolverChanged(DeferRecalcStyle);
+    }
+}
+
 void Page::setDebugger(JSC::Debugger* debugger)
 {
     if (m_debugger == debugger)
@@ -1818,12 +1829,7 @@
     if (m_userContentController)
         m_userContentController->addPage(*this);
 
-    for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
-        if (Document *document = frame->document()) {
-            document->extensionStyleSheets().invalidateInjectedStyleSheetCache();
-            document->styleResolverChanged(DeferRecalcStyle);
-        }
-    }
+    invalidateInjectedStyleSheetCacheInAllFrames();
 }
 
 void Page::setStorageNamespaceProvider(Ref<StorageNamespaceProvider>&& storageNamespaceProvider)
@@ -2008,4 +2014,19 @@
     return m_sessionID.isAlwaysOnLoggingAllowed();
 }
 
+String Page::captionUserPreferencesStyleSheet()
+{
+    return m_captionUserPreferencesStyleSheet;
+}
+
+void Page::setCaptionUserPreferencesStyleSheet(const String& styleSheet)
+{
+    if (m_captionUserPreferencesStyleSheet == styleSheet)
+        return;
+
+    m_captionUserPreferencesStyleSheet = styleSheet;
+    
+    invalidateInjectedStyleSheetCacheInAllFrames();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/Page.h (197830 => 197831)


--- trunk/Source/WebCore/page/Page.h	2016-03-09 02:50:22 UTC (rev 197830)
+++ trunk/Source/WebCore/page/Page.h	2016-03-09 04:39:49 UTC (rev 197831)
@@ -357,6 +357,8 @@
     WEBCORE_EXPORT void invalidateStylesForAllLinks();
     WEBCORE_EXPORT void invalidateStylesForLink(LinkHash);
 
+    void invalidateInjectedStyleSheetCacheInAllFrames();
+
     StorageNamespace* sessionStorage(bool optionalCreate = true);
     void setSessionStorage(RefPtr<StorageNamespace>&&);
 
@@ -509,6 +511,9 @@
 
     bool isAlwaysOnLoggingAllowed() const;
 
+    String captionUserPreferencesStyleSheet();
+    void setCaptionUserPreferencesStyleSheet(const String&);
+
 private:
     WEBCORE_EXPORT void initGroup();
 
@@ -609,6 +614,8 @@
     mutable bool m_didLoadUserStyleSheet;
     mutable time_t m_userStyleSheetModificationTime;
 
+    String m_captionUserPreferencesStyleSheet;
+
     std::unique_ptr<PageGroup> m_singlePageGroup;
     PageGroup* m_group;
 

Modified: trunk/Source/WebCore/page/UserContentController.cpp (197830 => 197831)


--- trunk/Source/WebCore/page/UserContentController.cpp	2016-03-09 02:50:22 UTC (rev 197830)
+++ trunk/Source/WebCore/page/UserContentController.cpp	2016-03-09 04:39:49 UTC (rev 197831)
@@ -123,7 +123,7 @@
     styleSheetsInWorld->append(WTFMove(userStyleSheet));
 
     if (injectionTime == InjectInExistingDocuments)
-        invalidateInjectedStyleSheetCacheInAllFrames();
+        invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
 }
 
 void UserContentController::removeUserStyleSheet(DOMWrapperWorld& world, const URL& url)
@@ -151,7 +151,7 @@
     if (stylesheets.isEmpty())
         m_userStyleSheets->remove(it);
 
-    invalidateInjectedStyleSheetCacheInAllFrames();
+    invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
 }
 
 void UserContentController::removeUserStyleSheets(DOMWrapperWorld& world)
@@ -162,7 +162,7 @@
     if (!m_userStyleSheets->remove(&world))
         return;
 
-    invalidateInjectedStyleSheetCacheInAllFrames();
+    invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
 }
 
 #if ENABLE(USER_MESSAGE_HANDLERS)
@@ -249,18 +249,14 @@
 
     if (m_userStyleSheets) {
         m_userStyleSheets = nullptr;
-        invalidateInjectedStyleSheetCacheInAllFrames();
+        invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
     }
 }
 
-void UserContentController::invalidateInjectedStyleSheetCacheInAllFrames()
+void UserContentController::invalidateInjectedStyleSheetCacheInAllFramesInAllPages()
 {
-    for (auto& page : m_pages) {
-        for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
-            frame->document()->extensionStyleSheets().invalidateInjectedStyleSheetCache();
-            frame->document()->styleResolverChanged(DeferRecalcStyle);
-        }
-    }
+    for (auto& page : m_pages)
+        page->invalidateInjectedStyleSheetCacheInAllFrames();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/UserContentController.h (197830 => 197831)


--- trunk/Source/WebCore/page/UserContentController.h	2016-03-09 02:50:22 UTC (rev 197830)
+++ trunk/Source/WebCore/page/UserContentController.h	2016-03-09 04:39:49 UTC (rev 197831)
@@ -103,7 +103,7 @@
 private:
     UserContentController();
 
-    void invalidateInjectedStyleSheetCacheInAllFrames();
+    void invalidateInjectedStyleSheetCacheInAllFramesInAllPages();
 
     HashSet<Page*> m_pages;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to