| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" | 5 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" |
| 14 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" | 14 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" |
| 15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 16 #include "content/browser/javascript_dialogs.h" | 16 #include "content/browser/javascript_dialogs.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "ui/base/javascript_message_type.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/message_box_flags.h" | |
| 20 | 20 |
| 21 class ChromeJavaScriptDialogCreator : public content::JavaScriptDialogCreator { | 21 class ChromeJavaScriptDialogCreator : public content::JavaScriptDialogCreator { |
| 22 public: | 22 public: |
| 23 static ChromeJavaScriptDialogCreator* GetInstance(); | 23 static ChromeJavaScriptDialogCreator* GetInstance(); |
| 24 | 24 |
| 25 virtual void RunJavaScriptDialog(content::JavaScriptDialogDelegate* delegate, | 25 virtual void RunJavaScriptDialog( |
| 26 TitleType title_type, | 26 content::JavaScriptDialogDelegate* delegate, |
| 27 const string16& title, | 27 TitleType title_type, |
| 28 int dialog_flags, | 28 const string16& title, |
| 29 const string16& message_text, | 29 ui::JavascriptMessageType javascript_message_type, |
| 30 const string16& default_prompt_text, | 30 const string16& message_text, |
| 31 IPC::Message* reply_message, | 31 const string16& default_prompt_text, |
| 32 bool* did_suppress_message) OVERRIDE; | 32 IPC::Message* reply_message, |
| 33 bool* did_suppress_message) OVERRIDE; |
| 33 | 34 |
| 34 virtual void RunBeforeUnloadDialog( | 35 virtual void RunBeforeUnloadDialog( |
| 35 content::JavaScriptDialogDelegate* delegate, | 36 content::JavaScriptDialogDelegate* delegate, |
| 36 const string16& message_text, | 37 const string16& message_text, |
| 37 IPC::Message* reply_message) OVERRIDE; | 38 IPC::Message* reply_message) OVERRIDE; |
| 38 | 39 |
| 39 virtual void ResetJavaScriptState( | 40 virtual void ResetJavaScriptState( |
| 40 content::JavaScriptDialogDelegate* delegate) OVERRIDE; | 41 content::JavaScriptDialogDelegate* delegate) OVERRIDE; |
| 41 | 42 |
| 42 private: | 43 private: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 | 69 |
| 69 /* static */ | 70 /* static */ |
| 70 ChromeJavaScriptDialogCreator* ChromeJavaScriptDialogCreator::GetInstance() { | 71 ChromeJavaScriptDialogCreator* ChromeJavaScriptDialogCreator::GetInstance() { |
| 71 return Singleton<ChromeJavaScriptDialogCreator>::get(); | 72 return Singleton<ChromeJavaScriptDialogCreator>::get(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void ChromeJavaScriptDialogCreator::RunJavaScriptDialog( | 75 void ChromeJavaScriptDialogCreator::RunJavaScriptDialog( |
| 75 content::JavaScriptDialogDelegate* delegate, | 76 content::JavaScriptDialogDelegate* delegate, |
| 76 TitleType title_type, | 77 TitleType title_type, |
| 77 const string16& title, | 78 const string16& title, |
| 78 int dialog_flags, | 79 ui::JavascriptMessageType javascript_message_type, |
| 79 const string16& message_text, | 80 const string16& message_text, |
| 80 const string16& default_prompt_text, | 81 const string16& default_prompt_text, |
| 81 IPC::Message* reply_message, | 82 IPC::Message* reply_message, |
| 82 bool* did_suppress_message) { | 83 bool* did_suppress_message) { |
| 83 *did_suppress_message = false; | 84 *did_suppress_message = false; |
| 84 | 85 |
| 85 ChromeJavaScriptDialogExtraData* extra_data = | 86 ChromeJavaScriptDialogExtraData* extra_data = |
| 86 &javascript_dialog_extra_data_[delegate]; | 87 &javascript_dialog_extra_data_[delegate]; |
| 87 | 88 |
| 88 if (extra_data->suppress_javascript_messages_) { | 89 if (extra_data->suppress_javascript_messages_) { |
| 89 *did_suppress_message = true; | 90 *did_suppress_message = true; |
| 90 return; | 91 return; |
| 91 } | 92 } |
| 92 | 93 |
| 93 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - | 94 base::TimeDelta time_since_last_message = base::TimeTicks::Now() - |
| 94 extra_data->last_javascript_message_dismissal_; | 95 extra_data->last_javascript_message_dismissal_; |
| 95 bool display_suppress_checkbox = false; | 96 bool display_suppress_checkbox = false; |
| 96 // Show a checkbox offering to suppress further messages if this message is | 97 // Show a checkbox offering to suppress further messages if this message is |
| 97 // being displayed within kJavascriptMessageExpectedDelay of the last one. | 98 // being displayed within kJavascriptMessageExpectedDelay of the last one. |
| 98 if (time_since_last_message < | 99 if (time_since_last_message < |
| 99 base::TimeDelta::FromMilliseconds( | 100 base::TimeDelta::FromMilliseconds( |
| 100 chrome::kJavascriptMessageExpectedDelay)) { | 101 chrome::kJavascriptMessageExpectedDelay)) { |
| 101 display_suppress_checkbox = true; | 102 display_suppress_checkbox = true; |
| 102 } | 103 } |
| 103 | 104 |
| 104 bool is_alert = dialog_flags == ui::MessageBoxFlags::kIsJavascriptAlert; | 105 bool is_alert = javascript_message_type == ui::JAVASCRIPT_MESSAGE_TYPE_ALERT; |
| 105 string16 dialog_title = GetTitle(title_type, title, is_alert); | 106 string16 dialog_title = GetTitle(title_type, title, is_alert); |
| 106 | 107 |
| 107 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( | 108 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( |
| 108 delegate, | 109 delegate, |
| 109 extra_data, | 110 extra_data, |
| 110 dialog_title, | 111 dialog_title, |
| 111 dialog_flags, | 112 javascript_message_type, |
| 112 message_text, | 113 message_text, |
| 113 default_prompt_text, | 114 default_prompt_text, |
| 114 display_suppress_checkbox, | 115 display_suppress_checkbox, |
| 115 false, // is_before_unload_dialog | 116 false, // is_before_unload_dialog |
| 116 reply_message)); | 117 reply_message)); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void ChromeJavaScriptDialogCreator::RunBeforeUnloadDialog( | 120 void ChromeJavaScriptDialogCreator::RunBeforeUnloadDialog( |
| 120 content::JavaScriptDialogDelegate* delegate, | 121 content::JavaScriptDialogDelegate* delegate, |
| 121 const string16& message_text, | 122 const string16& message_text, |
| 122 IPC::Message* reply_message) { | 123 IPC::Message* reply_message) { |
| 123 ChromeJavaScriptDialogExtraData* extra_data = | 124 ChromeJavaScriptDialogExtraData* extra_data = |
| 124 &javascript_dialog_extra_data_[delegate]; | 125 &javascript_dialog_extra_data_[delegate]; |
| 125 | 126 |
| 126 string16 full_message = message_text + ASCIIToUTF16("\n\n") + | 127 string16 full_message = message_text + ASCIIToUTF16("\n\n") + |
| 127 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); | 128 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_FOOTER); |
| 128 | 129 |
| 129 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( | 130 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( |
| 130 delegate, | 131 delegate, |
| 131 extra_data, | 132 extra_data, |
| 132 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE), | 133 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_TITLE), |
| 133 ui::MessageBoxFlags::kIsJavascriptConfirm, | 134 ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM, |
| 134 full_message, | 135 full_message, |
| 135 string16(), // default_prompt_text | 136 string16(), // default_prompt_text |
| 136 false, // display_suppress_checkbox | 137 false, // display_suppress_checkbox |
| 137 true, // is_before_unload_dialog | 138 true, // is_before_unload_dialog |
| 138 reply_message)); | 139 reply_message)); |
| 139 } | 140 } |
| 140 | 141 |
| 141 void ChromeJavaScriptDialogCreator::ResetJavaScriptState( | 142 void ChromeJavaScriptDialogCreator::ResetJavaScriptState( |
| 142 content::JavaScriptDialogDelegate* delegate) { | 143 content::JavaScriptDialogDelegate* delegate) { |
| 143 CancelPendingDialogs(delegate); | 144 CancelPendingDialogs(delegate); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if ((*i)->delegate() == delegate) | 183 if ((*i)->delegate() == delegate) |
| 183 (*i)->Invalidate(); | 184 (*i)->Invalidate(); |
| 184 } | 185 } |
| 185 } | 186 } |
| 186 | 187 |
| 187 //------------------------------------------------------------------------------ | 188 //------------------------------------------------------------------------------ |
| 188 | 189 |
| 189 content::JavaScriptDialogCreator* GetJavaScriptDialogCreatorInstance() { | 190 content::JavaScriptDialogCreator* GetJavaScriptDialogCreatorInstance() { |
| 190 return ChromeJavaScriptDialogCreator::GetInstance(); | 191 return ChromeJavaScriptDialogCreator::GetInstance(); |
| 191 } | 192 } |
| OLD | NEW |