Bug 184591 - Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame
Summary: Split WindowProxy handling out of ScriptController and into a new class owned...
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: 184467
Blocks: 184515 184640
  Show dependency treegraph
 
Reported: 2018-04-13 09:10 PDT by Chris Dumez
Modified: 2018-04-15 15:33 PDT (History)
11 users (show)

See Also:


Attachments
Patch (44.20 KB, patch)
2018-04-13 10:11 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (44.47 KB, patch)
2018-04-13 10:29 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (44.89 KB, patch)
2018-04-13 11:11 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (44.85 KB, patch)
2018-04-13 11:57 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (45.85 KB, patch)
2018-04-13 12:04 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 2018-04-13 09:10:38 PDT
Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame. RemoteFrames do not need a ScriptController but do need to maintain WindowProxies.
Comment 1 Chris Dumez 2018-04-13 10:11:23 PDT
Created attachment 337903 [details]
Patch
Comment 2 Chris Dumez 2018-04-13 10:29:12 PDT
Created attachment 337905 [details]
Patch
Comment 3 Chris Dumez 2018-04-13 11:11:29 PDT
Created attachment 337909 [details]
Patch
Comment 4 Sam Weinig 2018-04-13 11:43:56 PDT
Comment on attachment 337909 [details]
Patch

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

> Source/WebCore/bindings/js/DOMWrapperWorld.h:64
> +    HashSet<WindowProxyController*> m_controllersWithWindowProxies;

I think this can just be called m_windowProxyControllers.

> Source/WebCore/bindings/js/JSDOMWindowBase.cpp:270
> -    return frame.script().windowProxy(world)->window();
> +    return frame.script().globalObject(world);

Why globalObject() and not window() here?

> Source/WebCore/bindings/js/JSDOMWindowProxy.cpp:127
>  JSDOMWindowProxy* toJSDOMWindowProxy(Frame& frame, DOMWrapperWorld& world)
>  {
> -    return frame.script().windowProxy(world);
> +    return &frame.windowProxyController().windowProxy(world);
>  }

Can we switch this function to return a reference since this will never return null?  Or,

> Source/WebCore/bindings/js/WindowProxyController.h:41
> +    Vector<JSC::Strong<JSDOMWindowProxy>> windowProxiesAsVector() const;

Do all the places that use windowProxiesAsVector() really need to copy to a Vector?
Comment 5 Chris Dumez 2018-04-13 11:55:14 PDT
Comment on attachment 337909 [details]
Patch

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

>> Source/WebCore/bindings/js/DOMWrapperWorld.h:64
>> +    HashSet<WindowProxyController*> m_controllersWithWindowProxies;
> 
> I think this can just be called m_windowProxyControllers.

Ok.

>> Source/WebCore/bindings/js/JSDOMWindowBase.cpp:270
>> +    return frame.script().globalObject(world);
> 
> Why globalObject() and not window() here?

This is identical but shorter since ScriptController::globalObject() is implemented as:
JSDOMWindow* globalObject(DOMWrapperWorld& world)
{
    return windowProxyController().windowProxy(world).window();
}

Once benefit also is that in the next patch, JSDOMWindowProxy::window() will start returning a more generic type, which ScriptController::globalObject() can keep returning a JSDOMWindow* since it is associated with a (local) Frame.

>> Source/WebCore/bindings/js/JSDOMWindowProxy.cpp:127
>>  }
> 
> Can we switch this function to return a reference since this will never return null?  Or,

I will look into it, I was trying to limit patch size.

>> Source/WebCore/bindings/js/WindowProxyController.h:41
>> +    Vector<JSC::Strong<JSDOMWindowProxy>> windowProxiesAsVector() const;
> 
> Do all the places that use windowProxiesAsVector() really need to copy to a Vector?

Some of them definitely do and this maintain pre-existing behavior. I am trying to reduce the risk of regression from my refactoring by maintaining pre-existing behavior as much as possible.
Comment 6 Chris Dumez 2018-04-13 11:57:55 PDT
Created attachment 337915 [details]
Patch
Comment 7 Chris Dumez 2018-04-13 12:04:09 PDT
Created attachment 337916 [details]
Patch
Comment 8 Sam Weinig 2018-04-13 13:43:55 PDT
Comment on attachment 337916 [details]
Patch

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

> Source/WebCore/bindings/js/WindowProxyController.h:41
> +    Vector<JSC::Strong<JSDOMWindowProxy>> windowProxiesAsVector() const;

I kind of feel this function should have the word "copy" somewhere in its name, but I can't think of one that isn't overly verbose.

> Source/WebCore/bindings/js/WindowProxyController.h:43
> +    ProxyMap releaseWindowProxies() { return std::exchange(m_windowProxies, ProxyMap()); }

Does anyone call this?

> Source/WebCore/bindings/js/WindowProxyController.h:44
> +    void setWindowProxies(ProxyMap&& windowProxies) { m_windowProxies = WTFMove(windowProxies); }

Does anyone call this?
Comment 9 Chris Dumez 2018-04-13 13:47:53 PDT
Comment on attachment 337916 [details]
Patch

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

>> Source/WebCore/bindings/js/WindowProxyController.h:41
>> +    Vector<JSC::Strong<JSDOMWindowProxy>> windowProxiesAsVector() const;
> 
> I kind of feel this function should have the word "copy" somewhere in its name, but I can't think of one that isn't overly verbose.

copyWindowProxies() ?

>> Source/WebCore/bindings/js/WindowProxyController.h:43
>> +    ProxyMap releaseWindowProxies() { return std::exchange(m_windowProxies, ProxyMap()); }
> 
> Does anyone call this?

The next patch.

>> Source/WebCore/bindings/js/WindowProxyController.h:44
>> +    void setWindowProxies(ProxyMap&& windowProxies) { m_windowProxies = WTFMove(windowProxies); }
> 
> Does anyone call this?

The next patch.
Comment 10 WebKit Commit Bot 2018-04-13 14:24:00 PDT
Comment on attachment 337916 [details]
Patch

Clearing flags on attachment: 337916

Committed r230643: <https://trac.webkit.org/changeset/230643>
Comment 11 WebKit Commit Bot 2018-04-13 14:24:02 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Radar WebKit Bug Importer 2018-04-15 15:33:22 PDT
<rdar://problem/39444728>