blob: c206c59a4a1c63aafec6065d054a14f84e66daf1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/public/web/web_view_observer.h"
#include "third_party/blink/renderer/core/exported/web_view_impl.h"
namespace blink {
WebViewObserver::WebViewObserver(WebView* web_view)
: web_view_(static_cast<WebViewImpl*>(web_view)) {
// |web_view_| can be null on unit testing or if Observe() is used.
if (web_view_) {
web_view_->AddObserver(this);
}
}
WebViewObserver::~WebViewObserver() {
Observe(nullptr);
}
WebView* WebViewObserver::GetWebView() const {
return web_view_;
}
void WebViewObserver::Observe(WebView* web_view) {
if (web_view_) {
web_view_->RemoveObserver(this);
}
web_view_ = static_cast<WebViewImpl*>(web_view);
if (web_view_) {
web_view_->AddObserver(this);
}
}
void WebViewObserver::WebViewDestroyed() {
Observe(nullptr);
OnDestruct();
}
} // namespace blink
|