OLD | NEW |
---|---|
(Empty) | |
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 "components/web_modal/popup_manager.h" | |
6 | |
7 #include "components/web_modal/web_contents_modal_dialog_host.h" | |
8 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
9 #include "content/public/browser/web_contents.h" | |
10 #include "content/public/browser/web_contents_user_data.h" | |
11 #include "ui/gfx/geometry/size.h" | |
12 | |
13 using content::WebContents; | |
14 | |
15 namespace web_modal { | |
16 | |
17 namespace { | |
18 | |
19 const char kPopupManagerUserDataKey[] = "PopupManager"; | |
20 | |
21 class PopupManagerRelay : public content::WebContentsUserData<PopupManager> { | |
Finnur
2014/06/30 13:53:36
nit: Document purpose.
Greg Billock
2014/07/01 00:53:04
Done.
| |
22 public: | |
23 explicit PopupManagerRelay(base::WeakPtr<PopupManager> manager) | |
24 : manager_(manager) {} | |
25 | |
26 virtual ~PopupManagerRelay() {} | |
Finnur
2014/06/30 13:53:36
Does this need to be virtual?
Greg Billock
2014/07/01 00:53:04
I think so, for UserData.
| |
27 | |
28 base::WeakPtr<PopupManager> manager_; | |
Finnur
2014/06/30 13:53:36
Make this private plus add a public accessor, inst
Greg Billock
2014/07/01 00:53:04
I think this is clear enough. There's no real enca
| |
29 }; | |
Finnur
2014/06/30 13:53:36
Nit: Missing DISALLOW_etc?
Greg Billock
2014/07/01 00:53:04
This class is pretty single-purpose, so putting a
| |
30 | |
31 } // namespace | |
32 | |
33 PopupManager::PopupManager(WebContentsModalDialogHost* host) | |
34 : host_(host), | |
35 weak_factory_(this) {} | |
36 | |
37 PopupManager::~PopupManager() { | |
38 } | |
39 | |
40 void PopupManager::ShowPopup(scoped_ptr<SinglePopupManager> manager) { | |
41 content::WebContents* web_contents = manager->GetBoundWebContents(); | |
42 // TODO(gbillock): get rid of this when we handle bubbles | |
43 DCHECK(web_contents); | |
44 | |
45 // TODO(gbillock): remove when we port the popup management logic to this | |
46 // class. | |
47 NativeWebContentsModalDialog dialog = | |
48 static_cast<NativeWebContentsModalDialog>(manager->popup()); | |
49 | |
50 WebContentsModalDialogManager* wm_manager = | |
51 WebContentsModalDialogManager::FromWebContents(web_contents); | |
52 DCHECK(wm_manager); | |
53 wm_manager->ShowModalDialog(dialog); | |
54 } | |
55 | |
56 void PopupManager::ShowModalDialog(NativePopup popup, | |
57 content::WebContents* web_contents) { | |
58 // TODO make a new native popup manager and call ShowPopup. | |
59 // For now just lay off to WCMDM. | |
60 WebContentsModalDialogManager* manager = | |
61 WebContentsModalDialogManager::FromWebContents(web_contents); | |
62 manager->ShowModalDialog(popup); | |
63 } | |
64 | |
65 bool PopupManager::IsWebModalDialogActive( | |
66 const content::WebContents* web_contents) const { | |
67 if (web_contents == NULL) | |
68 return false; | |
69 | |
70 const WebContentsModalDialogManager* manager = | |
71 WebContentsModalDialogManager::FromWebContents(web_contents); | |
72 return manager && manager->IsDialogActive(); | |
73 } | |
74 | |
75 void PopupManager::WasFocused(const content::WebContents* web_contents) { | |
76 if (!IsWebModalDialogActive(web_contents)) | |
77 return; | |
78 | |
79 const WebContentsModalDialogManager* manager = | |
80 WebContentsModalDialogManager::FromWebContents(web_contents); | |
81 if (manager) | |
82 manager->FocusTopmostDialog(); | |
Finnur
2014/06/30 13:53:36
Just looking at this function (without any other c
Greg Billock
2014/07/01 00:53:04
I feel like OnFocus raises the doubt that the popu
| |
83 } | |
84 | |
85 void PopupManager::WillClose(NativePopup popup) { | |
86 } | |
87 | |
88 void PopupManager::RegisterWith(content::WebContents* web_contents) { | |
89 web_contents->SetUserData(kPopupManagerUserDataKey, | |
90 new PopupManagerRelay(weak_factory_.GetWeakPtr())); | |
groby-ooo-7-16
2014/07/01 18:12:38
Going back to my earlier question, I guess this is
Greg Billock
2014/07/01 19:33:19
PopupManagerRelay is scoped to the WebContents. Th
groby-ooo-7-16
2014/07/02 20:13:55
Ah, you're trying to reverse the dependecy. Got yo
Greg Billock
2014/07/02 21:17:26
Not exactly. We're sitting in a completely differe
groby-ooo-7-16
2014/07/03 01:11:25
Completely agreed - this is the problem we want to
Greg Billock
2014/07/03 01:33:15
I'm not sure what you mean -- there's no knowledge
groby-ooo-7-16
2014/07/03 02:23:44
There is, and there isn't. There's no _reference_
Mike Wittman
2014/07/03 03:21:06
It seems to me the PopupManager has to know that t
| |
91 // TODO(gbillock): Need to do something more extreme here to manage changing | |
92 // popup managers with popups in-flight? | |
93 } | |
94 | |
95 void PopupManager::UnregisterWith(content::WebContents* web_contents) { | |
96 web_contents->RemoveUserData(kPopupManagerUserDataKey); | |
97 // TODO(gbillock): Need to do something more extreme here to manage changing | |
98 // popup managers with popups in-flight? | |
99 } | |
100 | |
101 PopupManager* PopupManager::FromWebContents( | |
102 content::WebContents* web_contents) { | |
103 PopupManagerRelay* relay = static_cast<PopupManagerRelay*>( | |
104 web_contents->GetUserData(kPopupManagerUserDataKey)); | |
105 if (!relay) | |
106 return NULL; | |
107 | |
108 return relay->manager_.get(); | |
Finnur
2014/06/30 13:53:36
Maybe there's something I'm missing, but why do yo
Greg Billock
2014/07/01 00:53:04
No, not really. The object is in the wrong compone
| |
109 } | |
110 | |
111 gfx::NativeView PopupManager::GetHostView() const { | |
112 // TODO(gbillock): replace this with a PopupManagerHost or something. | |
113 DCHECK(host_); | |
114 return host_->GetHostView(); | |
115 } | |
116 | |
117 void PopupManager::CloseAllDialogsForTesting( | |
118 content::WebContents* web_contents) { | |
119 // TODO: re-implement, probably in terms of something in the host_, | |
120 // or of owned WCMDMs. | |
Finnur
2014/06/30 13:53:36
nit: This comment is hard to parse -- what does "r
Greg Billock
2014/07/01 00:53:04
This class will end up either consuming or owning
| |
121 WebContentsModalDialogManager* manager = | |
122 WebContentsModalDialogManager::FromWebContents(web_contents); | |
123 manager->CloseAllDialogs(); | |
124 } | |
125 | |
126 } // namespace web_modal | |
OLD | NEW |