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

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

Issue 1638013002: Add UMA histograms to track very brief or frequent tabs and JS dialogs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename histograms; ignore blocked JS dialogs Created 4 years, 10 months 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/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
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
97 AppModalDialog::Invalidate(); 100 AppModalDialog::Invalidate();
98 if (!callback_.is_null()) { 101 CallDialogClosedCallback(false, base::string16());
99 callback_.Run(false, base::string16());
100 callback_.Reset();
101 }
102 if (native_dialog()) 102 if (native_dialog())
103 CloseModalDialog(); 103 CloseModalDialog();
104 } 104 }
105 105
106 void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) { 106 void JavaScriptAppModalDialog::OnCancel(bool suppress_js_messages) {
107 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame 107 // We need to do this before WM_DESTROY (WindowClosing()) as any parent frame
108 // will receive its activation messages before this dialog receives 108 // will receive its activation messages before this dialog receives
109 // WM_DESTROY. The parent frame would then try to activate any modal dialogs 109 // WM_DESTROY. The parent frame would then try to activate any modal dialogs
110 // that were still open in the ModalDialogQueue, which would send activation 110 // that were still open in the ModalDialogQueue, which would send activation
111 // back to this one. The framework should be improved to handle this, so this 111 // back to this one. The framework should be improved to handle this, so this
(...skipping 23 matching lines...) Expand all
135 override_prompt_text_ = override_prompt_text; 135 override_prompt_text_ = override_prompt_text;
136 use_override_prompt_text_ = true; 136 use_override_prompt_text_ = true;
137 } 137 }
138 138
139 void JavaScriptAppModalDialog::NotifyDelegate(bool success, 139 void JavaScriptAppModalDialog::NotifyDelegate(bool success,
140 const base::string16& user_input, 140 const base::string16& user_input,
141 bool suppress_js_messages) { 141 bool suppress_js_messages) {
142 if (!IsValid()) 142 if (!IsValid())
143 return; 143 return;
144 144
145 if (!callback_.is_null()) { 145 CallDialogClosedCallback(success, user_input);
146 callback_.Run(success, user_input);
147 callback_.Reset();
148 }
149 146
150 // The callback_ above may delete web_contents_, thus removing the extra 147 // The close callback above may delete web_contents_, thus removing the extra
151 // data from the map owned by ::JavaScriptDialogManager. Make sure 148 // data from the map owned by ::JavaScriptDialogManager. Make sure
152 // to only use the data if still present. http://crbug.com/236476 149 // to only use the data if still present. http://crbug.com/236476
153 ExtraDataMap::iterator extra_data = 150 ExtraDataMap::iterator extra_data =
154 extra_data_map_->find(GetSerializedOriginForWebContents(web_contents())); 151 extra_data_map_->find(GetSerializedOriginForWebContents(web_contents()));
155 if (extra_data != extra_data_map_->end()) { 152 if (extra_data != extra_data_map_->end()) {
156 extra_data->second.has_already_shown_a_dialog_ = true; 153 extra_data->second.has_already_shown_a_dialog_ = true;
157 extra_data->second.suppress_javascript_messages_ = suppress_js_messages; 154 extra_data->second.suppress_javascript_messages_ = suppress_js_messages;
158 } 155 }
159 156
160 // On Views, we can end up coming through this code path twice :(. 157 // On Views, we can end up coming through this code path twice :(.
161 // See crbug.com/63732. 158 // See crbug.com/63732.
162 AppModalDialog::Invalidate(); 159 AppModalDialog::Invalidate();
163 } 160 }
164 161
162 void JavaScriptAppModalDialog::CallDialogClosedCallback(bool success,
163 const base::string16& user_input) {
164 // TODO(joenotcharles): Both the callers of this function also check IsValid
165 // and call AppModalDialog::Invalidate, but in different orders. If the
166 // difference is not significant, more common code could be moved here.
Avi (use Gerrit) 2016/01/30 04:41:31 It's probably not significant, but I'm not 100% su
167 UMA_HISTOGRAM_MEDIUM_TIMES(
168 "JSDialogs.FineTiming.TimeBetweenDialogCreatedAndSameDialogClosed",
169 base::TimeTicks::Now() - creation_time_);
170 if (!callback_.is_null()) {
171 callback_.Run(success, user_input);
172 callback_.Reset();
173 }
174 }
175
165 // static 176 // static
166 std::string JavaScriptAppModalDialog::GetSerializedOriginForWebContents( 177 std::string JavaScriptAppModalDialog::GetSerializedOriginForWebContents(
167 content::WebContents* contents) { 178 content::WebContents* contents) {
168 if (!contents) 179 if (!contents)
169 return url::Origin().Serialize(); 180 return url::Origin().Serialize();
170 return url::Origin(contents->GetLastCommittedURL()).Serialize(); 181 return url::Origin(contents->GetLastCommittedURL()).Serialize();
171 } 182 }
172 183
173 } // namespace app_modal 184 } // namespace app_modal
OLDNEW
« no previous file with comments | « components/app_modal/javascript_app_modal_dialog.h ('k') | components/app_modal/javascript_dialog_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698