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; |
11 import android.content.DialogInterface.OnCancelListener; | 11 import android.content.DialogInterface.OnCancelListener; |
12 import android.content.DialogInterface.OnClickListener; | 12 import android.content.DialogInterface.OnClickListener; |
13 import android.content.Intent; | 13 import android.content.Intent; |
14 import android.content.IntentFilter; | 14 import android.content.IntentFilter; |
15 import android.content.pm.PackageManager; | 15 import android.content.pm.PackageManager; |
16 import android.content.pm.ResolveInfo; | 16 import android.content.pm.ResolveInfo; |
17 import android.content.pm.Signature; | |
17 import android.net.Uri; | 18 import android.net.Uri; |
18 import android.os.Build; | 19 import android.os.Build; |
19 import android.os.StrictMode; | 20 import android.os.StrictMode; |
20 import android.os.TransactionTooLargeException; | 21 import android.os.TransactionTooLargeException; |
21 import android.provider.Browser; | 22 import android.provider.Browser; |
22 import android.provider.Telephony; | 23 import android.provider.Telephony; |
23 import android.support.v7.app.AlertDialog; | 24 import android.support.v7.app.AlertDialog; |
24 import android.text.TextUtils; | 25 import android.text.TextUtils; |
25 import android.util.Log; | 26 import android.util.Log; |
26 import android.webkit.MimeTypeMap; | 27 import android.webkit.MimeTypeMap; |
(...skipping 15 matching lines...) Expand all Loading... | |
42 import org.chromium.chrome.browser.tab.Tab; | 43 import org.chromium.chrome.browser.tab.Tab; |
43 import org.chromium.chrome.browser.util.FeatureUtilities; | 44 import org.chromium.chrome.browser.util.FeatureUtilities; |
44 import org.chromium.chrome.browser.util.UrlUtilities; | 45 import org.chromium.chrome.browser.util.UrlUtilities; |
45 import org.chromium.content_public.browser.LoadUrlParams; | 46 import org.chromium.content_public.browser.LoadUrlParams; |
46 import org.chromium.content_public.common.Referrer; | 47 import org.chromium.content_public.common.Referrer; |
47 import org.chromium.ui.base.PageTransition; | 48 import org.chromium.ui.base.PageTransition; |
48 import org.chromium.ui.base.WindowAndroid; | 49 import org.chromium.ui.base.WindowAndroid; |
49 import org.chromium.ui.base.WindowAndroid.PermissionCallback; | 50 import org.chromium.ui.base.WindowAndroid.PermissionCallback; |
50 import org.chromium.webapk.lib.client.WebApkValidator; | 51 import org.chromium.webapk.lib.client.WebApkValidator; |
51 | 52 |
53 import java.security.MessageDigest; | |
54 import java.security.NoSuchAlgorithmException; | |
52 import java.util.ArrayList; | 55 import java.util.ArrayList; |
56 import java.util.HashSet; | |
53 import java.util.List; | 57 import java.util.List; |
58 import java.util.Set; | |
54 | 59 |
55 /** | 60 /** |
56 * The main implementation of the {@link ExternalNavigationDelegate}. | 61 * The main implementation of the {@link ExternalNavigationDelegate}. |
57 */ | 62 */ |
58 public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat e { | 63 public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat e { |
59 private static final String TAG = "ExternalNavigationDelegateImpl"; | 64 private static final String TAG = "ExternalNavigationDelegateImpl"; |
60 private static final String PDF_VIEWER = "com.google.android.apps.docs"; | 65 private static final String PDF_VIEWER = "com.google.android.apps.docs"; |
61 private static final String PDF_MIME = "application/pdf"; | 66 private static final String PDF_MIME = "application/pdf"; |
62 private static final String PDF_SUFFIX = ".pdf"; | 67 private static final String PDF_SUFFIX = ".pdf"; |
63 private static final String PDF_EXTENSION = "pdf"; | 68 private static final String PDF_EXTENSION = "pdf"; |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 if (TextUtils.isEmpty(fileExtension)) return false; | 540 if (TextUtils.isEmpty(fileExtension)) return false; |
536 | 541 |
537 return PDF_EXTENSION.equals(fileExtension); | 542 return PDF_EXTENSION.equals(fileExtension); |
538 } | 543 } |
539 | 544 |
540 @Override | 545 @Override |
541 public void maybeRecordAppHandlersInIntent(Intent intent, List<ResolveInfo> infos) { | 546 public void maybeRecordAppHandlersInIntent(Intent intent, List<ResolveInfo> infos) { |
542 intent.putExtra(IntentHandler.EXTRA_EXTERNAL_NAV_PACKAGES, | 547 intent.putExtra(IntentHandler.EXTRA_EXTERNAL_NAV_PACKAGES, |
543 getSpecializedHandlersWithFilter(infos, null)); | 548 getSpecializedHandlersWithFilter(infos, null)); |
544 } | 549 } |
550 | |
551 | |
552 @Override | |
553 public Set<String> getPackageSHA256Fingerprints(String pkgName) { | |
554 PackageManager pm = getAvailableContext().getPackageManager(); | |
555 try { | |
556 Signature[] signatures = pm.getPackageInfo(pkgName, | |
557 PackageManager.GET_SIGNATURES).signatures; | |
please use gerrit instead
2016/08/01 21:05:24
Move the "catch" to this line. This is the only me
| |
558 HashSet<String> fingerPrint256Set = new HashSet<String>(); | |
please use gerrit instead
2016/08/01 21:05:24
Set<String> fingerprints = new HashSet<>();
| |
559 if (signatures.length > 0) { | |
please use gerrit instead
2016/08/01 21:05:24
No need to check the length of "signatures" here.
| |
560 for (Signature each : signatures) { | |
please use gerrit instead
2016/08/01 21:05:24
Range loops are inefficient. Use integer loops ins
| |
561 String fingerPrint = getSha256(each.toByteArray()); | |
562 if (fingerPrint == null) { | |
563 return null; | |
564 } | |
565 fingerPrint256Set.add(fingerPrint); | |
566 } | |
567 } | |
568 return fingerPrint256Set; | |
569 } catch (PackageManager.NameNotFoundException e) { | |
570 return null; | |
571 } | |
572 } | |
573 | |
574 /** | |
575 * Compute sha256 fingerprint from signature using MessageDigest. | |
576 * | |
577 * @param signature The signature to process. | |
578 * @return The hex string for the fingerprint or null on failure. | |
579 */ | |
580 private String getSha256(byte[] signature) { | |
581 MessageDigest digester; | |
582 try { | |
583 digester = MessageDigest.getInstance("SHA-256"); | |
584 } catch (NoSuchAlgorithmException e) { | |
585 return null; | |
586 } | |
587 digester.update(signature); | |
588 return byteArrayToHexString(digester.digest()); | |
589 } | |
590 | |
591 /** | |
592 * Convert bytes to a hex string. | |
593 * | |
594 * @param bytes The bytes to convert into a string. | |
595 * @return The hex string for the bytes. | |
596 */ | |
597 private String byteArrayToHexString(byte[] bytes) { | |
598 if (bytes.length == 0) { | |
599 return ""; | |
600 } | |
601 StringBuilder data = new StringBuilder(); | |
602 for (byte b : bytes) { | |
603 data.append(Integer.toHexString((b >> 4) & 0x0f)); | |
604 data.append(Integer.toHexString(b & 0x0f)); | |
605 } | |
606 return data.toString().toUpperCase(); | |
607 } | |
608 | |
545 } | 609 } |
OLD | NEW |