From: csagan5 <32685696+csagan5@users.noreply.github.com>
Date: Thu, 27 Feb 2020 23:23:59 +0100
Subject: Do not compile QR code sharing

License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
---
 .../chrome/browser/ui/RootUiCoordinator.java  |  5 --
 .../ChromeProvidedSharingOptionsProvider.java | 19 -----
 chrome/browser/share/android/java_sources.gni | 18 ----
 .../AssistantQrCodeCameraCallbacks.java       | 69 ---------------
 .../AssistantQrCodeImagePickerCallbacks.java  | 85 -------------------
 5 files changed, 196 deletions(-)

diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ui/RootUiCoordinator.java b/chrome/android/java/src/org/chromium/chrome/browser/ui/RootUiCoordinator.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/ui/RootUiCoordinator.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ui/RootUiCoordinator.java
@@ -99,7 +99,6 @@ import org.chromium.chrome.browser.share.ShareButtonController;
 import org.chromium.chrome.browser.share.ShareDelegate;
 import org.chromium.chrome.browser.share.ShareDelegate.ShareOrigin;
 import org.chromium.chrome.browser.share.ShareUtils;
-import org.chromium.chrome.browser.share.qrcode.QrCodeDialog;
 import org.chromium.chrome.browser.share.scroll_capture.ScrollCaptureManager;
 import org.chromium.chrome.browser.tab.AccessibilityVisibilityHandler;
 import org.chromium.chrome.browser.tab.AutofillSessionLifetimeController;
@@ -498,10 +497,6 @@ public class RootUiCoordinator
     }
 
     public void onAttachFragment(Fragment fragment) {
-        if (fragment instanceof QrCodeDialog) {
-            QrCodeDialog qrCodeDialog = (QrCodeDialog) fragment;
-            qrCodeDialog.setWindowAndroid(mWindowAndroid);
-        }
     }
 
     @Override
diff --git a/chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/share_sheet/ChromeProvidedSharingOptionsProvider.java b/chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/share_sheet/ChromeProvidedSharingOptionsProvider.java
--- a/chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/share_sheet/ChromeProvidedSharingOptionsProvider.java
+++ b/chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/share_sheet/ChromeProvidedSharingOptionsProvider.java
@@ -31,7 +31,6 @@ import org.chromium.chrome.browser.share.ChromeShareExtras.DetailedContentType;
 import org.chromium.chrome.browser.share.SaveBitmapDelegate;
 import org.chromium.chrome.browser.share.link_to_text.LinkToTextCoordinator.LinkGeneration;
 import org.chromium.chrome.browser.share.long_screenshots.LongScreenshotsCoordinator;
-import org.chromium.chrome.browser.share.qrcode.QrCodeCoordinator;
 import org.chromium.chrome.browser.share.screenshot.ScreenshotCoordinator;
 import org.chromium.chrome.browser.share.send_tab_to_self.SendTabToSelfAndroidBridge;
 import org.chromium.chrome.browser.share.send_tab_to_self.SendTabToSelfCoordinator;
@@ -311,9 +310,6 @@ public class ChromeProvidedSharingOptionsProvider {
                 || !ChromeFeatureList.isEnabled(ChromeFeatureList.SEND_TAB_TO_SELF_SIGNIN_PROMO)) {
             mOrderedFirstPartyOptions.add(createSendTabToSelfFirstPartyOption());
         }
-        if (!mIsIncognito) {
-            mOrderedFirstPartyOptions.add(createQrCodeFirstPartyOption());
-        }
         if (mTabProvider.hasValue() && UserPrefs.get(mProfile).getBoolean(Pref.PRINTING_ENABLED)) {
             mOrderedFirstPartyOptions.add(createPrintingFirstPartyOption());
         }
@@ -456,21 +452,6 @@ public class ChromeProvidedSharingOptionsProvider {
                 .build();
     }
 
-    private FirstPartyOption createQrCodeFirstPartyOption() {
-        return new FirstPartyOptionBuilder(
-                ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.IMAGE)
-                .setDetailedContentTypesToDisableFor(
-                        DetailedContentType.LIGHTWEIGHT_REACTION, DetailedContentType.WEB_NOTES)
-                .setIcon(R.drawable.qr_code, R.string.qr_code_share_icon_label)
-                .setFeatureNameForMetrics("SharingHubAndroid.QRCodeSelected")
-                .setOnClickCallback((view) -> {
-                    QrCodeCoordinator qrCodeCoordinator =
-                            new QrCodeCoordinator(mActivity, mUrl, mShareParams.getWindow());
-                    qrCodeCoordinator.show();
-                })
-                .build();
-    }
-
     private FirstPartyOption createPrintingFirstPartyOption() {
         return new FirstPartyOptionBuilder(ContentType.LINK_PAGE_VISIBLE)
                 .setIcon(R.drawable.sharing_print, R.string.print_share_activity_title)
diff --git a/chrome/browser/share/android/java_sources.gni b/chrome/browser/share/android/java_sources.gni
--- a/chrome/browser/share/android/java_sources.gni
+++ b/chrome/browser/share/android/java_sources.gni
@@ -27,24 +27,6 @@ share_java_sources = [
   "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/long_screenshots/bitmap_generation/LongScreenshotsTabService.java",
   "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/long_screenshots/bitmap_generation/LongScreenshotsTabServiceFactory.java",
   "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/long_screenshots/bitmap_generation/ScreenshotBoundsManager.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/QRCodeGenerationRequest.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/QrCodeCoordinator.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/QrCodeDialog.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/QrCodeDialogTab.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/QrCodePageAdapter.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/TabLayoutPageListener.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/CameraPreview.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/CameraPreviewOverlay.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/QrCodeScanCoordinator.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/QrCodeScanMediator.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/QrCodeScanView.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/QrCodeScanViewBinder.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/QrCodeScanViewProperties.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareCoordinator.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareMediator.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareView.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareViewBinder.java",
-  "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareViewProperties.java",
   "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/screenshot/EditorScreenshotSource.java",
   "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/screenshot/EditorScreenshotTask.java",
   "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/screenshot/ScreenshotCoordinator.java",
diff --git a/components/autofill_assistant/guided_browsing/android/java/src/org/chromium/components/autofill_assistant/guided_browsing/qr_code/camera_scan/AssistantQrCodeCameraCallbacks.java b/components/autofill_assistant/guided_browsing/android/java/src/org/chromium/components/autofill_assistant/guided_browsing/qr_code/camera_scan/AssistantQrCodeCameraCallbacks.java
--- a/components/autofill_assistant/guided_browsing/android/java/src/org/chromium/components/autofill_assistant/guided_browsing/qr_code/camera_scan/AssistantQrCodeCameraCallbacks.java
+++ b/components/autofill_assistant/guided_browsing/android/java/src/org/chromium/components/autofill_assistant/guided_browsing/qr_code/camera_scan/AssistantQrCodeCameraCallbacks.java
@@ -9,10 +9,6 @@ import android.graphics.ImageFormat;
 import android.hardware.Camera;
 import android.util.SparseArray;
 
-import com.google.android.gms.vision.Frame;
-import com.google.android.gms.vision.barcode.Barcode;
-import com.google.android.gms.vision.barcode.BarcodeDetector;
-
 import org.chromium.base.task.AsyncTask;
 import org.chromium.base.task.PostTask;
 import org.chromium.components.autofill_assistant.guided_browsing.qr_code.AssistantQrCodeDelegate;
@@ -29,8 +25,6 @@ public class AssistantQrCodeCameraCallbacks
     private final AssistantQrCodeCameraScanModel mCameraScanModel;
     private final AssistantQrCodeCameraScanCoordinator.DialogCallbacks mDialogCallbacks;
 
-    private BarcodeDetector mDetector;
-
     /**
      * The AssistantQrCodeCameraCallbacks constructor.
      */
@@ -39,10 +33,6 @@ public class AssistantQrCodeCameraCallbacks
         mContext = context;
         mCameraScanModel = cameraScanModel;
         mDialogCallbacks = dialogCallbacks;
-
-        // Set detector to null until it gets initialized asynchronously.
-        mDetector = null;
-        initBarcodeDetectorAsync();
     }
 
     /**
@@ -53,39 +43,6 @@ public class AssistantQrCodeCameraCallbacks
      */
     @Override
     public void onPreviewFrame(byte[] data, Camera camera) {
-        if (mDetector == null) {
-            return;
-        }
-
-        ByteBuffer buffer = ByteBuffer.allocate(data.length);
-        buffer.put(data);
-        Frame frame =
-                new Frame.Builder()
-                        .setImageData(buffer, camera.getParameters().getPreviewSize().width,
-                                camera.getParameters().getPreviewSize().height, ImageFormat.NV21)
-                        .build();
-        SparseArray<Barcode> barcodes = mDetector.detect(frame);
-        if (!mCameraScanModel.get(AssistantQrCodeCameraScanModel.IS_ON_FOREGROUND)) {
-            return;
-        }
-        if (barcodes.size() == 0 || barcodes.valueAt(0).rawValue.isEmpty()) {
-            camera.setOneShotPreviewCallback(this);
-            return;
-        }
-
-        Barcode firstCode = barcodes.valueAt(0);
-        PostTask.postTask(UiThreadTaskTraits.DEFAULT, new Runnable() {
-            @Override
-            public void run() {
-                AssistantQrCodeDelegate delegate =
-                        mCameraScanModel.get(AssistantQrCodeCameraScanModel.DELEGATE);
-                if (delegate != null) {
-                    delegate.onScanResult(firstCode.rawValue);
-                }
-            }
-        });
-        // Dismiss the QR Code scan UI dialog.
-        mDialogCallbacks.dismiss();
     }
 
     /**
@@ -94,31 +51,5 @@ public class AssistantQrCodeCameraCallbacks
      */
     @Override
     public void onError(int error, Camera camera) {
-        PostTask.postTask(UiThreadTaskTraits.DEFAULT, new Runnable() {
-            @Override
-            public void run() {
-                AssistantQrCodeDelegate delegate =
-                        mCameraScanModel.get(AssistantQrCodeCameraScanModel.DELEGATE);
-                if (delegate != null) {
-                    delegate.onCameraError();
-                }
-            }
-        });
-        // Dismiss the QR Code scan UI dialog.
-        mDialogCallbacks.dismiss();
-    }
-
-    private void initBarcodeDetectorAsync() {
-        new AsyncTask<BarcodeDetector>() {
-            @Override
-            protected BarcodeDetector doInBackground() {
-                return new BarcodeDetector.Builder(mContext).build();
-            }
-
-            @Override
-            protected void onPostExecute(BarcodeDetector detector) {
-                mDetector = detector;
-            }
-        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
     }
 }
diff --git a/components/autofill_assistant/guided_browsing/android/java/src/org/chromium/components/autofill_assistant/guided_browsing/qr_code/image_picker/AssistantQrCodeImagePickerCallbacks.java b/components/autofill_assistant/guided_browsing/android/java/src/org/chromium/components/autofill_assistant/guided_browsing/qr_code/image_picker/AssistantQrCodeImagePickerCallbacks.java
--- a/components/autofill_assistant/guided_browsing/android/java/src/org/chromium/components/autofill_assistant/guided_browsing/qr_code/image_picker/AssistantQrCodeImagePickerCallbacks.java
+++ b/components/autofill_assistant/guided_browsing/android/java/src/org/chromium/components/autofill_assistant/guided_browsing/qr_code/image_picker/AssistantQrCodeImagePickerCallbacks.java
@@ -12,10 +12,6 @@ import android.net.Uri;
 import android.provider.MediaStore;
 import android.util.SparseArray;
 
-import com.google.android.gms.vision.Frame;
-import com.google.android.gms.vision.barcode.Barcode;
-import com.google.android.gms.vision.barcode.BarcodeDetector;
-
 import org.chromium.base.task.AsyncTask;
 import org.chromium.base.task.PostTask;
 import org.chromium.components.autofill_assistant.guided_browsing.qr_code.AssistantQrCodeDelegate;
@@ -33,8 +29,6 @@ public class AssistantQrCodeImagePickerCallbacks implements IntentCallback {
     private final AssistantQrCodeImagePickerModel mImagePickerModel;
     private final AssistantQrCodeImagePickerCoordinator.DialogCallbacks mDialogCallbacks;
 
-    private BarcodeDetector mDetector;
-
     /**
      * The AssistantQrCodeImagePickerCallbacks constructor.
      */
@@ -44,10 +38,6 @@ public class AssistantQrCodeImagePickerCallbacks implements IntentCallback {
         mContext = context;
         mImagePickerModel = imagePickerModel;
         mDialogCallbacks = dialogCallbacks;
-
-        // Set detector to null until it gets initialized asynchronously.
-        mDetector = null;
-        initBarcodeDetectorAsync();
     }
 
     /**
@@ -57,43 +47,6 @@ public class AssistantQrCodeImagePickerCallbacks implements IntentCallback {
      */
     @Override
     public void onIntentCompleted(int resultCode, Intent data) {
-        // When the user presses back button, the resultCode will not be RESULT_OK.
-        if (resultCode != Activity.RESULT_OK) {
-            onQrCodeScanCancel();
-            return;
-        }
-        if (data == null || mDetector == null) {
-            onQrCodeScanFailure();
-            return;
-        }
-
-        Uri imageUri = data.getData();
-        try {
-            Bitmap bitmap =
-                    MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), imageUri);
-            Frame frame = new Frame.Builder().setBitmap(bitmap).build();
-            SparseArray<Barcode> barcodes = mDetector.detect(frame);
-            if (barcodes.size() == 0 || barcodes.valueAt(0).rawValue.isEmpty()) {
-                onQrCodeScanFailure();
-                return;
-            }
-            Barcode firstCode = barcodes.valueAt(0);
-            PostTask.postTask(UiThreadTaskTraits.DEFAULT, new Runnable() {
-                @Override
-                public void run() {
-                    AssistantQrCodeDelegate delegate =
-                            mImagePickerModel.get(AssistantQrCodeImagePickerModel.DELEGATE);
-                    if (delegate != null) {
-                        delegate.onScanResult(firstCode.rawValue);
-                    }
-                }
-            });
-            // Dismiss the QR Code scan UI dialog.
-            mDialogCallbacks.dismiss();
-        } catch (IOException e) {
-            onQrCodeScanFailure();
-            return;
-        }
     }
 
     /**
@@ -101,18 +54,6 @@ public class AssistantQrCodeImagePickerCallbacks implements IntentCallback {
      * Image Picker dialog UI.
      */
     private void onQrCodeScanCancel() {
-        PostTask.postTask(UiThreadTaskTraits.DEFAULT, new Runnable() {
-            @Override
-            public void run() {
-                AssistantQrCodeDelegate delegate =
-                        mImagePickerModel.get(AssistantQrCodeImagePickerModel.DELEGATE);
-                if (delegate != null) {
-                    delegate.onScanCancelled();
-                }
-            }
-        });
-        // Dismiss the QR Code scan UI dialog.
-        mDialogCallbacks.dismiss();
     }
 
     /**
@@ -120,31 +61,5 @@ public class AssistantQrCodeImagePickerCallbacks implements IntentCallback {
      * Code Image Picker dialog UI.
      */
     private void onQrCodeScanFailure() {
-        PostTask.postTask(UiThreadTaskTraits.DEFAULT, new Runnable() {
-            @Override
-            public void run() {
-                AssistantQrCodeDelegate delegate =
-                        mImagePickerModel.get(AssistantQrCodeImagePickerModel.DELEGATE);
-                if (delegate != null) {
-                    delegate.onScanFailure();
-                }
-            }
-        });
-        // Dismiss the QR Code scan UI dialog.
-        mDialogCallbacks.dismiss();
-    }
-
-    private void initBarcodeDetectorAsync() {
-        new AsyncTask<BarcodeDetector>() {
-            @Override
-            protected BarcodeDetector doInBackground() {
-                return new BarcodeDetector.Builder(mContext).build();
-            }
-
-            @Override
-            protected void onPostExecute(BarcodeDetector detector) {
-                mDetector = detector;
-            }
-        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
     }
 }
--
2.25.1
