Page::userContentController() should return a reference, not a pointer
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Feb 2015 20:51:14 +0000 (20:51 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Feb 2015 20:51:14 +0000 (20:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141764

Reviewed by Jer Noble.

Source/WebCore:

No new tests (No behavior change)

* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::updateInjectedStyleSheetCache):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::updateCaptionStyleSheetOveride):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::shouldHaveWebKitNamespaceForWorld):
* page/Frame.cpp:
(WebCore::Frame::injectUserScripts):
* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::~Page):
(WebCore::Page::setUserContentController):
* page/Page.h:
(WebCore::Page::userContentController):
* page/UserMessageHandlersNamespace.cpp:
(WebCore::UserMessageHandlersNamespace::handler):

Source/WebKit/mac:

* WebView/WebView.mm:
(-[WebView setGroupName:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180286 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/DocumentStyleSheetCollection.cpp
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/page/CaptionUserPreferences.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/Frame.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/UserMessageHandlersNamespace.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebView.mm

index 14ca21f..79129fb 100644 (file)
@@ -1,3 +1,31 @@
+2015-02-18  Brady Eidson  <beidson@apple.com>
+
+        Page::userContentController() should return a reference, not a pointer
+        https://bugs.webkit.org/show_bug.cgi?id=141764
+
+        Reviewed by Jer Noble.
+
+        No new tests (No behavior change)
+
+        * dom/DocumentStyleSheetCollection.cpp:
+        (WebCore::DocumentStyleSheetCollection::updateInjectedStyleSheetCache):
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::requestResource):
+        * page/CaptionUserPreferences.cpp:
+        (WebCore::CaptionUserPreferences::updateCaptionStyleSheetOveride):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::shouldHaveWebKitNamespaceForWorld):
+        * page/Frame.cpp:
+        (WebCore::Frame::injectUserScripts):
+        * page/Page.cpp:
+        (WebCore::Page::Page):
+        (WebCore::Page::~Page):
+        (WebCore::Page::setUserContentController):
+        * page/Page.h:
+        (WebCore::Page::userContentController):
+        * page/UserMessageHandlersNamespace.cpp:
+        (WebCore::UserMessageHandlersNamespace::handler):
+
 2015-02-18  Roger Fong  <roger_fong@apple.com>
 
         WebGL2: Promote various WebGL1 extensions to core for WebGL2.
index 8ae31e9..53d90b7 100644 (file)
@@ -137,11 +137,7 @@ void DocumentStyleSheetCollection::updateInjectedStyleSheetCache() const
     if (!owningPage)
         return;
 
-    const auto* userContentController = owningPage->userContentController();
-    if (!userContentController)
-        return;
-
-    const UserStyleSheetMap* userStyleSheets = userContentController->userStyleSheets();
+    const UserStyleSheetMap* userStyleSheets = owningPage->userContentController().userStyleSheets();
     if (!userStyleSheets)
         return;
 
index 07ba927..5fe5bf0 100644 (file)
@@ -464,7 +464,7 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
         return nullptr;
 
 #if ENABLE(CONTENT_EXTENSIONS)
-    if (frame() && frame()->page() && frame()->page()->userContentController() && frame()->page()->userContentController()->contentFilterBlocksURL(url))
+    if (frame() && frame()->page() && frame()->page()->userContentController().contentFilterBlocksURL(url))
         return nullptr;
 #endif
 
index 0ed2ca4..fe30a94 100644 (file)
@@ -276,20 +276,16 @@ void CaptionUserPreferences::updateCaptionStyleSheetOveride()
     DEPRECATED_DEFINE_STATIC_LOCAL(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);
-    }
+    for (auto& page : pages)
+        page->userContentController().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(), WTF::move(userStyleSheet), InjectInExistingDocuments);
-        }
+        auto userStyleSheet = std::make_unique<UserStyleSheet>(captionsOverrideStyleSheet, captionsStyleSheetURL, Vector<String>(), Vector<String>(), InjectInAllFrames, UserStyleAuthorLevel);
+        page->userContentController().addUserStyleSheet(mainThreadNormalWorld(), WTF::move(userStyleSheet), InjectInExistingDocuments);
     }
 }
 
index ea16158..db2a8b8 100644 (file)
@@ -758,11 +758,7 @@ bool DOMWindow::shouldHaveWebKitNamespaceForWorld(DOMWrapperWorld& world)
     if (!page)
         return false;
 
-    auto* userContentController = page->userContentController();
-    if (!userContentController)
-        return false;
-
-    auto* descriptorMap = userContentController->userMessageHandlerDescriptors();
+    auto* descriptorMap = page->userContentController().userMessageHandlerDescriptors();
     if (!descriptorMap)
         return false;
 
index 988ad06..5f8971b 100644 (file)
@@ -695,12 +695,8 @@ void Frame::injectUserScripts(UserScriptInjectionTime injectionTime)
     if (loader().stateMachine().creatingInitialEmptyDocument() && !settings().shouldInjectUserScriptsInInitialEmptyDocument())
         return;
 
-    const auto* userContentController = m_page->userContentController();
-    if (!userContentController)
-        return;
-
     // Walk the hashtable. Inject by world.
-    const UserScriptMap* userScripts = userContentController->userScripts();
+    const UserScriptMap* userScripts = m_page->userContentController().userScripts();
     if (!userScripts)
         return;
 
index 06b91ba..09ee317 100644 (file)
@@ -204,7 +204,7 @@ Page::Page(PageConfiguration& pageConfiguration)
     , m_framesHandlingBeforeUnloadEvent(0)
     , m_databaseProvider(*WTF::move(pageConfiguration.databaseProvider))
     , m_storageNamespaceProvider(*WTF::move(pageConfiguration.storageNamespaceProvider))
-    , m_userContentController(WTF::move(pageConfiguration.userContentController))
+    , m_userContentController(*WTF::move(pageConfiguration.userContentController))
     , m_visitedLinkStore(*WTF::move(pageConfiguration.visitedLinkStore))
     , m_sessionID(SessionID::defaultSessionID())
     , m_isClosing(false)
@@ -213,10 +213,7 @@ Page::Page(PageConfiguration& pageConfiguration)
     setTimerThrottlingEnabled(m_viewState & ViewState::IsVisuallyIdle);
 
     m_storageNamespaceProvider->addPage(*this);
-
-    if (m_userContentController)
-        m_userContentController->addPage(*this);
-
+    m_userContentController->addPage(*this);
     m_visitedLinkStore->addPage(*this);
 
     if (!allPages) {
@@ -268,9 +265,7 @@ Page::~Page()
 #endif
 
     m_storageNamespaceProvider->removePage(*this);
-
-    if (m_userContentController)
-        m_userContentController->removePage(*this);
+    m_userContentController->removePage(*this);
     m_visitedLinkStore->removePage(*this);
 }
 
@@ -1622,15 +1617,11 @@ bool Page::isAnyFrameHandlingBeforeUnloadEvent()
     return m_framesHandlingBeforeUnloadEvent;
 }
 
-void Page::setUserContentController(UserContentController* userContentController)
+void Page::setUserContentController(Ref<UserContentController>&& userContentController)
 {
-    if (m_userContentController)
-        m_userContentController->removePage(*this);
-
-    m_userContentController = userContentController;
-
-    if (m_userContentController)
-        m_userContentController->addPage(*this);
+    m_userContentController->removePage(*this);
+    m_userContentController = WTF::move(userContentController);
+    m_userContentController->addPage(*this);
 
     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
         if (Document *document = frame->document()) {
index 7fcf7ab..d45fcc1 100644 (file)
@@ -406,8 +406,8 @@ public:
     StorageNamespaceProvider& storageNamespaceProvider() { return m_storageNamespaceProvider.get(); }
     void setStorageNamespaceProvider(Ref<StorageNamespaceProvider>&&);
 
-    UserContentController* userContentController() { return m_userContentController.get(); }
-    WEBCORE_EXPORT void setUserContentController(UserContentController*);
+    UserContentController& userContentController() { return m_userContentController.get(); }
+    WEBCORE_EXPORT void setUserContentController(Ref<UserContentController>&&);
 
     VisitedLinkStore& visitedLinkStore();
     WEBCORE_EXPORT void setVisitedLinkStore(Ref<VisitedLinkStore>&&);
@@ -574,7 +574,7 @@ private:
 
     Ref<DatabaseProvider> m_databaseProvider;
     Ref<StorageNamespaceProvider> m_storageNamespaceProvider;
-    RefPtr<UserContentController> m_userContentController;
+    Ref<UserContentController> m_userContentController;
     Ref<VisitedLinkStore> m_visitedLinkStore;
 
     HashSet<ViewStateChangeObserver*> m_viewStateChangeObservers;
index c9ae926..f379ab3 100644 (file)
@@ -59,12 +59,8 @@ UserMessageHandler* UserMessageHandlersNamespace::handler(const AtomicString& na
     Page* page = frame()->page();
     if (!page)
         return nullptr;
-    
-    const auto* userContentController = page->userContentController();
-    if (!userContentController)
-        return nullptr;
 
-    const auto* userMessageHandlerDescriptors = userContentController->userMessageHandlerDescriptors();
+    const auto* userMessageHandlerDescriptors = page->userContentController().userMessageHandlerDescriptors();
     if (!userMessageHandlerDescriptors)
         return nullptr;
 
index 4679d53..74034d2 100644 (file)
@@ -1,3 +1,13 @@
+2015-02-18  Brady Eidson  <beidson@apple.com>
+
+        Page::userContentController() should return a reference, not a pointer
+        https://bugs.webkit.org/show_bug.cgi?id=141764
+
+        Reviewed by Jer Noble.
+
+        * WebView/WebView.mm:
+        (-[WebView setGroupName:]):
+
 2015-02-18  Chris Dumez  <cdumez@apple.com>
 
         Access FontCache global instance via singleton() static member function
index 65ee148..f2d6d03 100644 (file)
@@ -6117,7 +6117,7 @@ static WebFrame *incrementFrame(WebFrame *frame, WebFindOptions options = 0)
     if (!_private->page)
         return;
 
-    _private->page->setUserContentController(&_private->group->userContentController());
+    _private->page->setUserContentController(_private->group->userContentController());
     _private->page->setVisitedLinkStore(_private->group->visitedLinkStore());
     _private->page->setGroupName(groupName);
 }