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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 private: | 42 private: |
43 explicit ChromeJavaScriptDialogCreator(); | 43 explicit ChromeJavaScriptDialogCreator(); |
44 virtual ~ChromeJavaScriptDialogCreator(); | 44 virtual ~ChromeJavaScriptDialogCreator(); |
45 | 45 |
46 friend struct DefaultSingletonTraits<ChromeJavaScriptDialogCreator>; | 46 friend struct DefaultSingletonTraits<ChromeJavaScriptDialogCreator>; |
47 | 47 |
48 string16 GetTitle(TitleType title_type, | 48 string16 GetTitle(TitleType title_type, |
49 const string16& title, | 49 const string16& title, |
50 bool is_alert); | 50 bool is_alert); |
51 | 51 |
| 52 void CancelPendingDialogs(content::DialogDelegate* delegate); |
| 53 |
52 // Mapping between the JavaScriptDialogDelegates and their extra data. The key | 54 // Mapping between the JavaScriptDialogDelegates and their extra data. The key |
53 // is a void* because the pointer is just a cookie and is never dereferenced. | 55 // is a void* because the pointer is just a cookie and is never dereferenced. |
54 typedef std::map<void*, ChromeJavaScriptDialogExtraData> | 56 typedef std::map<void*, ChromeJavaScriptDialogExtraData> |
55 JavaScriptDialogExtraDataMap; | 57 JavaScriptDialogExtraDataMap; |
56 JavaScriptDialogExtraDataMap javascript_dialog_extra_data_; | 58 JavaScriptDialogExtraDataMap javascript_dialog_extra_data_; |
57 }; | 59 }; |
58 | 60 |
59 //------------------------------------------------------------------------------ | 61 //------------------------------------------------------------------------------ |
60 | 62 |
61 ChromeJavaScriptDialogCreator::ChromeJavaScriptDialogCreator() { | 63 ChromeJavaScriptDialogCreator::ChromeJavaScriptDialogCreator() { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 ui::MessageBoxFlags::kIsJavascriptConfirm, | 133 ui::MessageBoxFlags::kIsJavascriptConfirm, |
132 full_message, | 134 full_message, |
133 string16(), // default_prompt_text | 135 string16(), // default_prompt_text |
134 false, // display_suppress_checkbox | 136 false, // display_suppress_checkbox |
135 true, // is_before_unload_dialog | 137 true, // is_before_unload_dialog |
136 reply_message)); | 138 reply_message)); |
137 } | 139 } |
138 | 140 |
139 void ChromeJavaScriptDialogCreator::ResetJavaScriptState( | 141 void ChromeJavaScriptDialogCreator::ResetJavaScriptState( |
140 content::JavaScriptDialogDelegate* delegate) { | 142 content::JavaScriptDialogDelegate* delegate) { |
| 143 CancelPendingDialogs(delegate); |
141 javascript_dialog_extra_data_.erase(delegate); | 144 javascript_dialog_extra_data_.erase(delegate); |
142 } | 145 } |
143 | 146 |
144 string16 ChromeJavaScriptDialogCreator::GetTitle(TitleType title_type, | 147 string16 ChromeJavaScriptDialogCreator::GetTitle(TitleType title_type, |
145 const string16& title, | 148 const string16& title, |
146 bool is_alert) { | 149 bool is_alert) { |
147 switch (title_type) { | 150 switch (title_type) { |
148 case DIALOG_TITLE_NONE: { | 151 case DIALOG_TITLE_NONE: { |
149 return l10n_util::GetStringUTF16( | 152 return l10n_util::GetStringUTF16( |
150 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE | 153 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE |
(...skipping 10 matching lines...) Expand all Loading... |
161 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE | 164 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE |
162 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE, | 165 : IDS_JAVASCRIPT_MESSAGEBOX_TITLE, |
163 base::i18n::GetDisplayStringInLTRDirectionality(title)); | 166 base::i18n::GetDisplayStringInLTRDirectionality(title)); |
164 break; | 167 break; |
165 } | 168 } |
166 } | 169 } |
167 NOTREACHED(); | 170 NOTREACHED(); |
168 return string16(); | 171 return string16(); |
169 } | 172 } |
170 | 173 |
| 174 void ChromeJavaScriptDialogCreator::CancelPendingDialogs( |
| 175 content::DialogDelegate* delegate) { |
| 176 AppModalDialogQueue* queue = AppModalDialogQueue::GetInstance(); |
| 177 for (AppModalDialogQueue::iterator i = queue->begin(); |
| 178 i != queue->end(); ++i) { |
| 179 if ((*i)->delegate() == delegate) |
| 180 (*i)->Invalidate(); |
| 181 } |
| 182 } |
| 183 |
171 //------------------------------------------------------------------------------ | 184 //------------------------------------------------------------------------------ |
172 | 185 |
173 content::JavaScriptDialogCreator* GetJavaScriptDialogCreatorInstance() { | 186 content::JavaScriptDialogCreator* GetJavaScriptDialogCreatorInstance() { |
174 return ChromeJavaScriptDialogCreator::GetInstance(); | 187 return ChromeJavaScriptDialogCreator::GetInstance(); |
175 } | 188 } |
OLD | NEW |