Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(653)

Issue 2910233002: Do not fallback to FocusedOrMainFrame() in FocusedLocalFrameInWidget() (Closed)

Created:
3 years, 6 months ago by EhsanK
Modified:
3 years, 4 months ago
Reviewers:
alexmos, dcheng
CC:
chromium-reviews, blink-reviews, mlamouri+watch-blink_chromium.org, blink-reviews-frames_chromium.org, kinuko+watch, dcheng
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

Do not fallback to FocusedOrMainFrame() in FocusedLocalFrameInWidget() For tasks such as editing and IME we use FocusedLocalFrameInWidget() which is supposed to return the focused frame sharing the same local root as that of the frame widget. This in WebViewImpl is slightly different as the method could return the MainFrameImpl as the fallback value. However, the types of tasks which should rely on this method are those that are to be (eventually) handled by a WebFrameWidget and therefore, falling back to MainFrameImpl does not seem like the right thing to do. This CL will move the logic in FocusedLocalFrameInWidget() from both WebViewImpl and WebFrameWidgetImpl into WebFrameWidgetBase and leaves a shallow implementation in WebViewImpl that simply calls into the frame widget of the MainFrameImpl. That assures in calling FocusedLocalFrameInWidget we never hit FocusedOrMainFrame(). BUG=726763, 629721

Patch Set 1 #

Patch Set 2 : Rebased #

Patch Set 3 : Rebased #

Patch Set 4 : Fixed a crashing test #

Total comments: 9

Patch Set 5 : Addressing dcheng@'s comments #

Total comments: 3

Patch Set 6 : Rebased #

Unified diffs Side-by-side diffs Delta from patch set Stats (+57 lines, -81 lines) Patch
M third_party/WebKit/Source/core/frame/WebFrameWidgetBase.h View 1 2 3 4 5 2 chunks +11 lines, -1 line 0 comments Download
M third_party/WebKit/Source/core/frame/WebFrameWidgetBase.cpp View 1 2 3 4 5 3 chunks +3 lines, -3 lines 0 comments Download
M third_party/WebKit/Source/web/WebFrameWidgetImpl.h View 1 2 3 4 5 2 chunks +0 lines, -13 lines 0 comments Download
M third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp View 1 2 3 4 5 11 chunks +12 lines, -23 lines 0 comments Download
M third_party/WebKit/Source/web/WebViewImpl.h View 1 2 3 4 5 2 chunks +0 lines, -6 lines 0 comments Download
M third_party/WebKit/Source/web/WebViewImpl.cpp View 1 2 3 4 5 4 chunks +30 lines, -35 lines 0 comments Download
M third_party/WebKit/Source/web/tests/WebViewTest.cpp View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 28 (17 generated)
EhsanK
Daniel, PTAL. Note: I started making the move but during dry-run another CL (https://codereview.chromium.org/2807433003/) landed ...
3 years, 6 months ago (2017-05-30 21:55:54 UTC) #11
EhsanK
https://codereview.chromium.org/2910233002/diff/60001/third_party/WebKit/Source/web/tests/WebViewTest.cpp File third_party/WebKit/Source/web/tests/WebViewTest.cpp (right): https://codereview.chromium.org/2910233002/diff/60001/third_party/WebKit/Source/web/tests/WebViewTest.cpp#newcode2327 third_party/WebKit/Source/web/tests/WebViewTest.cpp:2327: web_view->SetInitialFocus(false); Without it line 2332 returns nullptr after the ...
3 years, 6 months ago (2017-05-30 22:39:22 UTC) #16
EhsanK
https://codereview.chromium.org/2910233002/diff/60001/third_party/WebKit/Source/web/tests/WebViewTest.cpp File third_party/WebKit/Source/web/tests/WebViewTest.cpp (right): https://codereview.chromium.org/2910233002/diff/60001/third_party/WebKit/Source/web/tests/WebViewTest.cpp#newcode2327 third_party/WebKit/Source/web/tests/WebViewTest.cpp:2327: web_view->SetInitialFocus(false); Without it line 2332 returns nullptr after the ...
3 years, 6 months ago (2017-05-30 22:39:23 UTC) #17
dcheng
I have a more general question as well, so adding alexmos@ In general, what behavior ...
3 years, 6 months ago (2017-06-01 04:20:49 UTC) #21
EhsanK
Thanks! PTAL. Some basic thoughts: 1- Hard to even do when the IPC is handled ...
3 years, 6 months ago (2017-06-01 13:47:45 UTC) #22
EhsanK
On 2017/06/01 13:47:45, EhsanK wrote: > Thanks! PTAL. > > Some basic thoughts: > 1- ...
3 years, 6 months ago (2017-06-14 17:36:36 UTC) #23
alexmos
Sorry, this definitely slipped through the cracks, so thanks for the ping! I'm fine with ...
3 years, 6 months ago (2017-06-15 02:53:06 UTC) #24
EhsanK
Thank you Alex for the very detailed explanation! PTAL. On 2017/06/15 02:53:06, alexmos wrote: > ...
3 years, 6 months ago (2017-06-15 15:17:12 UTC) #25
EhsanK
Sorry...forgot to send this comment. https://codereview.chromium.org/2910233002/diff/80001/third_party/WebKit/Source/web/WebViewImpl.cpp File third_party/WebKit/Source/web/WebViewImpl.cpp (right): https://codereview.chromium.org/2910233002/diff/80001/third_party/WebKit/Source/web/WebViewImpl.cpp#newcode2320 third_party/WebKit/Source/web/WebViewImpl.cpp:2320: ->ime_accept_events_ = true; On ...
3 years, 6 months ago (2017-06-16 19:25:14 UTC) #26
alexmos
On 2017/06/15 15:17:12, EhsanK wrote: > Thank you Alex for the very detailed explanation! PTAL. ...
3 years, 6 months ago (2017-06-17 01:06:43 UTC) #27
EhsanK
3 years, 4 months ago (2017-08-02 15:29:55 UTC) #28
On 2017/06/17 01:06:43, alexmos wrote:
> On 2017/06/15 15:17:12, EhsanK wrote:
> > Thank you Alex for the very detailed explanation! PTAL.
> > 
> > On 2017/06/15 02:53:06, alexmos wrote:
> > > Sorry, this definitely slipped through the cracks, so thanks for the ping!
> > > 
> > > I'm fine with this CL, as overall it seems to make IME focus saner and
less
> > > confusing.  Some thoughts around Daniel's questions:
> > > 
> > > > In general, what behavior do we want if we make an IPC to the renderer
> that
> > > acts
> > > > on the focused frame, but the focused frame has already changed?
> > > > 
> > > > I see several approaches:
> > > > 1 Drop IPC handling if the focused frame has changed. AFAIK, we don't
> really
> > > do
> > > > this.
> > > > 2. Try to target a focused frame in the same widget. I think this is
what
> > some
> > > > of the IME code does.
> > > > 3. Try to find any frame: I think most code does this, by virtue of
using
> > > > FocusedOrMainFrame.
> > > > 
> > > > For 2 and 3, the issue is the fallback won't work if the fallback
options
> > are
> > > > remote frames, so there's inconsistent behavior. However, if we do 1, it
> > would
> > > > be weird, because it means we would drop keyboard events if focus
changed,
> > > which
> > > > would be weird...
> > > 
> > > I'm curious which races you guys are thinking about here, since the
desired
> > > behavior might be different depending on the race.  For things like a user
> > > pressing a key just as the page changes frame focus via window.focus() or
> > > detaching the focused frame, dropping keyboard events might not be too
> weird,
> > as
> > > it might actually prevent you from typing into something that you probably
> > > didn't intend to type into anyway.
> > Agreed. I was under the impression that this is the right thing to do.
> > > In such cases, I actually wonder how
> > > terrible is it to deliver the input event to the *old* focused frame (if
it
> > > still exists)?
> > I think dropping the input is better than sending it to the wrong frame. At
> > least
> > the user would not have to go back and delete the unwanted characters :).
> 
> That's a fair point. :)
> 
> > 
> > > But a more common case seems to be the user clicks on something, and
before
> > the
> > > browser process gets notified of a focused frame change via
> > > FrameMsg_SetFocusedFrame, the user types something intended for the future
> > > focused frame, but the RenderWidgetHostInputEventRouter dispatches it to
the
> > > past focused frame.  That seems more suitable for options 2 and 3 (the
user
> > > probably prefers for the event to be delivered to the future frame). 
> Ideally
> > > we'd know on the browser process side how an input event will change frame
> > focus
> > > before forwarding it to the renderer, but that's probably really hard.
> > This seems quite reproducible (for instance in janky renderers). I still
think
> > it
> > is safer to drop input when there is a mismatch between the target defined
by
> > the
> > browser and the receiving end. Currently, all we can determine is the target
> > RenderWidget
> > so we can find mismatches at the local root level.
> 
> Daniel and I talked about this a bit today, and this race might not be as bad
as
> I thought due to existing input synchronization that we already do - but I
don't
> really know how it works, so I'll let Daniel comment on that (he was planning
to
> take another look at this CL soon).  
> 
> I agree that dropping input on mismatched focused frame seems like the safest
> option, and that falling back to something else is risky and might be
> inconsistent with OOPIFs.  Things are already pretty bad today: I think
> sometimes we fall back to main frame, but only when it's local, sometimes to
> another frame within the local root, sometimes we don't fall back at all? 
> Perhaps we should file a bug to ensure consistent behavior for focus races and
> continue this discussion there. 
> 
> > 
> > > If we didn't want to drop anything, even in remote focused frame cases, we
> > could
> > > use SendPageMessage and then drop the IPCs in all renderers except the one
> > with
> > > the currently focused frame -- terribly inefficient, but we could only do
it
> > if
> > > we somehow detect that we might be in a focused frame race (could we do
that
> > > with InputEventAcks and being clever about which kinds of events might
> change
> > > focused frames?). :)
> > > 
> > > For Ehsan's question that it's kind of hard to tell if an IPC for RV or RW
> is
> > > really targeting a focused frame, presumably we'll need to send over the
> > browser
> > > process's value of focused_frame in these IPCs, which we then can compare
to
> > the
> > > renderer value?
> > My suggestion was mostly about sending the IPC to the actual RenderFrameImpl
> as
> > opposed
> > to RenderWidget or RenderView. Alternatively send along the routing ID of
the
> > frame?
> 
> Yes, I was thinking about sending the routing ID of the focused frame in my
> suggestion.  Sending it to RenderFrame directly seems a bit weirder, as
widgets
> are supposed to deal with input events, though maybe that would work too
> depending on the IPC.
> 
>
https://codereview.chromium.org/2910233002/diff/80001/third_party/WebKit/Sour...
> File third_party/WebKit/Source/web/WebViewImpl.cpp (right):
> 
>
https://codereview.chromium.org/2910233002/diff/80001/third_party/WebKit/Sour...
> third_party/WebKit/Source/web/WebViewImpl.cpp:2320: ->ime_accept_events_ =
true;
> On 2017/06/16 19:25:14, EhsanK wrote:
> > On 2017/06/15 02:53:06, alexmos wrote:
> > > Ugh, really hope we can clean this up soon.  I agree with you that it'd be
> > nice
> > > to not dispatch IME events without page focus in the first place, but
that's
> > > probably not for this CL.
> > Agreed. I have been meaning to get started on this soon. I will try to put
up
> a
> > fix soon after this CL.
> > > Is there a use case for page focus in WebFrameWidgets
> > > other than IME?  If so, we should just consider calling
> > > WebFrameWidgetImpl::SetFocus.
> > 
> > From looking at WebFrameWidgetImpl::SetFocus(enabled)
> > 
> > 1- if (enabled): there is some reference to FocusController().SetActive()
> which
> > is perhaps incorrect since this should be done by WebViewImpl instead. Other
> > than that there seems to be some frame selection upates on the focused
frame.
> > 
> > 2- if(!enabled): this is the case where we commit an ongoing IME
composition.
> > Again dealing with the focused frame.
> > 
> > From 1 & 2 I actually do not see a compelling reason to keep
> > WebFrameWidget::SetFocus and perhaps it could live inside WebView.h instead.
> > However, it will be quite nice to expose WebView in RenderWidget so that
when
> > necessary (i.e., handling IME IPCs), RenderWidget can drop IPC if WebView is
> not
> > focused.
> > 
> > I will try to investigate this soon.
> 
> Sounds good.  The other concern I remember with this in the past was  that
this
> is really about page-level focus, so it made more sense to do it once per-view
> rather than multiple times for each widget.  I'll defer to Daniel about
exposing
> WebView.

This CL is quite outdated. I will redo/rebase thi and kick of reviews on gerrit.
Thanks!

Powered by Google App Engine
This is Rietveld 408576698