Index: components/app_modal_dialogs/javascript_dialog_manager_impl.cc |
diff --git a/chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.cc b/components/app_modal_dialogs/javascript_dialog_manager_impl.cc |
similarity index 52% |
rename from chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.cc |
rename to components/app_modal_dialogs/javascript_dialog_manager_impl.cc |
index 4b770cce29324d6e1820617d7def7ad3f401ea27..7a30a7d5f7fdf4c901634ad2ef9a453b893f284e 100644 |
--- a/chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.cc |
+++ b/components/app_modal_dialogs/javascript_dialog_manager_impl.cc |
@@ -2,16 +2,17 @@ |
// 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_impl.h" |
#include "base/bind.h" |
#include "base/compiler_specific.h" |
#include "base/i18n/rtl.h" |
-#include "base/memory/singleton.h" |
#include "base/strings/utf_string_conversions.h" |
#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" |
msw
2014/11/05 03:53:56
This is included in the header and not needed here
|
+#include "components/app_modal_dialogs/javascript_dialog_extensions_client.h" |
+#include "components/app_modal_dialogs/javascript_native_dialog_factory.h" |
#include "components/app_modal_dialogs/native_app_modal_dialog.h" |
msw
2014/11/05 03:53:56
I don't think this include is needed anymore.
oshima
2014/11/05 21:42:18
this is used to access native_dialog in HandleJava
|
#include "content/public/browser/web_contents.h" |
#include "content/public/common/content_client.h" |
@@ -20,133 +21,50 @@ |
#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; |
msw
2014/11/05 03:53:55
Remove this; the type is no longer used here.
oshima
2014/11/05 21:42:18
Done.
|
using content::JavaScriptDialogManager; |
msw
2014/11/05 03:53:56
Remove this; the type is no longer used here.
oshima
2014/11/05 21:42:19
Done.
|
using content::WebContents; |
msw
2014/11/05 03:53:56
nit: explicitly use "content::" and remove this, o
oshima
2014/11/05 21:42:18
Done.
|
-#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 { |
+class DefaultExtensionsClient : public JavaScriptDialogExtensionsClient { |
public: |
- static ChromeJavaScriptDialogManager* GetInstance(); |
- |
- void RunJavaScriptDialog(WebContents* web_contents, |
- const GURL& origin_url, |
- const std::string& accept_lang, |
- content::JavaScriptMessageType message_type, |
- const base::string16& message_text, |
- const base::string16& default_prompt_text, |
- const DialogClosedCallback& callback, |
- bool* did_suppress_message) override; |
- |
- void RunBeforeUnloadDialog(WebContents* web_contents, |
- const base::string16& message_text, |
- bool is_reload, |
- const DialogClosedCallback& callback) override; |
- |
- bool HandleJavaScriptDialog(WebContents* web_contents, |
- bool accept, |
- const base::string16* prompt_override) override; |
- |
- void CancelActiveAndPendingDialogs(WebContents* web_contents) override; |
- |
- void WebContentsDestroyed(WebContents* web_contents) override; |
+ DefaultExtensionsClient() {} |
+ ~DefaultExtensionsClient() override {} |
private: |
- friend struct DefaultSingletonTraits<ChromeJavaScriptDialogManager>; |
- |
- ChromeJavaScriptDialogManager(); |
- ~ChromeJavaScriptDialogManager() override; |
- |
- base::string16 GetTitle(WebContents* web_contents, |
- const GURL& origin_url, |
- const std::string& accept_lang, |
- bool is_alert); |
- |
- // Wrapper around a DialogClosedCallback so that we can intercept it before |
- // passing it onto the original callback. |
- void OnDialogClosed(WebContents* web_contents, |
- DialogClosedCallback callback, |
- bool success, |
- const base::string16& user_input); |
- |
- // Mapping between the WebContents and their extra data. The key |
- // is a void* because the pointer is just a cookie and is never dereferenced. |
- JavaScriptAppModalDialog::ExtraDataMap javascript_dialog_extra_data_; |
+ // JavaScriptDialogExtensionsClient: |
+ void IncrementLazyKeepaliveCount( |
+ content::WebContents* web_contents) override {} |
+ void DecrementLazyKeepaliveCount( |
+ content::WebContents* web_contents) override {} |
+ bool GetExtensionName(content::WebContents* web_contents, |
+ const GURL& origin_url, |
+ std::string* name_out) override { |
+ return false; |
+ } |
- DISALLOW_COPY_AND_ASSIGN(ChromeJavaScriptDialogManager); |
+ DISALLOW_COPY_AND_ASSIGN(DefaultExtensionsClient); |
}; |
+} // namespace |
+ |
//////////////////////////////////////////////////////////////////////////////// |
-// ChromeJavaScriptDialogManager, public: |
+// JavaScriptDialogManagerImpl, public: |
-ChromeJavaScriptDialogManager::ChromeJavaScriptDialogManager() { |
+JavaScriptDialogManagerImpl::JavaScriptDialogManagerImpl() |
msw
2014/11/05 03:53:56
nit: reorder to match decl.
oshima
2014/11/05 21:42:19
Done.
|
+ : extensions_client_(new DefaultExtensionsClient) { |
} |
-ChromeJavaScriptDialogManager::~ChromeJavaScriptDialogManager() { |
+JavaScriptDialogManagerImpl::~JavaScriptDialogManagerImpl() { |
msw
2014/11/05 03:53:56
nit: reorder to match decl.
oshima
2014/11/05 21:42:19
Done.
|
} |
// static |
-ChromeJavaScriptDialogManager* ChromeJavaScriptDialogManager::GetInstance() { |
- return Singleton<ChromeJavaScriptDialogManager>::get(); |
+JavaScriptDialogManagerImpl* JavaScriptDialogManagerImpl::GetInstance() { |
+ return Singleton<JavaScriptDialogManagerImpl>::get(); |
} |
-void ChromeJavaScriptDialogManager::RunJavaScriptDialog( |
+void JavaScriptDialogManagerImpl::RunJavaScriptDialog( |
WebContents* web_contents, |
const GURL& origin_url, |
const std::string& accept_lang, |
@@ -185,7 +103,7 @@ void ChromeJavaScriptDialogManager::RunJavaScriptDialog( |
base::string16 dialog_title = |
GetTitle(web_contents, origin_url, accept_lang, is_alert); |
- IncrementLazyKeepaliveCount(web_contents); |
+ extensions_client_->IncrementLazyKeepaliveCount(web_contents); |
AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( |
web_contents, |
@@ -197,11 +115,11 @@ void ChromeJavaScriptDialogManager::RunJavaScriptDialog( |
display_suppress_checkbox, |
false, // is_before_unload_dialog |
false, // is_reload |
- base::Bind(&ChromeJavaScriptDialogManager::OnDialogClosed, |
+ base::Bind(&JavaScriptDialogManagerImpl::OnDialogClosed, |
base::Unretained(this), web_contents, callback))); |
} |
-void ChromeJavaScriptDialogManager::RunBeforeUnloadDialog( |
+void JavaScriptDialogManagerImpl::RunBeforeUnloadDialog( |
WebContents* web_contents, |
const base::string16& message_text, |
bool is_reload, |
@@ -214,7 +132,7 @@ void ChromeJavaScriptDialogManager::RunBeforeUnloadDialog( |
base::string16 full_message = |
message_text + base::ASCIIToUTF16("\n\n") + footer; |
- IncrementLazyKeepaliveCount(web_contents); |
+ extensions_client_->IncrementLazyKeepaliveCount(web_contents); |
AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( |
web_contents, |
@@ -226,11 +144,11 @@ void ChromeJavaScriptDialogManager::RunBeforeUnloadDialog( |
false, // display_suppress_checkbox |
true, // is_before_unload_dialog |
is_reload, |
- base::Bind(&ChromeJavaScriptDialogManager::OnDialogClosed, |
+ base::Bind(&JavaScriptDialogManagerImpl::OnDialogClosed, |
base::Unretained(this), web_contents, callback))); |
} |
-bool ChromeJavaScriptDialogManager::HandleJavaScriptDialog( |
+bool JavaScriptDialogManagerImpl::HandleJavaScriptDialog( |
WebContents* web_contents, |
bool accept, |
const base::string16* prompt_override) { |
@@ -252,13 +170,23 @@ bool ChromeJavaScriptDialogManager::HandleJavaScriptDialog( |
return true; |
} |
-void ChromeJavaScriptDialogManager::WebContentsDestroyed( |
+void JavaScriptDialogManagerImpl::WebContentsDestroyed( |
WebContents* web_contents) { |
CancelActiveAndPendingDialogs(web_contents); |
javascript_dialog_extra_data_.erase(web_contents); |
} |
-base::string16 ChromeJavaScriptDialogManager::GetTitle( |
+void JavaScriptDialogManagerImpl::SetNativeDialogFactory( |
+ scoped_ptr<JavaScriptNativeDialogFactory> factory) { |
+ native_dialog_factory_ = factory.Pass(); |
+} |
+ |
+void JavaScriptDialogManagerImpl::SetExtensionsClient( |
+ scoped_ptr<JavaScriptDialogExtensionsClient> extensions_client) { |
+ extensions_client_ = extensions_client.Pass(); |
+} |
+ |
+base::string16 JavaScriptDialogManagerImpl::GetTitle( |
WebContents* web_contents, |
const GURL& origin_url, |
const std::string& accept_lang, |
@@ -272,13 +200,10 @@ 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 (extensions_client_->GetExtensionName(web_contents, origin_url, &name)) { |
msw
2014/11/05 03:53:55
nit: remove curly braces.
oshima
2014/11/05 21:42:19
Done.
|
+ return base::UTF8ToUTF16(name); |
} |
-#endif // defined(ENABLE_EXTENSIONS) |
// Otherwise, return the formatted URL. |
// In this case, force URL to have LTR directionality. |
@@ -289,7 +214,7 @@ base::string16 ChromeJavaScriptDialogManager::GetTitle( |
base::i18n::GetDisplayStringInLTRDirectionality(url_string)); |
} |
-void ChromeJavaScriptDialogManager::CancelActiveAndPendingDialogs( |
+void JavaScriptDialogManagerImpl::CancelActiveAndPendingDialogs( |
WebContents* web_contents) { |
AppModalDialogQueue* queue = AppModalDialogQueue::GetInstance(); |
AppModalDialog* active_dialog = queue->active_dialog(); |
@@ -302,7 +227,7 @@ void ChromeJavaScriptDialogManager::CancelActiveAndPendingDialogs( |
} |
} |
-void ChromeJavaScriptDialogManager::OnDialogClosed( |
+void JavaScriptDialogManagerImpl::OnDialogClosed( |
WebContents* web_contents, |
DialogClosedCallback callback, |
bool success, |
@@ -310,13 +235,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); |
+ extensions_client_->DecrementLazyKeepaliveCount(web_contents); |
callback.Run(success, user_input); |
} |
- |
-} // namespace |
- |
-content::JavaScriptDialogManager* GetJavaScriptDialogManagerInstance() { |
- return ChromeJavaScriptDialogManager::GetInstance(); |
-} |