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

Unified Diff: chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.cc

Issue 666533007: Move JavaScriptDialogManager, JavascriptAppModalDialogViews to components/app_modal_dialogs (Closed) Base URL: https://chromium.googlesource.com/chromium/src@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: chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.cc
diff --git a/chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.cc b/chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3040406183e7a9210b73ebb3ceb790a2145abfa3
--- /dev/null
+++ b/chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.cc
@@ -0,0 +1,87 @@
+// 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 "chrome/browser/ui/app_modal_dialogs/chrome_javascript_dialog_manager_client.h"
+
+#include "content/public/browser/web_contents.h"
+
+#if defined(ENABLE_EXTENSIONS)
+#include "extensions/browser/process_manager.h"
+#include "extensions/common/extension.h"
+
+using extensions::Extension;
+#endif // defined(ENABLE_EXTENSIONS)
+
+namespace {
+
+#if defined(ENABLE_EXTENSIONS)
+// 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 Extension* GetExtensionForWebContents(
+ content::WebContents* web_contents) {
+ extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
+ return pm->GetExtensionForRenderViewHost(web_contents->GetRenderViewHost());
+}
+#endif // defined(ENABLE_EXTENSIONS)
+
+} // namespace
+
+ChromeJavaScriptDialogManagerClient::ChromeJavaScriptDialogManagerClient() {}
+ChromeJavaScriptDialogManagerClient::~ChromeJavaScriptDialogManagerClient() {}
+
+NativeAppModalDialog*
+ChromeJavaScriptDialogManagerClient::CreateNativeJavaScriptPrompt(
+ JavaScriptAppModalDialog* dialog,
+ gfx::NativeWindow parent_window) {
+ return CreateChromeNativeJavaScriptPrompt(dialog, parent_window);
+}
+
+void ChromeJavaScriptDialogManagerClient::IncrementLazyKeepaliveCount(
+ content::WebContents* web_contents) {
+#if defined(ENABLE_EXTENSIONS)
+ const Extension* extension = GetExtensionForWebContents(web_contents);
+ if (extension == nullptr)
+ return;
+
+ DCHECK(web_contents);
+ extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
+ if (pm)
+ pm->IncrementLazyKeepaliveCount(extension);
+#endif // defined(ENABLE_EXTENSIONS)
+}
+
+void ChromeJavaScriptDialogManagerClient::DecrementLazyKeepaliveCount(
+ content::WebContents* web_contents) {
+#if defined(ENABLE_EXTENSIONS)
+ const Extension* extension = GetExtensionForWebContents(web_contents);
+ if (extension == nullptr)
+ return;
+
+ DCHECK(web_contents);
+ extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
+ if (pm)
+ pm->DecrementLazyKeepaliveCount(extension);
+#endif // defined(ENABLE_EXTENSIONS)
+}
+
+bool ChromeJavaScriptDialogManagerClient::GetExtensionName(
+ content::WebContents* web_contents,
+ const GURL& origin_url,
+ std::string* name_out) {
+#if defined(ENABLE_EXTENSIONS)
+ const Extension* extension = GetExtensionForWebContents(web_contents);
+ if (extension &&
+ web_contents->GetLastCommittedURL().GetOrigin() == origin_url) {
+ *name_out = extension->name();
+ return true;
+ }
+#endif // defined(ENABLE_EXTENSIONS)
+ return false;
+}

Powered by Google App Engine
This is Rietveld 408576698