Bug 84522 - Page::setDefersLoading() should have a call count
Summary: Page::setDefersLoading() should have a call count
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: Jon Honeycutt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-20 22:59 PDT by Jon Honeycutt
Modified: 2012-05-02 19:55 PDT (History)
2 users (show)

See Also:


Attachments
Patch (3.73 KB, patch)
2012-04-20 23:19 PDT, Jon Honeycutt
aestes: review-
Details | Formatted Diff | Diff
Patch v2 (14.91 KB, patch)
2012-05-01 17:21 PDT, Jon Honeycutt
aestes: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Honeycutt 2012-04-20 22:59:10 PDT
Page::setDefersLoading() should have a call count so that making several calls to defer loading must be balanced by an equal number of calls to resume loading.
Comment 1 Jon Honeycutt 2012-04-20 23:19:08 PDT
Created attachment 138221 [details]
Patch
Comment 2 WebKit Review Bot 2012-04-20 23:20:53 PDT
Attachment 138221 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCor..." exit_code: 1
Source/WebCore/page/Page.cpp:576:  An else if statement should be written as an if statement when the prior "if" concludes with a return, break, continue or goto statement.  [readability/control_flow] [4]
Total errors found: 1 in 3 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Andy Estes 2012-04-30 15:06:58 PDT
Comment on attachment 138221 [details]
Patch

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

As we discussed on IRC, as it stands this'll cause issues with WebKit nightly builds.

> Source/WebCore/page/Page.cpp:575
> +    ASSERT(defers || m_deferLoadingCallCount > 0);

If you made m_deferLoadingCallCount unsigned you could simplify this expression.

>> Source/WebCore/page/Page.cpp:576
>> +    if (defers && ++m_deferLoadingCallCount > 1)
> 
> An else if statement should be written as an if statement when the prior "if" concludes with a return, break, continue or goto statement.  [readability/control_flow] [4]

Like StyleBot says...

> Source/WebCore/page/Page.cpp:578
> +    else if (!defers && --m_deferLoadingCallCount > 0)

If you made m_deferLoadingCallCount unsigned you could simplify this expression.

> Source/WebCore/page/Page.h:221
> +        bool defersLoading() const { return m_deferLoadingCallCount > 0; }

If you made m_deferLoadingCallCount unsigned you could simplify this expression.

> Source/WebCore/page/Page.h:391
> +        int m_deferLoadingCallCount;

m_defersLoadingCallCount seems like a better name given the name of the method.
Comment 4 Jon Honeycutt 2012-05-01 17:21:26 PDT
Created attachment 139714 [details]
Patch v2
Comment 5 Andy Estes 2012-05-01 18:36:54 PDT
Comment on attachment 139714 [details]
Patch v2

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

r=me, although I like this new behavior so much that I find it unfortunate that it's opt-in rather than opt-out. If having the new behavior enabled by default causes bugs in other ports they can always opt out with a setting, or just fix their bug.

> Source/WebCore/page/Page.cpp:585
> -    if (defers == m_defersLoading)
> +    if (m_settings->wantsBalancedSetDefersLoadingBehavior()) {
> +        ASSERT(defers || m_defersLoadingCallCount);
> +        if (defers && ++m_defersLoadingCallCount > 1)
> +            return;
> +        if (!defers && --m_defersLoadingCallCount)
> +            return;
> +    } else if (defers == m_defersLoading)

I'd assert that m_defersLoadingCallCount is 0 if wantsBalancedSetDefersLoadingBehavior() is false, which catches the case where the setting changes from true to false between deferring and resuming. Your other assert already catches the case where it changes from false to true.
Comment 6 Jon Honeycutt 2012-05-02 19:55:54 PDT
(In reply to comment #5)
> (From update of attachment 139714 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=139714&action=review
> 
> r=me, although I like this new behavior so much that I find it unfortunate that it's opt-in rather than opt-out. If having the new behavior enabled by default causes bugs in other ports they can always opt out with a setting, or just fix their bug.

OK, I'll file a bug about making this opt-out.

> 
> > Source/WebCore/page/Page.cpp:585
> > -    if (defers == m_defersLoading)
> > +    if (m_settings->wantsBalancedSetDefersLoadingBehavior()) {
> > +        ASSERT(defers || m_defersLoadingCallCount);
> > +        if (defers && ++m_defersLoadingCallCount > 1)
> > +            return;
> > +        if (!defers && --m_defersLoadingCallCount)
> > +            return;
> > +    } else if (defers == m_defersLoading)
> 
> I'd assert that m_defersLoadingCallCount is 0 if wantsBalancedSetDefersLoadingBehavior() is false, which catches the case where the setting changes from true to false between deferring and resuming. Your other assert already catches the case where it changes from false to true.

Landed with this change in <http://trac.webkit.org/changeset/115925>.