Bug 159410 - When WKWebView prepares the session state blob, we should be able to filter it.
Summary: When WKWebView prepares the session state blob, we should be able to filter it.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-07-04 21:31 PDT by Yongjun Zhang
Modified: 2016-07-08 17:43 PDT (History)
7 users (show)

See Also:


Attachments
Patch. (12.52 KB, patch)
2016-07-04 21:48 PDT, Yongjun Zhang
no flags Details | Formatted Diff | Diff
Fix style issue. (12.48 KB, patch)
2016-07-04 22:03 PDT, Yongjun Zhang
beidson: review-
Details | Formatted Diff | Diff
Add a SPI to WKWebView so that we can filter the session state. (3.18 KB, patch)
2016-07-06 11:35 PDT, Yongjun Zhang
no flags Details | Formatted Diff | Diff
Address review comments. (2.98 KB, patch)
2016-07-06 14:40 PDT, Yongjun Zhang
no flags Details | Formatted Diff | Diff
Fix build issues. (2.98 KB, patch)
2016-07-07 10:44 PDT, Yongjun Zhang
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yongjun Zhang 2016-07-04 21:31:29 PDT
It would be nice to add a SPI to WKBackForwardList so that a WebKit client can remove the current item.
Comment 1 Yongjun Zhang 2016-07-04 21:32:23 PDT
rdar://problem/26565813
Comment 2 Yongjun Zhang 2016-07-04 21:48:44 PDT
Created attachment 282746 [details]
Patch.
Comment 3 WebKit Commit Bot 2016-07-04 21:51:14 PDT
Attachment 282746 [details] did not pass style-queue:


ERROR: Source/WebKit2/ChangeLog:16:  Line contains tab character.  [whitespace/tab] [5]
ERROR: Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKBackForwardList.mm:29:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKBackForwardList.mm:33:  Bad include order. Mixing system and custom headers.  [build/include_order] [4]
Total errors found: 3 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Yongjun Zhang 2016-07-04 22:03:25 PDT
Created attachment 282747 [details]
Fix style issue.
Comment 5 Brady Eidson 2016-07-05 08:46:03 PDT
Comment on attachment 282747 [details]
Fix style issue.

We've resisted APIs to directly manipulate the back/forward list for the entirety of WK2.

Every time we've heard that one is needed, we've always found an alternate.

Why is this needed?
Comment 6 Yongjun Zhang 2016-07-05 10:00:43 PDT
(In reply to comment #5)
> Comment on attachment 282747 [details]
> Fix style issue.
> 
> We've resisted APIs to directly manipulate the back/forward list for the
> entirety of WK2.
> 
> Every time we've heard that one is needed, we've always found an alternate.
> 
> Why is this needed?

Sometimes when we restore the saved session state from disk, we would like to skip the current item (to prevent crash-loop if the app crashed because of loading the URL in current item). We can't just do bfList->back since that would make it possible to go forward and crash again if user swipes forward.

Seems like there isn't a good way to achieve this with the current API/SPI. Any suggestions?
Comment 7 Brady Eidson 2016-07-05 10:05:03 PDT
(In reply to comment #6)
> (In reply to comment #5)
> > Comment on attachment 282747 [details]
> > Fix style issue.
> > 
> > We've resisted APIs to directly manipulate the back/forward list for the
> > entirety of WK2.
> > 
> > Every time we've heard that one is needed, we've always found an alternate.
> > 
> > Why is this needed?
> 
> Sometimes when we restore the saved session state from disk, we would like
> to skip the current item (to prevent crash-loop if the app crashed because
> of loading the URL in current item). We can't just do bfList->back since
> that would make it possible to go forward and crash again if user swipes
> forward.
> 
> Seems like there isn't a good way to achieve this with the current API/SPI.
> Any suggestions?

-Take the session state blob
-Restore without navigating
-Make a new session state blob, but filter out the bad url.
-Restore the new session state blob
Comment 8 Yongjun Zhang 2016-07-05 20:14:43 PDT
(In reply to comment #7)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > Comment on attachment 282747 [details]
> > > Fix style issue.
> > > 
> > > We've resisted APIs to directly manipulate the back/forward list for the
> > > entirety of WK2.
> > > 
> > > Every time we've heard that one is needed, we've always found an alternate.
> > > 
> > > Why is this needed?
> > 
> > Sometimes when we restore the saved session state from disk, we would like
> > to skip the current item (to prevent crash-loop if the app crashed because
> > of loading the URL in current item). We can't just do bfList->back since
> > that would make it possible to go forward and crash again if user swipes
> > forward.
> > 
> > Seems like there isn't a good way to achieve this with the current API/SPI.
> > Any suggestions?
> 
> -Take the session state blob
> -Restore without navigating
> -Make a new session state blob, but filter out the bad url.
> -Restore the new session state blob

Thanks Brady! I will try this approach.
Comment 9 Yongjun Zhang 2016-07-06 11:35:14 PDT
Created attachment 282914 [details]
Add a SPI to WKWebView so that we can filter the session state.
Comment 10 Brady Eidson 2016-07-06 14:03:54 PDT
Comment on attachment 282914 [details]
Add a SPI to WKWebView so that we can filter the session state.

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

> Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm:3378
> +    auto handler = adoptNS([filter copy]);
> +    WebKit::SessionState sessionState = _page->sessionState([handler](WebKit::WebBackForwardListItem& item) {

Can put the filter copy inside the lambda:
[handler = adoptNS([filter copy])]

> Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm:3384
> +        BOOL (^filterBlock)(WKBackForwardListItem *item) = (BOOL (^)(WKBackForwardListItem *item))handler.get();
> +        if (filterBlock) {
> +            if (!filterBlock(wrapper(item)))
> +                return false;
> +        }
> +        return true;

This should be able to be simpler:

if (!handler)
   return true;

BOOL (^filterBlock)(WKBackForwardListItem *item) = (BOOL (^)(WKBackForwardListItem *item))handler.get();
return filterBlock(wrapper(item));
Comment 11 Anders Carlsson 2016-07-06 14:06:55 PDT
Comment on attachment 282914 [details]
Add a SPI to WKWebView so that we can filter the session state.

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

>> Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm:3378
>> +    WebKit::SessionState sessionState = _page->sessionState([handler](WebKit::WebBackForwardListItem& item) {
> 
> Can put the filter copy inside the lambda:
> [handler = adoptNS([filter copy])]

I don't think the block needs to be copied at all? If it does, just use WTF::BlockPtr instead.
Comment 12 Yongjun Zhang 2016-07-06 14:35:51 PDT
(In reply to comment #11)
> Comment on attachment 282914 [details]
> Add a SPI to WKWebView so that we can filter the session state.
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=282914&action=review
> 
> >> Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm:3378
> >> +    WebKit::SessionState sessionState = _page->sessionState([handler](WebKit::WebBackForwardListItem& item) {
> > 
> > Can put the filter copy inside the lambda:
> > [handler = adoptNS([filter copy])]
> 
> I don't think the block needs to be copied at all? If it does, just use
> WTF::BlockPtr instead.

Right, we don't need copy here since WebPageProxy::sessionState is a synchronous call.
Comment 13 Yongjun Zhang 2016-07-06 14:40:51 PDT
Created attachment 282950 [details]
Address review comments.
Comment 14 Yongjun Zhang 2016-07-07 10:44:56 PDT
Created attachment 283023 [details]
Fix build issues.
Comment 15 Brady Eidson 2016-07-08 17:09:14 PDT
Comment on attachment 283023 [details]
Fix build issues.

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

> Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm:3377
> +    WebKit::SessionState sessionState = _page->sessionState([filter](WebKit::WebBackForwardListItem& item) {

[filter = WTFMove(filter)] will avoid a copy. It might just be a pointer copy as I'm not exactly sure how blocks are represented... but probably couldn't hurt!
Comment 16 WebKit Commit Bot 2016-07-08 17:43:56 PDT
Comment on attachment 283023 [details]
Fix build issues.

Clearing flags on attachment: 283023

Committed r203014: <http://trac.webkit.org/changeset/203014>
Comment 17 WebKit Commit Bot 2016-07-08 17:43:59 PDT
All reviewed patches have been landed.  Closing bug.