|
|
Chromium Code Reviews|
Created:
6 years, 2 months ago by dcheng Modified:
6 years, 2 months ago CC:
arv+blink, blink-reviews, blink-reviews-bindings_chromium.org, sof, site-isolation-reviews_chromium.org Base URL:
svn://svn.chromium.org/blink/trunk Project:
blink Visibility:
Public. |
DescriptionAdd a basic DOMWindow base class and use it in WindowProxy.
This is the first step towards providing RemoteFrames with a
DOMWindow so things like postMessage() on a remote frame will work.
This patch also moves Frame::setDOMWindow with a LocalDOMWindow to
LocalFrame, since it's only called on a LocalFrame. The
corresponding member has also been moved to LocalFrame, since it
was never set to a non-null value for RemoteFrames anyway.
BUG=425623
Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=184244
Patch Set 1 #Patch Set 2 : . #Patch Set 3 : Move the member too #
Total comments: 7
Patch Set 4 : Address comments #
Messages
Total messages: 25 (6 generated)
dcheng@chromium.org changed reviewers: + haraken@chromium.org, japhet@chromium.org
lgtm
https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/Frame.h File Source/core/frame/Frame.h (right): https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/Frame.... Source/core/frame/Frame.h:63: virtual LocalDOMWindow* domWindow() const = 0; I meant to include this as a comment, but I'm not sure if making this virtual will have a perf impact (it was non-virtual before, and inlined too, it looks like)
haraken@chromium.org changed reviewers: + yukishiino@chromium.or
Just to confirm: Are you planning to make RemoteFrame inherit from DOMWindow in the future? https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... File Source/core/frame/DOMWindow.h (right): https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... Source/core/frame/DOMWindow.h:9: class DOMWindow { I'm curious why DOMWindow can't inherit from ScriptWrappableBase?
RemoteFrame itself probably won't inherit from DOMWindow, but we'll add a RemoteDOMWindow that will. https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... File Source/core/frame/DOMWindow.h (right): https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... Source/core/frame/DOMWindow.h:9: class DOMWindow { On 2014/10/22 00:59:14, haraken wrote: > > I'm curious why DOMWindow can't inherit from ScriptWrappableBase? LocalDOMWindow is an EventTarget (and I don't think it makes sense for RemoteDOMWindow to be an EventTarget -- I don't think you can register an event listener on a cross-origin DOMWindow). If this was also a ScriptWrappable, then you would have to explicitly say you wanted to use the ScriptWrappableBase from EventTargetWithInlineData or the ScriptWrappableBase from DOMWindow.
On 2014/10/22 01:01:47, dcheng wrote: > RemoteFrame itself probably won't inherit from DOMWindow, but we'll add a > RemoteDOMWindow that will. Sorry, I meant RemoteDOMWindow :) > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > File Source/core/frame/DOMWindow.h (right): > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > Source/core/frame/DOMWindow.h:9: class DOMWindow { > On 2014/10/22 00:59:14, haraken wrote: > > > > I'm curious why DOMWindow can't inherit from ScriptWrappableBase? > > LocalDOMWindow is an EventTarget (and I don't think it makes sense for > RemoteDOMWindow to be an EventTarget -- I don't think you can register an event > listener on a cross-origin DOMWindow). If this was also a ScriptWrappable, then > you would have to explicitly say you wanted to use the ScriptWrappableBase from > EventTargetWithInlineData or the ScriptWrappableBase from DOMWindow. Given that LocalDOMWindow is an EventTarget (which inherits from ScriptWrappableBase), LocalDOMWindow should already be able to use toScriptWrappableBase(). Why do we need to add toScriptWrappableBase() to DOMWindow then? The idea is: - We want to make all DOM objects (i.e., objects exposed to JavaScript) inherit from ScriptWrappable(Base). - toScriptWrappableBase() should be defined only in ScriptWrappableBase.
On 2014/10/22 01:16:56, haraken wrote: > On 2014/10/22 01:01:47, dcheng wrote: > > RemoteFrame itself probably won't inherit from DOMWindow, but we'll add a > > RemoteDOMWindow that will. > > Sorry, I meant RemoteDOMWindow :) > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > File Source/core/frame/DOMWindow.h (right): > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > Source/core/frame/DOMWindow.h:9: class DOMWindow { > > On 2014/10/22 00:59:14, haraken wrote: > > > > > > I'm curious why DOMWindow can't inherit from ScriptWrappableBase? > > > > LocalDOMWindow is an EventTarget (and I don't think it makes sense for > > RemoteDOMWindow to be an EventTarget -- I don't think you can register an > event > > listener on a cross-origin DOMWindow). If this was also a ScriptWrappable, > then > > you would have to explicitly say you wanted to use the ScriptWrappableBase > from > > EventTargetWithInlineData or the ScriptWrappableBase from DOMWindow. > > Given that LocalDOMWindow is an EventTarget (which inherits from > ScriptWrappableBase), LocalDOMWindow should already be able to use > toScriptWrappableBase(). Why do we need to add toScriptWrappableBase() to > DOMWindow then? > > The idea is: > > - We want to make all DOM objects (i.e., objects exposed to JavaScript) inherit > from ScriptWrappable(Base). > - toScriptWrappableBase() should be defined only in ScriptWrappableBase. Ah, I'm getting to understand the situation... Conceptually we should have the following class inheritance: class EventTarget { }; // Don't inherit from ScriptWrappable class DOMWindow : public ScriptWrappable { }; class LocalDOMWindow : public DOMWindow, public EventTarget { }; class RemoteDOMWindow : public DOMWindow { }; The complexity comes from the fact that currently EventTarget inherits from ScriptWrappable. This is conceptually not right but we do this in order not to increase sizeof(Node)... class Node : public EventTarget, public ScriptWrappable { }; ^^^ This will increase sizeof(Node) because both EventTarget and ScriptWrappable have vtables.
The CQ bit was checked by dcheng@chromium.org
The CQ bit was unchecked by dcheng@chromium.org
On 2014/10/22 at 01:22:06, haraken wrote: > On 2014/10/22 01:16:56, haraken wrote: > > On 2014/10/22 01:01:47, dcheng wrote: > > > RemoteFrame itself probably won't inherit from DOMWindow, but we'll add a > > > RemoteDOMWindow that will. > > > > Sorry, I meant RemoteDOMWindow :) > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > File Source/core/frame/DOMWindow.h (right): > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > Source/core/frame/DOMWindow.h:9: class DOMWindow { > > > On 2014/10/22 00:59:14, haraken wrote: > > > > > > > > I'm curious why DOMWindow can't inherit from ScriptWrappableBase? > > > > > > LocalDOMWindow is an EventTarget (and I don't think it makes sense for > > > RemoteDOMWindow to be an EventTarget -- I don't think you can register an > > event > > > listener on a cross-origin DOMWindow). If this was also a ScriptWrappable, > > then > > > you would have to explicitly say you wanted to use the ScriptWrappableBase > > from > > > EventTargetWithInlineData or the ScriptWrappableBase from DOMWindow. > > > > Given that LocalDOMWindow is an EventTarget (which inherits from > > ScriptWrappableBase), LocalDOMWindow should already be able to use > > toScriptWrappableBase(). Why do we need to add toScriptWrappableBase() to > > DOMWindow then? > > > > The idea is: > > > > - We want to make all DOM objects (i.e., objects exposed to JavaScript) inherit > > from ScriptWrappable(Base). > > - toScriptWrappableBase() should be defined only in ScriptWrappableBase. > > Ah, I'm getting to understand the situation... > > Conceptually we should have the following class inheritance: > > class EventTarget { }; // Don't inherit from ScriptWrappable > class DOMWindow : public ScriptWrappable { }; > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > class RemoteDOMWindow : public DOMWindow { }; > > The complexity comes from the fact that currently EventTarget inherits from ScriptWrappable. This is conceptually not right but we do this in order not to increase sizeof(Node)... > > class Node : public EventTarget, public ScriptWrappable { }; > > ^^^ This will increase sizeof(Node) because both EventTarget and ScriptWrappable have vtables. Yeah, this is the reason I had to take this approach. Otherwise, we end up with the following situation: class DOMWindow : public ScriptWrappable { }; class EventTarget : public ScriptWrappable { }; class LocalDOMWindow : public DOMWindow, public EventTarget { }; Now if you have: LocalDOMWindow* w; then this will fail to compile: w->wrapperTypeInfo(); because the compiler doesn't know which base class to go through to get to ScriptWrappable. Instead, I would have to write: static_cast<DOMWindow*>(w)->wrapperTypeInfo();
On 2014/10/22 01:36:53, dcheng wrote: > On 2014/10/22 at 01:22:06, haraken wrote: > > On 2014/10/22 01:16:56, haraken wrote: > > > On 2014/10/22 01:01:47, dcheng wrote: > > > > RemoteFrame itself probably won't inherit from DOMWindow, but we'll add a > > > > RemoteDOMWindow that will. > > > > > > Sorry, I meant RemoteDOMWindow :) > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > File Source/core/frame/DOMWindow.h (right): > > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > Source/core/frame/DOMWindow.h:9: class DOMWindow { > > > > On 2014/10/22 00:59:14, haraken wrote: > > > > > > > > > > I'm curious why DOMWindow can't inherit from ScriptWrappableBase? > > > > > > > > LocalDOMWindow is an EventTarget (and I don't think it makes sense for > > > > RemoteDOMWindow to be an EventTarget -- I don't think you can register an > > > event > > > > listener on a cross-origin DOMWindow). If this was also a ScriptWrappable, > > > then > > > > you would have to explicitly say you wanted to use the ScriptWrappableBase > > > from > > > > EventTargetWithInlineData or the ScriptWrappableBase from DOMWindow. > > > > > > Given that LocalDOMWindow is an EventTarget (which inherits from > > > ScriptWrappableBase), LocalDOMWindow should already be able to use > > > toScriptWrappableBase(). Why do we need to add toScriptWrappableBase() to > > > DOMWindow then? > > > > > > The idea is: > > > > > > - We want to make all DOM objects (i.e., objects exposed to JavaScript) > inherit > > > from ScriptWrappable(Base). > > > - toScriptWrappableBase() should be defined only in ScriptWrappableBase. > > > > Ah, I'm getting to understand the situation... > > > > Conceptually we should have the following class inheritance: > > > > class EventTarget { }; // Don't inherit from ScriptWrappable > > class DOMWindow : public ScriptWrappable { }; > > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > class RemoteDOMWindow : public DOMWindow { }; > > > > The complexity comes from the fact that currently EventTarget inherits from > ScriptWrappable. This is conceptually not right but we do this in order not to > increase sizeof(Node)... > > > > class Node : public EventTarget, public ScriptWrappable { }; > > > > ^^^ This will increase sizeof(Node) because both EventTarget and > ScriptWrappable have vtables. > > Yeah, this is the reason I had to take this approach. Otherwise, we end up with > the following situation: > > class DOMWindow : public ScriptWrappable { }; > class EventTarget : public ScriptWrappable { }; > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > Now if you have: > LocalDOMWindow* w; > then this will fail to compile: > w->wrapperTypeInfo(); > because the compiler doesn't know which base class to go through to get to > ScriptWrappable. Instead, I would have to write: > static_cast<DOMWindow*>(w)->wrapperTypeInfo(); Thanks, I understand what you're doing :) shiino-san: Do you have any idea on this?
On 2014/10/22 01:42:25, haraken wrote: > On 2014/10/22 01:36:53, dcheng wrote: > > On 2014/10/22 at 01:22:06, haraken wrote: > > > On 2014/10/22 01:16:56, haraken wrote: > > > > On 2014/10/22 01:01:47, dcheng wrote: > > > > > RemoteFrame itself probably won't inherit from DOMWindow, but we'll add > a > > > > > RemoteDOMWindow that will. > > > > > > > > Sorry, I meant RemoteDOMWindow :) > > > > > > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > > File Source/core/frame/DOMWindow.h (right): > > > > > > > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > > Source/core/frame/DOMWindow.h:9: class DOMWindow { > > > > > On 2014/10/22 00:59:14, haraken wrote: > > > > > > > > > > > > I'm curious why DOMWindow can't inherit from ScriptWrappableBase? > > > > > > > > > > LocalDOMWindow is an EventTarget (and I don't think it makes sense for > > > > > RemoteDOMWindow to be an EventTarget -- I don't think you can register > an > > > > event > > > > > listener on a cross-origin DOMWindow). If this was also a > ScriptWrappable, > > > > then > > > > > you would have to explicitly say you wanted to use the > ScriptWrappableBase > > > > from > > > > > EventTargetWithInlineData or the ScriptWrappableBase from DOMWindow. > > > > > > > > Given that LocalDOMWindow is an EventTarget (which inherits from > > > > ScriptWrappableBase), LocalDOMWindow should already be able to use > > > > toScriptWrappableBase(). Why do we need to add toScriptWrappableBase() to > > > > DOMWindow then? > > > > > > > > The idea is: > > > > > > > > - We want to make all DOM objects (i.e., objects exposed to JavaScript) > > inherit > > > > from ScriptWrappable(Base). > > > > - toScriptWrappableBase() should be defined only in ScriptWrappableBase. > > > > > > Ah, I'm getting to understand the situation... > > > > > > Conceptually we should have the following class inheritance: > > > > > > class EventTarget { }; // Don't inherit from ScriptWrappable > > > class DOMWindow : public ScriptWrappable { }; > > > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > > class RemoteDOMWindow : public DOMWindow { }; > > > > > > The complexity comes from the fact that currently EventTarget inherits from > > ScriptWrappable. This is conceptually not right but we do this in order not to > > increase sizeof(Node)... > > > > > > class Node : public EventTarget, public ScriptWrappable { }; > > > > > > ^^^ This will increase sizeof(Node) because both EventTarget and > > ScriptWrappable have vtables. > > > > Yeah, this is the reason I had to take this approach. Otherwise, we end up > with > > the following situation: > > > > class DOMWindow : public ScriptWrappable { }; > > class EventTarget : public ScriptWrappable { }; > > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > > > Now if you have: > > LocalDOMWindow* w; > > then this will fail to compile: > > w->wrapperTypeInfo(); > > because the compiler doesn't know which base class to go through to get to > > ScriptWrappable. Instead, I would have to write: > > static_cast<DOMWindow*>(w)->wrapperTypeInfo(); > > Thanks, I understand what you're doing :) > > shiino-san: Do you have any idea on this? I understand that it's not ideal that EventTarget inherits from ScriptWrappable, and that RemoteDOMWindow conceptually doesn't need to inherit from EventTarget, however, we have a serious memory size issue about Node and we need this trick to reduce the size of Node. With these constraints, I think the simplest way is that DOMWindow inherits from EventTarget even though it's not necessary. Anyway we need tricky code here or there, then, this is the simplest trick, I think. We can write an excuse at DOMWindow definition.
On 2014/10/22 at 04:23:38, yukishiino wrote: > On 2014/10/22 01:42:25, haraken wrote: > > On 2014/10/22 01:36:53, dcheng wrote: > > > On 2014/10/22 at 01:22:06, haraken wrote: > > > > On 2014/10/22 01:16:56, haraken wrote: > > > > > On 2014/10/22 01:01:47, dcheng wrote: > > > > > > RemoteFrame itself probably won't inherit from DOMWindow, but we'll add > > a > > > > > > RemoteDOMWindow that will. > > > > > > > > > > Sorry, I meant RemoteDOMWindow :) > > > > > > > > > > > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > > > File Source/core/frame/DOMWindow.h (right): > > > > > > > > > > > > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > > > Source/core/frame/DOMWindow.h:9: class DOMWindow { > > > > > > On 2014/10/22 00:59:14, haraken wrote: > > > > > > > > > > > > > > I'm curious why DOMWindow can't inherit from ScriptWrappableBase? > > > > > > > > > > > > LocalDOMWindow is an EventTarget (and I don't think it makes sense for > > > > > > RemoteDOMWindow to be an EventTarget -- I don't think you can register > > an > > > > > event > > > > > > listener on a cross-origin DOMWindow). If this was also a > > ScriptWrappable, > > > > > then > > > > > > you would have to explicitly say you wanted to use the > > ScriptWrappableBase > > > > > from > > > > > > EventTargetWithInlineData or the ScriptWrappableBase from DOMWindow. > > > > > > > > > > Given that LocalDOMWindow is an EventTarget (which inherits from > > > > > ScriptWrappableBase), LocalDOMWindow should already be able to use > > > > > toScriptWrappableBase(). Why do we need to add toScriptWrappableBase() to > > > > > DOMWindow then? > > > > > > > > > > The idea is: > > > > > > > > > > - We want to make all DOM objects (i.e., objects exposed to JavaScript) > > > inherit > > > > > from ScriptWrappable(Base). > > > > > - toScriptWrappableBase() should be defined only in ScriptWrappableBase. > > > > > > > > Ah, I'm getting to understand the situation... > > > > > > > > Conceptually we should have the following class inheritance: > > > > > > > > class EventTarget { }; // Don't inherit from ScriptWrappable > > > > class DOMWindow : public ScriptWrappable { }; > > > > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > > > class RemoteDOMWindow : public DOMWindow { }; > > > > > > > > The complexity comes from the fact that currently EventTarget inherits from > > > ScriptWrappable. This is conceptually not right but we do this in order not to > > > increase sizeof(Node)... > > > > > > > > class Node : public EventTarget, public ScriptWrappable { }; > > > > > > > > ^^^ This will increase sizeof(Node) because both EventTarget and > > > ScriptWrappable have vtables. > > > > > > Yeah, this is the reason I had to take this approach. Otherwise, we end up > > with > > > the following situation: > > > > > > class DOMWindow : public ScriptWrappable { }; > > > class EventTarget : public ScriptWrappable { }; > > > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > > > > > Now if you have: > > > LocalDOMWindow* w; > > > then this will fail to compile: > > > w->wrapperTypeInfo(); > > > because the compiler doesn't know which base class to go through to get to > > > ScriptWrappable. Instead, I would have to write: > > > static_cast<DOMWindow*>(w)->wrapperTypeInfo(); > > > > Thanks, I understand what you're doing :) > > > > shiino-san: Do you have any idea on this? > > I understand that it's not ideal that EventTarget inherits from ScriptWrappable, and that RemoteDOMWindow conceptually doesn't need to inherit from EventTarget, however, we have a serious memory size issue about Node and we need this trick to reduce the size of Node. > I understand why this is important for Node, but I'm not sure why this would matter for DOMWindow? > With these constraints, I think the simplest way is that DOMWindow inherits from EventTarget even though it's not necessary. Anyway we need tricky code here or there, then, this is the simplest trick, I think. We can write an excuse at DOMWindow definition. EventTarget brings a lot of extra baggage that doesn't make sense in RemoteDOMWindow. If I do this, RemoteDOMWindow: - needs to trace into EventTarget. - needs to override executionContext(), even though it never has one. - exposes a bunch of methods that should not be called (without inheriting from EventTarget, it would be a compile-time error instead, which is much better))
yukishiino@chromium.org changed reviewers: + yukishiino@chromium.org - yukishiino@chromium.or
On 2014/10/22 06:14:16, dcheng wrote: > On 2014/10/22 at 04:23:38, yukishiino wrote: > > On 2014/10/22 01:42:25, haraken wrote: > > > On 2014/10/22 01:36:53, dcheng wrote: > > > > On 2014/10/22 at 01:22:06, haraken wrote: > > > > > On 2014/10/22 01:16:56, haraken wrote: > > > > > > On 2014/10/22 01:01:47, dcheng wrote: > > > > > > > RemoteFrame itself probably won't inherit from DOMWindow, but we'll > add > > > a > > > > > > > RemoteDOMWindow that will. > > > > > > > > > > > > Sorry, I meant RemoteDOMWindow :) > > > > > > > > > > > > > > > > > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > > > > File Source/core/frame/DOMWindow.h (right): > > > > > > > > > > > > > > > > > > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > > > > Source/core/frame/DOMWindow.h:9: class DOMWindow { > > > > > > > On 2014/10/22 00:59:14, haraken wrote: > > > > > > > > > > > > > > > > I'm curious why DOMWindow can't inherit from ScriptWrappableBase? > > > > > > > > > > > > > > LocalDOMWindow is an EventTarget (and I don't think it makes sense > for > > > > > > > RemoteDOMWindow to be an EventTarget -- I don't think you can > register > > > an > > > > > > event > > > > > > > listener on a cross-origin DOMWindow). If this was also a > > > ScriptWrappable, > > > > > > then > > > > > > > you would have to explicitly say you wanted to use the > > > ScriptWrappableBase > > > > > > from > > > > > > > EventTargetWithInlineData or the ScriptWrappableBase from DOMWindow. > > > > > > > > > > > > Given that LocalDOMWindow is an EventTarget (which inherits from > > > > > > ScriptWrappableBase), LocalDOMWindow should already be able to use > > > > > > toScriptWrappableBase(). Why do we need to add toScriptWrappableBase() > to > > > > > > DOMWindow then? > > > > > > > > > > > > The idea is: > > > > > > > > > > > > - We want to make all DOM objects (i.e., objects exposed to > JavaScript) > > > > inherit > > > > > > from ScriptWrappable(Base). > > > > > > - toScriptWrappableBase() should be defined only in > ScriptWrappableBase. > > > > > > > > > > Ah, I'm getting to understand the situation... > > > > > > > > > > Conceptually we should have the following class inheritance: > > > > > > > > > > class EventTarget { }; // Don't inherit from ScriptWrappable > > > > > class DOMWindow : public ScriptWrappable { }; > > > > > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > > > > class RemoteDOMWindow : public DOMWindow { }; > > > > > > > > > > The complexity comes from the fact that currently EventTarget inherits > from > > > > ScriptWrappable. This is conceptually not right but we do this in order > not to > > > > increase sizeof(Node)... > > > > > > > > > > class Node : public EventTarget, public ScriptWrappable { }; > > > > > > > > > > ^^^ This will increase sizeof(Node) because both EventTarget and > > > > ScriptWrappable have vtables. > > > > > > > > Yeah, this is the reason I had to take this approach. Otherwise, we end up > > > with > > > > the following situation: > > > > > > > > class DOMWindow : public ScriptWrappable { }; > > > > class EventTarget : public ScriptWrappable { }; > > > > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > > > > > > > Now if you have: > > > > LocalDOMWindow* w; > > > > then this will fail to compile: > > > > w->wrapperTypeInfo(); > > > > because the compiler doesn't know which base class to go through to get to > > > > ScriptWrappable. Instead, I would have to write: > > > > static_cast<DOMWindow*>(w)->wrapperTypeInfo(); > > > > > > Thanks, I understand what you're doing :) > > > > > > shiino-san: Do you have any idea on this? > > > > I understand that it's not ideal that EventTarget inherits from > ScriptWrappable, and that RemoteDOMWindow conceptually doesn't need to inherit > from EventTarget, however, we have a serious memory size issue about Node and we > need this trick to reduce the size of Node. > > > > I understand why this is important for Node, but I'm not sure why this would > matter for DOMWindow? > > > With these constraints, I think the simplest way is that DOMWindow inherits > from EventTarget even though it's not necessary. Anyway we need tricky code > here or there, then, this is the simplest trick, I think. We can write an > excuse at DOMWindow definition. > > EventTarget brings a lot of extra baggage that doesn't make sense in > RemoteDOMWindow. If I do this, RemoteDOMWindow: > - needs to trace into EventTarget. > - needs to override executionContext(), even though it never has one. > - exposes a bunch of methods that should not be called (without inheriting from > EventTarget, it would be a compile-time error instead, which is much better)) As long as DOMWindow itself does not need to be ScriptWrappable, your approach makes sense. lgtm with a nit.
On 2014/10/23 04:45:18, Yuki wrote: > On 2014/10/22 06:14:16, dcheng wrote: > > On 2014/10/22 at 04:23:38, yukishiino wrote: > > > On 2014/10/22 01:42:25, haraken wrote: > > > > On 2014/10/22 01:36:53, dcheng wrote: > > > > > On 2014/10/22 at 01:22:06, haraken wrote: > > > > > > On 2014/10/22 01:16:56, haraken wrote: > > > > > > > On 2014/10/22 01:01:47, dcheng wrote: > > > > > > > > RemoteFrame itself probably won't inherit from DOMWindow, but > we'll > > add > > > > a > > > > > > > > RemoteDOMWindow that will. > > > > > > > > > > > > > > Sorry, I meant RemoteDOMWindow :) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > > > > > File Source/core/frame/DOMWindow.h (right): > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/DOMWin... > > > > > > > > Source/core/frame/DOMWindow.h:9: class DOMWindow { > > > > > > > > On 2014/10/22 00:59:14, haraken wrote: > > > > > > > > > > > > > > > > > > I'm curious why DOMWindow can't inherit from > ScriptWrappableBase? > > > > > > > > > > > > > > > > LocalDOMWindow is an EventTarget (and I don't think it makes sense > > for > > > > > > > > RemoteDOMWindow to be an EventTarget -- I don't think you can > > register > > > > an > > > > > > > event > > > > > > > > listener on a cross-origin DOMWindow). If this was also a > > > > ScriptWrappable, > > > > > > > then > > > > > > > > you would have to explicitly say you wanted to use the > > > > ScriptWrappableBase > > > > > > > from > > > > > > > > EventTargetWithInlineData or the ScriptWrappableBase from > DOMWindow. > > > > > > > > > > > > > > Given that LocalDOMWindow is an EventTarget (which inherits from > > > > > > > ScriptWrappableBase), LocalDOMWindow should already be able to use > > > > > > > toScriptWrappableBase(). Why do we need to add > toScriptWrappableBase() > > to > > > > > > > DOMWindow then? > > > > > > > > > > > > > > The idea is: > > > > > > > > > > > > > > - We want to make all DOM objects (i.e., objects exposed to > > JavaScript) > > > > > inherit > > > > > > > from ScriptWrappable(Base). > > > > > > > - toScriptWrappableBase() should be defined only in > > ScriptWrappableBase. > > > > > > > > > > > > Ah, I'm getting to understand the situation... > > > > > > > > > > > > Conceptually we should have the following class inheritance: > > > > > > > > > > > > class EventTarget { }; // Don't inherit from ScriptWrappable > > > > > > class DOMWindow : public ScriptWrappable { }; > > > > > > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > > > > > class RemoteDOMWindow : public DOMWindow { }; > > > > > > > > > > > > The complexity comes from the fact that currently EventTarget inherits > > from > > > > > ScriptWrappable. This is conceptually not right but we do this in order > > not to > > > > > increase sizeof(Node)... > > > > > > > > > > > > class Node : public EventTarget, public ScriptWrappable { }; > > > > > > > > > > > > ^^^ This will increase sizeof(Node) because both EventTarget and > > > > > ScriptWrappable have vtables. > > > > > > > > > > Yeah, this is the reason I had to take this approach. Otherwise, we end > up > > > > with > > > > > the following situation: > > > > > > > > > > class DOMWindow : public ScriptWrappable { }; > > > > > class EventTarget : public ScriptWrappable { }; > > > > > class LocalDOMWindow : public DOMWindow, public EventTarget { }; > > > > > > > > > > Now if you have: > > > > > LocalDOMWindow* w; > > > > > then this will fail to compile: > > > > > w->wrapperTypeInfo(); > > > > > because the compiler doesn't know which base class to go through to get > to > > > > > ScriptWrappable. Instead, I would have to write: > > > > > static_cast<DOMWindow*>(w)->wrapperTypeInfo(); > > > > > > > > Thanks, I understand what you're doing :) > > > > > > > > shiino-san: Do you have any idea on this? > > > > > > I understand that it's not ideal that EventTarget inherits from > > ScriptWrappable, and that RemoteDOMWindow conceptually doesn't need to inherit > > from EventTarget, however, we have a serious memory size issue about Node and > we > > need this trick to reduce the size of Node. > > > > > > > I understand why this is important for Node, but I'm not sure why this would > > matter for DOMWindow? > > > > > With these constraints, I think the simplest way is that DOMWindow inherits > > from EventTarget even though it's not necessary. Anyway we need tricky code > > here or there, then, this is the simplest trick, I think. We can write an > > excuse at DOMWindow definition. > > > > EventTarget brings a lot of extra baggage that doesn't make sense in > > RemoteDOMWindow. If I do this, RemoteDOMWindow: > > - needs to trace into EventTarget. > > - needs to override executionContext(), even though it never has one. > > - exposes a bunch of methods that should not be called (without inheriting > from > > EventTarget, it would be a compile-time error instead, which is much better)) > > As long as DOMWindow itself does not need to be ScriptWrappable, your approach > makes sense. lgtm with a nit. LGTM
Sorry, I forgot to send these comments. https://codereview.chromium.org/640803004/diff/40001/Source/bindings/core/v8/... File Source/bindings/core/v8/WindowProxy.cpp (right): https://codereview.chromium.org/640803004/diff/40001/Source/bindings/core/v8/... Source/bindings/core/v8/WindowProxy.cpp:294: DOMWindow* window = m_frame->domWindow(); ScriptWrappable* scriptWrappable = m_frame->domWindow()->toScriptWrappable(); would make more sense and more effective? I'm seeing too many window->toScriptWrappable(). https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/Frame.h File Source/core/frame/Frame.h (right): https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/Frame.... Source/core/frame/Frame.h:63: virtual LocalDOMWindow* domWindow() const = 0; IIUC, no one in this CL expects domWindow() returns LocalDOMWindow. Who expects LocalDOMWindow? (I'm just curious.)
Also let's add a good comment about the situation on DOMWindow.h.
The CQ bit was checked by dcheng@chromium.org
I've also added a comment to DOMWindow::toScriptWrappable to describe why we need a silly looking conversion method like this. https://codereview.chromium.org/640803004/diff/40001/Source/bindings/core/v8/... File Source/bindings/core/v8/WindowProxy.cpp (right): https://codereview.chromium.org/640803004/diff/40001/Source/bindings/core/v8/... Source/bindings/core/v8/WindowProxy.cpp:294: DOMWindow* window = m_frame->domWindow(); On 2014/10/23 06:03:34, Yuki wrote: > ScriptWrappable* scriptWrappable = m_frame->domWindow()->toScriptWrappable(); > > would make more sense and more effective? > I'm seeing too many window->toScriptWrappable(). Yeah, makes sense to alias it. Done. https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/Frame.h File Source/core/frame/Frame.h (right): https://codereview.chromium.org/640803004/diff/40001/Source/core/frame/Frame.... Source/core/frame/Frame.h:63: virtual LocalDOMWindow* domWindow() const = 0; On 2014/10/23 06:03:34, Yuki wrote: > IIUC, no one in this CL expects domWindow() returns LocalDOMWindow. Who expects > LocalDOMWindow? (I'm just curious.) A lot of places depend on this to return LocalDOMWindow. LocalDOMWindow::parent(), top(), opener(), parts of WindowProxy, but also places in Source/core that do something like frame->domWindow()->someLocalDOMWindowMethod(). I'm actually working on changing this in some followup CLs.
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/640803004/60001
Message was sent while issue was closed.
Committed patchset #4 (id:60001) as 184244 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
