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

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

Issue 2863233002: [WebView] Move files from native to browser (Closed)
Patch Set: Created 3 years, 7 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 "android_webview/native/aw_web_contents_delegate.h" 5 #include "android_webview/browser/aw_web_contents_delegate.h"
6 6
7 #include "android_webview/browser/aw_contents.h"
8 #include "android_webview/browser/aw_contents_io_thread_client_impl.h"
7 #include "android_webview/browser/aw_javascript_dialog_manager.h" 9 #include "android_webview/browser/aw_javascript_dialog_manager.h"
8 #include "android_webview/browser/find_helper.h" 10 #include "android_webview/browser/find_helper.h"
9 #include "android_webview/native/aw_contents.h" 11 #include "android_webview/browser/permission/media_access_permission_request.h"
10 #include "android_webview/native/aw_contents_io_thread_client_impl.h" 12 #include "android_webview/browser/permission/permission_request_handler.h"
11 #include "android_webview/native/permission/media_access_permission_request.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"
(...skipping 22 matching lines...) Expand all
45 45
46 // WARNING: these constants are exposed in the public interface Java side, so 46 // WARNING: these constants are exposed in the public interface Java side, so
47 // must remain in sync with what clients are expecting. 47 // must remain in sync with what clients are expecting.
48 const int kFileChooserModeOpenMultiple = 1 << 0; 48 const int kFileChooserModeOpenMultiple = 1 << 0;
49 const int kFileChooserModeOpenFolder = 1 << 1; 49 const int kFileChooserModeOpenFolder = 1 << 1;
50 50
51 base::LazyInstance<AwJavaScriptDialogManager>::Leaky 51 base::LazyInstance<AwJavaScriptDialogManager>::Leaky
52 g_javascript_dialog_manager = LAZY_INSTANCE_INITIALIZER; 52 g_javascript_dialog_manager = LAZY_INSTANCE_INITIALIZER;
53 } 53 }
54 54
55 AwWebContentsDelegate::AwWebContentsDelegate( 55 AwWebContentsDelegate::AwWebContentsDelegate(JNIEnv* env, jobject obj)
56 JNIEnv* env, 56 : WebContentsDelegateAndroid(env, obj), is_fullscreen_(false) {}
57 jobject obj)
58 : WebContentsDelegateAndroid(env, obj),
59 is_fullscreen_(false) {
60 }
61 57
62 AwWebContentsDelegate::~AwWebContentsDelegate() { 58 AwWebContentsDelegate::~AwWebContentsDelegate() {}
63 }
64 59
65 content::JavaScriptDialogManager* 60 content::JavaScriptDialogManager*
66 AwWebContentsDelegate::GetJavaScriptDialogManager(WebContents* source) { 61 AwWebContentsDelegate::GetJavaScriptDialogManager(WebContents* source) {
67 return g_javascript_dialog_manager.Pointer(); 62 return g_javascript_dialog_manager.Pointer();
68 } 63 }
69 64
70 void AwWebContentsDelegate::FindReply(WebContents* web_contents, 65 void AwWebContentsDelegate::FindReply(WebContents* web_contents,
71 int request_id, 66 int request_id,
72 int number_of_matches, 67 int number_of_matches,
73 const gfx::Rect& selection_rect, 68 const gfx::Rect& selection_rect,
74 int active_match_ordinal, 69 int active_match_ordinal,
75 bool final_update) { 70 bool final_update) {
76 AwContents* aw_contents = AwContents::FromWebContents(web_contents); 71 AwContents* aw_contents = AwContents::FromWebContents(web_contents);
77 if (!aw_contents) 72 if (!aw_contents)
78 return; 73 return;
79 74
80 aw_contents->GetFindHelper()->HandleFindReply(request_id, 75 aw_contents->GetFindHelper()->HandleFindReply(
81 number_of_matches, 76 request_id, number_of_matches, active_match_ordinal, final_update);
82 active_match_ordinal,
83 final_update);
84 } 77 }
85 78
86 void AwWebContentsDelegate::CanDownload( 79 void AwWebContentsDelegate::CanDownload(
87 const GURL& url, 80 const GURL& url,
88 const std::string& request_method, 81 const std::string& request_method,
89 const base::Callback<void(bool)>& callback) { 82 const base::Callback<void(bool)>& callback) {
90 // Android webview intercepts download in its resource dispatcher host 83 // Android webview intercepts download in its resource dispatcher host
91 // delegate, so should not reach here. 84 // delegate, so should not reach here.
92 NOTREACHED(); 85 NOTREACHED();
93 callback.Run(false); 86 callback.Run(false);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, 233 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
241 std::unique_ptr<content::MediaStreamUI>()); 234 std::unique_ptr<content::MediaStreamUI>());
242 return; 235 return;
243 } 236 }
244 aw_contents->GetPermissionRequestHandler()->SendRequest( 237 aw_contents->GetPermissionRequestHandler()->SendRequest(
245 std::unique_ptr<AwPermissionRequestDelegate>( 238 std::unique_ptr<AwPermissionRequestDelegate>(
246 new MediaAccessPermissionRequest(request, callback))); 239 new MediaAccessPermissionRequest(request, callback)));
247 } 240 }
248 241
249 void AwWebContentsDelegate::EnterFullscreenModeForTab( 242 void AwWebContentsDelegate::EnterFullscreenModeForTab(
250 content::WebContents* web_contents, const GURL& origin) { 243 content::WebContents* web_contents,
244 const GURL& origin) {
251 WebContentsDelegateAndroid::EnterFullscreenModeForTab(web_contents, origin); 245 WebContentsDelegateAndroid::EnterFullscreenModeForTab(web_contents, origin);
252 is_fullscreen_ = true; 246 is_fullscreen_ = true;
253 web_contents->GetRenderViewHost()->GetWidget()->WasResized(); 247 web_contents->GetRenderViewHost()->GetWidget()->WasResized();
254 } 248 }
255 249
256 void AwWebContentsDelegate::ExitFullscreenModeForTab( 250 void AwWebContentsDelegate::ExitFullscreenModeForTab(
257 content::WebContents* web_contents) { 251 content::WebContents* web_contents) {
258 WebContentsDelegateAndroid::ExitFullscreenModeForTab(web_contents); 252 WebContentsDelegateAndroid::ExitFullscreenModeForTab(web_contents);
259 is_fullscreen_ = false; 253 is_fullscreen_ = false;
260 web_contents->GetRenderViewHost()->GetWidget()->WasResized(); 254 web_contents->GetRenderViewHost()->GetWidget()->WasResized();
(...skipping 23 matching lines...) Expand all
284 base::android::AppendJavaStringArrayToStringVector(env, file_paths, 278 base::android::AppendJavaStringArrayToStringVector(env, file_paths,
285 &file_path_str); 279 &file_path_str);
286 base::android::AppendJavaStringArrayToStringVector(env, display_names, 280 base::android::AppendJavaStringArrayToStringVector(env, display_names,
287 &display_name_str); 281 &display_name_str);
288 std::vector<content::FileChooserFileInfo> files; 282 std::vector<content::FileChooserFileInfo> files;
289 files.reserve(file_path_str.size()); 283 files.reserve(file_path_str.size());
290 for (size_t i = 0; i < file_path_str.size(); ++i) { 284 for (size_t i = 0; i < file_path_str.size(); ++i) {
291 GURL url(file_path_str[i]); 285 GURL url(file_path_str[i]);
292 if (!url.is_valid()) 286 if (!url.is_valid())
293 continue; 287 continue;
294 base::FilePath path(url.SchemeIsFile() ? 288 base::FilePath path(
295 net::UnescapeURLComponent(url.path(), 289 url.SchemeIsFile()
296 net::UnescapeRule::SPACES | 290 ? net::UnescapeURLComponent(
297 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS) : 291 url.path(), net::UnescapeRule::SPACES |
298 file_path_str[i]); 292 net::UnescapeRule::
293 URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS)
294 : file_path_str[i]);
299 content::FileChooserFileInfo file_info; 295 content::FileChooserFileInfo file_info;
300 file_info.file_path = path; 296 file_info.file_path = path;
301 if (!display_name_str[i].empty()) 297 if (!display_name_str[i].empty())
302 file_info.display_name = display_name_str[i]; 298 file_info.display_name = display_name_str[i];
303 files.push_back(file_info); 299 files.push_back(file_info);
304 } 300 }
305 FileChooserParams::Mode mode; 301 FileChooserParams::Mode mode;
306 if (mode_flags & kFileChooserModeOpenFolder) { 302 if (mode_flags & kFileChooserModeOpenFolder) {
307 mode = FileChooserParams::UploadFolder; 303 mode = FileChooserParams::UploadFolder;
308 } else if (mode_flags & kFileChooserModeOpenMultiple) { 304 } else if (mode_flags & kFileChooserModeOpenMultiple) {
309 mode = FileChooserParams::OpenMultiple; 305 mode = FileChooserParams::OpenMultiple;
310 } else { 306 } else {
311 mode = FileChooserParams::Open; 307 mode = FileChooserParams::Open;
312 } 308 }
313 DVLOG(0) << "File Chooser result: mode = " << mode 309 DVLOG(0) << "File Chooser result: mode = " << mode
314 << ", file paths = " << base::JoinString(file_path_str, ":"); 310 << ", file paths = " << base::JoinString(file_path_str, ":");
315 rfh->FilesSelectedInChooser(files, mode); 311 rfh->FilesSelectedInChooser(files, mode);
316 } 312 }
317 313
318 bool RegisterAwWebContentsDelegate(JNIEnv* env) { 314 bool RegisterAwWebContentsDelegate(JNIEnv* env) {
319 return RegisterNativesImpl(env); 315 return RegisterNativesImpl(env);
320 } 316 }
321 317
322 } // namespace android_webview 318 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698