OLD | NEW |
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.chrome.browser.externalnav; | 5 package org.chromium.chrome.browser.externalnav; |
6 | 6 |
7 import android.Manifest.permission; | 7 import android.Manifest.permission; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.DialogInterface; | 10 import android.content.DialogInterface; |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 public boolean shouldRequestFileAccess(String url, Tab tab) { | 419 public boolean shouldRequestFileAccess(String url, Tab tab) { |
420 // If the tab is null, then do not attempt to prompt for access. | 420 // If the tab is null, then do not attempt to prompt for access. |
421 if (tab == null) return false; | 421 if (tab == null) return false; |
422 | 422 |
423 // If the url points inside of Chromium's data directory, no permissions
are necessary. | 423 // If the url points inside of Chromium's data directory, no permissions
are necessary. |
424 // This is required to prevent permission prompt when uses wants to acce
ss offline pages. | 424 // This is required to prevent permission prompt when uses wants to acce
ss offline pages. |
425 if (url.startsWith(UrlConstants.FILE_URL_PREFIX + PathUtils.getDataDirec
tory())) { | 425 if (url.startsWith(UrlConstants.FILE_URL_PREFIX + PathUtils.getDataDirec
tory())) { |
426 return false; | 426 return false; |
427 } | 427 } |
428 | 428 |
429 return !tab.getWindowAndroid().hasPermission(permission.WRITE_EXTERNAL_S
TORAGE) | 429 return !tab.getWindowAndroid().hasPermission(permission.READ_EXTERNAL_ST
ORAGE) |
430 && tab.getWindowAndroid().canRequestPermission(permission.WRITE_
EXTERNAL_STORAGE); | 430 && tab.getWindowAndroid().canRequestPermission(permission.READ_E
XTERNAL_STORAGE); |
431 } | 431 } |
432 | 432 |
433 @Override | 433 @Override |
434 public void startFileIntent(final Intent intent, final String referrerUrl, f
inal Tab tab, | 434 public void startFileIntent(final Intent intent, final String referrerUrl, f
inal Tab tab, |
435 final boolean needsToCloseTab) { | 435 final boolean needsToCloseTab) { |
436 PermissionCallback permissionCallback = new PermissionCallback() { | 436 PermissionCallback permissionCallback = new PermissionCallback() { |
437 @Override | 437 @Override |
438 public void onRequestPermissionsResult(String[] permissions, int[] g
rantResults) { | 438 public void onRequestPermissionsResult(String[] permissions, int[] g
rantResults) { |
439 if (grantResults.length > 0 | 439 if (grantResults.length > 0 |
440 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
{ | 440 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
{ |
441 loadIntent(intent, referrerUrl, null, tab, needsToCloseTab,
tab.isIncognito()); | 441 loadIntent(intent, referrerUrl, null, tab, needsToCloseTab,
tab.isIncognito()); |
442 } else { | 442 } else { |
443 // TODO(tedchoc): Show an indication to the user that the na
vigation failed | 443 // TODO(tedchoc): Show an indication to the user that the na
vigation failed |
444 // instead of silently dropping it on the flo
or. | 444 // instead of silently dropping it on the flo
or. |
445 if (needsToCloseTab) { | 445 if (needsToCloseTab) { |
446 // If the access was not granted, then close the tab if
necessary. | 446 // If the access was not granted, then close the tab if
necessary. |
447 closeTab(tab); | 447 closeTab(tab); |
448 } | 448 } |
449 } | 449 } |
450 } | 450 } |
451 }; | 451 }; |
452 tab.getWindowAndroid().requestPermissions( | 452 tab.getWindowAndroid().requestPermissions( |
453 new String[] {permission.WRITE_EXTERNAL_STORAGE}, permissionCall
back); | 453 new String[] {permission.READ_EXTERNAL_STORAGE}, permissionCallb
ack); |
454 } | 454 } |
455 | 455 |
456 private void loadIntent(Intent intent, String referrerUrl, String fallbackUr
l, Tab tab, | 456 private void loadIntent(Intent intent, String referrerUrl, String fallbackUr
l, Tab tab, |
457 boolean needsToCloseTab, boolean launchIncogntio) { | 457 boolean needsToCloseTab, boolean launchIncogntio) { |
458 boolean needsToStartIntent = false; | 458 boolean needsToStartIntent = false; |
459 if (tab == null || tab.isClosing() || !tab.isInitialized()) { | 459 if (tab == null || tab.isClosing() || !tab.isInitialized()) { |
460 needsToStartIntent = true; | 460 needsToStartIntent = true; |
461 needsToCloseTab = false; | 461 needsToCloseTab = false; |
462 } else if (needsToCloseTab) { | 462 } else if (needsToCloseTab) { |
463 needsToStartIntent = true; | 463 needsToStartIntent = true; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 * @param intent The bare intent we were going to send. | 604 * @param intent The bare intent we were going to send. |
605 */ | 605 */ |
606 protected void dispatchAuthenticatedIntent(Intent intent) { | 606 protected void dispatchAuthenticatedIntent(Intent intent) { |
607 Intent proxyIntent = new Intent(Intent.ACTION_MAIN); | 607 Intent proxyIntent = new Intent(Intent.ACTION_MAIN); |
608 proxyIntent.setClass(getAvailableContext(), AuthenticatedProxyActivity.c
lass); | 608 proxyIntent.setClass(getAvailableContext(), AuthenticatedProxyActivity.c
lass); |
609 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 609 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
610 proxyIntent.putExtra(AuthenticatedProxyActivity.AUTHENTICATED_INTENT_EXT
RA, intent); | 610 proxyIntent.putExtra(AuthenticatedProxyActivity.AUTHENTICATED_INTENT_EXT
RA, intent); |
611 getAvailableContext().startActivity(proxyIntent); | 611 getAvailableContext().startActivity(proxyIntent); |
612 } | 612 } |
613 } | 613 } |
OLD | NEW |