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 throws PackageManager.NameNotFoundException { | |
555 PackageManager pm = getAvailableContext().getPackageManager(); | |
556 Signature[] signatures = pm.getPackageInfo(pkgName, | |
557 PackageManager.GET_SIGNATURES).signatures; | |
please use gerrit instead
2016/07/29 16:59:52
Surround lines 556-557 with try-catch block for Na
| |
558 HashSet<String> fingerPrint256Set = new HashSet<String>(); | |
559 if (signatures.length > 0) { | |
560 for (Signature each : signatures) { | |
561 String fingerPrint = getSha256(each.toByteArray()); | |
please use gerrit instead
2016/07/29 16:59:52
if (fingerPrint == null) return null;
Use null to
| |
562 fingerPrint256Set.add(fingerPrint); | |
563 } | |
564 } | |
565 return fingerPrint256Set; | |
566 } | |
567 | |
568 /** | |
569 * Compute sha256 fingerprint from signature using MessageDigest. | |
570 * | |
571 * @param signature The signature to process. | |
572 * @return The hex string for the fingerprint. | |
please use gerrit instead
2016/07/29 16:59:52
@return The hex string for the fingerprint or null
| |
573 */ | |
574 private String getSha256(byte[] signature) { | |
575 MessageDigest digester; | |
576 try { | |
577 digester = MessageDigest.getInstance("SHA-256"); | |
578 } catch (NoSuchAlgorithmException e) { | |
579 return ""; | |
please use gerrit instead
2016/07/29 16:59:52
return null;
Use null to indicate failure.
| |
580 } | |
581 digester.update(signature); | |
582 return byteArrayToHexString(digester.digest()); | |
583 } | |
584 | |
585 /** | |
586 * Convert bytes to a hex string. | |
587 * | |
588 * @param bytes The bytes to convert into a string. | |
589 * @return The hex string for the bytes. | |
590 */ | |
591 private String byteArrayToHexString(byte[] bytes) { | |
592 if (bytes.length == 0) { | |
593 return ""; | |
594 } | |
595 StringBuilder data = new StringBuilder(); | |
596 for (byte b : bytes) { | |
597 data.append(Integer.toHexString((b >> 4) & 0x0f)); | |
598 data.append(Integer.toHexString(b & 0x0f)); | |
599 } | |
600 return data.toString().toUpperCase(); | |
601 } | |
602 | |
545 } | 603 } |
OLD | NEW |