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/javascript_app_modal_dialog.h" | 5 #include "components/app_modal/javascript_app_modal_dialog.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | |
8 #include "base/time/time.h" | |
7 #include "build/build_config.h" | 9 #include "build/build_config.h" |
8 #include "components/app_modal/javascript_dialog_manager.h" | 10 #include "components/app_modal/javascript_dialog_manager.h" |
9 #include "components/app_modal/javascript_native_dialog_factory.h" | 11 #include "components/app_modal/javascript_native_dialog_factory.h" |
10 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
11 #include "ui/gfx/text_elider.h" | 13 #include "ui/gfx/text_elider.h" |
12 #include "url/origin.h" | 14 #include "url/origin.h" |
13 | 15 |
14 namespace app_modal { | 16 namespace app_modal { |
15 namespace { | 17 namespace { |
16 | 18 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 bool is_before_unload_dialog, | 67 bool is_before_unload_dialog, |
66 bool is_reload, | 68 bool is_reload, |
67 const content::JavaScriptDialogManager::DialogClosedCallback& callback) | 69 const content::JavaScriptDialogManager::DialogClosedCallback& callback) |
68 : AppModalDialog(web_contents, title), | 70 : AppModalDialog(web_contents, title), |
69 extra_data_map_(extra_data_map), | 71 extra_data_map_(extra_data_map), |
70 javascript_message_type_(javascript_message_type), | 72 javascript_message_type_(javascript_message_type), |
71 display_suppress_checkbox_(display_suppress_checkbox), | 73 display_suppress_checkbox_(display_suppress_checkbox), |
72 is_before_unload_dialog_(is_before_unload_dialog), | 74 is_before_unload_dialog_(is_before_unload_dialog), |
73 is_reload_(is_reload), | 75 is_reload_(is_reload), |
74 callback_(callback), | 76 callback_(callback), |
75 use_override_prompt_text_(false) { | 77 use_override_prompt_text_(false), |
78 creation_time_(base::TimeTicks::Now()) { | |
76 EnforceMaxTextSize(message_text, &message_text_); | 79 EnforceMaxTextSize(message_text, &message_text_); |
77 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_); | 80 EnforceMaxPromptSize(default_prompt_text, &default_prompt_text_); |
78 } | 81 } |
79 | 82 |
80 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { | 83 JavaScriptAppModalDialog::~JavaScriptAppModalDialog() { |
81 } | 84 } |
82 | 85 |
83 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { | 86 NativeAppModalDialog* JavaScriptAppModalDialog::CreateNativeDialog() { |
84 return JavaScriptDialogManager::GetInstance() | 87 return JavaScriptDialogManager::GetInstance() |
85 ->native_dialog_factory() | 88 ->native_dialog_factory() |
86 ->CreateNativeJavaScriptDialog(this); | 89 ->CreateNativeJavaScriptDialog(this); |
87 } | 90 } |
88 | 91 |
89 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { | 92 bool JavaScriptAppModalDialog::IsJavaScriptModalDialog() { |
90 return true; | 93 return true; |
91 } | 94 } |
92 | 95 |
93 void JavaScriptAppModalDialog::Invalidate() { | 96 void JavaScriptAppModalDialog::Invalidate() { |
94 if (!IsValid()) | 97 if (!IsValid()) |
95 return; | 98 return; |
96 | 99 |
100 UMA_HISTOGRAM_FINE_TIMES_100("JSDialogs.FineTiming.DialogLifetime", | |
101 base::TimeTicks::Now() - creation_time_); | |
Ilya Sherman
2016/01/26 22:39:04
Is this intentionally the same histogram name as t
Joe Mason
2016/01/27 19:43:50
Done.
| |
102 | |
97 AppModalDialog::Invalidate(); | 103 AppModalDialog::Invalidate(); |
98 if (!callback_.is_null()) { | 104 if (!callback_.is_null()) { |
99 callback_.Run(false, base::string16()); | 105 callback_.Run(false, base::string16()); |
100 callback_.Reset(); | 106 callback_.Reset(); |
101 } | 107 } |
102 if (native_dialog()) | 108 if (native_dialog()) |
103 CloseModalDialog(); | 109 CloseModalDialog(); |
104 } | 110 } |
105 | 111 |
106 void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) { | 112 void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) { |
(...skipping 28 matching lines...) Expand all Loading... | |
135 override_prompt_text_ = override_prompt_text; | 141 override_prompt_text_ = override_prompt_text; |
136 use_override_prompt_text_ = true; | 142 use_override_prompt_text_ = true; |
137 } | 143 } |
138 | 144 |
139 void JavaScriptAppModalDialog::NotifyDelegate(bool success, | 145 void JavaScriptAppModalDialog::NotifyDelegate(bool success, |
140 const base::string16& user_input, | 146 const base::string16& user_input, |
141 bool suppress_js_messages) { | 147 bool suppress_js_messages) { |
142 if (!IsValid()) | 148 if (!IsValid()) |
143 return; | 149 return; |
144 | 150 |
151 UMA_HISTOGRAM_FINE_TIMES_100("JSDialogs.FineTiming.DialogLifetime", | |
152 base::TimeTicks::Now() - creation_time_); | |
Ilya Sherman
2016/01/26 22:39:04
This histogram is designed to distinguish a dialog
Joe Mason
2016/01/27 16:51:21
An example question I'm trying to answer with this
Ilya Sherman
2016/01/28 05:25:26
Okay. I guess it's okay to land these histograms
| |
153 | |
145 if (!callback_.is_null()) { | 154 if (!callback_.is_null()) { |
146 callback_.Run(success, user_input); | 155 callback_.Run(success, user_input); |
147 callback_.Reset(); | 156 callback_.Reset(); |
148 } | 157 } |
149 | 158 |
150 // The callback_ above may delete web_contents_, thus removing the extra | 159 // The callback_ above may delete web_contents_, thus removing the extra |
151 // data from the map owned by ::JavaScriptDialogManager. Make sure | 160 // data from the map owned by ::JavaScriptDialogManager. Make sure |
152 // to only use the data if still present. http://crbug.com/236476 | 161 // to only use the data if still present. http://crbug.com/236476 |
153 ExtraDataMap::iterator extra_data = | 162 ExtraDataMap::iterator extra_data = |
154 extra_data_map_->find(GetSerializedOriginForWebContents(web_contents())); | 163 extra_data_map_->find(GetSerializedOriginForWebContents(web_contents())); |
155 if (extra_data != extra_data_map_->end()) { | 164 if (extra_data != extra_data_map_->end()) { |
156 extra_data->second.has_already_shown_a_dialog_ = true; | 165 extra_data->second.has_already_shown_a_dialog_ = true; |
157 extra_data->second.suppress_javascript_messages_ = suppress_js_messages; | 166 extra_data->second.suppress_javascript_messages_ = suppress_js_messages; |
158 } | 167 } |
159 | 168 |
160 // On Views, we can end up coming through this code path twice :(. | 169 // On Views, we can end up coming through this code path twice :(. |
161 // See crbug.com/63732. | 170 // See crbug.com/63732. |
162 AppModalDialog::Invalidate(); | 171 AppModalDialog::Invalidate(); |
163 } | 172 } |
164 | 173 |
165 // static | 174 // static |
166 std::string JavaScriptAppModalDialog::GetSerializedOriginForWebContents( | 175 std::string JavaScriptAppModalDialog::GetSerializedOriginForWebContents( |
167 content::WebContents* contents) { | 176 content::WebContents* contents) { |
168 if (!contents) | 177 if (!contents) |
169 return url::Origin().Serialize(); | 178 return url::Origin().Serialize(); |
170 return url::Origin(contents->GetLastCommittedURL()).Serialize(); | 179 return url::Origin(contents->GetLastCommittedURL()).Serialize(); |
171 } | 180 } |
172 | 181 |
173 } // namespace app_modal | 182 } // namespace app_modal |
OLD | NEW |