Bug 204320 - Move [UIDevice currentDevice] calls to UI process
Summary: Move [UIDevice currentDevice] calls to UI process
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Per Arne Vollan
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-11-18 14:55 PST by Per Arne Vollan
Modified: 2020-02-18 10:27 PST (History)
11 users (show)

See Also:


Attachments
Patch (23.02 KB, patch)
2020-02-13 16:04 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (22.97 KB, patch)
2020-02-14 11:07 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (23.00 KB, patch)
2020-02-17 11:12 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (22.90 KB, patch)
2020-02-17 13:28 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Per Arne Vollan 2019-11-18 14:55:10 PST
Calling [UIDevice currentDevice] will cause the runningboard daemon to be accessed. Since this service will be removed from the WebContent sandbox, these calls should be moved to the UI process.

For example, the function exernalDeviceDisplayNameForPlayer in MediaPlayerPrivateAVFoundationObjC.mm is calling [[PAL::getUIDeviceClass() currentDevice] localizedModel], which should be moved to the UI process.
Comment 1 Radar WebKit Bug Importer 2019-11-18 14:55:37 PST
<rdar://problem/57299885>
Comment 2 Per Arne Vollan 2020-02-13 16:04:46 PST
Created attachment 390700 [details]
Patch
Comment 3 Per Arne Vollan 2020-02-13 17:43:40 PST
Comment on attachment 390700 [details]
Patch

Needs more work.
Comment 4 Per Arne Vollan 2020-02-14 11:07:10 PST
Created attachment 390787 [details]
Patch
Comment 5 Darin Adler 2020-02-16 16:49:06 PST
Comment on attachment 390787 [details]
Patch

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

Looks great, but one significant problem.

> Source/WebCore/platform/ios/LocalizedDeviceModel.mm:47
> +    auto localizedDeviceModel = retainPtr([[PAL::getUIDeviceClass() currentDevice] localizedModel]);

This isn’t setting cachedLocalizedDeviceModel, and it should be setting it. Unless our intent is to never cache it?

There should be no need to explicitly call retainPtr. It’s almost never something you have to call explicitly.
Comment 6 Per Arne Vollan 2020-02-17 11:12:24 PST
Created attachment 390943 [details]
Patch
Comment 7 Per Arne Vollan 2020-02-17 11:14:48 PST
(In reply to Darin Adler from comment #5)
> Comment on attachment 390787 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=390787&action=review
> 
> Looks great, but one significant problem.
> 
> > Source/WebCore/platform/ios/LocalizedDeviceModel.mm:47
> > +    auto localizedDeviceModel = retainPtr([[PAL::getUIDeviceClass() currentDevice] localizedModel]);
> 
> This isn’t setting cachedLocalizedDeviceModel, and it should be setting it.
> Unless our intent is to never cache it?
> 

Good point!

> There should be no need to explicitly call retainPtr. It’s almost never
> something you have to call explicitly.

Thanks for reviewing! I have updated the patch accordingly.
Comment 8 Darin Adler 2020-02-17 12:36:20 PST
Comment on attachment 390943 [details]
Patch

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

review- before of the overrelease, otherwise looks great

> Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:2737
> +            displayName =  [[NSString stringWithFormat:@"%@ %@", localizedDeviceModelName, displayName] autorelease];

The stringWithFormat function already returns something autoreleased. Calling autorelease on it a second time is going to overrelease it! Please do not do this.

Could remove that extra space on this line after the "=" since you are touching this.

> Source/WebCore/platform/ios/LocalizedDeviceModel.h:30
> +#import <wtf/text/WTFString.h>

Only need to include Forward.h here. No need to include WTFString.h.

> Source/WebCore/platform/ios/LocalizedDeviceModel.mm:50
> +    if (cachedLocalizedDeviceModel().hasValue())
> +        return *cachedLocalizedDeviceModel();
> +
> +    auto localizedModel = String([[PAL::getUIDeviceClass() currentDevice] localizedModel]);
> +    cachedLocalizedDeviceModel() = localizedModel;
> +
> +    return localizedModel;

Here’s how I think we should write this:

    auto& deviceModel = cachedLocalizedDeviceModel();
    if (!deviceModel)
        deviceModel = String([[PAL::getUIDeviceClass() currentDevice] localizedModel]);
    return *deviceModel;
Comment 9 Darin Adler 2020-02-17 12:36:40 PST
(In reply to Darin Adler from comment #8)
> review- before of the overrelease, otherwise looks great

because of
Comment 10 Per Arne Vollan 2020-02-17 13:28:34 PST
Created attachment 390964 [details]
Patch
Comment 11 Per Arne Vollan 2020-02-17 13:30:11 PST
(In reply to Darin Adler from comment #8)
> Comment on attachment 390943 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=390943&action=review
> 
> review- before of the overrelease, otherwise looks great
> 
> > Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:2737
> > +            displayName =  [[NSString stringWithFormat:@"%@ %@", localizedDeviceModelName, displayName] autorelease];
> 
> The stringWithFormat function already returns something autoreleased.
> Calling autorelease on it a second time is going to overrelease it! Please
> do not do this.
> 

Ah, thanks for catching this!

> Could remove that extra space on this line after the "=" since you are
> touching this.
> 

Done.

> > Source/WebCore/platform/ios/LocalizedDeviceModel.h:30
> > +#import <wtf/text/WTFString.h>
> 
> Only need to include Forward.h here. No need to include WTFString.h.
> 

Fixed.

> > Source/WebCore/platform/ios/LocalizedDeviceModel.mm:50
> > +    if (cachedLocalizedDeviceModel().hasValue())
> > +        return *cachedLocalizedDeviceModel();
> > +
> > +    auto localizedModel = String([[PAL::getUIDeviceClass() currentDevice] localizedModel]);
> > +    cachedLocalizedDeviceModel() = localizedModel;
> > +
> > +    return localizedModel;
> 
> Here’s how I think we should write this:
> 
>     auto& deviceModel = cachedLocalizedDeviceModel();
>     if (!deviceModel)
>         deviceModel = String([[PAL::getUIDeviceClass() currentDevice]
> localizedModel]);
>     return *deviceModel;

Yes, that is much better :)

Thanks for reviewing!
Comment 12 Per Arne Vollan 2020-02-18 09:30:52 PST
Comment on attachment 390964 [details]
Patch

Thanks for reviewing!
Comment 13 WebKit Commit Bot 2020-02-18 10:27:06 PST
Comment on attachment 390964 [details]
Patch

Clearing flags on attachment: 390964

Committed r256839: <https://trac.webkit.org/changeset/256839>
Comment 14 WebKit Commit Bot 2020-02-18 10:27:08 PST
All reviewed patches have been landed.  Closing bug.