Index: components/web_modal/popup_manager.cc |
diff --git a/components/web_modal/popup_manager.cc b/components/web_modal/popup_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5877fd3ab44134594a5a09515c47400670b45ff9 |
--- /dev/null |
+++ b/components/web_modal/popup_manager.cc |
@@ -0,0 +1,132 @@ |
+// Copyright (c) 2012 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 "components/web_modal/popup_manager.h" |
+ |
+#include "components/web_modal/web_contents_modal_dialog_host.h" |
+#include "components/web_modal/web_contents_modal_dialog_manager.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/browser/web_contents_user_data.h" |
+#include "ui/gfx/geometry/size.h" |
+ |
+using content::WebContents; |
+ |
+namespace web_modal { |
+ |
+namespace { |
+ |
+const char kPopupManagerUserDataKey[] = "PopupManager"; |
+ |
+class PopupManagerRelay : public content::WebContentsUserData<PopupManager> { |
+ public: |
+ explicit PopupManagerRelay(base::WeakPtr<PopupManager> manager) |
+ : manager_(manager) {} |
+ |
+ virtual ~PopupManagerRelay() {} |
+ |
+ base::WeakPtr<PopupManager> manager_; |
+}; |
+ |
+} // namespace |
+ |
+PopupManager::PopupManager(WebContentsModalDialogHost* host) |
+ : host_(host), |
+ weak_factory_(this) {} |
+ |
+PopupManager::~PopupManager() { |
+} |
+ |
+void PopupManager::ShowPopup(scoped_ptr<SinglePopupManager> manager) { |
+ content::WebContents* web_contents = manager->GetBoundWebContents(); |
+ // TODO(gbillock): get rid of this when we handle bubbles |
+ DCHECK(web_contents); |
+ |
+ // TODO(gbillock): remove when we port the popup management logic to this |
+ // class. |
+ NativeWebContentsModalDialog dialog = |
+ static_cast<NativeWebContentsModalDialog>(manager->popup()); |
+ |
+ WebContentsModalDialogManager* wm_manager = |
+ WebContentsModalDialogManager::FromWebContents(web_contents); |
+ DCHECK(wm_manager); |
+ wm_manager->ShowModalDialog(dialog); |
+} |
+ |
+void PopupManager::ShowModalDialog(NativePopup popup, |
+ content::WebContents* web_contents) { |
+ // TODO make a new native popup manager and call ShowPopup. |
+ // For now just lay off to WCMDM. |
+ WebContentsModalDialogManager* manager = |
+ WebContentsModalDialogManager::FromWebContents(web_contents); |
+ manager->ShowModalDialog(popup); |
+} |
+ |
+bool PopupManager::IsWebModalDialogActive( |
+ const content::WebContents* web_contents) const { |
+ if (web_contents == NULL) |
+ return false; |
+ |
+ const WebContentsModalDialogManager* manager = |
+ WebContentsModalDialogManager::FromWebContents(web_contents); |
+ return manager ? manager->IsDialogActive() : false; |
Mike Wittman
2014/06/25 02:38:50
nit: manager && manager->IsDialogActive()
Greg Billock
2014/06/25 19:06:14
Done.
|
+} |
+ |
+void PopupManager::WasFocused(const content::WebContents* web_contents) { |
+ if (!IsWebModalDialogActive(web_contents)) |
+ return; |
+ |
+ const WebContentsModalDialogManager* manager = |
+ WebContentsModalDialogManager::FromWebContents(web_contents); |
+ if (manager) |
+ manager->FocusTopmostDialog(); |
+} |
+ |
+void PopupManager::WillClose(NativePopup popup) { |
+} |
+ |
+void PopupManager::RegisterWith(content::WebContents* web_contents) { |
+ web_contents->SetUserData(kPopupManagerUserDataKey, |
+ new PopupManagerRelay(weak_factory_.GetWeakPtr())); |
+ // TODO(gbillock): Need to do something more extreme here to manage changing |
+ // popup managers with popups in-flight? |
+} |
+ |
+PopupManager* PopupManager::FromWebContents( |
+ content::WebContents* web_contents) { |
+ PopupManagerRelay* relay = static_cast<PopupManagerRelay*>( |
+ web_contents->GetUserData(kPopupManagerUserDataKey)); |
+ if (!relay) |
+ return NULL; |
+ |
+ return relay->manager_.get(); |
+} |
+ |
+gfx::NativeView PopupManager::GetHostView() const { |
+ // TODO(gbillock): replace this with a PopupManagerHost or something. |
+ return host_->GetHostView(); |
+} |
+ |
+void PopupManager::CloseAllDialogsForTesting() { |
+ // TODO: implement, probably in terms of something in the host_ for now, |
Mike Wittman
2014/06/25 02:38:50
Needs resolution.
Greg Billock
2014/06/25 19:06:14
Will do. I think long term we'll absorb WCMDM, but
|
+ // or just do something different at call sites. |
+ |
+ //Widget* widget = Widget::GetWidgetForNativeView(GetHostView()) |
+ //if (!widget) |
+ // return; |
+ //Browser* browser = BrowserFinder::FindBrowserWithWindow( |
+ // widget->GetNativeWindow()); |
+ //if (!browser) |
+ // return; |
+ // |
+ //for (int i = 0; i < browser->tab_strip_model()->count(); i++) |
+ // content::WebContents* web_contents = |
+ // browser->tab_strip_model()->GetWebContentsAt(i); |
+ // if (!web_contents) continue; |
+ // const WebContentsModalDialogManager* manager = |
+ // WebContentsModalDialogManager::FromWebContents(web_contents); |
+ // manager->CloseAllDialogs(); |
+ //} |
+} |
+ |
+} // namespace web_modal |