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

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

Issue 11555004: Refactoring JavaScript modal dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed proguard Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/android/javascript_app_modal_dialog_android.h ('k') | chrome/chrome.gyp » ('j') | 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/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 10
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
12 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" 13 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/javascript_message_type.h" 16 #include "content/public/common/javascript_message_type.h"
16 #include "jni/JavascriptAppModalDialog_jni.h" 17 #include "jni/JavascriptAppModalDialog_jni.h"
17 #include "ui/gfx/android/window_android.h" 18 #include "ui/gfx/android/window_android.h"
18 19
19 using base::android::AttachCurrentThread; 20 using base::android::AttachCurrentThread;
20 using base::android::ConvertUTF16ToJavaString; 21 using base::android::ConvertUTF16ToJavaString;
22 using base::android::ScopedJavaGlobalRef;
21 using base::android::ScopedJavaLocalRef; 23 using base::android::ScopedJavaLocalRef;
22 using content::BrowserThread; 24 using content::BrowserThread;
23 25
24 // static 26 // static
25 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( 27 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt(
26 JavaScriptAppModalDialog* dialog, 28 JavaScriptAppModalDialog* dialog,
27 gfx::NativeWindow parent_window) { 29 gfx::NativeWindow parent_window) {
28 return new JavascriptAppModalDialogAndroid(AttachCurrentThread(), 30 return new JavascriptAppModalDialogAndroid(AttachCurrentThread(),
29 dialog, parent_window); 31 dialog, parent_window);
30 } 32 }
(...skipping 19 matching lines...) Expand all
50 NOTIMPLEMENTED(); 52 NOTIMPLEMENTED();
51 return 0; 53 return 0;
52 } 54 }
53 55
54 void JavascriptAppModalDialogAndroid::ShowAppModalDialog() { 56 void JavascriptAppModalDialogAndroid::ShowAppModalDialog() {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 58
57 JNIEnv* env = AttachCurrentThread(); 59 JNIEnv* env = AttachCurrentThread();
58 // Keep a strong ref to the parent window while we make the call to java to 60 // Keep a strong ref to the parent window while we make the call to java to
59 // display the dialog. 61 // display the dialog.
60 ScopedJavaLocalRef<jobject> parent_jobj = parent_jobject_weak_ref_.get( 62 ScopedJavaLocalRef<jobject> parent_jobj = parent_jobject_weak_ref_.get(env);
61 env);
62 if (parent_jobj.is_null()) { 63 if (parent_jobj.is_null()) {
63 CancelAppModalDialog(); 64 CancelAppModalDialog();
64 return; 65 return;
65 } 66 }
66 67
67 ScopedJavaLocalRef<jobject> dialog_object; 68 ScopedJavaLocalRef<jobject> dialog_object;
68 ScopedJavaLocalRef<jstring> title = 69 ScopedJavaLocalRef<jstring> title =
69 ConvertUTF16ToJavaString(env, dialog_->title()); 70 ConvertUTF16ToJavaString(env, dialog_->title());
70 ScopedJavaLocalRef<jstring> message = 71 ScopedJavaLocalRef<jstring> message =
71 ConvertUTF16ToJavaString(env, dialog_->message_text()); 72 ConvertUTF16ToJavaString(env, dialog_->message_text());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 dialog_->OnCancel(false); 135 dialog_->OnCancel(false);
135 delete this; 136 delete this;
136 } 137 }
137 138
138 void JavascriptAppModalDialogAndroid::DidCancelAppModalDialog( 139 void JavascriptAppModalDialogAndroid::DidCancelAppModalDialog(
139 JNIEnv* env, jobject, bool should_suppress_js_dialogs) { 140 JNIEnv* env, jobject, bool should_suppress_js_dialogs) {
140 dialog_->OnCancel(should_suppress_js_dialogs); 141 dialog_->OnCancel(should_suppress_js_dialogs);
141 delete this; 142 delete this;
142 } 143 }
143 144
145 const ScopedJavaGlobalRef<jobject>&
146 JavascriptAppModalDialogAndroid::GetDialogObject() const {
147 return dialog_jobject_;
148 }
149
150 // static
151 jobject GetCurrentModalDialog(JNIEnv* env, jclass clazz) {
152 AppModalDialog* dialog = AppModalDialogQueue::GetInstance()->active_dialog();
153 if (!dialog || !dialog->native_dialog())
154 return NULL;
155
156 JavascriptAppModalDialogAndroid* js_dialog =
157 static_cast<JavascriptAppModalDialogAndroid*>(dialog->native_dialog());
158 return js_dialog->GetDialogObject().obj();
159 }
160
144 // static 161 // static
145 bool JavascriptAppModalDialogAndroid::RegisterJavascriptAppModalDialog( 162 bool JavascriptAppModalDialogAndroid::RegisterJavascriptAppModalDialog(
146 JNIEnv* env) { 163 JNIEnv* env) {
147 return RegisterNativesImpl(env); 164 return RegisterNativesImpl(env);
148 } 165 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/android/javascript_app_modal_dialog_android.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698