Bug 143505 - Open WebSockets should not prevent a page from entering PageCache
Summary: Open WebSockets should not prevent a page from entering PageCache
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on: 143806
Blocks:
  Show dependency treegraph
 
Reported: 2015-04-07 17:18 PDT by Chris Dumez
Modified: 2015-04-15 15:43 PDT (History)
4 users (show)

See Also:


Attachments
Patch (9.17 KB, patch)
2015-04-07 17:27 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2015-04-07 17:18:19 PDT
Open WebSockets should not prevent a page from entering PageCache. This is currently causing mobile.nytimes.com to not be page-cacheable.

We could close the WebSocket when entering the page cache and fire the "close" event after resuming, similarly to what we did for XMLHttpRequest in Bug 142612.

Radar: <rdar://problem/19923085>
Comment 1 Chris Dumez 2015-04-07 17:27:52 PDT
Created attachment 250319 [details]
Patch
Comment 2 Alexey Proskuryakov 2015-04-07 19:45:06 PDT
Comment on attachment 250319 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=250319&action=review

> Source/WebCore/Modules/websockets/WebSocket.cpp:481
> +            m_channel->suspend();

Is DocumentWillBecomeInactive the only reason for which canSuspend is respected, or are you changing the behavior for other suspension reasons too? If the latter, how did you confirm that it's right?
Comment 3 Chris Dumez 2015-04-07 20:23:16 PDT
Comment on attachment 250319 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=250319&action=review

>> Source/WebCore/Modules/websockets/WebSocket.cpp:481
>> +            m_channel->suspend();
> 
> Is DocumentWillBecomeInactive the only reason for which canSuspend is respected, or are you changing the behavior for other suspension reasons too? If the latter, how did you confirm that it's right?

I am not changing the behavior for other suspensions than page cache as far as I know. canSuspend() is only called from ScriptExecutionContext::canSuspendActiveDOMObjects(), which is only called from PageCache::canCachePageContainingThisFrame(). When PageCache::canCache() returns true, we call PageCache::add() which constructs a CachedPage and CachedFrame. In the CachedFrame constructor, we call Document::suspendActiveDOMObjects(ActiveDOMObject::DocumentWillBecomeInactive); This is the only place this ReasonForSuspension is used.

Also note the following comment in ActiveDOMObject.h:
virtual bool canSuspend() const = 0; // Returning false in canSuspend() will prevent the page from entering the PageCache.

This time the comment seems accurate :)
Comment 4 Alexey Proskuryakov 2015-04-07 20:32:28 PDT
Makes sense! We should upgrade the comment to a function name (something like canSuspendForPageCache). And ActiveDOMObject::DocumentWillBecomeInactive is a suspicious name too.
Comment 5 Chris Dumez 2015-04-07 20:36:54 PDT
(In reply to comment #4)
> Makes sense! We should upgrade the comment to a function name (something
> like canSuspendForPageCache). And
> ActiveDOMObject::DocumentWillBecomeInactive is a suspicious name too.

Good idea, I'll do the renaming in a follow-up patch.
Comment 6 WebKit Commit Bot 2015-04-07 21:25:19 PDT
Comment on attachment 250319 [details]
Patch

Clearing flags on attachment: 250319

Committed r182517: <http://trac.webkit.org/changeset/182517>
Comment 7 WebKit Commit Bot 2015-04-07 21:25:26 PDT
All reviewed patches have been landed.  Closing bug.