[email protected] | fada28b | 2012-09-01 01:33:03 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "android_webview/renderer/aw_render_view_ext.h" | ||||
[email protected] | fada28b | 2012-09-01 01:33:03 | [diff] [blame] | 6 | #include "android_webview/common/render_view_messages.h" |
hush | 28fab0866 | 2016-01-14 18:42:51 | [diff] [blame] | 7 | #include "content/public/renderer/render_frame.h" |
[email protected] | fada28b | 2012-09-01 01:33:03 | [diff] [blame] | 8 | #include "content/public/renderer/render_view.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 9 | #include "third_party/blink/public/web/web_local_frame.h" |
10 | #include "third_party/blink/public/web/web_view.h" | ||||
[email protected] | fada28b | 2012-09-01 01:33:03 | [diff] [blame] | 11 | |
12 | namespace android_webview { | ||||
13 | |||||
14 | AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) | ||||
hush | 28fab0866 | 2016-01-14 18:42:51 | [diff] [blame] | 15 | : content::RenderViewObserver(render_view) {} |
[email protected] | fada28b | 2012-09-01 01:33:03 | [diff] [blame] | 16 | |
hush | 28fab0866 | 2016-01-14 18:42:51 | [diff] [blame] | 17 | AwRenderViewExt::~AwRenderViewExt() {} |
[email protected] | fada28b | 2012-09-01 01:33:03 | [diff] [blame] | 18 | |
19 | // static | ||||
20 | void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) { | ||||
21 | new AwRenderViewExt(render_view); // |render_view| takes ownership. | ||||
22 | } | ||||
23 | |||||
[email protected] | 5614eae | 2013-04-19 12:46:38 | [diff] [blame] | 24 | void AwRenderViewExt::DidCommitCompositorFrame() { |
Philip Rogers | 601fd07 | 2018-08-07 22:58:22 | [diff] [blame] | 25 | UpdateContentsSize(); |
[email protected] | 5614eae | 2013-04-19 12:46:38 | [diff] [blame] | 26 | } |
27 | |||||
Philip Rogers | 07965881 | 2018-08-01 23:19:09 | [diff] [blame] | 28 | void AwRenderViewExt::DidUpdateMainFrameLayout() { |
Philip Rogers | 33cd2bcc | 2018-08-13 21:29:29 | [diff] [blame] | 29 | // The size may have changed. |
30 | needs_contents_size_update_ = true; | ||||
hush | f4e647c | 2015-09-28 19:33:12 | [diff] [blame] | 31 | } |
32 | |||||
xjz | 694b50a9 | 2016-06-07 21:49:37 | [diff] [blame] | 33 | void AwRenderViewExt::OnDestruct() { |
34 | delete this; | ||||
35 | } | ||||
36 | |||||
Philip Rogers | 601fd07 | 2018-08-07 22:58:22 | [diff] [blame] | 37 | void AwRenderViewExt::UpdateContentsSize() { |
hush | f4e647c | 2015-09-28 19:33:12 | [diff] [blame] | 38 | blink::WebView* webview = render_view()->GetWebView(); |
hush | 43e876f | 2016-05-24 00:18:04 | [diff] [blame] | 39 | content::RenderFrame* main_render_frame = render_view()->GetMainRenderFrame(); |
40 | |||||
41 | // Even without out-of-process iframes, we now create RemoteFrames for the | ||||
42 | // main frame when you navigate cross-process, to create a placeholder in the | ||||
43 | // old process. This is necessary to support things like postMessage across | ||||
44 | // windows that have references to each other. The RemoteFrame will | ||||
45 | // immediately go away if there aren't any active frames left in the old | ||||
46 | // process. RenderView's main frame pointer will become null in the old | ||||
47 | // process when it is no longer the active main frame. | ||||
48 | if (!webview || !main_render_frame) | ||||
hush | f4e647c | 2015-09-28 19:33:12 | [diff] [blame] | 49 | return; |
50 | |||||
Philip Rogers | 33cd2bcc | 2018-08-13 21:29:29 | [diff] [blame] | 51 | if (!needs_contents_size_update_) |
52 | return; | ||||
53 | needs_contents_size_update_ = false; | ||||
54 | |||||
David Bokan | 2989927f | 2018-01-23 15:38:37 | [diff] [blame] | 55 | gfx::Size contents_size = main_render_frame->GetWebFrame()->DocumentSize(); |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 56 | |
57 | // Fall back to contentsPreferredMinimumSize if the mainFrame is reporting a | ||||
58 | // 0x0 size (this happens during initial load). | ||||
59 | if (contents_size.IsEmpty()) { | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 60 | contents_size = webview->ContentsPreferredMinimumSize(); |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 61 | } |
62 | |||||
63 | if (contents_size == last_sent_contents_size_) | ||||
64 | return; | ||||
65 | |||||
66 | last_sent_contents_size_ = contents_size; | ||||
hush | 43e876f | 2016-05-24 00:18:04 | [diff] [blame] | 67 | main_render_frame->Send(new AwViewHostMsg_OnContentsSizeChanged( |
68 | main_render_frame->GetRoutingID(), contents_size)); | ||||
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 69 | } |
70 | |||||
[email protected] | fada28b | 2012-09-01 01:33:03 | [diff] [blame] | 71 | } // namespace android_webview |