electron/atom/browser/atom_javascript_dialog_manager.cc

71 lines
2.2 KiB
C++
Raw Normal View History

// Copyright (c) 2013 GitHub, Inc.
2014-04-25 09:49:37 +00:00
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
2014-03-16 00:30:26 +00:00
#include "atom/browser/atom_javascript_dialog_manager.h"
#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 "ui/gfx/image/image_skia.h"
using content::JavaScriptMessageType;
namespace atom {
2014-03-01 11:53:50 +00:00
void AtomJavaScriptDialogManager::RunJavaScriptDialog(
content::WebContents* web_contents,
const GURL& origin_url,
JavaScriptMessageType message_type,
2014-06-28 11:36:57 +00:00
const base::string16& message_text,
const base::string16& default_prompt_text,
2014-03-01 11:53:50 +00:00
const DialogClosedCallback& callback,
bool* did_suppress_message) {
if (message_type != JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_ALERT &&
message_type != JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) {
callback.Run(false, base::string16());
return;
}
2017-01-06 16:53:06 +00:00
std::vector<std::string> buttons = {"OK"};
if (message_type == JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) {
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), "", "", false,
gfx::ImageSkia(),
base::Bind(&OnMessageBoxCallback, callback));
2014-03-01 11:53:50 +00:00
}
void AtomJavaScriptDialogManager::RunBeforeUnloadDialog(
content::WebContents* web_contents,
bool is_reload,
const DialogClosedCallback& callback) {
2016-05-23 01:59:39 +00:00
// FIXME(zcbenz): the |message_text| is removed, figure out what should we do.
callback.Run(false, base::ASCIIToUTF16("This should not be displayed"));
}
2017-01-24 03:18:56 +00:00
void AtomJavaScriptDialogManager::CancelDialogs(
content::WebContents* web_contents,
bool suppress_callbacks,
bool reset_state) {
}
// static
void AtomJavaScriptDialogManager::OnMessageBoxCallback(
const DialogClosedCallback& callback,
int code,
bool checkbox_checked) {
callback.Run(code == 0, base::string16());
}
} // namespace atom