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

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

Issue 666533007: Move JavaScriptDialogManager, JavascriptAppModalDialogViews to components/app_modal_dialogs (Closed) Base URL: https://chromium.googlesource.com/chromium/src@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 "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/strings/utf_string_conversions.h" 9 #include "chrome/browser/ui/android/javascript_app_modal_dialog_android.h"
msw 2014/11/05 23:34:37 nit: Remove redundant include (same as first).
oshima 2014/11/06 00:04:32 Done.
10 10 #include "chrome/browser/ui/app_modal_dialogs/chrome_javascript_native_dialog_fa ctory.h"
11 #include "chrome/browser/browser_process.h"
12 #include "components/app_modal_dialogs/app_modal_dialog_queue.h" 11 #include "components/app_modal_dialogs/app_modal_dialog_queue.h"
13 #include "components/app_modal_dialogs/javascript_app_modal_dialog.h" 12 #include "components/app_modal_dialogs/javascript_app_modal_dialog.h"
13 #include "components/app_modal_dialogs/javascript_dialog_manager.h"
14 #include "components/app_modal_dialogs/javascript_native_dialog_factory.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/javascript_message_type.h" 16 #include "content/public/common/javascript_message_type.h"
17 #include "jni/JavascriptAppModalDialog_jni.h" 17 #include "jni/JavascriptAppModalDialog_jni.h"
18 #include "ui/base/android/window_android.h" 18 #include "ui/base/android/window_android.h"
19 19
20 using base::android::AttachCurrentThread; 20 using base::android::AttachCurrentThread;
21 using base::android::ConvertUTF16ToJavaString; 21 using base::android::ConvertUTF16ToJavaString;
22 using base::android::ScopedJavaGlobalRef; 22 using base::android::ScopedJavaGlobalRef;
23 using base::android::ScopedJavaLocalRef; 23 using base::android::ScopedJavaLocalRef;
24 using content::BrowserThread;
25
26 // static
27 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt(
28 JavaScriptAppModalDialog* dialog,
29 gfx::NativeWindow parent_window) {
30 return new JavascriptAppModalDialogAndroid(AttachCurrentThread(),
31 dialog, parent_window);
32 }
33 24
34 JavascriptAppModalDialogAndroid::JavascriptAppModalDialogAndroid( 25 JavascriptAppModalDialogAndroid::JavascriptAppModalDialogAndroid(
35 JNIEnv* env, 26 JNIEnv* env,
36 JavaScriptAppModalDialog* dialog, 27 JavaScriptAppModalDialog* dialog,
37 gfx::NativeWindow parent) 28 gfx::NativeWindow parent)
38 : dialog_(dialog), 29 : dialog_(dialog),
39 parent_jobject_weak_ref_(env, parent->GetJavaObject().obj()) { 30 parent_jobject_weak_ref_(env, parent->GetJavaObject().obj()) {
40 } 31 }
41 32
42 int JavascriptAppModalDialogAndroid::GetAppModalDialogButtons() const { 33 int JavascriptAppModalDialogAndroid::GetAppModalDialogButtons() const {
43 NOTIMPLEMENTED(); 34 NOTIMPLEMENTED();
44 return 0; 35 return 0;
45 } 36 }
46 37
47 void JavascriptAppModalDialogAndroid::ShowAppModalDialog() { 38 void JavascriptAppModalDialogAndroid::ShowAppModalDialog() {
48 DCHECK_CURRENTLY_ON(BrowserThread::UI); 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
49 40
50 JNIEnv* env = AttachCurrentThread(); 41 JNIEnv* env = AttachCurrentThread();
51 // Keep a strong ref to the parent window while we make the call to java to 42 // Keep a strong ref to the parent window while we make the call to java to
52 // display the dialog. 43 // display the dialog.
53 ScopedJavaLocalRef<jobject> parent_jobj = parent_jobject_weak_ref_.get(env); 44 ScopedJavaLocalRef<jobject> parent_jobj = parent_jobject_weak_ref_.get(env);
54 if (parent_jobj.is_null()) { 45 if (parent_jobj.is_null()) {
55 CancelAppModalDialog(); 46 CancelAppModalDialog();
56 return; 47 return;
57 } 48 }
58 49
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 149
159 JavascriptAppModalDialogAndroid::~JavascriptAppModalDialogAndroid() { 150 JavascriptAppModalDialogAndroid::~JavascriptAppModalDialogAndroid() {
160 // In case the dialog is still displaying, tell it to close itself. 151 // In case the dialog is still displaying, tell it to close itself.
161 // This can happen if you trigger a dialog but close the Tab before it's 152 // This can happen if you trigger a dialog but close the Tab before it's
162 // shown, and then accept the dialog. 153 // shown, and then accept the dialog.
163 if (!dialog_jobject_.is_null()) { 154 if (!dialog_jobject_.is_null()) {
164 JNIEnv* env = AttachCurrentThread(); 155 JNIEnv* env = AttachCurrentThread();
165 Java_JavascriptAppModalDialog_dismiss(env, dialog_jobject_.obj()); 156 Java_JavascriptAppModalDialog_dismiss(env, dialog_jobject_.obj());
166 } 157 }
167 } 158 }
159
160 namespace {
161
162 class ChromeJavaScriptNativeDialogAndroidFactory
163 : public JavaScriptNativeDialogFactory {
164 public:
165 ChromeJavaScriptNativeDialogAndroidFactory() {}
166 ~ChromeJavaScriptNativeDialogAndroidFactory() override {}
167
168 private:
169 NativeAppModalDialog* CreateNativeJavaScriptDialog(
170 JavaScriptAppModalDialog* dialog,
171 gfx::NativeWindow parent_window) override {
172 return new JavascriptAppModalDialogAndroid(
173 base::android::AttachCurrentThread(),
174 dialog, parent_window);
175 }
176
177 DISALLOW_COPY_AND_ASSIGN(ChromeJavaScriptNativeDialogAndroidFactory);
178 };
179
180 } // namespace
181
182 void InstallChromeJavaScriptNativeDialogFactory() {
183 SetJavaScriptNativeDialogFactory(
184 make_scoped_ptr(new ChromeJavaScriptNativeDialogAndroidFactory));
185 }
186
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698