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

Unified Diff: components/app_modal_dialogs/javascript_dialog_manager.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: components/app_modal_dialogs/javascript_dialog_manager.cc
diff --git a/chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.cc b/components/app_modal_dialogs/javascript_dialog_manager.cc
similarity index 78%
rename from chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.cc
rename to components/app_modal_dialogs/javascript_dialog_manager.cc
index 4b770cce29324d6e1820617d7def7ad3f401ea27..c945c5352767b42e8d8d0914b49c6408f67bd546 100644
--- a/chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.cc
+++ b/components/app_modal_dialogs/javascript_dialog_manager.cc
@@ -2,7 +2,7 @@
// 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/javascript_dialog_manager.h"
+#include "components/app_modal_dialogs/javascript_dialog_manager.h"
#include "base/bind.h"
#include "base/compiler_specific.h"
@@ -12,6 +12,7 @@
#include "components/app_modal_dialogs/app_modal_dialog.h"
#include "components/app_modal_dialogs/app_modal_dialog_queue.h"
#include "components/app_modal_dialogs/javascript_app_modal_dialog.h"
+#include "components/app_modal_dialogs/javascript_dialog_manager_client.h"
#include "components/app_modal_dialogs/native_app_modal_dialog.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_client.h"
@@ -20,67 +21,12 @@
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
-#if defined(ENABLE_EXTENSIONS)
-#include "extensions/browser/process_manager.h"
-#include "extensions/common/extension.h"
-#endif // defined(ENABLE_EXTENSIONS)
-
using content::BrowserContext;
using content::JavaScriptDialogManager;
using content::WebContents;
-#if defined(ENABLE_EXTENSIONS)
-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(
- 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(WebContents* web_contents) {
- extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
- return pm->GetExtensionForRenderViewHost(web_contents->GetRenderViewHost());
-}
-#endif // defined(ENABLE_EXTENSIONS)
-
-// Keeps an |extension| from shutting down its lazy background page. If an
-// extension opens a dialog its lazy background page must stay alive until the
-// dialog closes.
-void IncrementLazyKeepaliveCount(WebContents* web_contents) {
-#if defined(ENABLE_EXTENSIONS)
- const Extension* extension = GetExtensionForWebContents(web_contents);
- if (extension == NULL)
- return;
-
- DCHECK(web_contents);
- extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
- if (pm)
- pm->IncrementLazyKeepaliveCount(extension);
-#endif // defined(ENABLE_EXTENSIONS)
-}
-
-// Allows an |extension| to shut down its lazy background page after a dialog
-// closes (if nothing else is keeping it open).
-void DecrementLazyKeepaliveCount(WebContents* web_contents) {
-#if defined(ENABLE_EXTENSIONS)
- const Extension* extension = GetExtensionForWebContents(web_contents);
- if (extension == NULL)
- return;
-
- DCHECK(web_contents);
- extensions::ProcessManager* pm = GetExtensionsProcessManager(web_contents);
- if (pm)
- pm->DecrementLazyKeepaliveCount(extension);
-#endif // defined(ENABLE_EXTENSIONS)
-}
-
class ChromeJavaScriptDialogManager : public JavaScriptDialogManager {
public:
static ChromeJavaScriptDialogManager* GetInstance();
@@ -185,7 +131,7 @@ void ChromeJavaScriptDialogManager::RunJavaScriptDialog(
base::string16 dialog_title =
GetTitle(web_contents, origin_url, accept_lang, is_alert);
- IncrementLazyKeepaliveCount(web_contents);
+ GetJavaScriptDialogManagerClient()->IncrementLazyKeepaliveCount(web_contents);
AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
web_contents,
@@ -214,7 +160,7 @@ void ChromeJavaScriptDialogManager::RunBeforeUnloadDialog(
base::string16 full_message =
message_text + base::ASCIIToUTF16("\n\n") + footer;
- IncrementLazyKeepaliveCount(web_contents);
+ GetJavaScriptDialogManagerClient()->IncrementLazyKeepaliveCount(web_contents);
AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
web_contents,
@@ -272,13 +218,11 @@ base::string16 ChromeJavaScriptDialogManager::GetTitle(
// For extensions, show the extension name, but only if the origin of
// the alert matches the top-level WebContents.
-#if defined(ENABLE_EXTENSIONS)
- const Extension* extension = GetExtensionForWebContents(web_contents);
- if (extension &&
- web_contents->GetLastCommittedURL().GetOrigin() == origin_url) {
- return base::UTF8ToUTF16(extension->name());
+ std::string name;
+ if (GetJavaScriptDialogManagerClient()
+ ->GetExtensionName(web_contents, origin_url, &name)) {
+ return base::UTF8ToUTF16(name);
}
-#endif // defined(ENABLE_EXTENSIONS)
// Otherwise, return the formatted URL.
// In this case, force URL to have LTR directionality.
@@ -310,7 +254,7 @@ void ChromeJavaScriptDialogManager::OnDialogClosed(
// If an extension opened this dialog then the extension may shut down its
// lazy background page after the dialog closes. (Dialogs are closed before
// their WebContents is destroyed so |web_contents| is still valid here.)
- DecrementLazyKeepaliveCount(web_contents);
+ GetJavaScriptDialogManagerClient()->DecrementLazyKeepaliveCount(web_contents);
callback.Run(success, user_input);
}

Powered by Google App Engine
This is Rietveld 408576698