• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #include "libcef/browser/web_contents_dialog_helper.h"
6 
7 #include "libcef/browser/browser_platform_delegate.h"
8 
9 #include "chrome/browser/platform_util.h"
10 #include "components/web_modal/web_contents_modal_dialog_manager.h"
11 
12 #if defined(TOOLKIT_VIEWS)
13 #include "ui/views/widget/widget.h"
14 #endif
15 
CefWebContentsDialogHelper(content::WebContents * web_contents,CefBrowserPlatformDelegate * browser_delegate)16 CefWebContentsDialogHelper::CefWebContentsDialogHelper(
17     content::WebContents* web_contents,
18     CefBrowserPlatformDelegate* browser_delegate)
19     : browser_delegate_(browser_delegate), weak_factory_(this) {
20   web_modal::WebContentsModalDialogManager::CreateForWebContents(web_contents);
21   web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
22       ->SetDelegate(this);
23 }
24 
GetBoundsChangedCallback()25 base::RepeatingClosure CefWebContentsDialogHelper::GetBoundsChangedCallback() {
26   return base::BindRepeating(&CefWebContentsDialogHelper::OnBoundsChanged,
27                              weak_factory_.GetWeakPtr());
28 }
29 
IsWebContentsVisible(content::WebContents * web_contents)30 bool CefWebContentsDialogHelper::IsWebContentsVisible(
31     content::WebContents* web_contents) {
32   return platform_util::IsVisible(web_contents->GetNativeView());
33 }
34 
35 web_modal::WebContentsModalDialogHost*
GetWebContentsModalDialogHost()36 CefWebContentsDialogHelper::GetWebContentsModalDialogHost() {
37   return this;
38 }
39 
GetHostView() const40 gfx::NativeView CefWebContentsDialogHelper::GetHostView() const {
41 #if defined(TOOLKIT_VIEWS)
42   return browser_delegate_->GetWindowWidget()->GetNativeView();
43 #else
44   NOTIMPLEMENTED();
45   return gfx::NativeView();
46 #endif
47 }
48 
GetDialogPosition(const gfx::Size & size)49 gfx::Point CefWebContentsDialogHelper::GetDialogPosition(
50     const gfx::Size& size) {
51   return browser_delegate_->GetDialogPosition(size);
52 }
53 
GetMaximumDialogSize()54 gfx::Size CefWebContentsDialogHelper::GetMaximumDialogSize() {
55   return browser_delegate_->GetMaximumDialogSize();
56 }
57 
AddObserver(web_modal::ModalDialogHostObserver * observer)58 void CefWebContentsDialogHelper::AddObserver(
59     web_modal::ModalDialogHostObserver* observer) {
60   if (observer && !observer_list_.HasObserver(observer))
61     observer_list_.AddObserver(observer);
62 }
63 
RemoveObserver(web_modal::ModalDialogHostObserver * observer)64 void CefWebContentsDialogHelper::RemoveObserver(
65     web_modal::ModalDialogHostObserver* observer) {
66   observer_list_.RemoveObserver(observer);
67 }
68 
OnBoundsChanged()69 void CefWebContentsDialogHelper::OnBoundsChanged() {
70   for (auto& observer : observer_list_)
71     observer.OnPositionRequiresUpdate();
72 }
73