This source file includes following definitions.
- EnforceMaxTextSize
- EnforceMaxPromptSize
- EnforceMaxTextSize
- EnforceMaxPromptSize
- use_override_prompt_text_
- CreateNativeDialog
- IsJavaScriptModalDialog
- Invalidate
- OnCancel
- OnAccept
- OnClose
- SetOverridePromptText
- NotifyDelegate
#include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "ui/gfx/text_elider.h"
#if defined(USE_AURA)
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#endif
using content::JavaScriptDialogManager;
using content::WebContents;
namespace {
#if defined(OS_POSIX) && !defined(OS_MACOSX)
const int kMessageTextMaxRows = 32;
const int kMessageTextMaxCols = 132;
const int kDefaultPromptMaxRows = 24;
const int kDefaultPromptMaxCols = 132;
void EnforceMaxTextSize(const base::string16& in_string,
base::string16* out_string) {
gfx::ElideRectangleString(in_string, kMessageTextMaxRows,
kMessageTextMaxCols, false, out_string);
}
void EnforceMaxPromptSize(const base::string16& in_string,
base::string16* out_string) {
gfx::ElideRectangleString(in_string, kDefaultPromptMaxRows,
kDefaultPromptMaxCols, false, out_string);
}
#else
const int kMessageTextMaxSize = 3000;
const int kDefaultPromptMaxSize = 2000;
void EnforceMaxTextSize(const base::string16& in_string,
base::string16* out_string) {
gfx::ElideString(in_string, kMessageTextMaxSize, out_string);
}
void EnforceMaxPromptSize(const base::string16& in_string,
base::string16* out_string) {
gfx::ElideString(in_string, kDefaultPromptMaxSize, out_string);
}
#endif
}
ChromeJavaScriptDialogExtraData::ChromeJavaScriptDialogExtraData()
: suppress_javascript_messages_(false) {
}
JavaScriptAppModalDialog::JavaScriptAppModalDialog(
WebContents* web_contents,
ExtraDataMap* extra_data_map,
const base::string16& title,
content::JavaScriptMessageType javascript_message_type,
const base::string16& message_text,
const base::string16& default_prompt_text,
bool display_suppress_checkbox,
bool is_before_unload_dialog,
bool is_reload,
const JavaScriptDialogManager::DialogClosedCallback& callback)
: AppModalDialog(web_contents, title),
extra_data_map_(extra_data_map),
javascript_message_type_(javascript_message_type),
display_suppress_checkbox_(display_suppress_checkbox),
is_before_unload_dialog_(is_before_unload_dialog),
is_reload_(is_reload),
callback_(callback),
use_override_prompt_text_(false) {
EnforceMaxTextSize(message_text, &message_text_);
EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_);
}
JavaScriptAppModalDialog::~JavaScriptAppModalDialog() {
}
NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() {
gfx::NativeWindow parent_window =
web_contents()->GetView()->GetTopLevelNativeWindow();
#if defined(USE_AURA)
if (!parent_window->GetRootWindow()) {
parent_window = NULL;
}
#endif
return NativeAppModalDialog::CreateNativeJavaScriptPrompt(this,
parent_window);
}
bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() {
return true;
}
void JavaScriptAppModalDialog::Invalidate() {
if (!IsValid())
return;
AppModalDialog::Invalidate();
if (!callback_.is_null()) {
callback_.Run(false, base::string16());
callback_.Reset();
}
if (native_dialog())
CloseModalDialog();
}
void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) {
CompleteDialog();
NotifyDelegate(false, base::string16(), suppress_js_messages);
}
void JavaScriptAppModalDialog::OnAccept(const base::string16& prompt_text,
bool suppress_js_messages) {
base::string16 prompt_text_to_use = prompt_text;
if (use_override_prompt_text_)
prompt_text_to_use = override_prompt_text_;
CompleteDialog();
NotifyDelegate(true, prompt_text_to_use, suppress_js_messages);
}
void JavaScriptAppModalDialog::OnClose() {
NotifyDelegate(false, base::string16(), false);
}
void JavaScriptAppModalDialog::SetOverridePromptText(
const base::string16& override_prompt_text) {
override_prompt_text_ = override_prompt_text;
use_override_prompt_text_ = true;
}
void JavaScriptAppModalDialog::NotifyDelegate(bool success,
const base::string16& user_input,
bool suppress_js_messages) {
if (!IsValid())
return;
if (!callback_.is_null()) {
callback_.Run(success, user_input);
callback_.Reset();
}
ExtraDataMap::iterator extra_data = extra_data_map_->find(web_contents());
if (extra_data != extra_data_map_->end()) {
extra_data->second.last_javascript_message_dismissal_ =
base::TimeTicks::Now();
extra_data->second.suppress_javascript_messages_ = suppress_js_messages;
}
AppModalDialog::Invalidate();
}