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

Unified Diff: athena/extensions/athena_javascript_dialog_manager_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_javascript_dialog_manager_client.cc
diff --git a/athena/extensions/athena_javascript_dialog_manager_client.cc b/athena/extensions/athena_javascript_dialog_manager_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..030674db40bee77fe17224ebd5fe66803712eb30
--- /dev/null
+++ b/athena/extensions/athena_javascript_dialog_manager_client.cc
@@ -0,0 +1,104 @@
+// 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_javascript_dialog_manager_client.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "components/app_modal_dialogs/javascript_dialog_manager_client.h"
+#include "components/app_modal_dialogs/views/javascript_app_modal_dialog_views.h"
+#include "components/constrained_window/constrained_window_views.h"
Mr4D (OOO till 08-26) 2014/10/29 23:10:07 Are you sure you need this?
oshima 2014/10/31 00:37:50 Yes (:49)
Mr4D (OOO till 08-26) 2014/10/31 04:26:01 Acknowledged.
+#include "content/public/browser/web_contents.h"
+#include "extensions/browser/process_manager.h"
+#include "extensions/common/extension.h"
+#include "ui/gfx/native_widget_types.h"
+
+class JavaScriptAppModalDialog;
+class NativeAppModalDialog;
+
+namespace athena {
+
Mr4D (OOO till 08-26) 2014/10/29 23:10:07 No newline
oshima 2014/10/31 00:37:50 Done.
+namespace {
+
+// Returns the ProcessManager for the browser context from |web_contents|.
+extensions::ProcessManager* GetExtensionsProcessManager(
+ content::WebContents* web_contents) {
+ return extensions::ProcessManager::Get(web_contents->GetBrowserContext());
+}
+
+// Returns the extension associated with |web_contents| or NULL if there is no
+// associated extension (or extensions are not supported).
+const extensions::Extension* GetExtensionForWebContents(
+ content::WebContents* web_contents) {
+ extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
+ return pm->GetExtensionForRenderViewHost(web_contents->GetRenderViewHost());
+}
+
+class AthenaJavaScriptDialogManagerClient
+ : public JavaScriptDialogManagerClient {
+ public:
+ AthenaJavaScriptDialogManagerClient() {}
+ ~AthenaJavaScriptDialogManagerClient() override {}
+
+ // JavaScriptDialogManagerClient:
+ NativeAppModalDialog* CreateNativeJavaScriptPrompt(
+ JavaScriptAppModalDialog* dialog,
+ gfx::NativeWindow parent_window) override {
+ JavaScriptAppModalDialogViews* d =
+ new JavaScriptAppModalDialogViews(dialog);
+ CreateWindowModalDialogViews(d, parent_window);
+ return d;
+ }
+ void IncrementLazyKeepaliveCount(
+ content::WebContents* web_contents) override {
+ const extensions::Extension* extension =
+ GetExtensionForWebContents(web_contents);
+ if (extension == nullptr)
+ return;
+
+ DCHECK(web_contents);
+ extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
+ if (pm)
+ pm->IncrementLazyKeepaliveCount(extension);
+ }
+ void DecrementLazyKeepaliveCount(
+ content::WebContents* web_contents) override {
+ const extensions::Extension* extension =
+ GetExtensionForWebContents(web_contents);
+ if (extension == nullptr)
+ return;
+
+ DCHECK(web_contents);
+ extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
+ if (pm)
+ pm->DecrementLazyKeepaliveCount(extension);
+ }
+ bool GetExtensionName(content::WebContents* web_contents,
+ const GURL& origin_url,
+ std::string* name_out) override {
+ const extensions::Extension* extension =
+ GetExtensionForWebContents(web_contents);
+ if (extension &&
+ web_contents->GetLastCommittedURL().GetOrigin() == origin_url) {
+ *name_out = extension->name();
+ return true;
+ }
+ return false;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AthenaJavaScriptDialogManagerClient);
+};
+
+} // namespace
+
+void InstallJavaScriptDialogManagerClient() {
+ SetJavaScriptDialogManagerClient(
+ make_scoped_ptr(new AthenaJavaScriptDialogManagerClient));
+}
+
+void UninstallJavaScriptDialogManagerClient() {
+ SetJavaScriptDialogManagerClient(nullptr);
+}
+
+} // namespace athena

Powered by Google App Engine
This is Rietveld 408576698