Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: components/app_modal_dialogs/javascript_app_modal_dialog.cc

Issue 688853005: Consolidate javascript_dialog_manager.h and javascript_dialog_manager_impl.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
20 namespace { 19 namespace {
21 20
22 // Control maximum sizes of various texts passed to us from javascript. 21 // Control maximum sizes of various texts passed to us from javascript.
23 #if defined(OS_POSIX) && !defined(OS_MACOSX) 22 #if defined(OS_POSIX) && !defined(OS_MACOSX)
24 // Two-dimensional eliding. Reformat the text of the message dialog 23 // Two-dimensional eliding. Reformat the text of the message dialog
25 // inserting line breaks because otherwise a single long line can overflow 24 // inserting line breaks because otherwise a single long line can overflow
26 // the message dialog (and crash/hang the GTK, depending on the version). 25 // the message dialog (and crash/hang the GTK, depending on the version).
27 const int kMessageTextMaxRows = 32; 26 const int kMessageTextMaxRows = 32;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 JavaScriptAppModalDialog::JavaScriptAppModalDialog( 61 JavaScriptAppModalDialog::JavaScriptAppModalDialog(
63 WebContents* web_contents, 62 WebContents* web_contents,
64 ExtraDataMap* extra_data_map, 63 ExtraDataMap* extra_data_map,
65 const base::string16& title, 64 const base::string16& title,
66 content::JavaScriptMessageType javascript_message_type, 65 content::JavaScriptMessageType javascript_message_type,
67 const base::string16& message_text, 66 const base::string16& message_text,
68 const base::string16& default_prompt_text, 67 const base::string16& default_prompt_text,
69 bool display_suppress_checkbox, 68 bool display_suppress_checkbox,
70 bool is_before_unload_dialog, 69 bool is_before_unload_dialog,
71 bool is_reload, 70 bool is_reload,
72 const JavaScriptDialogManager::DialogClosedCallback& callback) 71 const content::JavaScriptDialogManager::DialogClosedCallback& callback)
73 : AppModalDialog(web_contents, title), 72 : AppModalDialog(web_contents, title),
74 extra_data_map_(extra_data_map), 73 extra_data_map_(extra_data_map),
75 javascript_message_type_(javascript_message_type), 74 javascript_message_type_(javascript_message_type),
76 display_suppress_checkbox_(display_suppress_checkbox), 75 display_suppress_checkbox_(display_suppress_checkbox),
77 is_before_unload_dialog_(is_before_unload_dialog), 76 is_before_unload_dialog_(is_before_unload_dialog),
78 is_reload_(is_reload), 77 is_reload_(is_reload),
79 callback_(callback), 78 callback_(callback),
80 use_override_prompt_text_(false) { 79 use_override_prompt_text_(false) {
81 EnforceMaxTextSize(message_text, &message_text_); 80 EnforceMaxTextSize(message_text, &message_text_);
82 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_); 81 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_);
83 } 82 }
84 83
85 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { 84 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() {
86 } 85 }
87 86
88 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { 87 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() {
89 gfx::NativeWindow parent_window = web_contents()->GetTopLevelNativeWindow(); 88 gfx::NativeWindow parent_window = web_contents()->GetTopLevelNativeWindow();
90 89
91 #if defined(USE_AURA) 90 #if defined(USE_AURA)
92 if (!parent_window->GetRootWindow()) { 91 if (!parent_window->GetRootWindow()) {
93 // When we are part of a WebContents that isn't actually being displayed on 92 // When we are part of a WebContents that isn't actually being displayed on
94 // the screen, we can't actually attach to it. 93 // the screen, we can't actually attach to it.
95 parent_window = NULL; 94 parent_window = NULL;
96 } 95 }
97 #endif // defined(USE_AURA) 96 #endif // defined(USE_AURA)
98 return JavaScriptDialogManagerImpl::GetInstance()->native_dialog_factory()-> 97 return JavaScriptDialogManager::GetInstance()->native_dialog_factory()->
99 CreateNativeJavaScriptDialog(this, parent_window); 98 CreateNativeJavaScriptDialog(this, parent_window);
100 } 99 }
101 100
102 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { 101 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() {
103 return true; 102 return true;
104 } 103 }
105 104
106 void JavaScriptAppModalDialog::Invalidate() { 105 void JavaScriptAppModalDialog::Invalidate() {
107 if (!IsValid()) 106 if (!IsValid())
108 return; 107 return;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 bool suppress_js_messages) { 153 bool suppress_js_messages) {
155 if (!IsValid()) 154 if (!IsValid())
156 return; 155 return;
157 156
158 if (!callback_.is_null()) { 157 if (!callback_.is_null()) {
159 callback_.Run(success, user_input); 158 callback_.Run(success, user_input);
160 callback_.Reset(); 159 callback_.Reset();
161 } 160 }
162 161
163 // The callback_ above may delete web_contents_, thus removing the extra 162 // The callback_ above may delete web_contents_, thus removing the extra
164 // data from the map owned by ChromeJavaScriptDialogManager. Make sure 163 // data from the map owned by ::JavaScriptDialogManager. Make sure
165 // to only use the data if still present. http://crbug.com/236476 164 // to only use the data if still present. http://crbug.com/236476
166 ExtraDataMap::iterator extra_data = extra_data_map_->find(web_contents()); 165 ExtraDataMap::iterator extra_data = extra_data_map_->find(web_contents());
167 if (extra_data != extra_data_map_->end()) { 166 if (extra_data != extra_data_map_->end()) {
168 extra_data->second.last_javascript_message_dismissal_ = 167 extra_data->second.last_javascript_message_dismissal_ =
169 base::TimeTicks::Now(); 168 base::TimeTicks::Now();
170 extra_data->second.suppress_javascript_messages_ = suppress_js_messages; 169 extra_data->second.suppress_javascript_messages_ = suppress_js_messages;
171 } 170 }
172 171
173 // On Views, we can end up coming through this code path twice :(. 172 // On Views, we can end up coming through this code path twice :(.
174 // See crbug.com/63732. 173 // See crbug.com/63732.
175 AppModalDialog::Invalidate(); 174 AppModalDialog::Invalidate();
176 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698