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

Unified Diff: athena/extensions/athena_constrained_window_views_client.cc

Issue 692563002: JS dialogs for athena (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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: athena/extensions/athena_constrained_window_views_client.cc
diff --git a/athena/extensions/athena_constrained_window_views_client.cc b/athena/extensions/athena_constrained_window_views_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..497ac949863ae41ee14c270148ea38dd8eb78053
--- /dev/null
+++ b/athena/extensions/athena_constrained_window_views_client.cc
@@ -0,0 +1,134 @@
+// Copyright 2014 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 "athena/extensions/athena_constrained_window_views_client.h"
+
+#include "athena/activity/public/activity.h"
+#include "athena/activity/public/activity_manager.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
+#include "components/constrained_window/constrained_window_views.h"
+#include "components/constrained_window/constrained_window_views_client.h"
+#include "components/web_modal/web_contents_modal_dialog_host.h"
+#include "extensions/browser/guest_view/guest_view_base.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_observer.h"
+#include "ui/aura/window_property.h"
+
+namespace athena {
+namespace {
+
Mr4D (OOO till 08-26) 2014/10/29 23:10:07 Could you add a comment what this class actually d
oshima 2014/10/31 00:37:50 This implements WebContentsModalDialogHost and the
+class ModalDialogHostImpl : public web_modal::WebContentsModalDialogHost,
+ public aura::WindowObserver {
+ public:
+ // Returns a modal dialog host for |window|. It creates one and
+ // stores as owned property if it doesn't exist.
Mr4D (OOO till 08-26) 2014/10/29 23:10:07 Maybe "if it doesn't exist it creates one and stor
oshima 2014/10/31 00:37:50 Done.
+ static ModalDialogHost* GetModalDialogHost(aura::Window* window);
+
+ private:
+ explicit ModalDialogHostImpl(aura::Window* host_window)
+ : host_window_(host_window) {
+ host_window_->AddObserver(this);
+ }
+ ~ModalDialogHostImpl() override {}
+
+ // web_modal::ModalDialogHost:
+ gfx::NativeView GetHostView() const override {
+ return host_window_;
+ }
+ gfx::Point GetDialogPosition(const gfx::Size& size) override {
+ gfx::Rect host_bounds = host_window_->GetBoundsInScreen();
+ host_bounds.ClampToCenteredSize(size);
+ return host_bounds.origin();
+ }
+ void AddObserver(web_modal::ModalDialogHostObserver* observer) override {
+ observer_list_.AddObserver(observer);
+ }
+ void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override {
+ observer_list_.RemoveObserver(observer);
+ }
+
+ // web_modal::WebContensModalDialogHost:
+ gfx::Size GetMaximumDialogSize() override {
+ return host_window_->bounds().size();
+ }
+
+ // aura::WindowObserver:
+ void OnWindowDestroying(aura::Window* window) override {
+ if (window != host_window_)
+ return;
+ host_window_->RemoveObserver(this);
+ FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver,
+ observer_list_,
+ OnHostDestroying());
+ }
+ void OnWindowBoundsChanged(aura::Window* window,
+ const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds) override {
+ if (window != host_window_)
+ return;
+ FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver,
+ observer_list_,
+ OnPositionRequiresUpdate());
+ }
+
+ aura::Window* host_window_;
+ ObserverList<web_modal::ModalDialogHostObserver> observer_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(ModalDialogHostImpl);
+};
+
+DEFINE_OWNED_WINDOW_PROPERTY_KEY(web_modal::ModalDialogHost,
+ kModalDialogHostKey,
+ nullptr);
+
+// static
+web_modal::ModalDialogHost* ModalDialogHostImpl::GetModalDialogHost(
+ aura::Window* window) {
+ web_modal::ModalDialogHost* host = window->GetProperty(kModalDialogHostKey);
+ if (!host) {
+ host = new ModalDialogHostImpl(window);
+ window->SetProperty(kModalDialogHostKey, host);
+ }
+ return host;
+}
+
+class AthenaConstrainedWindowViewsClient
+ : public ConstrainedWindowViewsClient {
+ public:
+ AthenaConstrainedWindowViewsClient() {}
+ ~AthenaConstrainedWindowViewsClient() override {}
+
+ private:
+ // ConstrainedWindowViewsClient:
+ content::WebContents* GetEmbedderWebContents(
+ content::WebContents* initiator_web_contents) override {
+ extensions::GuestViewBase* guest_view =
+ extensions::GuestViewBase::FromWebContents(initiator_web_contents);
+ return guest_view && guest_view->embedder_web_contents() ?
+ guest_view->embedder_web_contents() : initiator_web_contents;
+ }
+ web_modal::ModalDialogHost* GetModalDialogHost(
+ gfx::NativeWindow parent) override {
+ Activity* activity = ActivityManager::Get()->GetActivityForWindow(parent);
+ if (activity)
+ return ModalDialogHostImpl::GetModalDialogHost(parent);
+ return nullptr;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(AthenaConstrainedWindowViewsClient);
+};
+
+} // namespace
+
+void InstallConstrainedWindowViewsClient() {
+ SetConstrainedWindowViewsClient(
+ make_scoped_ptr(new AthenaConstrainedWindowViewsClient));
+}
+
+void UninstallConstrainedWindowViewsClient() {
+ SetConstrainedWindowViewsClient(nullptr);
+}
+
+} // namespace athena

Powered by Google App Engine
This is Rietveld 408576698