Implement alert/confirm through dialog manager
This commit is contained in:
parent
52390120ae
commit
1f08634d62
2 changed files with 42 additions and 2 deletions
|
@ -5,20 +5,50 @@
|
||||||
#include "atom/browser/atom_javascript_dialog_manager.h"
|
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "atom/browser/native_window.h"
|
||||||
|
#include "atom/browser/ui/message_box.h"
|
||||||
|
#include "base/bind.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
|
#include "ui/gfx/image/image_skia.h"
|
||||||
|
|
||||||
|
using content::JavaScriptMessageType;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
void AtomJavaScriptDialogManager::RunJavaScriptDialog(
|
void AtomJavaScriptDialogManager::RunJavaScriptDialog(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
const GURL& origin_url,
|
const GURL& origin_url,
|
||||||
content::JavaScriptMessageType javascript_message_type,
|
JavaScriptMessageType message_type,
|
||||||
const base::string16& message_text,
|
const base::string16& message_text,
|
||||||
const base::string16& default_prompt_text,
|
const base::string16& default_prompt_text,
|
||||||
const DialogClosedCallback& callback,
|
const DialogClosedCallback& callback,
|
||||||
bool* did_suppress_message) {
|
bool* did_suppress_message) {
|
||||||
callback.Run(false, base::string16());
|
|
||||||
|
if (message_type != JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_ALERT &&
|
||||||
|
message_type != JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) {
|
||||||
|
callback.Run(false, base::string16());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> buttons;
|
||||||
|
if (message_type == JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) {
|
||||||
|
buttons.push_back("OK");
|
||||||
|
buttons.push_back("Cancel");
|
||||||
|
}
|
||||||
|
|
||||||
|
atom::ShowMessageBox(NativeWindow::FromWebContents(web_contents),
|
||||||
|
atom::MessageBoxType::MESSAGE_BOX_TYPE_NONE,
|
||||||
|
buttons,
|
||||||
|
-1,
|
||||||
|
0,
|
||||||
|
atom::MessageBoxOptions::MESSAGE_BOX_NONE,
|
||||||
|
"",
|
||||||
|
base::UTF16ToUTF8(message_text),
|
||||||
|
"",
|
||||||
|
gfx::ImageSkia(),
|
||||||
|
base::Bind(&OnMessageBoxCallback, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomJavaScriptDialogManager::RunBeforeUnloadDialog(
|
void AtomJavaScriptDialogManager::RunBeforeUnloadDialog(
|
||||||
|
@ -29,4 +59,10 @@ void AtomJavaScriptDialogManager::RunBeforeUnloadDialog(
|
||||||
callback.Run(false, base::ASCIIToUTF16("This should not be displayed"));
|
callback.Run(false, base::ASCIIToUTF16("This should not be displayed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void AtomJavaScriptDialogManager::OnMessageBoxCallback(
|
||||||
|
const DialogClosedCallback& callback, int code) {
|
||||||
|
callback.Run(code == 0, base::string16());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -29,6 +29,10 @@ class AtomJavaScriptDialogManager : public content::JavaScriptDialogManager {
|
||||||
void CancelActiveAndPendingDialogs(
|
void CancelActiveAndPendingDialogs(
|
||||||
content::WebContents* web_contents) override {}
|
content::WebContents* web_contents) override {}
|
||||||
void ResetDialogState(content::WebContents* web_contents) override {};
|
void ResetDialogState(content::WebContents* web_contents) override {};
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void OnMessageBoxCallback(const DialogClosedCallback& callback,
|
||||||
|
int code);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue