blob: b0e5fdb4cfac5cea3605dd373137f139c9e7616b [file] [log] [blame]
[email protected]fada28b2012-09-01 01:33:031// 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]fada28b2012-09-01 01:33:036#include "android_webview/common/render_view_messages.h"
hush28fab08662016-01-14 18:42:517#include "content/public/renderer/render_frame.h"
[email protected]fada28b2012-09-01 01:33:038#include "content/public/renderer/render_view.h"
lukaszac469ccc02017-06-26 21:25:089#include "third_party/WebKit/public/web/WebLocalFrame.h"
[email protected]a0962a92013-06-20 18:27:3410#include "third_party/WebKit/public/web/WebView.h"
[email protected]fada28b2012-09-01 01:33:0311
12namespace android_webview {
13
14AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view)
hush28fab08662016-01-14 18:42:5115 : content::RenderViewObserver(render_view) {}
[email protected]fada28b2012-09-01 01:33:0316
hush28fab08662016-01-14 18:42:5117AwRenderViewExt::~AwRenderViewExt() {}
[email protected]fada28b2012-09-01 01:33:0318
19// static
20void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) {
21 new AwRenderViewExt(render_view); // |render_view| takes ownership.
22}
23
[email protected]5614eae2013-04-19 12:46:3824void AwRenderViewExt::DidCommitCompositorFrame() {
mcnee432e47d2015-11-09 19:37:4625 PostCheckContentsSize();
[email protected]5614eae2013-04-19 12:46:3826}
27
[email protected]d01b2a62013-09-18 23:21:3328void AwRenderViewExt::DidUpdateLayout() {
mcnee432e47d2015-11-09 19:37:4629 PostCheckContentsSize();
hushf4e647c2015-09-28 19:33:1230}
31
xjz694b50a92016-06-07 21:49:3732void AwRenderViewExt::OnDestruct() {
33 delete this;
34}
35
mcnee432e47d2015-11-09 19:37:4636void AwRenderViewExt::PostCheckContentsSize() {
[email protected]d01b2a62013-09-18 23:21:3337 if (check_contents_size_timer_.IsRunning())
38 return;
39
40 check_contents_size_timer_.Start(FROM_HERE,
hush28fab08662016-01-14 18:42:5141 base::TimeDelta::FromMilliseconds(0), this,
42 &AwRenderViewExt::CheckContentsSize);
[email protected]d01b2a62013-09-18 23:21:3343}
44
mcnee432e47d2015-11-09 19:37:4645void AwRenderViewExt::CheckContentsSize() {
hushf4e647c2015-09-28 19:33:1246 blink::WebView* webview = render_view()->GetWebView();
hush43e876f2016-05-24 00:18:0447 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)
hushf4e647c2015-09-28 19:33:1257 return;
58
David Bokan2989927f2018-01-23 15:38:3759 gfx::Size contents_size = main_render_frame->GetWebFrame()->DocumentSize();
[email protected]d01b2a62013-09-18 23:21:3360
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 Reformat1c4d759e2017-04-09 16:34:5464 contents_size = webview->ContentsPreferredMinimumSize();
[email protected]d01b2a62013-09-18 23:21:3365 }
66
67 if (contents_size == last_sent_contents_size_)
68 return;
69
70 last_sent_contents_size_ = contents_size;
hush43e876f2016-05-24 00:18:0471 main_render_frame->Send(new AwViewHostMsg_OnContentsSizeChanged(
72 main_render_frame->GetRoutingID(), contents_size));
[email protected]d01b2a62013-09-18 23:21:3373}
74
[email protected]fada28b2012-09-01 01:33:0375} // namespace android_webview