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

Issue 1635513003: Implement webview.captureVisibleRegion() (Closed)

Created:
4 years, 11 months ago by wjmaclean
Modified:
4 years, 10 months ago
CC:
chromium-apps-reviews_chromium.org, chromium-reviews, creis+watch_chromium.org, danakj+watch_chromium.org, darin-cc_chromium.org, extensions-reviews_chromium.org, jam, jbauman+watch_chromium.org, kalyank, miu+watch_chromium.org, nasko+codewatch_chromium.org, piman+watch_chromium.org, sievers+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Implement webview.captureVisibleRegion() This CL implements webview.captureVisibleRegion(), an extension/apps API to allow WebView users to capture screenshots of the contents displayed in a WebView. The surfaces contents capture has been plumbed via RenderWidgetHostViewChildFrame so this implementation should not require changes when WebView switches to using OOPIF. As part of the implementation, there are two notable refactors: 1) CaptureWebContentsFunction has been refactored into WebContentsCaptureClient to remove the extensions::AsyncExtensionFunction dependence so that this code can be used by both tabs.captureVisibleTab and webview.captureVisibleRegion, and 2) common code from DelegatedFrameHost has ben moved to content/browser/compositor/surface_utils.* in order to avoid duplication as both DelegatedFrameHost and RenderWidgetHostViewChildFrame now use the code. Finally, this CL adds a surface-drawn callback to RenderWidgetHostViewChildFrame, to allow deferring a screen capture request until a frame has actually been drawn. This callback can be used to simplify some existing tests. BUG=326755 CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_site_isolation Committed: https://crrev.com/f89035216b627283b79731c3e6a7957707ed9034 Cr-Commit-Position: refs/heads/master@{#372799}

Patch Set 1 #

Patch Set 2 : Add frame-drawn callback, remove first-frame check from test. #

Patch Set 3 : Remove WaitForFirstFrame() from browser_test_utils (cleanup). #

Total comments: 15

Patch Set 4 : Move callback processing to OnSwapCompositorFrame. #

Total comments: 2

Patch Set 5 : Remove ScheduleComposite(), add TODO for merging similar code in RWHVAndroid. #

Patch Set 6 : Save bug number to surface_utils.cc. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+584 lines, -468 lines) Patch
M chrome/browser/extensions/api/tabs/tabs_api.h View 2 chunks +12 lines, -4 lines 0 comments Download
M chrome/browser/extensions/api/tabs/tabs_api.cc View 1 2 3 2 chunks +38 lines, -0 lines 0 comments Download
M chrome/common/extensions/api/webview_tag.json View 1 chunk +22 lines, -0 lines 0 comments Download
M content/browser/compositor/delegated_frame_host.h View 1 2 3 1 chunk +0 lines, -15 lines 0 comments Download
M content/browser/compositor/delegated_frame_host.cc View 1 2 3 3 chunks +5 lines, -153 lines 0 comments Download
M content/browser/compositor/surface_utils.h View 2 chunks +10 lines, -0 lines 0 comments Download
M content/browser/compositor/surface_utils.cc View 1 2 3 4 5 3 chunks +174 lines, -0 lines 0 comments Download
M content/browser/frame_host/render_widget_host_view_child_frame.h View 1 2 3 4 chunks +23 lines, -0 lines 0 comments Download
M content/browser/frame_host/render_widget_host_view_child_frame.cc View 1 2 3 4 4 chunks +50 lines, -6 lines 0 comments Download
M content/browser/frame_host/render_widget_host_view_guest.cc View 1 2 3 1 chunk +2 lines, -0 lines 0 comments Download
M content/browser/renderer_host/render_widget_host_view_android.cc View 1 2 3 4 1 chunk +5 lines, -0 lines 0 comments Download
D extensions/browser/api/capture_web_contents_function.h View 1 chunk +0 lines, -67 lines 0 comments Download
D extensions/browser/api/capture_web_contents_function.cc View 1 2 3 1 chunk +0 lines, -150 lines 0 comments Download
M extensions/browser/api/guest_view/extension_view/extension_view_internal_api.h View 1 chunk +0 lines, -1 line 0 comments Download
M extensions/browser/api/guest_view/web_view/web_view_internal_api.h View 2 chunks +24 lines, -1 line 0 comments Download
M extensions/browser/api/guest_view/web_view/web_view_internal_api.cc View 1 chunk +56 lines, -0 lines 0 comments Download
A + extensions/browser/api/web_contents_capture_client.h View 2 chunks +14 lines, -23 lines 0 comments Download
A + extensions/browser/api/web_contents_capture_client.cc View 1 2 3 6 chunks +39 lines, -45 lines 0 comments Download
M extensions/browser/guest_view/web_view/web_view_apitest.cc View 1 1 chunk +3 lines, -0 lines 0 comments Download
M extensions/common/api/_api_features.json View 1 chunk +6 lines, -0 lines 0 comments Download
M extensions/common/api/web_view_internal.json View 1 chunk +27 lines, -0 lines 0 comments Download
M extensions/extensions.gypi View 2 chunks +2 lines, -2 lines 0 comments Download
M extensions/renderer/dispatcher.cc View 2 chunks +6 lines, -0 lines 0 comments Download
M extensions/renderer/resources/extensions_renderer_resources.grd View 1 chunk +1 line, -0 lines 0 comments Download
M extensions/renderer/resources/guest_view/web_view/web_view.js View 2 chunks +9 lines, -0 lines 0 comments Download
A extensions/renderer/resources/guest_view/web_view/web_view_experimental.js View 1 chunk +24 lines, -0 lines 0 comments Download
M extensions/test/data/web_view/apitest/main.js View 1 2 chunks +32 lines, -1 line 0 comments Download

Messages

Total messages: 43 (14 generated)
wjmaclean
The first attempt at landing this got reverted due to the new test failing sometime. ...
4 years, 11 months ago (2016-01-25 16:05:51 UTC) #4
Fady Samuel
Could you please put this in the previous issue so we can focus on the ...
4 years, 11 months ago (2016-01-25 16:13:23 UTC) #5
Fady Samuel
On 2016/01/25 16:13:23, Fady Samuel wrote: > Could you please put this in the previous ...
4 years, 11 months ago (2016-01-25 16:13:54 UTC) #6
wjmaclean
On 2016/01/25 16:13:23, Fady Samuel wrote: > Could you please put this in the previous ...
4 years, 11 months ago (2016-01-25 17:00:12 UTC) #7
wjmaclean
+piman@ for the SurfaceDrawn placement of the callback notification. I've updated the CL so that ...
4 years, 11 months ago (2016-01-27 18:04:21 UTC) #9
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1635513003/20001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1635513003/20001
4 years, 11 months ago (2016-01-27 18:05:34 UTC) #11
commit-bot: I haz the power
Dry run: This issue passed the CQ dry run.
4 years, 11 months ago (2016-01-27 20:06:45 UTC) #14
wjmaclean
On 2016/01/27 20:06:45, commit-bot: I haz the power wrote: > Dry run: This issue passed ...
4 years, 11 months ago (2016-01-27 20:18:39 UTC) #15
ncarter (slow)
https://codereview.chromium.org/1635513003/diff/40001/content/browser/frame_host/render_widget_host_view_child_frame.cc File content/browser/frame_host/render_widget_host_view_child_frame.cc (right): https://codereview.chromium.org/1635513003/diff/40001/content/browser/frame_host/render_widget_host_view_child_frame.cc#newcode446 content/browser/frame_host/render_widget_host_view_child_frame.cc:446: if (!IsSurfaceAvailableForCopy()) { This behavior goes somewhat against the ...
4 years, 11 months ago (2016-01-27 21:08:25 UTC) #16
ncarter (slow)
Also, +miu for tab capture expertise.
4 years, 11 months ago (2016-01-27 21:10:47 UTC) #17
wjmaclean
https://codereview.chromium.org/1635513003/diff/40001/content/browser/frame_host/render_widget_host_view_child_frame.cc File content/browser/frame_host/render_widget_host_view_child_frame.cc (right): https://codereview.chromium.org/1635513003/diff/40001/content/browser/frame_host/render_widget_host_view_child_frame.cc#newcode446 content/browser/frame_host/render_widget_host_view_child_frame.cc:446: if (!IsSurfaceAvailableForCopy()) { On 2016/01/27 21:08:24, ncarter wrote: > ...
4 years, 11 months ago (2016-01-27 21:28:01 UTC) #19
ncarter (slow)
https://codereview.chromium.org/1635513003/diff/40001/content/browser/frame_host/render_widget_host_view_child_frame.h File content/browser/frame_host/render_widget_host_view_child_frame.h (right): https://codereview.chromium.org/1635513003/diff/40001/content/browser/frame_host/render_widget_host_view_child_frame.h#newcode66 content/browser/frame_host/render_widget_host_view_child_frame.h:66: // types, such as RenderWidgetHostViewAura. On 2016/01/27 21:28:01, wjmaclean ...
4 years, 10 months ago (2016-01-28 20:49:59 UTC) #20
ncarter (slow)
I'm giving a high-level lgtm on the changes here
4 years, 10 months ago (2016-01-28 21:22:38 UTC) #21
piman
https://codereview.chromium.org/1635513003/diff/40001/content/browser/compositor/surface_utils.cc File content/browser/compositor/surface_utils.cc (right): https://codereview.chromium.org/1635513003/diff/40001/content/browser/compositor/surface_utils.cc#newcode62 content/browser/compositor/surface_utils.cc:62: // implement it here. See the code in content/browser/renderer_host/render_widget_host_view_android.cc, ...
4 years, 10 months ago (2016-01-29 04:29:46 UTC) #22
wjmaclean
piman@ - PTAL? I left a TODO with your ldap on it, which is a ...
4 years, 10 months ago (2016-01-29 21:01:57 UTC) #23
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1635513003/60001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1635513003/60001
4 years, 10 months ago (2016-01-29 21:06:21 UTC) #25
piman
https://codereview.chromium.org/1635513003/diff/40001/content/browser/compositor/surface_utils.cc File content/browser/compositor/surface_utils.cc (right): https://codereview.chromium.org/1635513003/diff/40001/content/browser/compositor/surface_utils.cc#newcode62 content/browser/compositor/surface_utils.cc:62: // implement it here. On 2016/01/29 21:01:57, wjmaclean wrote: ...
4 years, 10 months ago (2016-01-29 22:28:54 UTC) #26
commit-bot: I haz the power
Dry run: This issue passed the CQ dry run.
4 years, 10 months ago (2016-01-30 00:35:54 UTC) #28
wjmaclean
Comments addressed, PTAL? https://codereview.chromium.org/1635513003/diff/60001/content/browser/frame_host/render_widget_host_view_child_frame.cc File content/browser/frame_host/render_widget_host_view_child_frame.cc (right): https://codereview.chromium.org/1635513003/diff/60001/content/browser/frame_host/render_widget_host_view_child_frame.cc#newcode457 content/browser/frame_host/render_widget_host_view_child_frame.cc:457: host_->ScheduleComposite(); On 2016/01/29 22:28:54, piman wrote: ...
4 years, 10 months ago (2016-02-01 15:36:04 UTC) #29
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1635513003/80001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1635513003/80001
4 years, 10 months ago (2016-02-01 15:37:01 UTC) #31
piman
lgtm
4 years, 10 months ago (2016-02-01 16:42:49 UTC) #32
wjmaclean
rockot@ - ptal for extensions LGTM? (I don't think anything in extensions has really changed ...
4 years, 10 months ago (2016-02-01 16:47:26 UTC) #33
ncarter (slow)
lgtm
4 years, 10 months ago (2016-02-01 19:50:20 UTC) #34
Charlie Reis
On 2016/02/01 16:47:26, wjmaclean wrote: > rockot@ - ptal for extensions LGTM? (I don't think ...
4 years, 10 months ago (2016-02-01 19:52:22 UTC) #35
Ken Rockot(use gerrit already)
rs lgtm
4 years, 10 months ago (2016-02-01 21:27:09 UTC) #36
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1635513003/100001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1635513003/100001
4 years, 10 months ago (2016-02-01 21:29:09 UTC) #38
commit-bot: I haz the power
Committed patchset #6 (id:100001)
4 years, 10 months ago (2016-02-01 22:54:57 UTC) #40
commit-bot: I haz the power
Patchset 6 (id:??) landed as https://crrev.com/f89035216b627283b79731c3e6a7957707ed9034 Cr-Commit-Position: refs/heads/master@{#372799}
4 years, 10 months ago (2016-02-01 22:56:26 UTC) #42
miu
4 years, 10 months ago (2016-02-04 20:19:11 UTC) #43
Message was sent while issue was closed.
Sorry...some unpublished drafts I thought I had sent:

https://codereview.chromium.org/1635513003/diff/40001/content/browser/frame_h...
File content/browser/frame_host/render_widget_host_view_child_frame.h (right):

https://codereview.chromium.org/1635513003/diff/40001/content/browser/frame_h...
content/browser/frame_host/render_widget_host_view_child_frame.h:66: // types,
such as RenderWidgetHostViewAura.
On 2016/01/28 20:49:58, ncarter wrote:
> On 2016/01/27 21:28:01, wjmaclean wrote:
> > On 2016/01/27 21:08:25, ncarter wrote:
> > > This seems fairly similar in purpose to
RenderWidgetHostViewFrameSubscriber,
>
> Having done a little more thinking, I am now wondering whether an even better
> long-term approach might be for RenderWidgetHostViewFrameSubscriber to be
> eliminated...

Agreed.  I have it on my roadmap this year to do some significant refactoring in
this area.  In particular, FrameSubscriber was solving problems in the
"pre-Uber-Compositor world" and has suffered some rather weird code factoring
issues over the past 2+ years.  In one case (that I was not aware of at the
time), someone threw up their arms and just copy-and-pasted a bunch of code from
DelegatedFrameHost in order to implement screen capture on CrOS.  That's not
good.

So, for the future, I think it makes sense for the Compositor to provide some
kind of "frame observer" interface instead of the RenderWidgetHostView*
providing a "frame subscriber" interface.  I have a number of ideas that I plan
to prototype-out before proposing a new design.

> Anyhow: the upshot of this is that I'm on board with RWHVBase having a
> RegisterFrameDrawnCallback.

I'm not sure it will stay that way for long, but I don't see this as a bad idea
now, nor would it seem to make my future refactoring efforts any more difficult.

https://codereview.chromium.org/1635513003/diff/40001/content/browser/frame_h...
content/browser/frame_host/render_widget_host_view_child_frame.h:67: void
RegisterFrameDrawnCallback(scoped_ptr<base::Closure> callback);
On 2016/01/28 20:49:58, ncarter wrote:
> On 2016/01/27 21:28:01, wjmaclean wrote:
> > On 2016/01/27 21:08:25, ncarter wrote:
> > > In the webview case, is there really necessarily a "frame drawn" event in
> the
> > > RWHVChildFrame for every visible change to the pixel content (I'm thinking
> > about
> > > when there are oopifs or, I dunno, flash or something, that could cause an
> > > additional delegated layer under the current one)?
> > > 
> > > If these were OOPIFs, then in the A(B(C)) case, if we're capturing B, will
> > > reading from B's RWHVChildFrame actually include the pixel content from C?
> > 
> > I'm not entirely sure, though I suspect the surface for B would include it.
> It's
> > easy enough to test.
> 
> OK.

My understanding here is that the Compositor will execute a "copy request on
layer B" on the result from drawing "B(C)".  In other words, I'd expect to see
the pixels for B and C.

Powered by Google App Engine
This is Rietveld 408576698