Update more DOMWindow getters to return references instead of raw pointers
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Oct 2018 18:11:18 +0000 (18:11 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Oct 2018 18:11:18 +0000 (18:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190654

Reviewed by Youenn Fablet.

Update more DOMWindow getters to return references instead of raw pointers, since they
can no longer return null after recent refactoring.

* Modules/gamepad/GamepadManager.cpp:
(WebCore::navigatorGamepadFromDOMWindow):
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::JSDOMWindow::heapSnapshot):
* dom/Document.cpp:
(WebCore::Document::location const):
(WebCore::Document::dispatchPopstateEvent):
* dom/Event.cpp:
(WebCore::Event::timeStampForBindings const):
* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::loadRequest):
* loader/ResourceTimingInformation.cpp:
(WebCore::ResourceTimingInformation::addResourceTiming):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::screen):
(WebCore::DOMWindow::history):
(WebCore::DOMWindow::crypto const):
(WebCore::DOMWindow::locationbar):
(WebCore::DOMWindow::menubar):
(WebCore::DOMWindow::personalbar):
(WebCore::DOMWindow::scrollbars):
(WebCore::DOMWindow::statusbar):
(WebCore::DOMWindow::toolbar):
(WebCore::DOMWindow::applicationCache):
(WebCore::DOMWindow::navigator):
(WebCore::DOMWindow::performance const):
(WebCore::DOMWindow::nowTimestamp const):
(WebCore::DOMWindow::location):
(WebCore::DOMWindow::visualViewport):
(WebCore::DOMWindow::styleMedia):
* page/DOMWindow.h:
* page/FrameView.cpp:
(WebCore::FrameView::updateLayoutViewport):
* page/History.cpp:
(WebCore::History::stateObjectAdded):
* page/IntersectionObserver.cpp:
(WebCore::IntersectionObserver::createTimestamp const):
* page/PerformanceObserver.cpp:
(WebCore::PerformanceObserver::PerformanceObserver):
* platform/cocoa/VideoFullscreenModelVideoElement.mm:
(WebCore::VideoFullscreenModelVideoElement::requestFullscreenMode):

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

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/gamepad/GamepadManager.cpp
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Event.cpp
Source/WebCore/loader/DocumentThreadableLoader.cpp
Source/WebCore/loader/ResourceTimingInformation.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/History.cpp
Source/WebCore/page/IntersectionObserver.cpp
Source/WebCore/page/PerformanceObserver.cpp
Source/WebCore/platform/cocoa/VideoFullscreenModelVideoElement.mm

index 4ca2304..939c02e 100644 (file)
@@ -1,3 +1,55 @@
+2018-10-17  Chris Dumez  <cdumez@apple.com>
+
+        Update more DOMWindow getters to return references instead of raw pointers
+        https://bugs.webkit.org/show_bug.cgi?id=190654
+
+        Reviewed by Youenn Fablet.
+
+        Update more DOMWindow getters to return references instead of raw pointers, since they
+        can no longer return null after recent refactoring.
+
+        * Modules/gamepad/GamepadManager.cpp:
+        (WebCore::navigatorGamepadFromDOMWindow):
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::JSDOMWindow::heapSnapshot):
+        * dom/Document.cpp:
+        (WebCore::Document::location const):
+        (WebCore::Document::dispatchPopstateEvent):
+        * dom/Event.cpp:
+        (WebCore::Event::timeStampForBindings const):
+        * loader/DocumentThreadableLoader.cpp:
+        (WebCore::DocumentThreadableLoader::loadRequest):
+        * loader/ResourceTimingInformation.cpp:
+        (WebCore::ResourceTimingInformation::addResourceTiming):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::screen):
+        (WebCore::DOMWindow::history):
+        (WebCore::DOMWindow::crypto const):
+        (WebCore::DOMWindow::locationbar):
+        (WebCore::DOMWindow::menubar):
+        (WebCore::DOMWindow::personalbar):
+        (WebCore::DOMWindow::scrollbars):
+        (WebCore::DOMWindow::statusbar):
+        (WebCore::DOMWindow::toolbar):
+        (WebCore::DOMWindow::applicationCache):
+        (WebCore::DOMWindow::navigator):
+        (WebCore::DOMWindow::performance const):
+        (WebCore::DOMWindow::nowTimestamp const):
+        (WebCore::DOMWindow::location):
+        (WebCore::DOMWindow::visualViewport):
+        (WebCore::DOMWindow::styleMedia):
+        * page/DOMWindow.h:
+        * page/FrameView.cpp:
+        (WebCore::FrameView::updateLayoutViewport):
+        * page/History.cpp:
+        (WebCore::History::stateObjectAdded):
+        * page/IntersectionObserver.cpp:
+        (WebCore::IntersectionObserver::createTimestamp const):
+        * page/PerformanceObserver.cpp:
+        (WebCore::PerformanceObserver::PerformanceObserver):
+        * platform/cocoa/VideoFullscreenModelVideoElement.mm:
+        (WebCore::VideoFullscreenModelVideoElement::requestFullscreenMode):
+
 2018-10-17  Chris Fleizach  <cfleizach@apple.com>
 
         AX: Certain tags should identify their context to iOS API
index 3d30ec7..9f72496 100644 (file)
@@ -43,11 +43,7 @@ namespace WebCore {
 
 static NavigatorGamepad* navigatorGamepadFromDOMWindow(DOMWindow* window)
 {
-    Navigator* navigator = window->navigator();
-    if (!navigator)
-        return nullptr;
-
-    return NavigatorGamepad::from(navigator);
+    return NavigatorGamepad::from(&window->navigator());
 }
 
 GamepadManager& GamepadManager::singleton()
index ffeebb1..33b88ca 100644 (file)
@@ -312,8 +312,8 @@ bool JSDOMWindow::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned
 void JSDOMWindow::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
 {
     JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(cell);
-    if (auto* location = thisObject->wrapped().location())
-        builder.setLabelForCell(cell, location->href());
+    auto& location = thisObject->wrapped().location();
+    builder.setLabelForCell(cell, location.href());
 
     Base::heapSnapshot(cell, builder);
 }
index 9927e07..c5ed5da 100644 (file)
@@ -2829,10 +2829,7 @@ ExceptionOr<void> Document::setBodyOrFrameset(RefPtr<HTMLElement>&& newBody)
 Location* Document::location() const
 {
     auto* window = domWindow();
-    if (!window)
-        return nullptr;
-
-    return window->location();
+    return window ? &window->location() : nullptr;
 }
 
 HTMLHeadElement* Document::head()
@@ -6110,7 +6107,7 @@ void Document::enqueueHashchangeEvent(const String& oldURL, const String& newURL
 
 void Document::dispatchPopstateEvent(RefPtr<SerializedScriptValue>&& stateObject)
 {
-    dispatchWindowEvent(PopStateEvent::create(WTFMove(stateObject), m_domWindow ? m_domWindow->history() : nullptr));
+    dispatchWindowEvent(PopStateEvent::create(WTFMove(stateObject), m_domWindow ? &m_domWindow->history() : nullptr));
 }
 
 void Document::addMediaCanStartListener(MediaCanStartListener* listener)
index 3388d37..53062df 100644 (file)
@@ -151,7 +151,7 @@ DOMHighResTimeStamp Event::timeStampForBindings(ScriptExecutionContext& context)
     if (is<WorkerGlobalScope>(context))
         performance = &downcast<WorkerGlobalScope>(context).performance();
     else if (auto* window = downcast<Document>(context).domWindow())
-        performance = window->performance();
+        performance = &window->performance();
 
     if (!performance)
         return 0;
index da17102..da3416e 100644 (file)
@@ -623,8 +623,8 @@ void DocumentThreadableLoader::loadRequest(ResourceRequest&& request, SecurityCh
         if (options().initiatorContext == InitiatorContext::Worker)
             finishedTimingForWorkerLoad(resourceTiming);
         else {
-            if (document().domWindow() && document().domWindow()->performance())
-                document().domWindow()->performance()->addResourceTiming(WTFMove(resourceTiming));
+            if (auto* window = document().domWindow())
+                window->performance().addResourceTiming(WTFMove(resourceTiming));
         }
     }
 
index 6a9ae8a..b9260f1 100644 (file)
@@ -76,14 +76,14 @@ void ResourceTimingInformation::addResourceTiming(CachedResource& resource, Docu
     }
     if (!initiatorDocument)
         return;
-    if (!initiatorDocument->domWindow())
-        return;
-    if (!initiatorDocument->domWindow()->performance())
+
+    auto* initiatorWindow = initiatorDocument->domWindow();
+    if (!initiatorWindow)
         return;
 
     resourceTiming.overrideInitiatorName(info.name);
 
-    initiatorDocument->domWindow()->performance()->addResourceTiming(WTFMove(resourceTiming));
+    initiatorWindow->performance().addResourceTiming(WTFMove(resourceTiming));
 
     info.added = Added;
 }
index ec926b7..7f3bad4 100644 (file)
@@ -635,67 +635,67 @@ int DOMWindow::orientation() const
 
 #endif
 
-Screen* DOMWindow::screen()
+Screen& DOMWindow::screen()
 {
     if (!m_screen)
         m_screen = Screen::create(*this);
-    return m_screen.get();
+    return *m_screen;
 }
 
-History* DOMWindow::history()
+History& DOMWindow::history()
 {
     if (!m_history)
         m_history = History::create(*this);
-    return m_history.get();
+    return *m_history;
 }
 
-Crypto* DOMWindow::crypto() const
+Crypto& DOMWindow::crypto() const
 {
     if (!m_crypto)
         m_crypto = Crypto::create(document());
-    return m_crypto.get();
+    return *m_crypto;
 }
 
-BarProp* DOMWindow::locationbar()
+BarProp& DOMWindow::locationbar()
 {
     if (!m_locationbar)
         m_locationbar = BarProp::create(*this, BarProp::Locationbar);
-    return m_locationbar.get();
+    return *m_locationbar;
 }
 
-BarProp* DOMWindow::menubar()
+BarProp& DOMWindow::menubar()
 {
     if (!m_menubar)
         m_menubar = BarProp::create(*this, BarProp::Menubar);
-    return m_menubar.get();
+    return *m_menubar;
 }
 
-BarProp* DOMWindow::personalbar()
+BarProp& DOMWindow::personalbar()
 {
     if (!m_personalbar)
         m_personalbar = BarProp::create(*this, BarProp::Personalbar);
-    return m_personalbar.get();
+    return *m_personalbar;
 }
 
-BarProp* DOMWindow::scrollbars()
+BarProp& DOMWindow::scrollbars()
 {
     if (!m_scrollbars)
         m_scrollbars = BarProp::create(*this, BarProp::Scrollbars);
-    return m_scrollbars.get();
+    return *m_scrollbars;
 }
 
-BarProp* DOMWindow::statusbar()
+BarProp& DOMWindow::statusbar()
 {
     if (!m_statusbar)
         m_statusbar = BarProp::create(*this, BarProp::Statusbar);
-    return m_statusbar.get();
+    return *m_statusbar;
 }
 
-BarProp* DOMWindow::toolbar()
+BarProp& DOMWindow::toolbar()
 {
     if (!m_toolbar)
         m_toolbar = BarProp::create(*this, BarProp::Toolbar);
-    return m_toolbar.get();
+    return *m_toolbar;
 }
 
 PageConsoleClient* DOMWindow::console() const
@@ -707,47 +707,47 @@ PageConsoleClient* DOMWindow::console() const
     return frame->page() ? &frame->page()->console() : nullptr;
 }
 
-DOMApplicationCache* DOMWindow::applicationCache()
+DOMApplicationCache& DOMWindow::applicationCache()
 {
     if (!m_applicationCache)
         m_applicationCache = DOMApplicationCache::create(*this);
-    return m_applicationCache.get();
+    return *m_applicationCache;
 }
 
-Navigator* DOMWindow::navigator()
+Navigator& DOMWindow::navigator()
 {
     if (!m_navigator)
         m_navigator = Navigator::create(scriptExecutionContext(), *this);
 
-    return m_navigator.get();
+    return *m_navigator;
 }
 
-Performance* DOMWindow::performance() const
+Performance& DOMWindow::performance() const
 {
     if (!m_performance) {
         MonotonicTime timeOrigin = document() && document()->loader() ? document()->loader()->timing().referenceMonotonicTime() : MonotonicTime::now();
         m_performance = Performance::create(document(), timeOrigin);
     }
-    return m_performance.get();
+    return *m_performance;
 }
 
 double DOMWindow::nowTimestamp() const
 {
-    return performance() ? performance()->now() / 1000 : 0;
+    return performance().now() / 1000.;
 }
 
-Location* DOMWindow::location()
+Location& DOMWindow::location()
 {
     if (!m_location)
         m_location = Location::create(*this);
-    return m_location.get();
+    return *m_location;
 }
 
-VisualViewport* DOMWindow::visualViewport()
+VisualViewport& DOMWindow::visualViewport()
 {
     if (!m_visualViewport)
         m_visualViewport = VisualViewport::create(*this);
-    return m_visualViewport.get();
+    return *m_visualViewport;
 }
 
 #if ENABLE(USER_MESSAGE_HANDLERS)
@@ -1433,11 +1433,11 @@ Document* DOMWindow::document() const
     return downcast<Document>(ContextDestructionObserver::scriptExecutionContext());
 }
 
-RefPtr<StyleMedia> DOMWindow::styleMedia()
+StyleMedia& DOMWindow::styleMedia()
 {
     if (!m_media)
         m_media = StyleMedia::create(*this);
-    return m_media;
+    return *m_media;
 }
 
 Ref<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element& element, const String& pseudoElt) const
index 65873a4..da5929e 100644 (file)
@@ -131,20 +131,20 @@ public:
     static bool canShowModalDialog(const Frame&);
     WEBCORE_EXPORT void setCanShowModalDialogOverride(bool);
 
-    Screen* screen();
-    History* history();
-    Crypto* crypto() const;
-    BarProp* locationbar();
-    BarProp* menubar();
-    BarProp* personalbar();
-    BarProp* scrollbars();
-    BarProp* statusbar();
-    BarProp* toolbar();
-    Navigator* navigator();
+    Screen& screen();
+    History& history();
+    Crypto& crypto() const;
+    BarProp& locationbar();
+    BarProp& menubar();
+    BarProp& personalbar();
+    BarProp& scrollbars();
+    BarProp& statusbar();
+    BarProp& toolbar();
+    Navigator& navigator();
     Navigator* optionalNavigator() const { return m_navigator.get(); }
-    Navigator* clientInformation() { return navigator(); }
+    Navigator& clientInformation() { return navigator(); }
 
-    Location* location();
+    Location& location();
     void setLocation(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& location, SetLocationLocking = LockHistoryBasedOnGestureState);
 
     DOMSelection* getSelection();
@@ -209,7 +209,7 @@ public:
 
     // CSSOM View Module
 
-    RefPtr<StyleMedia> styleMedia();
+    StyleMedia& styleMedia();
 
     // DOM Level 2 Style Interface
 
@@ -245,7 +245,7 @@ public:
     void resizeBy(float x, float y) const;
     void resizeTo(float width, float height) const;
 
-    VisualViewport* visualViewport();
+    VisualViewport& visualViewport();
 
     // Timers
     ExceptionOr<int> setTimeout(JSC::ExecState&, std::unique_ptr<ScheduledAction>, int timeout, Vector<JSC::Strong<JSC::Unknown>>&& arguments);
@@ -286,7 +286,7 @@ public:
     Storage* optionalSessionStorage() const { return m_sessionStorage.get(); }
     Storage* optionalLocalStorage() const { return m_localStorage.get(); }
 
-    DOMApplicationCache* applicationCache();
+    DOMApplicationCache& applicationCache();
     DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
 
     CustomElementRegistry* customElementRegistry() { return m_customElementRegistry.get(); }
@@ -302,7 +302,7 @@ public:
     int orientation() const;
 #endif
 
-    Performance* performance() const;
+    Performance& performance() const;
     WEBCORE_EXPORT double nowTimestamp() const;
 
 #if PLATFORM(IOS)
index 9cb3f16..e3827c6 100644 (file)
@@ -1711,10 +1711,8 @@ void FrameView::updateLayoutViewport()
             setLayoutViewportOverrideRect(LayoutRect(newOrigin, m_layoutViewportOverrideRect.value().size()));
         }
         if (frame().settings().visualViewportAPIEnabled()) {
-            if (Document* document = frame().document()) {
-                if (VisualViewport* visualViewport = document->domWindow()->visualViewport())
-                    visualViewport->update();
-            }
+            if (auto* window = frame().window())
+                window->visualViewport().update();
         }
         return;
     }
@@ -1725,10 +1723,8 @@ void FrameView::updateLayoutViewport()
         LOG_WITH_STREAM(Scrolling, stream << "layoutViewport changed to " << layoutViewportRect());
     }
     if (frame().settings().visualViewportAPIEnabled()) {
-        if (Document* document = frame().document()) {
-            if (VisualViewport* visualViewport = document->domWindow()->visualViewport())
-                visualViewport->update();
-        }
+        if (auto* window = frame().window())
+            window->visualViewport().update();
     }
 }
 
index 7d80c1f..fd1921d 100644 (file)
@@ -208,23 +208,19 @@ ExceptionOr<void> History::stateObjectAdded(RefPtr<SerializedScriptValue>&& data
     if (!allowSandboxException && !documentSecurityOrigin.canRequest(fullURL) && (fullURL.path() != documentURL.path() || fullURL.query() != documentURL.query()))
         return createBlockedURLSecurityErrorWithMessageSuffix("Paths and fragments must match for a sandboxed document.");
 
-    Document* mainDocument = frame->page()->mainFrame().document();
-    History* mainHistory = nullptr;
-    if (mainDocument) {
-        if (auto* mainDOMWindow = mainDocument->domWindow())
-            mainHistory = mainDOMWindow->history();
-    }
-
-    if (!mainHistory)
+    auto* mainWindow = frame->page()->mainFrame().window();
+    if (!mainWindow)
         return { };
 
+    auto& mainHistory = mainWindow->history();
+
     WallTime currentTimestamp = WallTime::now();
-    if (currentTimestamp - mainHistory->m_currentStateObjectTimeSpanStart > stateObjectTimeSpan) {
-        mainHistory->m_currentStateObjectTimeSpanStart = currentTimestamp;
-        mainHistory->m_currentStateObjectTimeSpanObjectsAdded = 0;
+    if (currentTimestamp - mainHistory.m_currentStateObjectTimeSpanStart > stateObjectTimeSpan) {
+        mainHistory.m_currentStateObjectTimeSpanStart = currentTimestamp;
+        mainHistory.m_currentStateObjectTimeSpanObjectsAdded = 0;
     }
     
-    if (mainHistory->m_currentStateObjectTimeSpanObjectsAdded >= perStateObjectTimeSpanLimit) {
+    if (mainHistory.m_currentStateObjectTimeSpanObjectsAdded >= perStateObjectTimeSpanLimit) {
         if (stateObjectType == StateObjectType::Replace)
             return Exception { SecurityError, String::format("Attempt to use history.replaceState() more than %u times per %f seconds", perStateObjectTimeSpanLimit, stateObjectTimeSpan.seconds()) };
         return Exception { SecurityError, String::format("Attempt to use history.pushState() more than %u times per %f seconds", perStateObjectTimeSpanLimit, stateObjectTimeSpan.seconds()) };
@@ -240,7 +236,7 @@ ExceptionOr<void> History::stateObjectAdded(RefPtr<SerializedScriptValue>&& data
     payloadSize += urlSize;
     payloadSize += data ? data->data().size() : 0;
 
-    Checked<uint64_t> newTotalUsage = mainHistory->m_totalStateObjectUsage;
+    Checked<uint64_t> newTotalUsage = mainHistory.m_totalStateObjectUsage;
 
     if (stateObjectType == StateObjectType::Replace)
         newTotalUsage -= m_mostRecentStateObjectUsage;
@@ -254,8 +250,8 @@ ExceptionOr<void> History::stateObjectAdded(RefPtr<SerializedScriptValue>&& data
 
     m_mostRecentStateObjectUsage = payloadSize.unsafeGet();
 
-    mainHistory->m_totalStateObjectUsage = newTotalUsage.unsafeGet();
-    ++mainHistory->m_currentStateObjectTimeSpanObjectsAdded;
+    mainHistory.m_totalStateObjectUsage = newTotalUsage.unsafeGet();
+    ++mainHistory.m_currentStateObjectTimeSpanObjectsAdded;
 
     if (!urlString.isEmpty())
         frame->document()->updateURLForPushOrReplaceState(fullURL);
index cfdaa44..51d1ad2 100644 (file)
@@ -236,10 +236,8 @@ bool IntersectionObserver::createTimestamp(DOMHighResTimeStamp& timestamp) const
     ASSERT(context->isDocument());
     auto& document = downcast<Document>(*context);
     if (auto* window = document.domWindow()) {
-        if (auto* performance = window->performance()) {
-            timestamp = performance->now();
-            return true;
-        }
+        timestamp =  window->performance().now();
+        return true;
     }
     return false;
 }
index 849641c..11e5949 100644 (file)
@@ -40,7 +40,7 @@ PerformanceObserver::PerformanceObserver(ScriptExecutionContext& scriptExecution
     if (is<Document>(scriptExecutionContext)) {
         auto& document = downcast<Document>(scriptExecutionContext);
         if (DOMWindow* window = document.domWindow())
-            m_performance = window->performance();
+            m_performance = &window->performance();
     } else if (is<WorkerGlobalScope>(scriptExecutionContext)) {
         auto& workerGlobalScope = downcast<WorkerGlobalScope>(scriptExecutionContext);
         m_performance = &workerGlobalScope.performance();
index de092a6..0326204 100644 (file)
@@ -150,10 +150,8 @@ void VideoFullscreenModelVideoElement::requestFullscreenMode(HTMLMediaElementEnu
 
     if (m_videoElement && finishedWithMedia && mode == MediaPlayerEnums::VideoFullscreenModeNone) {
         if (m_videoElement->document().isMediaDocument()) {
-            if (DOMWindow* window = m_videoElement->document().domWindow()) {
-                if (History* history = window->history())
-                    history->back();
-            }
+            if (auto* window = m_videoElement->document().domWindow())
+                window->history().back();
         }
     }
 }