| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/app_modal_dialogs/javascript_app_modal_dialog.h" | 5 #include "components/app_modal_dialogs/javascript_app_modal_dialog.h" |
| 6 | 6 |
| 7 #include "components/app_modal_dialogs/javascript_dialog_manager_impl.h" | 7 #include "components/app_modal_dialogs/javascript_dialog_manager.h" |
| 8 #include "components/app_modal_dialogs/javascript_native_dialog_factory.h" | 8 #include "components/app_modal_dialogs/javascript_native_dialog_factory.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "ui/gfx/text_elider.h" | 10 #include "ui/gfx/text_elider.h" |
| 11 | 11 |
| 12 #if defined(USE_AURA) | 12 #if defined(USE_AURA) |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 using content::JavaScriptDialogManager; | |
| 18 using content::WebContents; | 17 using content::WebContents; |
| 19 | 18 |
| 19 namespace app_modal_dialogs { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Control maximum sizes of various texts passed to us from javascript. | 22 // Control maximum sizes of various texts passed to us from javascript. |
| 23 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 23 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 24 // Two-dimensional eliding. Reformat the text of the message dialog | 24 // Two-dimensional eliding. Reformat the text of the message dialog |
| 25 // inserting line breaks because otherwise a single long line can overflow | 25 // inserting line breaks because otherwise a single long line can overflow |
| 26 // the message dialog (and crash/hang the GTK, depending on the version). | 26 // the message dialog (and crash/hang the GTK, depending on the version). |
| 27 const int kMessageTextMaxRows = 32; | 27 const int kMessageTextMaxRows = 32; |
| 28 const int kMessageTextMaxCols = 132; | 28 const int kMessageTextMaxCols = 132; |
| 29 const int kDefaultPromptMaxRows = 24; | 29 const int kDefaultPromptMaxRows = 24; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 JavaScriptAppModalDialog::JavaScriptAppModalDialog( | 62 JavaScriptAppModalDialog::JavaScriptAppModalDialog( |
| 63 WebContents* web_contents, | 63 WebContents* web_contents, |
| 64 ExtraDataMap* extra_data_map, | 64 ExtraDataMap* extra_data_map, |
| 65 const base::string16& title, | 65 const base::string16& title, |
| 66 content::JavaScriptMessageType javascript_message_type, | 66 content::JavaScriptMessageType javascript_message_type, |
| 67 const base::string16& message_text, | 67 const base::string16& message_text, |
| 68 const base::string16& default_prompt_text, | 68 const base::string16& default_prompt_text, |
| 69 bool display_suppress_checkbox, | 69 bool display_suppress_checkbox, |
| 70 bool is_before_unload_dialog, | 70 bool is_before_unload_dialog, |
| 71 bool is_reload, | 71 bool is_reload, |
| 72 const JavaScriptDialogManager::DialogClosedCallback& callback) | 72 const content::JavaScriptDialogManager::DialogClosedCallback& callback) |
| 73 : AppModalDialog(web_contents, title), | 73 : AppModalDialog(web_contents, title), |
| 74 extra_data_map_(extra_data_map), | 74 extra_data_map_(extra_data_map), |
| 75 javascript_message_type_(javascript_message_type), | 75 javascript_message_type_(javascript_message_type), |
| 76 display_suppress_checkbox_(display_suppress_checkbox), | 76 display_suppress_checkbox_(display_suppress_checkbox), |
| 77 is_before_unload_dialog_(is_before_unload_dialog), | 77 is_before_unload_dialog_(is_before_unload_dialog), |
| 78 is_reload_(is_reload), | 78 is_reload_(is_reload), |
| 79 callback_(callback), | 79 callback_(callback), |
| 80 use_override_prompt_text_(false) { | 80 use_override_prompt_text_(false) { |
| 81 EnforceMaxTextSize(message_text, &message_text_); | 81 EnforceMaxTextSize(message_text, &message_text_); |
| 82 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_); | 82 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_); |
| 83 } | 83 } |
| 84 | 84 |
| 85 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { | 85 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { |
| 86 } | 86 } |
| 87 | 87 |
| 88 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { | 88 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { |
| 89 gfx::NativeWindow parent_window = web_contents()->GetTopLevelNativeWindow(); | 89 gfx::NativeWindow parent_window = web_contents()->GetTopLevelNativeWindow(); |
| 90 | 90 |
| 91 #if defined(USE_AURA) | 91 #if defined(USE_AURA) |
| 92 if (!parent_window->GetRootWindow()) { | 92 if (!parent_window->GetRootWindow()) { |
| 93 // When we are part of a WebContents that isn't actually being displayed on | 93 // When we are part of a WebContents that isn't actually being displayed on |
| 94 // the screen, we can't actually attach to it. | 94 // the screen, we can't actually attach to it. |
| 95 parent_window = NULL; | 95 parent_window = NULL; |
| 96 } | 96 } |
| 97 #endif // defined(USE_AURA) | 97 #endif // defined(USE_AURA) |
| 98 return JavaScriptDialogManagerImpl::GetInstance()->native_dialog_factory()-> | 98 return JavaScriptDialogManager::GetInstance()->native_dialog_factory()-> |
| 99 CreateNativeJavaScriptDialog(this, parent_window); | 99 CreateNativeJavaScriptDialog(this, parent_window); |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { | 102 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { |
| 103 return true; | 103 return true; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void JavaScriptAppModalDialog::Invalidate() { | 106 void JavaScriptAppModalDialog::Invalidate() { |
| 107 if (!IsValid()) | 107 if (!IsValid()) |
| 108 return; | 108 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 bool suppress_js_messages) { | 154 bool suppress_js_messages) { |
| 155 if (!IsValid()) | 155 if (!IsValid()) |
| 156 return; | 156 return; |
| 157 | 157 |
| 158 if (!callback_.is_null()) { | 158 if (!callback_.is_null()) { |
| 159 callback_.Run(success, user_input); | 159 callback_.Run(success, user_input); |
| 160 callback_.Reset(); | 160 callback_.Reset(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // The callback_ above may delete web_contents_, thus removing the extra | 163 // The callback_ above may delete web_contents_, thus removing the extra |
| 164 // data from the map owned by ChromeJavaScriptDialogManager. Make sure | 164 // data from the map owned by ::JavaScriptDialogManager. Make sure |
| 165 // to only use the data if still present. http://crbug.com/236476 | 165 // to only use the data if still present. http://crbug.com/236476 |
| 166 ExtraDataMap::iterator extra_data = extra_data_map_->find(web_contents()); | 166 ExtraDataMap::iterator extra_data = extra_data_map_->find(web_contents()); |
| 167 if (extra_data != extra_data_map_->end()) { | 167 if (extra_data != extra_data_map_->end()) { |
| 168 extra_data->second.last_javascript_message_dismissal_ = | 168 extra_data->second.last_javascript_message_dismissal_ = |
| 169 base::TimeTicks::Now(); | 169 base::TimeTicks::Now(); |
| 170 extra_data->second.suppress_javascript_messages_ = suppress_js_messages; | 170 extra_data->second.suppress_javascript_messages_ = suppress_js_messages; |
| 171 } | 171 } |
| 172 | 172 |
| 173 // On Views, we can end up coming through this code path twice :(. | 173 // On Views, we can end up coming through this code path twice :(. |
| 174 // See crbug.com/63732. | 174 // See crbug.com/63732. |
| 175 AppModalDialog::Invalidate(); | 175 AppModalDialog::Invalidate(); |
| 176 } | 176 } |
| 177 |
| 178 } // namespace app_modal_dialogs |
| OLD | NEW |