Title: [258767] trunk/Source
Revision
258767
Author
[email protected]
Date
2020-03-20 10:02:11 -0700 (Fri, 20 Mar 2020)

Log Message

[iOS] Articles on NYTimes.com get truncated when switching between MobileSafari and another app
https://bugs.webkit.org/show_bug.cgi?id=209321
<rdar://problem/59763843>

Reviewed by Tim Horton.

Articles on NYTimes.com get truncated when switching between MobileSafari and another app
Source/WebCore:

(multitasking). The reason is that when you home out of MobileSafari, snapshots of the
web view are taken at various sizes and we were firing 5 resizes events at the page as a
result. Those resize events were confusing the logic on NYTimes.com and causing it to
truncate the article.

To address the issue, we stop firing resize events at the page if the resize is happening
during the snapshotting sequence.

* page/FrameView.cpp:
(WebCore::FrameView::sendResizeEventIfNeeded):
* page/Page.h:
(WebCore::Page::shouldFireResizeEvents const):
(WebCore::Page::setShouldFireResizeEvents):

Source/WebKit:

(multitasking). The reason is that when you home out of MobileSafari, snapshots of the
web view are taken at various sizes and we were firing 5 resizes events at the page as a
result. Those resize events were confusing the logic on NYTimes.com and causing it to
truncate the article.

To address the issue, we stop firing resize events at the page if the resize is happening
during the snapshotting sequence.

* Platform/spi/ios/UIKitSPI.h:
* UIProcess/ApplicationStateTracker.h:
* UIProcess/ApplicationStateTracker.mm:
(WebKit::ApplicationStateTracker::ApplicationStateTracker):
(WebKit::ApplicationStateTracker::~ApplicationStateTracker):
(WebKit::ApplicationStateTracker::willBeginSnapshotSequence):
(WebKit::ApplicationStateTracker::didCompleteSnapshotSequence):
* UIProcess/WebPageProxy.cpp:
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKApplicationStateTrackingView.mm:
(-[WKApplicationStateTrackingView didMoveToWindow]):
(-[WKApplicationStateTrackingView _willBeginSnapshotSequence]):
(-[WKApplicationStateTrackingView _didCompleteSnapshotSequence]):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setShouldFireResizeEvents):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (258766 => 258767)


--- trunk/Source/WebCore/ChangeLog	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebCore/ChangeLog	2020-03-20 17:02:11 UTC (rev 258767)
@@ -1,3 +1,26 @@
+2020-03-20  Chris Dumez  <[email protected]>
+
+        [iOS] Articles on NYTimes.com get truncated when switching between MobileSafari and another app
+        https://bugs.webkit.org/show_bug.cgi?id=209321
+        <rdar://problem/59763843>
+
+        Reviewed by Tim Horton.
+
+        Articles on NYTimes.com get truncated when switching between MobileSafari and another app
+        (multitasking). The reason is that when you home out of MobileSafari, snapshots of the
+        web view are taken at various sizes and we were firing 5 resizes events at the page as a
+        result. Those resize events were confusing the logic on NYTimes.com and causing it to
+        truncate the article.
+
+        To address the issue, we stop firing resize events at the page if the resize is happening
+        during the snapshotting sequence.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::sendResizeEventIfNeeded):
+        * page/Page.h:
+        (WebCore::Page::shouldFireResizeEvents const):
+        (WebCore::Page::setShouldFireResizeEvents):
+
 2020-03-20  Jacob Uphoff  <[email protected]>
 
         Unreviewed, reverting r258748.

Modified: trunk/Source/WebCore/page/FrameView.cpp (258766 => 258767)


--- trunk/Source/WebCore/page/FrameView.cpp	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebCore/page/FrameView.cpp	2020-03-20 17:02:11 UTC (rev 258767)
@@ -3350,7 +3350,8 @@
     if (!renderView || renderView->printing())
         return;
 
-    if (frame().page() && frame().page()->chrome().client().isSVGImageChromeClient())
+    auto* page = frame().page();
+    if (page && page->chrome().client().isSVGImageChromeClient())
         return;
 
     IntSize currentSize = sizeForResizeEvent();
@@ -3375,15 +3376,18 @@
     }
 #endif
 
+    if (page && !page->shouldFireResizeEvents()) {
+        FRAMEVIEW_RELEASE_LOG_IF_ALLOWED(Events, "sendResizeEventIfNeeded: Not firing resize events because they are temporarily disabled for this page");
+        return;
+    }
+
     LOG_WITH_STREAM(Events, stream << "FrameView" << this << "sendResizeEventIfNeeded scheduling resize event for document" << frame().document() << ", size " << currentSize);
     frame().document()->setNeedsDOMWindowResizeEvent();
 
     bool isMainFrame = frame().isMainFrame();
     if (InspectorInstrumentation::hasFrontends() && isMainFrame) {
-        if (Page* page = frame().page()) {
-            if (InspectorClient* inspectorClient = page->inspectorController().inspectorClient())
-                inspectorClient->didResizeMainFrame(&frame());
-        }
+        if (InspectorClient* inspectorClient = page ? page->inspectorController().inspectorClient() : nullptr)
+            inspectorClient->didResizeMainFrame(&frame());
     }
 }
 

Modified: trunk/Source/WebCore/page/Page.h (258766 => 258767)


--- trunk/Source/WebCore/page/Page.h	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebCore/page/Page.h	2020-03-20 17:02:11 UTC (rev 258767)
@@ -727,6 +727,9 @@
     WEBCORE_EXPORT void injectUserStyleSheet(UserStyleSheet&);
     WEBCORE_EXPORT void removeInjectedUserStyleSheet(UserStyleSheet&);
 
+    bool shouldFireResizeEvents() const { return m_shouldFireResizeEvents; }
+    void setShouldFireResizeEvents(bool shouldFireResizeEvents) { m_shouldFireResizeEvents = shouldFireResizeEvents; }
+
 private:
     struct Navigation {
         RegistrableDomain domain;
@@ -1005,6 +1008,7 @@
 
     Vector<UserContentURLPattern> m_corsDisablingPatterns;
     Vector<UserStyleSheet> m_userStyleSheetsPendingInjection;
+    bool m_shouldFireResizeEvents { true };
 };
 
 inline PageGroup& Page::group()

Modified: trunk/Source/WebKit/ChangeLog (258766 => 258767)


--- trunk/Source/WebKit/ChangeLog	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/ChangeLog	2020-03-20 17:02:11 UTC (rev 258767)
@@ -1,3 +1,38 @@
+2020-03-20  Chris Dumez  <[email protected]>
+
+        [iOS] Articles on NYTimes.com get truncated when switching between MobileSafari and another app
+        https://bugs.webkit.org/show_bug.cgi?id=209321
+        <rdar://problem/59763843>
+
+        Reviewed by Tim Horton.
+
+        Articles on NYTimes.com get truncated when switching between MobileSafari and another app
+        (multitasking). The reason is that when you home out of MobileSafari, snapshots of the 
+        web view are taken at various sizes and we were firing 5 resizes events at the page as a
+        result. Those resize events were confusing the logic on NYTimes.com and causing it to
+        truncate the article.
+
+        To address the issue, we stop firing resize events at the page if the resize is happening
+        during the snapshotting sequence.
+
+        * Platform/spi/ios/UIKitSPI.h:
+        * UIProcess/ApplicationStateTracker.h:
+        * UIProcess/ApplicationStateTracker.mm:
+        (WebKit::ApplicationStateTracker::ApplicationStateTracker):
+        (WebKit::ApplicationStateTracker::~ApplicationStateTracker):
+        (WebKit::ApplicationStateTracker::willBeginSnapshotSequence):
+        (WebKit::ApplicationStateTracker::didCompleteSnapshotSequence):
+        * UIProcess/WebPageProxy.cpp:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WKApplicationStateTrackingView.mm:
+        (-[WKApplicationStateTrackingView didMoveToWindow]):
+        (-[WKApplicationStateTrackingView _willBeginSnapshotSequence]):
+        (-[WKApplicationStateTrackingView _didCompleteSnapshotSequence]):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setShouldFireResizeEvents):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2020-03-20  Jacob Uphoff  <[email protected]>
 
         Unreviewed, reverting r258748.

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (258766 => 258767)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2020-03-20 17:02:11 UTC (rev 258767)
@@ -61,6 +61,7 @@
 #import <UIKit/UIPopoverPresentationController_Private.h>
 #import <UIKit/UIPresentationController_Private.h>
 #import <UIKit/UIResponder_Private.h>
+#import <UIKit/UIScene_Private.h>
 #import <UIKit/UIScrollView_Private.h>
 #import <UIKit/UIStringDrawing_Private.h>
 #import <UIKit/UITableViewCell_Private.h>
@@ -1408,4 +1409,7 @@
 extern NSString * const NSWebResourceLoadDelegateDocumentOption;
 extern NSString * const NSTextSizeMultiplierDocumentOption;
 
+extern NSNotificationName const _UISceneWillBeginSystemSnapshotSequence;
+extern NSNotificationName const _UISceneDidCompleteSystemSnapshotSequence;
+
 WTF_EXTERN_C_END

Modified: trunk/Source/WebKit/UIProcess/ApplicationStateTracker.h (258766 => 258767)


--- trunk/Source/WebKit/UIProcess/ApplicationStateTracker.h	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/UIProcess/ApplicationStateTracker.h	2020-03-20 17:02:11 UTC (rev 258767)
@@ -41,7 +41,7 @@
 class ApplicationStateTracker : public CanMakeWeakPtr<ApplicationStateTracker> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    ApplicationStateTracker(UIView *, SEL didEnterBackgroundSelector, SEL didFinishSnapshottingAfterEnteringBackgroundSelector, SEL willEnterForegroundSelector);
+    ApplicationStateTracker(UIView *, SEL didEnterBackgroundSelector, SEL didFinishSnapshottingAfterEnteringBackgroundSelector, SEL willEnterForegroundSelector, SEL willBeginSnapshotSequenceSelector, SEL didCompleteSnapshotSequenceSelector);
     ~ApplicationStateTracker();
 
     bool isInBackground() const { return m_isInBackground; }
@@ -50,11 +50,15 @@
     void applicationDidEnterBackground();
     void applicationDidFinishSnapshottingAfterEnteringBackground();
     void applicationWillEnterForeground();
+    void willBeginSnapshotSequence();
+    void didCompleteSnapshotSequence();
 
     WeakObjCPtr<UIView> m_view;
     SEL m_didEnterBackgroundSelector;
     SEL m_didFinishSnapshottingAfterEnteringBackgroundSelector;
     SEL m_willEnterForegroundSelector;
+    SEL m_willBeginSnapshotSequenceSelector;
+    SEL m_didCompleteSnapshotSequenceSelector;
 
     bool m_isInBackground;
 
@@ -63,6 +67,10 @@
     id m_didEnterBackgroundObserver;
     id m_didFinishSnapshottingAfterEnteringBackgroundObserver;
     id m_willEnterForegroundObserver;
+#if HAVE(UISCENE)
+    id m_willBeginSnapshotSequenceObserver;
+    id m_didCompleteSnapshotSequenceObserver;
+#endif
 };
 
 enum class ApplicationType {

Modified: trunk/Source/WebKit/UIProcess/ApplicationStateTracker.mm (258766 => 258767)


--- trunk/Source/WebKit/UIProcess/ApplicationStateTracker.mm	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/UIProcess/ApplicationStateTracker.mm	2020-03-20 17:02:11 UTC (rev 258767)
@@ -75,11 +75,13 @@
     }
 }
 
-ApplicationStateTracker::ApplicationStateTracker(UIView *view, SEL didEnterBackgroundSelector, SEL didFinishSnapshottingAfterEnteringBackgroundSelector, SEL willEnterForegroundSelector)
+ApplicationStateTracker::ApplicationStateTracker(UIView *view, SEL didEnterBackgroundSelector, SEL didFinishSnapshottingAfterEnteringBackgroundSelector, SEL willEnterForegroundSelector, SEL willBeginSnapshotSequenceSelector, SEL didCompleteSnapshotSequenceSelector)
     : m_view(view)
     , m_didEnterBackgroundSelector(didEnterBackgroundSelector)
     , m_didFinishSnapshottingAfterEnteringBackgroundSelector(didFinishSnapshottingAfterEnteringBackgroundSelector)
     , m_willEnterForegroundSelector(willEnterForegroundSelector)
+    , m_willBeginSnapshotSequenceSelector(willBeginSnapshotSequenceSelector)
+    , m_didCompleteSnapshotSequenceSelector(didCompleteSnapshotSequenceSelector)
     , m_isInBackground(true)
     , m_didEnterBackgroundObserver(nullptr)
     , m_didFinishSnapshottingAfterEnteringBackgroundObserver(nullptr)
@@ -123,6 +125,14 @@
                 applicationWillEnterForeground();
             }
         }];
+
+        m_willBeginSnapshotSequenceObserver = [notificationCenter addObserverForName:_UISceneWillBeginSystemSnapshotSequence object:nil queue:nil usingBlock:[this](NSNotification *notification) {
+            willBeginSnapshotSequence();
+        }];
+
+        m_didCompleteSnapshotSequenceObserver = [notificationCenter addObserverForName:_UISceneDidCompleteSystemSnapshotSequence object:nil queue:nil usingBlock:[this](NSNotification *notification) {
+            didCompleteSnapshotSequence();
+        }];
 #else
         m_isInBackground = application.applicationState == UIApplicationStateBackground;
         RELEASE_LOG(ViewState, "%p - ApplicationStateTracker::ApplicationStateTracker(): m_isInBackground: %d", this, m_isInBackground);
@@ -196,6 +206,10 @@
     [notificationCenter removeObserver:m_didEnterBackgroundObserver];
     [notificationCenter removeObserver:m_didFinishSnapshottingAfterEnteringBackgroundObserver];
     [notificationCenter removeObserver:m_willEnterForegroundObserver];
+#if HAVE(UISCENE)
+    [notificationCenter removeObserver:m_willBeginSnapshotSequenceObserver];
+    [notificationCenter removeObserver:m_didCompleteSnapshotSequenceObserver];
+#endif
 }
 
 void ApplicationStateTracker::applicationDidEnterBackground()
@@ -220,6 +234,20 @@
         wtfObjCMsgSend<void>(view.get(), m_willEnterForegroundSelector);
 }
 
+void ApplicationStateTracker::willBeginSnapshotSequence()
+{
+    RELEASE_LOG(ViewState, "%p - ApplicationStateTracker:willBeginSnapshotSequence()", this);
+    if (auto view = m_view.get())
+        wtfObjCMsgSend<void>(view.get(), m_willBeginSnapshotSequenceSelector);
 }
 
+void ApplicationStateTracker::didCompleteSnapshotSequence()
+{
+    RELEASE_LOG(ViewState, "%p - ApplicationStateTracker:didCompleteSnapshotSequence()", this);
+    if (auto view = m_view.get())
+        wtfObjCMsgSend<void>(view.get(), m_didCompleteSnapshotSequenceSelector);
+}
+
+}
+
 #endif

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (258766 => 258767)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-03-20 17:02:11 UTC (rev 258767)
@@ -9923,6 +9923,11 @@
     send(Messages::WebPage::SetOverriddenMediaType(mediaType));
 }
 
+void WebPageProxy::setShouldFireResizeEvents(bool shouldFireResizeEvents)
+{
+    send(Messages::WebPage::SetShouldFireResizeEvents(shouldFireResizeEvents));
+}
+
 #if !PLATFORM(IOS_FAMILY)
 bool WebPageProxy::shouldUseForegroundPriorityForClientNavigation() const
 {

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (258766 => 258767)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-03-20 17:02:11 UTC (rev 258767)
@@ -1712,6 +1712,8 @@
     void grantAccessToPreferenceService();
 #endif
 
+    void setShouldFireResizeEvents(bool);
+
     void setIsNavigatingToAppBoundDomainTesting(bool, CompletionHandler<void()>&&);
     void isNavigatingToAppBoundDomainTesting(CompletionHandler<void(bool)>&&);
     NavigatingToAppBoundDomain isNavigatingToAppBoundDomain() const { return m_isNavigatingToAppBoundDomain; }

Modified: trunk/Source/WebKit/UIProcess/ios/WKApplicationStateTrackingView.mm (258766 => 258767)


--- trunk/Source/WebKit/UIProcess/ios/WKApplicationStateTrackingView.mm	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/UIProcess/ios/WKApplicationStateTrackingView.mm	2020-03-20 17:02:11 UTC (rev 258767)
@@ -68,7 +68,7 @@
     auto page = [_webViewToTrack _page];
     bool lastObservedStateWasBackground = page ? page->lastObservedStateWasBackground() : false;
 
-    _applicationStateTracker = makeUnique<WebKit::ApplicationStateTracker>(self, @selector(_applicationDidEnterBackground), @selector(_applicationDidFinishSnapshottingAfterEnteringBackground), @selector(_applicationWillEnterForeground));
+    _applicationStateTracker = makeUnique<WebKit::ApplicationStateTracker>(self, @selector(_applicationDidEnterBackground), @selector(_applicationDidFinishSnapshottingAfterEnteringBackground), @selector(_applicationWillEnterForeground), @selector(_willBeginSnapshotSequence), @selector(_didCompleteSnapshotSequence));
     RELEASE_LOG(ViewState, "%p - WKApplicationStateTrackingView: View with page [%p, pageProxyID: %" PRIu64 "] was added to a window, _lastObservedStateWasBackground: %d, isNowBackground: %d", self, page.get(), page ? page->identifier().toUInt64() : 0, lastObservedStateWasBackground, [self isBackground]);
 
     if (lastObservedStateWasBackground && ![self isBackground])
@@ -103,6 +103,24 @@
     page->activityStateDidChange(WebCore::ActivityState::allFlags() - WebCore::ActivityState::IsInWindow, WebKit::WebPageProxy::ActivityStateChangeDispatchMode::Immediate, WebKit::WebPageProxy::ActivityStateChangeReplyMode::Synchronous);
 }
 
+- (void)_willBeginSnapshotSequence
+{
+    auto page = [_webViewToTrack _page];
+    if (!page)
+        return;
+
+    page->setShouldFireResizeEvents(false);
+}
+
+- (void)_didCompleteSnapshotSequence
+{
+    auto page = [_webViewToTrack _page];
+    if (!page)
+        return;
+
+    page->setShouldFireResizeEvents(true);
+}
+
 - (BOOL)isBackground
 {
     return _applicationStateTracker ? _applicationStateTracker->isInBackground() : YES;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (258766 => 258767)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-03-20 17:02:11 UTC (rev 258767)
@@ -3345,6 +3345,14 @@
     send(Messages::WebPageProxy::ShowPage());
 }
 
+void WebPage::setShouldFireResizeEvents(bool shouldFireResizeEvents)
+{
+    RELEASE_LOG_IF_ALLOWED(Resize, "setShouldFireResizeEvents(%d)", shouldFireResizeEvents);
+
+    if (m_page)
+        m_page->setShouldFireResizeEvents(shouldFireResizeEvents);
+}
+
 String WebPage::userAgent(const URL& webCoreURL) const
 {
     String userAgent = platformUserAgent(webCoreURL);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (258766 => 258767)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-03-20 17:02:11 UTC (rev 258767)
@@ -1679,6 +1679,8 @@
     void urlSchemeTaskDidReceiveData(uint64_t handlerIdentifier, uint64_t taskIdentifier, const IPC::SharedBufferDataReference&);
     void urlSchemeTaskDidComplete(uint64_t handlerIdentifier, uint64_t taskIdentifier, const WebCore::ResourceError&);
 
+    void setShouldFireResizeEvents(bool);
+
     void setIsSuspended(bool);
 
     RefPtr<WebImage> snapshotAtSize(const WebCore::IntRect&, const WebCore::IntSize& bitmapSize, SnapshotOptions);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (258766 => 258767)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2020-03-20 16:31:51 UTC (rev 258766)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2020-03-20 17:02:11 UTC (rev 258767)
@@ -596,6 +596,8 @@
     SetOverriddenMediaType(String mediaType)
     GetProcessDisplayName() -> (String displayName) Async
 
+    SetShouldFireResizeEvents(bool shouldFireResizeEvents)
+
     SetHasResourceLoadClient(bool has)
     SetIsNavigatingToAppBoundDomainTesting(bool isNavigatingToAppBoundDomain) -> () Async
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to