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

Side by Side Diff: chrome/browser/ui/android/javascript_app_modal_dialog_android.cc

Issue 2628943003: Add metrics for triggering of JS dialogs on Android. (Closed)
Patch Set: Rebase and updated comment Created 3 years, 11 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
« no previous file with comments | « chrome/browser/android/tab_android.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/ui/android/javascript_app_modal_dialog_android.h" 5 #include "chrome/browser/ui/android/javascript_app_modal_dialog_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram_macros.h"
12 #include "chrome/browser/android/tab_android.h"
11 #include "chrome/browser/ui/javascript_dialogs/chrome_javascript_native_dialog_f actory.h" 13 #include "chrome/browser/ui/javascript_dialogs/chrome_javascript_native_dialog_f actory.h"
12 #include "components/app_modal/app_modal_dialog_queue.h" 14 #include "components/app_modal/app_modal_dialog_queue.h"
13 #include "components/app_modal/javascript_app_modal_dialog.h" 15 #include "components/app_modal/javascript_app_modal_dialog.h"
14 #include "components/app_modal/javascript_dialog_manager.h" 16 #include "components/app_modal/javascript_dialog_manager.h"
15 #include "components/app_modal/javascript_native_dialog_factory.h" 17 #include "components/app_modal/javascript_native_dialog_factory.h"
16 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_delegate.h" 20 #include "content/public/browser/web_contents_delegate.h"
19 #include "content/public/common/javascript_message_type.h" 21 #include "content/public/common/javascript_message_type.h"
20 #include "jni/JavascriptAppModalDialog_jni.h" 22 #include "jni/JavascriptAppModalDialog_jni.h"
(...skipping 18 matching lines...) Expand all
39 return 0; 41 return 0;
40 } 42 }
41 43
42 void JavascriptAppModalDialogAndroid::ShowAppModalDialog() { 44 void JavascriptAppModalDialogAndroid::ShowAppModalDialog() {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
44 46
45 JNIEnv* env = AttachCurrentThread(); 47 JNIEnv* env = AttachCurrentThread();
46 // Keep a strong ref to the parent window while we make the call to java to 48 // Keep a strong ref to the parent window while we make the call to java to
47 // display the dialog. 49 // display the dialog.
48 ScopedJavaLocalRef<jobject> parent_jobj = parent_jobject_weak_ref_.get(env); 50 ScopedJavaLocalRef<jobject> parent_jobj = parent_jobject_weak_ref_.get(env);
49 if (parent_jobj.is_null()) { 51
52 TabAndroid* tab = TabAndroid::FromWebContents(dialog_->web_contents());
53 if (parent_jobj.is_null() || !tab) {
50 CancelAppModalDialog(); 54 CancelAppModalDialog();
51 return; 55 return;
52 } 56 }
53 57
54 ScopedJavaLocalRef<jobject> dialog_object; 58 ScopedJavaLocalRef<jobject> dialog_object;
55 ScopedJavaLocalRef<jstring> title = 59 ScopedJavaLocalRef<jstring> title =
56 ConvertUTF16ToJavaString(env, dialog_->title()); 60 ConvertUTF16ToJavaString(env, dialog_->title());
57 ScopedJavaLocalRef<jstring> message = 61 ScopedJavaLocalRef<jstring> message =
58 ConvertUTF16ToJavaString(env, dialog_->message_text()); 62 ConvertUTF16ToJavaString(env, dialog_->message_text());
59 63
64 bool foremost = tab->IsUserInteractable();
60 switch (dialog_->javascript_message_type()) { 65 switch (dialog_->javascript_message_type()) {
61 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: { 66 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: {
67 UMA_HISTOGRAM_BOOLEAN("JSDialogs.IsForemost.Alert", foremost);
62 dialog_object = Java_JavascriptAppModalDialog_createAlertDialog( 68 dialog_object = Java_JavascriptAppModalDialog_createAlertDialog(
63 env, title, message, dialog_->display_suppress_checkbox()); 69 env, title, message, dialog_->display_suppress_checkbox());
64 break; 70 break;
65 } 71 }
66 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: { 72 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: {
67 if (dialog_->is_before_unload_dialog()) { 73 if (dialog_->is_before_unload_dialog()) {
68 dialog_object = Java_JavascriptAppModalDialog_createBeforeUnloadDialog( 74 dialog_object = Java_JavascriptAppModalDialog_createBeforeUnloadDialog(
69 env, title, message, dialog_->is_reload(), 75 env, title, message, dialog_->is_reload(),
70 dialog_->display_suppress_checkbox()); 76 dialog_->display_suppress_checkbox());
71 } else { 77 } else {
78 UMA_HISTOGRAM_BOOLEAN("JSDialogs.IsForemost.Confirm", foremost);
72 dialog_object = Java_JavascriptAppModalDialog_createConfirmDialog( 79 dialog_object = Java_JavascriptAppModalDialog_createConfirmDialog(
73 env, title, message, dialog_->display_suppress_checkbox()); 80 env, title, message, dialog_->display_suppress_checkbox());
74 } 81 }
75 break; 82 break;
76 } 83 }
77 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: { 84 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: {
85 UMA_HISTOGRAM_BOOLEAN("JSDialogs.IsForemost.Prompt", foremost);
78 ScopedJavaLocalRef<jstring> default_prompt_text = 86 ScopedJavaLocalRef<jstring> default_prompt_text =
79 ConvertUTF16ToJavaString(env, dialog_->default_prompt_text()); 87 ConvertUTF16ToJavaString(env, dialog_->default_prompt_text());
80 dialog_object = Java_JavascriptAppModalDialog_createPromptDialog( 88 dialog_object = Java_JavascriptAppModalDialog_createPromptDialog(
81 env, title, message, dialog_->display_suppress_checkbox(), 89 env, title, message, dialog_->display_suppress_checkbox(),
82 default_prompt_text); 90 default_prompt_text);
83 break; 91 break;
84 } 92 }
85 default: 93 default:
86 NOTREACHED(); 94 NOTREACHED();
87 } 95 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 DISALLOW_COPY_AND_ASSIGN(ChromeJavaScriptNativeDialogAndroidFactory); 199 DISALLOW_COPY_AND_ASSIGN(ChromeJavaScriptNativeDialogAndroidFactory);
192 }; 200 };
193 201
194 } // namespace 202 } // namespace
195 203
196 void InstallChromeJavaScriptNativeDialogFactory() { 204 void InstallChromeJavaScriptNativeDialogFactory() {
197 app_modal::JavaScriptDialogManager::GetInstance()->SetNativeDialogFactory( 205 app_modal::JavaScriptDialogManager::GetInstance()->SetNativeDialogFactory(
198 base::WrapUnique(new ChromeJavaScriptNativeDialogAndroidFactory)); 206 base::WrapUnique(new ChromeJavaScriptNativeDialogAndroidFactory));
199 } 207 }
200 208
OLDNEW
« no previous file with comments | « chrome/browser/android/tab_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698