OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/web_modal/popup_manager.h" | 5 #include "components/web_modal/popup_manager.h" |
6 | 6 |
7 #include "components/web_modal/web_contents_modal_dialog_host.h" | 7 #include "components/web_modal/web_contents_modal_dialog_host.h" |
8 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 8 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/web_contents_user_data.h" | 10 #include "content/public/browser/web_contents_user_data.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 weak_factory_(this) {} | 38 weak_factory_(this) {} |
39 | 39 |
40 PopupManager::~PopupManager() { | 40 PopupManager::~PopupManager() { |
41 } | 41 } |
42 | 42 |
43 void PopupManager::ShowPopup(scoped_ptr<SinglePopupManager> manager) { | 43 void PopupManager::ShowPopup(scoped_ptr<SinglePopupManager> manager) { |
44 content::WebContents* web_contents = manager->GetBoundWebContents(); | 44 content::WebContents* web_contents = manager->GetBoundWebContents(); |
45 // TODO(gbillock): get rid of this when we handle bubbles | 45 // TODO(gbillock): get rid of this when we handle bubbles |
46 DCHECK(web_contents); | 46 DCHECK(web_contents); |
47 | 47 |
48 // TODO(gbillock): remove when we port the popup management logic to this | |
49 // class. | |
50 NativeWebContentsModalDialog dialog = | |
51 static_cast<NativeWebContentsModalDialog>(manager->popup()); | |
52 | |
53 WebContentsModalDialogManager* wm_manager = | 48 WebContentsModalDialogManager* wm_manager = |
54 WebContentsModalDialogManager::FromWebContents(web_contents); | 49 WebContentsModalDialogManager::FromWebContents(web_contents); |
55 DCHECK(wm_manager); | 50 DCHECK(wm_manager); |
56 wm_manager->ShowModalDialog(dialog); | 51 wm_manager->ShowModalDialog(manager->popup()); |
57 } | 52 } |
58 | 53 |
59 void PopupManager::ShowModalDialog(NativePopup popup, | 54 void PopupManager::ShowModalDialog(gfx::NativeWindow popup, |
60 content::WebContents* web_contents) { | 55 content::WebContents* web_contents) { |
61 // TODO make a new native popup manager and call ShowPopup. | 56 // TODO make a new native popup manager and call ShowPopup. |
62 // For now just lay off to WCMDM. | 57 // For now just lay off to WCMDM. |
63 WebContentsModalDialogManager* manager = | 58 WebContentsModalDialogManager* manager = |
64 WebContentsModalDialogManager::FromWebContents(web_contents); | 59 WebContentsModalDialogManager::FromWebContents(web_contents); |
65 manager->ShowModalDialog(popup); | 60 manager->ShowModalDialog(popup); |
66 } | 61 } |
67 | 62 |
68 bool PopupManager::IsWebModalDialogActive( | 63 bool PopupManager::IsWebModalDialogActive( |
69 const content::WebContents* web_contents) const { | 64 const content::WebContents* web_contents) const { |
70 if (web_contents == NULL) | 65 if (web_contents == NULL) |
71 return false; | 66 return false; |
72 | 67 |
73 const WebContentsModalDialogManager* manager = | 68 const WebContentsModalDialogManager* manager = |
74 WebContentsModalDialogManager::FromWebContents(web_contents); | 69 WebContentsModalDialogManager::FromWebContents(web_contents); |
75 return manager && manager->IsDialogActive(); | 70 return manager && manager->IsDialogActive(); |
76 } | 71 } |
77 | 72 |
78 void PopupManager::WasFocused(const content::WebContents* web_contents) { | 73 void PopupManager::WasFocused(const content::WebContents* web_contents) { |
79 if (!IsWebModalDialogActive(web_contents)) | 74 if (!IsWebModalDialogActive(web_contents)) |
80 return; | 75 return; |
81 | 76 |
82 const WebContentsModalDialogManager* manager = | 77 const WebContentsModalDialogManager* manager = |
83 WebContentsModalDialogManager::FromWebContents(web_contents); | 78 WebContentsModalDialogManager::FromWebContents(web_contents); |
84 if (manager) | 79 if (manager) |
85 manager->FocusTopmostDialog(); | 80 manager->FocusTopmostDialog(); |
86 } | 81 } |
87 | 82 |
88 void PopupManager::WillClose(NativePopup popup) { | 83 void PopupManager::WillClose(gfx::NativeWindow popup) { |
89 } | 84 } |
90 | 85 |
91 void PopupManager::RegisterWith(content::WebContents* web_contents) { | 86 void PopupManager::RegisterWith(content::WebContents* web_contents) { |
92 web_contents->SetUserData(kPopupManagerUserDataKey, | 87 web_contents->SetUserData(kPopupManagerUserDataKey, |
93 new PopupManagerRelay(weak_factory_.GetWeakPtr())); | 88 new PopupManagerRelay(weak_factory_.GetWeakPtr())); |
94 // TODO(gbillock): Need to do something more extreme here to manage changing | 89 // TODO(gbillock): Need to do something more extreme here to manage changing |
95 // popup managers with popups in-flight? | 90 // popup managers with popups in-flight? |
96 } | 91 } |
97 | 92 |
98 void PopupManager::UnregisterWith(content::WebContents* web_contents) { | 93 void PopupManager::UnregisterWith(content::WebContents* web_contents) { |
(...skipping 21 matching lines...) Expand all Loading... |
120 void PopupManager::CloseAllDialogsForTesting( | 115 void PopupManager::CloseAllDialogsForTesting( |
121 content::WebContents* web_contents) { | 116 content::WebContents* web_contents) { |
122 // TODO: re-implement, probably in terms of something in the host_, | 117 // TODO: re-implement, probably in terms of something in the host_, |
123 // or of owned WCMDMs. | 118 // or of owned WCMDMs. |
124 WebContentsModalDialogManager* manager = | 119 WebContentsModalDialogManager* manager = |
125 WebContentsModalDialogManager::FromWebContents(web_contents); | 120 WebContentsModalDialogManager::FromWebContents(web_contents); |
126 manager->CloseAllDialogs(); | 121 manager->CloseAllDialogs(); |
127 } | 122 } |
128 | 123 |
129 } // namespace web_modal | 124 } // namespace web_modal |
OLD | NEW |