blob: b62510b14b79749999c53cd23e7ac76291d0b7af [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"
Blink Reformata30d4232018-04-07 15:31:069#include "third_party/blink/public/web/web_local_frame.h"
10#include "third_party/blink/public/web/web_view.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() {
Philip Rogers601fd072018-08-07 22:58:2225 UpdateContentsSize();
[email protected]5614eae2013-04-19 12:46:3826}
27
Philip Rogers079658812018-08-01 23:19:0928void AwRenderViewExt::DidUpdateMainFrameLayout() {
Philip Rogers33cd2bcc2018-08-13 21:29:2929 // The size may have changed.
30 needs_contents_size_update_ = true;
hushf4e647c2015-09-28 19:33:1231}
32
xjz694b50a92016-06-07 21:49:3733void AwRenderViewExt::OnDestruct() {
34 delete this;
35}
36
Philip Rogers601fd072018-08-07 22:58:2237void AwRenderViewExt::UpdateContentsSize() {
hushf4e647c2015-09-28 19:33:1238 blink::WebView* webview = render_view()->GetWebView();
hush43e876f2016-05-24 00:18:0439 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)
hushf4e647c2015-09-28 19:33:1249 return;
50
Philip Rogers33cd2bcc2018-08-13 21:29:2951 if (!needs_contents_size_update_)
52 return;
53 needs_contents_size_update_ = false;
54
David Bokan2989927f2018-01-23 15:38:3755 gfx::Size contents_size = main_render_frame->GetWebFrame()->DocumentSize();
[email protected]d01b2a62013-09-18 23:21:3356
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 Reformat1c4d759e2017-04-09 16:34:5460 contents_size = webview->ContentsPreferredMinimumSize();
[email protected]d01b2a62013-09-18 23:21:3361 }
62
63 if (contents_size == last_sent_contents_size_)
64 return;
65
66 last_sent_contents_size_ = contents_size;
hush43e876f2016-05-24 00:18:0467 main_render_frame->Send(new AwViewHostMsg_OnContentsSizeChanged(
68 main_render_frame->GetRoutingID(), contents_size));
[email protected]d01b2a62013-09-18 23:21:3369}
70
[email protected]fada28b2012-09-01 01:33:0371} // namespace android_webview