Bug 200436 - navigator.geolocation wrapper should not become GC-collectable once its frame is detached
Summary: navigator.geolocation wrapper should not become GC-collectable once its frame...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Bindings (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-08-05 08:34 PDT by Chris Dumez
Modified: 2019-08-06 11:41 PDT (History)
13 users (show)

See Also:


Attachments
Patch (26.20 KB, patch)
2019-08-05 09:58 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (26.31 KB, patch)
2019-08-05 10:07 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (26.94 KB, patch)
2019-08-05 10:15 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews103 for mac-highsierra (3.20 MB, application/zip)
2019-08-05 11:16 PDT, EWS Watchlist
no flags Details
Patch (28.00 KB, patch)
2019-08-05 11:53 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (28.14 KB, patch)
2019-08-05 11:55 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (29.87 KB, patch)
2019-08-05 14:28 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 2019-08-05 08:34:41 PDT
navigator.geolocation wrapper should not become GC-collectable once its frame is detached, given that it can outlive the frame.
Comment 1 Chris Dumez 2019-08-05 09:58:28 PDT
Created attachment 375530 [details]
Patch
Comment 2 EWS Watchlist 2019-08-05 10:00:08 PDT
Attachment 375530 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:164:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:165:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:166:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 3 in 23 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Chris Dumez 2019-08-05 10:07:54 PDT
Created attachment 375531 [details]
Patch
Comment 4 EWS Watchlist 2019-08-05 10:10:04 PDT
Attachment 375531 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:164:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:165:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:166:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 3 in 23 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Chris Dumez 2019-08-05 10:15:45 PDT
Created attachment 375533 [details]
Patch
Comment 6 EWS Watchlist 2019-08-05 10:17:06 PDT
Attachment 375533 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:164:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:165:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:166:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 3 in 24 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 EWS Watchlist 2019-08-05 11:16:20 PDT
Comment on attachment 375533 [details]
Patch

Attachment 375533 [details] did not pass mac-ews (mac):
Output: https://webkit-queues.webkit.org/results/12864090

New failing tests:
fast/dom/navigator-property-gc-after-frame-detach.html
Comment 8 EWS Watchlist 2019-08-05 11:16:22 PDT
Created attachment 375537 [details]
Archive of layout-test-results from ews103 for mac-highsierra

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews103  Port: mac-highsierra  Platform: Mac OS X 10.13.6
Comment 9 Chris Dumez 2019-08-05 11:53:45 PDT
Created attachment 375542 [details]
Patch
Comment 10 Chris Dumez 2019-08-05 11:55:16 PDT
Created attachment 375543 [details]
Patch
Comment 11 EWS Watchlist 2019-08-05 11:56:29 PDT
Attachment 375543 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:164:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:165:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:166:  enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums.  [readability/enum_casing] [4]
Total errors found: 3 in 25 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 12 Darin Adler 2019-08-05 13:31:55 PDT
Comment on attachment 375543 [details]
Patch

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

Looks great.

> Source/WebCore/Modules/geolocation/Geolocation.h:77
> +    WEBCORE_EXPORT Frame* frame() const;

I guess there must be important clients of this function, but seems annoying that we have it.

> Source/WebCore/Modules/geolocation/Geolocation.h:163
> +    } m_allowGeolocation { Unknown };

Not sure you will agree, but I think this would read slightly better all on one line:

    enum { Unknown, InProgress, Yes, No } m_allowGeolocation { Unknown };

> Source/WebCore/Modules/geolocation/NavigatorGeolocation.cpp:76
> +        m_geolocation = Geolocation::create(*m_navigator);

Is this correct for the case where m_navigator is nullptr? I assume it can be null because it’s a WeakPtr.

> Source/WebCore/bindings/js/JSNavigatorCustom.cpp:33
> +    visitor.addOpaqueRoot(static_cast<NavigatorBase*>(&wrapped()));

I wish there was a safer cast for upcasts rather than static_cast, which can also do other kinds of casting like downcasts. I also wish there was less void* danger here. If we passed &wrapped() without casting to NavigatorBase*, how would we know we had it wrong?

> Source/WebCore/bindings/js/JSWorkerNavigatorCustom.cpp:33
> +    visitor.addOpaqueRoot(static_cast<NavigatorBase*>(&wrapped()));

Ditto.

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:4686
> +                $rootString  = "    auto* root = static_cast<NavigatorBase*>(WTF::getPtr(js${interfaceName}->wrapped().navigator()));\n";

Ditto.

> Source/WebCore/plugins/DOMMimeTypeArray.h:43
> +    Navigator* navigator() { return m_navigator.get(); }

Inconsistent that the other getter functions are const, but not this.

> Source/WebCore/plugins/DOMMimeTypeArray.h:44
> +    Frame* frame() const { return m_navigator ? m_navigator->frame() : nullptr; }

I assume we need these because there was a DOMWindowProperty::frame function. But since it’s not new I can’t see the call sites in this patch. Seems like it would be more elegant if we didn’t need these, but maybe if I saw the call sites I would understand why we do.

> Source/WebCore/plugins/DOMPluginArray.h:47
> +    Frame* frame() const { return m_navigator ? m_navigator->frame() : nullptr; }

Ditto.
Comment 13 Darin Adler 2019-08-05 13:37:10 PDT
Comment on attachment 375543 [details]
Patch

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

>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:4686
>> +                $rootString  = "    auto* root = static_cast<NavigatorBase*>(WTF::getPtr(js${interfaceName}->wrapped().navigator()));\n";
> 
> Ditto.

Since it’s a local variable we could write this without the static_cast:

    NavigatorBase* root = WTF::getPtr(js${interfaceName}->wrapped().navigator());

But not sure if overall that makes this better or worse.
Comment 14 Chris Dumez 2019-08-05 14:21:00 PDT
Comment on attachment 375543 [details]
Patch

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

>> Source/WebCore/Modules/geolocation/Geolocation.h:77
>> +    WEBCORE_EXPORT Frame* frame() const;
> 
> I guess there must be important clients of this function, but seems annoying that we have it.

Yes, this one is actually used by WebKit2 or WebKitLegacy, which is why I had to export it. I will check what it is used for.

>> Source/WebCore/Modules/geolocation/Geolocation.h:163
>> +    } m_allowGeolocation { Unknown };
> 
> Not sure you will agree, but I think this would read slightly better all on one line:
> 
>     enum { Unknown, InProgress, Yes, No } m_allowGeolocation { Unknown };

Ok.

>> Source/WebCore/Modules/geolocation/NavigatorGeolocation.cpp:76
>> +        m_geolocation = Geolocation::create(*m_navigator);
> 
> Is this correct for the case where m_navigator is nullptr? I assume it can be null because it’s a WeakPtr.

It actually cannot be null, this is a NavigatorSupplement so it is owned by Navigator. I should not be using a WeakPtr in this class.

>> Source/WebCore/bindings/js/JSNavigatorCustom.cpp:33
>> +    visitor.addOpaqueRoot(static_cast<NavigatorBase*>(&wrapped()));
> 
> I wish there was a safer cast for upcasts rather than static_cast, which can also do other kinds of casting like downcasts. I also wish there was less void* danger here. If we passed &wrapped() without casting to NavigatorBase*, how would we know we had it wrong?

It is a bit error-prone yes, but my test would fail if we would get it wrong.

>>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:4686
>>> +                $rootString  = "    auto* root = static_cast<NavigatorBase*>(WTF::getPtr(js${interfaceName}->wrapped().navigator()));\n";
>> 
>> Ditto.
> 
> Since it’s a local variable we could write this without the static_cast:
> 
>     NavigatorBase* root = WTF::getPtr(js${interfaceName}->wrapped().navigator());
> 
> But not sure if overall that makes this better or worse.

I like it, will switch.

>> Source/WebCore/plugins/DOMMimeTypeArray.h:44
>> +    Frame* frame() const { return m_navigator ? m_navigator->frame() : nullptr; }
> 
> I assume we need these because there was a DOMWindowProperty::frame function. But since it’s not new I can’t see the call sites in this patch. Seems like it would be more elegant if we didn’t need these, but maybe if I saw the call sites I would understand why we do.

Those frame() getters on DOMMimeTypeArray and DOMPluginArray are only used by the internal implementation iirc (for early returns). At the very least, I can likely make them private.

>> Source/WebCore/plugins/DOMPluginArray.h:47
>> +    Frame* frame() const { return m_navigator ? m_navigator->frame() : nullptr; }
> 
> Ditto.

See comment above.
Comment 15 Chris Dumez 2019-08-05 14:27:35 PDT
Comment on attachment 375543 [details]
Patch

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

>>> Source/WebCore/Modules/geolocation/Geolocation.h:77
>>> +    WEBCORE_EXPORT Frame* frame() const;
>> 
>> I guess there must be important clients of this function, but seems annoying that we have it.
> 
> Yes, this one is actually used by WebKit2 or WebKitLegacy, which is why I had to export it. I will check what it is used for.

/Volumes/Data/WebKit/OpenSource/Source/WebKitLegacy/mac/WebCoreSupport/WebGeolocationClient.mm:114:32: error: 'frame' is a private member of 'WebCore::Geolocation'
    Frame *frame = geolocation.frame();
    if (!frame) {
        geolocation.setIsAllowed(false);
        return;
    }
Comment 16 Chris Dumez 2019-08-05 14:28:15 PDT
Created attachment 375556 [details]
Patch
Comment 17 WebKit Commit Bot 2019-08-05 16:00:32 PDT
Comment on attachment 375556 [details]
Patch

Clearing flags on attachment: 375556

Committed r248276: <https://trac.webkit.org/changeset/248276>
Comment 18 WebKit Commit Bot 2019-08-05 16:00:34 PDT
All reviewed patches have been landed.  Closing bug.
Comment 19 Radar WebKit Bug Importer 2019-08-05 16:01:20 PDT
<rdar://problem/53962896>
Comment 20 Alexey Proskuryakov 2019-08-06 10:55:04 PDT
Comment on attachment 375556 [details]
Patch

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

> LayoutTests/platform/wk2/TestExpectations:-163
> -webkit.org/b/141122 editing/selection/programmatic-selection-on-mac-is-directionless.html [ Pass Failure ]

This change landed accidentally, could you please undo it?
Comment 21 Chris Dumez 2019-08-06 10:56:07 PDT
(In reply to Alexey Proskuryakov from comment #20)
> Comment on attachment 375556 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=375556&action=review
> 
> > LayoutTests/platform/wk2/TestExpectations:-163
> > -webkit.org/b/141122 editing/selection/programmatic-selection-on-mac-is-directionless.html [ Pass Failure ]
> 
> This change landed accidentally, could you please undo it?

Ah.. That will teach me to work on 2 things at the same time. Will fix now.
Comment 22 Chris Dumez 2019-08-06 10:57:58 PDT
<https://trac.webkit.org/changeset/248306>
Comment 23 Darin Adler 2019-08-06 11:41:40 PDT
(In reply to Chris Dumez from comment #15)
> /Volumes/Data/WebKit/OpenSource/Source/WebKitLegacy/mac/WebCoreSupport/
> WebGeolocationClient.mm:114:32: error: 'frame' is a private member of
> 'WebCore::Geolocation'

So we need to keep this as long as we want to support the webView:decidePolicyForGeolocationRequestFromOrigin:frame:listener: delegate method on the iOS platform family.

As an aside, I think we could consider dropping support for that at some point as part of cutting down the complexity of WebKitLegacy.