Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: components/web_modal/popup_manager.cc

Issue 287123002: [WebModals] New API for browser-scoped popup management. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tweaks Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..cfa9d1fc5ebdcda78396064903c505bb24499e87
--- /dev/null
+++ b/components/web_modal/popup_manager.cc
@@ -0,0 +1,126 @@
+// 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> {
Finnur 2014/06/30 13:53:36 nit: Document purpose.
Greg Billock 2014/07/01 00:53:04 Done.
+ public:
+ explicit PopupManagerRelay(base::WeakPtr<PopupManager> manager)
+ : manager_(manager) {}
+
+ 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.
+
+ 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
+};
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
+
+} // 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();
+}
+
+void PopupManager::WasFocused(const content::WebContents* web_contents) {
+ if (!IsWebModalDialogActive(web_contents))
+ return;
+
+ const WebContentsModalDialogManager* manager =
+ WebContentsModalDialogManager::FromWebContents(web_contents);
+ if (manager)
+ 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
+}
+
+void PopupManager::WillClose(NativePopup popup) {
+}
+
+void PopupManager::RegisterWith(content::WebContents* web_contents) {
+ web_contents->SetUserData(kPopupManagerUserDataKey,
+ 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
+ // TODO(gbillock): Need to do something more extreme here to manage changing
+ // popup managers with popups in-flight?
+}
+
+void PopupManager::UnregisterWith(content::WebContents* web_contents) {
+ web_contents->RemoveUserData(kPopupManagerUserDataKey);
+ // 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();
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
+}
+
+gfx::NativeView PopupManager::GetHostView() const {
+ // TODO(gbillock): replace this with a PopupManagerHost or something.
+ DCHECK(host_);
+ return host_->GetHostView();
+}
+
+void PopupManager::CloseAllDialogsForTesting(
+ content::WebContents* web_contents) {
+ // TODO: re-implement, probably in terms of something in the host_,
+ // 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
+ WebContentsModalDialogManager* manager =
+ WebContentsModalDialogManager::FromWebContents(web_contents);
+ manager->CloseAllDialogs();
+}
+
+} // namespace web_modal

Powered by Google App Engine
This is Rietveld 408576698