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

Side by Side Diff: android_webview/tools/WebViewShell/src/org/chromium/webview_shell/WebViewBrowserActivity.java

Issue 1420833002: WebViewShell crashes on Android <= L. Fix that. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 package org.chromium.webview_shell; 5 package org.chromium.webview_shell;
6 6
7 import android.Manifest; 7 import android.Manifest;
8 import android.app.Activity; 8 import android.app.Activity;
9 import android.app.AlertDialog; 9 import android.app.AlertDialog;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 private void requestPermissionsForPage(PermissionRequest request) { 231 private void requestPermissionsForPage(PermissionRequest request) {
232 // Deny any unrecognized permissions. 232 // Deny any unrecognized permissions.
233 for (String webkitPermission : request.getResources()) { 233 for (String webkitPermission : request.getResources()) {
234 if (!sPermissions.containsKey(webkitPermission)) { 234 if (!sPermissions.containsKey(webkitPermission)) {
235 Log.w(TAG, "Unrecognized WebKit permission: " + webkitPermission ); 235 Log.w(TAG, "Unrecognized WebKit permission: " + webkitPermission );
236 request.deny(); 236 request.deny();
237 return; 237 return;
238 } 238 }
239 } 239 }
240 240
241 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
242 request.grant(request.getResources());
243 return;
244 }
245
241 // Find what Android permissions we need before we can grant these WebKi t permissions. 246 // Find what Android permissions we need before we can grant these WebKi t permissions.
242 ArrayList<String> androidPermissionsNeeded = new ArrayList<String>(); 247 ArrayList<String> androidPermissionsNeeded = new ArrayList<String>();
243 for (String webkitPermission : request.getResources()) { 248 for (String webkitPermission : request.getResources()) {
244 if (!canGrant(webkitPermission)) { 249 if (!canGrant(webkitPermission)) {
245 // We already checked for unrecognized permissions, and canGrant will skip over 250 // We already checked for unrecognized permissions, and canGrant will skip over
246 // NO_ANDROID_PERMISSION cases, so this is guaranteed to be a re gular Android 251 // NO_ANDROID_PERMISSION cases, so this is guaranteed to be a re gular Android
247 // permission. 252 // permission.
248 String androidPermission = sPermissions.get(webkitPermission); 253 String androidPermission = sPermissions.get(webkitPermission);
249 androidPermissionsNeeded.add(androidPermission); 254 androidPermissionsNeeded.add(androidPermission);
250 } 255 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 364
360 // Returns true is a method has no arguments and returns either a boolean or a String. 365 // Returns true is a method has no arguments and returns either a boolean or a String.
361 private boolean methodIsSimpleInspector(Method method) { 366 private boolean methodIsSimpleInspector(Method method) {
362 Class<?> returnType = method.getReturnType(); 367 Class<?> returnType = method.getReturnType();
363 return ((returnType.equals(boolean.class) || returnType.equals(String.cl ass)) 368 return ((returnType.equals(boolean.class) || returnType.equals(String.cl ass))
364 && method.getParameterTypes().length == 0); 369 && method.getParameterTypes().length == 0);
365 } 370 }
366 371
367 private void loadUrl(String url) { 372 private void loadUrl(String url) {
368 // Request read access if necessary 373 // Request read access if necessary
369 if ("file".equals(Uri.parse(url).getScheme())) { 374 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
370 if (PackageManager.PERMISSION_DENIED 375 && "file".equals(Uri.parse(url).getScheme())
371 == checkSelfPermission(Manifest.permission.READ_EXTERNAL_STO RAGE)) { 376 && PackageManager.PERMISSION_DENIED
372 requestPermissionsForPage(new FilePermissionRequest(url)); 377 == checkSelfPermission(Manifest.permission.READ_EXTERNAL _STORAGE)) {
373 } 378 requestPermissionsForPage(new FilePermissionRequest(url));
374 } 379 }
375 380
376 // If it is file:// and we don't have permission, they'll get the "Webpa ge not available" 381 // If it is file:// and we don't have permission, they'll get the "Webpa ge not available"
377 // "net::ERR_ACCESS_DENIED" page. When we get permission, FilePermission Request.grant() 382 // "net::ERR_ACCESS_DENIED" page. When we get permission, FilePermission Request.grant()
378 // will reload. 383 // will reload.
379 mWebView.loadUrl(url); 384 mWebView.loadUrl(url);
380 mWebView.requestFocus(); 385 mWebView.requestFocus();
381 } 386 }
382 387
383 private void setUrlBarText(String url) { 388 private void setUrlBarText(String url) {
(...skipping 12 matching lines...) Expand all
396 private static boolean hideKeyboard(View view) { 401 private static boolean hideKeyboard(View view) {
397 InputMethodManager imm = (InputMethodManager) view.getContext().getSyste mService( 402 InputMethodManager imm = (InputMethodManager) view.getContext().getSyste mService(
398 Context.INPUT_METHOD_SERVICE); 403 Context.INPUT_METHOD_SERVICE);
399 return imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 404 return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
400 } 405 }
401 406
402 private static String getUrlFromIntent(Intent intent) { 407 private static String getUrlFromIntent(Intent intent) {
403 return intent != null ? intent.getDataString() : null; 408 return intent != null ? intent.getDataString() : null;
404 } 409 }
405 } 410 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698