[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" |
lukasza | c469ccc0 | 2017-06-26 21:25:08 | [diff] [blame] | 9 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
[email protected] | a0962a9 | 2013-06-20 18:27:34 | [diff] [blame] | 10 | #include "third_party/WebKit/public/web/WebView.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() { |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 25 | PostCheckContentsSize(); |
[email protected] | 5614eae | 2013-04-19 12:46:38 | [diff] [blame] | 26 | } |
27 | |||||
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 28 | void AwRenderViewExt::DidUpdateLayout() { |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 29 | PostCheckContentsSize(); |
hush | f4e647c | 2015-09-28 19:33:12 | [diff] [blame] | 30 | } |
31 | |||||
xjz | 694b50a9 | 2016-06-07 21:49:37 | [diff] [blame] | 32 | void AwRenderViewExt::OnDestruct() { |
33 | delete this; | ||||
34 | } | ||||
35 | |||||
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 36 | void AwRenderViewExt::PostCheckContentsSize() { |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 37 | if (check_contents_size_timer_.IsRunning()) |
38 | return; | ||||
39 | |||||
40 | check_contents_size_timer_.Start(FROM_HERE, | ||||
hush | 28fab0866 | 2016-01-14 18:42:51 | [diff] [blame] | 41 | base::TimeDelta::FromMilliseconds(0), this, |
42 | &AwRenderViewExt::CheckContentsSize); | ||||
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 43 | } |
44 | |||||
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 45 | void AwRenderViewExt::CheckContentsSize() { |
hush | f4e647c | 2015-09-28 19:33:12 | [diff] [blame] | 46 | blink::WebView* webview = render_view()->GetWebView(); |
hush | 43e876f | 2016-05-24 00:18:04 | [diff] [blame] | 47 | content::RenderFrame* main_render_frame = render_view()->GetMainRenderFrame(); |
48 | |||||
49 | // Even without out-of-process iframes, we now create RemoteFrames for the | ||||
50 | // main frame when you navigate cross-process, to create a placeholder in the | ||||
51 | // old process. This is necessary to support things like postMessage across | ||||
52 | // windows that have references to each other. The RemoteFrame will | ||||
53 | // immediately go away if there aren't any active frames left in the old | ||||
54 | // process. RenderView's main frame pointer will become null in the old | ||||
55 | // process when it is no longer the active main frame. | ||||
56 | if (!webview || !main_render_frame) | ||||
hush | f4e647c | 2015-09-28 19:33:12 | [diff] [blame] | 57 | return; |
58 | |||||
David Bokan | 2989927f | 2018-01-23 15:38:37 | [diff] [blame] | 59 | gfx::Size contents_size = main_render_frame->GetWebFrame()->DocumentSize(); |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 60 | |
61 | // Fall back to contentsPreferredMinimumSize if the mainFrame is reporting a | ||||
62 | // 0x0 size (this happens during initial load). | ||||
63 | if (contents_size.IsEmpty()) { | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 64 | contents_size = webview->ContentsPreferredMinimumSize(); |
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 65 | } |
66 | |||||
67 | if (contents_size == last_sent_contents_size_) | ||||
68 | return; | ||||
69 | |||||
70 | last_sent_contents_size_ = contents_size; | ||||
hush | 43e876f | 2016-05-24 00:18:04 | [diff] [blame] | 71 | main_render_frame->Send(new AwViewHostMsg_OnContentsSizeChanged( |
72 | main_render_frame->GetRoutingID(), contents_size)); | ||||
[email protected] | d01b2a6 | 2013-09-18 23:21:33 | [diff] [blame] | 73 | } |
74 | |||||
[email protected] | fada28b | 2012-09-01 01:33:03 | [diff] [blame] | 75 | } // namespace android_webview |