Bug 143505

Summary: Open WebSockets should not prevent a page from entering PageCache
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, barraclough, commit-queue, kling
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=142612
Bug Depends on: 143806    
Bug Blocks:    
Attachments:
Description Flags
Patch none

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.