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

Side by Side Diff: android_webview/native/aw_web_contents_delegate.cc

Issue 2059533002: Change WebContentsDelegate::RunFileChooser to be frame based. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes based on reviews. Created 4 years, 6 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 | « android_webview/native/aw_web_contents_delegate.h ('k') | apps/custom_launcher_page_contents.h » ('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 "android_webview/native/aw_web_contents_delegate.h" 5 #include "android_webview/native/aw_web_contents_delegate.h"
6 6
7 #include "android_webview/browser/aw_javascript_dialog_manager.h" 7 #include "android_webview/browser/aw_javascript_dialog_manager.h"
8 #include "android_webview/browser/find_helper.h" 8 #include "android_webview/browser/find_helper.h"
9 #include "android_webview/native/aw_contents.h" 9 #include "android_webview/native/aw_contents.h"
10 #include "android_webview/native/aw_contents_io_thread_client_impl.h" 10 #include "android_webview/native/aw_contents_io_thread_client_impl.h"
11 #include "android_webview/native/permission/media_access_permission_request.h" 11 #include "android_webview/native/permission/media_access_permission_request.h"
12 #include "android_webview/native/permission/permission_request_handler.h" 12 #include "android_webview/native/permission/permission_request_handler.h"
13 #include "base/android/jni_array.h" 13 #include "base/android/jni_array.h"
14 #include "base/android/jni_string.h" 14 #include "base/android/jni_string.h"
15 #include "base/android/scoped_java_ref.h" 15 #include "base/android/scoped_java_ref.h"
16 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/render_view_host.h" 25 #include "content/public/browser/render_view_host.h"
25 #include "content/public/browser/render_widget_host.h" 26 #include "content/public/browser/render_widget_host.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/file_chooser_file_info.h" 28 #include "content/public/common/file_chooser_file_info.h"
28 #include "content/public/common/file_chooser_params.h" 29 #include "content/public/common/file_chooser_params.h"
29 #include "content/public/common/media_stream_request.h" 30 #include "content/public/common/media_stream_request.h"
30 #include "jni/AwWebContentsDelegate_jni.h" 31 #include "jni/AwWebContentsDelegate_jni.h"
31 #include "net/base/escape.h" 32 #include "net/base/escape.h"
32 33
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 void AwWebContentsDelegate::CanDownload( 85 void AwWebContentsDelegate::CanDownload(
85 const GURL& url, 86 const GURL& url,
86 const std::string& request_method, 87 const std::string& request_method,
87 const base::Callback<void(bool)>& callback) { 88 const base::Callback<void(bool)>& callback) {
88 // Android webview intercepts download in its resource dispatcher host 89 // Android webview intercepts download in its resource dispatcher host
89 // delegate, so should not reach here. 90 // delegate, so should not reach here.
90 NOTREACHED(); 91 NOTREACHED();
91 callback.Run(false); 92 callback.Run(false);
92 } 93 }
93 94
94 void AwWebContentsDelegate::RunFileChooser(WebContents* web_contents, 95 void AwWebContentsDelegate::RunFileChooser(
95 const FileChooserParams& params) { 96 content::RenderFrameHost* render_frame_host,
97 const FileChooserParams& params) {
96 JNIEnv* env = AttachCurrentThread(); 98 JNIEnv* env = AttachCurrentThread();
97 ScopedJavaLocalRef<jobject> java_delegate = GetJavaDelegate(env); 99 ScopedJavaLocalRef<jobject> java_delegate = GetJavaDelegate(env);
98 if (!java_delegate.obj()) 100 if (!java_delegate.obj())
99 return; 101 return;
100 102
101 int mode_flags = 0; 103 int mode_flags = 0;
102 if (params.mode == FileChooserParams::OpenMultiple) { 104 if (params.mode == FileChooserParams::OpenMultiple) {
103 mode_flags |= kFileChooserModeOpenMultiple; 105 mode_flags |= kFileChooserModeOpenMultiple;
104 } else if (params.mode == FileChooserParams::UploadFolder) { 106 } else if (params.mode == FileChooserParams::UploadFolder) {
105 // Folder implies multiple in Chrome. 107 // Folder implies multiple in Chrome.
106 mode_flags |= kFileChooserModeOpenMultiple | kFileChooserModeOpenFolder; 108 mode_flags |= kFileChooserModeOpenMultiple | kFileChooserModeOpenFolder;
107 } else if (params.mode == FileChooserParams::Save) { 109 } else if (params.mode == FileChooserParams::Save) {
108 // Save not supported, so cancel it. 110 // Save not supported, so cancel it.
109 web_contents->GetRenderViewHost()->FilesSelectedInChooser( 111 render_frame_host->FilesSelectedInChooser(
110 std::vector<content::FileChooserFileInfo>(), 112 std::vector<content::FileChooserFileInfo>(), params.mode);
111 params.mode);
112 return; 113 return;
113 } else { 114 } else {
114 DCHECK_EQ(FileChooserParams::Open, params.mode); 115 DCHECK_EQ(FileChooserParams::Open, params.mode);
115 } 116 }
116 Java_AwWebContentsDelegate_runFileChooser(env, 117 Java_AwWebContentsDelegate_runFileChooser(
117 java_delegate.obj(), 118 env, java_delegate.obj(), render_frame_host->GetProcess()->GetID(),
118 web_contents->GetRenderProcessHost()->GetID(), 119 render_frame_host->GetRoutingID(), mode_flags,
119 web_contents->GetRenderViewHost()->GetRoutingID(), 120 ConvertUTF16ToJavaString(
120 mode_flags, 121 env, base::JoinString(params.accept_types, base::ASCIIToUTF16(",")))
121 ConvertUTF16ToJavaString(env, 122 .obj(),
122 base::JoinString(params.accept_types, base::ASCIIToUTF16(","))).obj(), 123 params.title.empty() ? NULL
123 params.title.empty() ? NULL : 124 : ConvertUTF16ToJavaString(env, params.title).obj(),
124 ConvertUTF16ToJavaString(env, params.title).obj(), 125 params.default_file_name.empty()
125 params.default_file_name.empty() ? NULL : 126 ? NULL
126 ConvertUTF8ToJavaString(env, params.default_file_name.value()).obj(), 127 : ConvertUTF8ToJavaString(env, params.default_file_name.value())
128 .obj(),
127 params.capture); 129 params.capture);
128 } 130 }
129 131
130 void AwWebContentsDelegate::AddNewContents(WebContents* source, 132 void AwWebContentsDelegate::AddNewContents(WebContents* source,
131 WebContents* new_contents, 133 WebContents* new_contents,
132 WindowOpenDisposition disposition, 134 WindowOpenDisposition disposition,
133 const gfx::Rect& initial_rect, 135 const gfx::Rect& initial_rect,
134 bool user_gesture, 136 bool user_gesture,
135 bool* was_blocked) { 137 bool* was_blocked) {
136 JNIEnv* env = AttachCurrentThread(); 138 JNIEnv* env = AttachCurrentThread();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 266 }
265 267
266 static void FilesSelectedInChooser( 268 static void FilesSelectedInChooser(
267 JNIEnv* env, 269 JNIEnv* env,
268 const JavaParamRef<jclass>& clazz, 270 const JavaParamRef<jclass>& clazz,
269 jint process_id, 271 jint process_id,
270 jint render_id, 272 jint render_id,
271 jint mode_flags, 273 jint mode_flags,
272 const JavaParamRef<jobjectArray>& file_paths, 274 const JavaParamRef<jobjectArray>& file_paths,
273 const JavaParamRef<jobjectArray>& display_names) { 275 const JavaParamRef<jobjectArray>& display_names) {
274 content::RenderViewHost* rvh = content::RenderViewHost::FromID(process_id, 276 content::RenderFrameHost* rfh =
275 render_id); 277 content::RenderFrameHost::FromID(process_id, render_id);
276 if (!rvh) 278 if (!rfh)
277 return; 279 return;
278 280
279 std::vector<std::string> file_path_str; 281 std::vector<std::string> file_path_str;
280 std::vector<std::string> display_name_str; 282 std::vector<std::string> display_name_str;
281 // Note file_paths maybe NULL, but this will just yield a zero-length vector. 283 // Note file_paths maybe NULL, but this will just yield a zero-length vector.
282 base::android::AppendJavaStringArrayToStringVector(env, file_paths, 284 base::android::AppendJavaStringArrayToStringVector(env, file_paths,
283 &file_path_str); 285 &file_path_str);
284 base::android::AppendJavaStringArrayToStringVector(env, display_names, 286 base::android::AppendJavaStringArrayToStringVector(env, display_names,
285 &display_name_str); 287 &display_name_str);
286 std::vector<content::FileChooserFileInfo> files; 288 std::vector<content::FileChooserFileInfo> files;
(...skipping 16 matching lines...) Expand all
303 FileChooserParams::Mode mode; 305 FileChooserParams::Mode mode;
304 if (mode_flags & kFileChooserModeOpenFolder) { 306 if (mode_flags & kFileChooserModeOpenFolder) {
305 mode = FileChooserParams::UploadFolder; 307 mode = FileChooserParams::UploadFolder;
306 } else if (mode_flags & kFileChooserModeOpenMultiple) { 308 } else if (mode_flags & kFileChooserModeOpenMultiple) {
307 mode = FileChooserParams::OpenMultiple; 309 mode = FileChooserParams::OpenMultiple;
308 } else { 310 } else {
309 mode = FileChooserParams::Open; 311 mode = FileChooserParams::Open;
310 } 312 }
311 DVLOG(0) << "File Chooser result: mode = " << mode 313 DVLOG(0) << "File Chooser result: mode = " << mode
312 << ", file paths = " << base::JoinString(file_path_str, ":"); 314 << ", file paths = " << base::JoinString(file_path_str, ":");
313 rvh->FilesSelectedInChooser(files, mode); 315 rfh->FilesSelectedInChooser(files, mode);
314 } 316 }
315 317
316 bool RegisterAwWebContentsDelegate(JNIEnv* env) { 318 bool RegisterAwWebContentsDelegate(JNIEnv* env) {
317 return RegisterNativesImpl(env); 319 return RegisterNativesImpl(env);
318 } 320 }
319 321
320 } // namespace android_webview 322 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_web_contents_delegate.h ('k') | apps/custom_launcher_page_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698