Commit 723d89c1 authored by Tanisha Mandre's avatar Tanisha Mandre Committed by Commit Bot

Refactor QR scanner view controller files to subclass from Scanner View Controller

Architecture:
Superclass - scannerView
Subclasses - qrScannerView

Files just renamed and shifted to scanner directory:
- camera_controller
- qr_scanner_alerts
- qr_transitioning_delegate
- qr_scanner_presenting

Bug: 990744

Change-Id: I3fddd13f05e1a2bdd5de239c32f86979399eb925
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1741974
Commit-Queue: Tanisha Mandre <tanishamandre@google.com>
Reviewed-by: default avatarEric Noyau <noyau@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688254}
parent 60a9fb66
......@@ -237,22 +237,22 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_PRODUCT_NAME" desc="The Chrome application name">
Chromium
</message>
<message name="IDS_IOS_QR_SCANNER_CAMERA_IN_USE_ALERT_DETAIL" desc="Body of a modal dialog shown when the user tries to open the QR scanner but the camera is in use by another application. [Length: 140em] [iOS only]">
<message name="IDS_IOS_SCANNER_CAMERA_IN_USE_ALERT_DETAIL" desc="Body of a modal dialog shown when the user tries to open the QR or credit card scanner but the camera is in use by another application. [Length: 140em] [iOS only]">
Chromium can't use your camera because it's in use by another application
</message>
<message name="IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_DETAIL" desc="Body of modal dialog shown when the user tries to open the QR scanner but the application lacks permission to use the camera. The text instructs the user how to change the permissions setting. [Length: 140em] [iOS only]">
<message name="IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_DETAIL" desc="Body of modal dialog shown when the user tries to open the QR or credit card scanner but the application lacks permission to use the camera. The text instructs the user how to change the permissions setting. [Length: 140em] [iOS only]">
Open Settings &gt; Privacy &gt; Camera &gt; Chromium and turn on the camera.
</message>
<message name="IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE" desc="Title of modal dialog shown when the user tries to open the QR scanner but the application lacks permission to use the camera. The body of this dialog instructs the user how to change the permissions setting. [Length: 50em] [iOS only]">
Start using Chromium QR scanner
<message name="IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE" desc="Title of modal dialog shown when the user tries to open the QR or Credit Card scanner but the application lacks permission to use the camera. The body of this dialog instructs the user how to change the permissions setting. [Length: 50em] [iOS only]">
Start using Chromium scanner
</message>
<message name="IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE_GO_TO_SETTINGS" desc="Title of modal dialog shown when the user tries to open the QR scanner but the application lacks permission to use the camera. [Length: 40em] [iOS only]">
Turn on Chromium QR scanner
<message name="IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE_GO_TO_SETTINGS" desc="Title of modal dialog shown when the user tries to open the QR or credit card scanner but the application lacks permission to use the camera. [Length: 40em] [iOS only]">
Turn on Chromium scanner
</message>
<message name="IDS_IOS_QR_SCANNER_CAMERA_UNAVAILABLE_ALERT_DETAIL" desc="Body of a modal dialog shown when the user tries to open the QR scanner but the camera is unavailable. [Length: 140em] [iOS only]">
<message name="IDS_IOS_SCANNER_CAMERA_UNAVAILABLE_ALERT_DETAIL" desc="Body of a modal dialog shown when the user tries to open the QR or credit card scanner but the camera is unavailable. [Length: 140em] [iOS only]">
Chromium can't use your camera right now
</message>
<message name="IDS_IOS_QR_SCANNER_MULTIPLE_FOREGROUND_APPS_ALERT_DETAIL" desc="Body of a modal dialog shown when the user tries to open the QR scanner in a Split View mode, when the camera is unavailable. [Length: 140em] [iOS only]">
<message name="IDS_IOS_SCANNER_MULTIPLE_FOREGROUND_APPS_ALERT_DETAIL" desc="Body of a modal dialog shown when the user tries to open the QR or credit card scanner in a Split View mode, when the camera is unavailable. [Length: 140em] [iOS only]">
Chromium can't use your camera in Split View mode
</message>
<message name="IDS_IOS_SAFE_MODE_NAMED_TWEAKS_FOUND" desc="The message indicating a 3rd party tweak has been found that is known to crash Chromium. After the ':', we will list the names of the libraries. [Length: 140em]">
......
......@@ -246,8 +246,8 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE" desc="Title of modal dialog shown when the user tries to open the QR scanner but the application lacks permission to use the camera. The body of this dialog instructs the user how to change the permissions setting. [Length: 50em] [iOS only]">
Start using Google Chrome QR scanner
</message>
<message name="IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE_GO_TO_SETTINGS" desc="Title of modal dialog shown when the user tries to open the QR scanner but the application lacks permission to use the camera. [Length: 40em] [iOS only]">
Turn on Google Chrome QR scanner
<message name="IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE_GO_TO_SETTINGS" desc="Title of modal dialog shown when the user tries to open the QR or credit card scanner but the application lacks permission to use the camera. [Length: 40em] [iOS only]">
Chrome Would Like to Access the Camera
</message>
<message name="IDS_IOS_QR_SCANNER_CAMERA_UNAVAILABLE_ALERT_DETAIL" desc="Body of a modal dialog shown when the user tries to open the QR scanner but the camera is unavailable. [Length: 140em] [iOS only]">
Google Chrome can't use your camera right now
......
......@@ -1250,13 +1250,13 @@ Handoff must also be enabled in the General section of Settings, and your device
<message name="IDS_IOS_QR_SCANNER_MULTIPLE_FOREGROUND_APPS_ALERT_TITLE" desc="Title of a modal dialog shown when the user tries to open the QR scanner in a Split View mode. [Length: 40em] [iOS only]" meaning="Title of a Split View error dialog in QR Scanner.">
Split View
</message>
<message name="IDS_IOS_SCANNER_TORCH_BUTTON_ACCESSIBILITY_LABEL" desc="Accessibility label for the button to turn torch on and off in the scanner. The current state of the button is communicated using the accessibility value. [Length: unlimited] [iOS only]">
<message name="IDS_IOS_SCANNER_TORCH_BUTTON_ACCESSIBILITY_LABEL" desc="Accessibility label for the button to turn torch on and off in the Scanner. The current state of the button is communicated using the accessibility value. [Length: unlimited] [iOS only]" meaning="The button to turn on and off the torch. [20em] [Read by Text-to-Speech]">
Torch
</message>
<message name="IDS_IOS_SCANNER_TORCH_OFF_ACCESSIBILITY_VALUE" desc="Accessiblity value of the button to turn torch on in the scanner. The button communicates that the torch is current off. [Length: unlimited] [iOS only]">
<message name="IDS_IOS_SCANNER_TORCH_OFF_ACCESSIBILITY_VALUE" desc="Accessiblity value of the button to turn torch on in the Scanner. The button communicates that the torch is current off. [Length: unlimited] [iOS only]" meaning="The user will put off the torch [20em] [Read by Text-to-Speech]">
Off
</message>
<message name="IDS_IOS_SCANNER_TORCH_ON_ACCESSIBILITY_VALUE" desc="Accessibility value of the button to turn torch off in the scanner. The button communicates that the torch is currently on. [Length: unlimited] [iOS only]">
<message name="IDS_IOS_SCANNER_TORCH_ON_ACCESSIBILITY_VALUE" desc="Accessibility value of the button to turn torch off in the Scanner. The button communicates that the torch is currently on. [Length: unlimited] [iOS only]" meaning="The user will put on the torch [20em] [Read by Text-to-Speech]">
On
</message>
<message name="IDS_IOS_QR_SCANNER_VIEWPORT_CAPTION" desc="Message displayed below the QR scanner viewport instructing the user to position the scanned QR or bar code inside the viewport. [Length: unlimited] [iOS only]">
......@@ -1277,6 +1277,27 @@ Handoff must also be enabled in the General section of Settings, and your device
<message name="IDS_IOS_READING_LIST_CANCEL_BUTTON" desc="Label of the button to stop editing the reading list entries (delete, mark as read/unread) [Length: 25em]" meaning="Stop editing. [Length: 25em]">
Cancel
</message>
<message name="IDS_IOS_SCANNER_ALERT_CANCEL" desc="Title for a button to cancel a Scanner error dialog. The dialog will be dismissed and no action will be taken. [Length: 20em] [iOS only]" meaning="A button to cancel a Scanner error dialog.">
Cancel
</message>
<message name="IDS_IOS_SCANNER_CAMERA_IN_USE_ALERT_TITLE" desc="Title of a modal dialog shown when the user tries to open the scanner but the camera is in use by another application. [Length: 40em] [iOS only]">
Camera is in use
</message>
<message name="IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_DETAIL_GO_TO_SETTINGS" desc="Body of modal dialog shown when the user tries to open the scanner but the application lacks permission to use the camera. This body tells the users they'll be redirected to the Settings app. [Length: 140em] [iOS only]">
To scan a QR code or credit card, enable the camera from settings.
</message>
<message name="IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_GO_TO_SETTINGS" desc="Title for a button to go to System settings app. [Length: 20em] [iOS only]">
Settings
</message>
<message name="IDS_IOS_SCANNER_CAMERA_UNAVAILABLE_ALERT_TITLE" desc="Title of a modal dialog shown when the user tries to open the scanner but the camera is unavailable. [Length: 40em] [iOS only]">
Camera is unavailable
</message>
<message name="IDS_IOS_SCANNER_SCANNED_ACCESSIBILITY_ANNOUNCEMENT" desc="The accessibility announcement read by Voice Over when the user scans a QR code, bar code, or Credit Card. [Length: unlimited] [iOS only]">
Scanned
</message>
<message name="IDS_IOS_SCANNER_MULTIPLE_FOREGROUND_APPS_ALERT_TITLE" desc="Title of a modal dialog shown when the user tries to open the scanner in a Split View mode. [Length: 40em] [iOS only]" meaning="Title of a Split View error dialog in Scanner.">
Split View
</message>
<message name="IDS_IOS_TOOLS_MENU_CELL_NEW_FEATURE_BADGE" desc="Title and accessibility label of the badge displayed on a tools menu item when it represents a new feature [Length: 20em]" meaning="A badge with this title is displayed informing the user that this feature that is new to them.">
New
</message>
......
......@@ -5,13 +5,6 @@
source_set("qr_scanner") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"camera_controller.h",
"camera_controller.mm",
"qr_scanner_alerts.h",
"qr_scanner_alerts.mm",
"qr_scanner_presenting.h",
"qr_scanner_transitioning_delegate.h",
"qr_scanner_transitioning_delegate.mm",
"qr_scanner_view.h",
"qr_scanner_view.mm",
"qr_scanner_view_controller.h",
......@@ -47,6 +40,7 @@ source_set("coordinator") {
"//base",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/scanner",
"//ios/chrome/browser/ui/toolbar/public",
]
}
......@@ -70,6 +64,7 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/icons",
"//ios/chrome/browser/ui/location_bar",
"//ios/chrome/browser/ui/omnibox",
"//ios/chrome/browser/ui/scanner",
"//ios/chrome/browser/ui/toolbar",
"//ios/chrome/browser/ui/toolbar/public:feature_flags",
"//ios/chrome/browser/ui/util",
......
......@@ -7,15 +7,15 @@
#include "base/logging.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/qr_scanner/qr_scanner_presenting.h"
#import "ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller.h"
#import "ios/chrome/browser/ui/scanner/scanner_presenting.h"
#import "ios/chrome/browser/ui/toolbar/public/omnibox_focuser.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface QRScannerLegacyCoordinator ()<QRScannerPresenting>
@interface QRScannerLegacyCoordinator () <ScannerPresenting>
@property(nonatomic, readwrite, strong) QRScannerViewController* viewController;
......@@ -71,8 +71,8 @@
#pragma mark - QRScannerPresenting
- (void)dismissQRScannerViewController:(UIViewController*)controller
completion:(void (^)(void))completion {
- (void)dismissScannerViewController:(UIViewController*)controller
completion:(void (^)(void))completion {
DCHECK_EQ(self.viewController,
self.baseViewController.presentedViewController);
[self.baseViewController dismissViewControllerAnimated:YES
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_TRANSITIONING_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_TRANSITIONING_DELEGATE_H_
#import <UIKit/UIKit.h>
@interface QRScannerTransitioningDelegate
: NSObject<UIViewControllerTransitioningDelegate>
@end
#endif // IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_TRANSITIONING_DELEGATE_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#include "ios/chrome/browser/ui/qr_scanner/camera_controller.h"
#include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view.h"
#import "ios/chrome/browser/ui/scanner/scanner_view_controller.h"
@protocol LoadQueryCommands;
@protocol QRScannerPresenting;
// View controller for the QR scanner.
@interface QRScannerViewController
: UIViewController <CameraControllerDelegate, ScannerViewDelegate>
// View controller for the QR Scanner.
@interface QRScannerViewController : ScannerViewController
- (instancetype)initWithPresentationProvider:
(id<QRScannerPresenting>)presentationProvider
(id<ScannerPresenting>)presentationProvider
queryLoader:(id<LoadQueryCommands>)queryLoader
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithPresentationProvider:
(id<ScannerPresenting>)presentationProvider
cameraController:(CameraController*)cameraController
NS_UNAVAILABLE;
- (instancetype)initWithNibName:(NSString*)name
bundle:(NSBundle*)bundle NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)coder NS_UNAVAILABLE;
// Returns a view controller to be presented based on the camera state. Returns
// |self| if the camera is available or an appropriate UIAlertController if
// there was an error loading the camera.
- (UIViewController*)getViewControllerToPresent;
// Builds a scanner view overlay. Can be overridden by a subclass.
- (QRScannerView*)scannerView;
@end
#endif // IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_VIEW_CONTROLLER_H_
......@@ -16,9 +16,9 @@
#import "ios/chrome/browser/ui/location_bar/location_bar_coordinator.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_url_loader.h"
#include "ios/chrome/browser/ui/omnibox/location_bar_delegate.h"
#include "ios/chrome/browser/ui/qr_scanner/camera_controller.h"
#include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view.h"
#include "ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller.h"
#include "ios/chrome/browser/ui/scanner/camera_controller.h"
#import "ios/chrome/browser/ui/toolbar/public/features.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h"
......@@ -42,7 +42,7 @@
#endif
using namespace chrome_test_util;
using namespace qr_scanner;
using namespace scanner;
namespace {
......@@ -380,7 +380,7 @@ void TapKeyboardReturnKeyInOmniboxWithText(std::string text) {
IDS_IOS_QR_SCANNER_CAMERA_IN_USE_ALERT_TITLE);
case CAMERA_PERMISSION_DENIED:
return l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE_GO_TO_SETTINGS);
IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE_GO_TO_SETTINGS);
case CAMERA_UNAVAILABLE_DUE_TO_SYSTEM_PRESSURE:
case CAMERA_UNAVAILABLE:
return l10n_util::GetNSString(
......
......@@ -5,10 +5,19 @@
source_set("scanner") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"camera_controller.h",
"camera_controller.mm",
"preview_overlay_view.h",
"preview_overlay_view.mm",
"scanner_alerts.h",
"scanner_alerts.mm",
"scanner_presenting.h",
"scanner_transitioning_delegate.h",
"scanner_transitioning_delegate.mm",
"scanner_view.h",
"scanner_view.mm",
"scanner_view_controller.h",
"scanner_view_controller.mm",
"video_preview_view.h",
"video_preview_view.mm",
]
......
......@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_QR_SCANNER_CAMERA_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_QR_SCANNER_CAMERA_CONTROLLER_H_
#ifndef IOS_CHROME_BROWSER_UI_SCANNER_CAMERA_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SCANNER_CAMERA_CONTROLLER_H_
#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>
#include "base/ios/block_types.h"
namespace qr_scanner {
namespace scanner {
// Values to distinguish between different camera states to display the correct
// view controller or system alert.
......@@ -38,7 +38,7 @@ enum CameraState {
CAMERA_NOT_LOADED,
};
} // namespace qr_scanner
} // namespace scanner
@protocol CameraControllerDelegate
......@@ -46,7 +46,7 @@ enum CameraState {
// preview.
- (void)captureSessionIsConnected;
// Called on the main queue when the camera state changes.
- (void)cameraStateChanged:(qr_scanner::CameraState)state;
- (void)cameraStateChanged:(scanner::CameraState)state;
// Called on the main queue when the torch state changes.
- (void)torchStateChanged:(BOOL)torchIsOn;
// Called on the main queue when the torch availability changes.
......@@ -109,4 +109,4 @@ enum CameraState {
@end
#endif // IOS_CHROME_BROWSER_UI_QR_SCANNER_CAMERA_CONTROLLER_H_
#endif // IOS_CHROME_BROWSER_UI_SCANNER_CAMERA_CONTROLLER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/qr_scanner/camera_controller.h"
#import "ios/chrome/browser/ui/scanner/camera_controller.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
......@@ -13,7 +13,7 @@
#error "This file requires ARC support."
#endif
@interface CameraController ()<AVCaptureMetadataOutputObjectsDelegate> {
@interface CameraController () <AVCaptureMetadataOutputObjectsDelegate> {
// The queue for dispatching calls to |_captureSession|.
dispatch_queue_t _sessionQueue;
}
......@@ -23,7 +23,7 @@
@property(nonatomic, readwrite, weak) id<CameraControllerDelegate> delegate;
// The current state of the camera. The state is set to CAMERA_NOT_LOADED before
// the camera is first loaded, and afterwards it is never CAMERA_NOT_LOADED.
@property(nonatomic, readwrite, assign) qr_scanner::CameraState cameraState;
@property(nonatomic, readwrite, assign) scanner::CameraState cameraState;
// Redeclaration of |torchActive| to make the setter private.
@property(nonatomic, readwrite, assign, getter=isTorchActive) BOOL torchActive;
// The current availability of the torch.
......@@ -59,7 +59,7 @@
@implementation CameraController
#pragma mark lifecycle
#pragma mark - Lifecycle
+ (instancetype)cameraControllerWithDelegate:
(id<CameraControllerDelegate>)delegate {
......@@ -72,7 +72,7 @@
self = [super init];
if (self) {
DCHECK(delegate);
_cameraState = qr_scanner::CAMERA_NOT_LOADED;
_cameraState = scanner::CAMERA_NOT_LOADED;
_delegate = delegate;
std::string queueName =
base::StringPrintf("%s.chrome.ios.QRScannerCaptureSessionQueue",
......@@ -90,7 +90,7 @@
[self stopReceivingNotifications];
}
#pragma mark public methods
#pragma mark - Public methods
- (AVAuthorizationStatus)getAuthorizationStatus {
return [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
......@@ -105,8 +105,7 @@
requestAccessForMediaType:AVMediaTypeVideo
completionHandler:^void(BOOL granted) {
if (!granted) {
[weakSelf
setCameraState:qr_scanner::CAMERA_PERMISSION_DENIED];
[weakSelf setCameraState:scanner::CAMERA_PERMISSION_DENIED];
} else {
[weakSelf loadCaptureSession:previewLayer];
}
......@@ -186,15 +185,15 @@
});
}
#pragma mark private methods
#pragma mark - Private methods
- (BOOL)isCameraAvailable {
return [self cameraState] == qr_scanner::CAMERA_AVAILABLE;
return [self cameraState] == scanner::CAMERA_AVAILABLE;
}
- (void)loadCaptureSession:(AVCaptureVideoPreviewLayer*)previewLayer {
DCHECK(previewLayer);
DCHECK([self cameraState] == qr_scanner::CAMERA_NOT_LOADED);
DCHECK([self cameraState] == scanner::CAMERA_NOT_LOADED);
DCHECK([self getAuthorizationStatus] == AVAuthorizationStatusAuthorized);
__weak CameraController* weakSelf = self;
dispatch_async(_sessionQueue, ^{
......@@ -213,7 +212,7 @@
position:AVCaptureDevicePositionBack];
videoCaptureDevices = [discoverySession devices];
if ([videoCaptureDevices count] == 0) {
[self setCameraState:qr_scanner::CAMERA_UNAVAILABLE];
[self setCameraState:scanner::CAMERA_UNAVAILABLE];
return;
}
......@@ -225,7 +224,7 @@
// Allow only the back camera.
if (cameraIndex == NSNotFound) {
[self setCameraState:qr_scanner::CAMERA_UNAVAILABLE];
[self setCameraState:scanner::CAMERA_UNAVAILABLE];
return;
}
AVCaptureDevice* camera = videoCaptureDevices[cameraIndex];
......@@ -235,13 +234,13 @@
AVCaptureDeviceInput* videoInput =
[AVCaptureDeviceInput deviceInputWithDevice:camera error:&error];
if (error || !videoInput) {
[self setCameraState:qr_scanner::CAMERA_UNAVAILABLE];
[self setCameraState:scanner::CAMERA_UNAVAILABLE];
return;
}
AVCaptureSession* session = [[AVCaptureSession alloc] init];
if (![session canAddInput:videoInput]) {
[self setCameraState:qr_scanner::CAMERA_UNAVAILABLE];
[self setCameraState:scanner::CAMERA_UNAVAILABLE];
return;
}
[session addInput:videoInput];
......@@ -252,7 +251,7 @@
[metadataOutput setMetadataObjectsDelegate:self
queue:dispatch_get_main_queue()];
if (![session canAddOutput:metadataOutput]) {
[self setCameraState:qr_scanner::CAMERA_UNAVAILABLE];
[self setCameraState:scanner::CAMERA_UNAVAILABLE];
return;
}
[session addOutput:metadataOutput];
......@@ -260,14 +259,14 @@
// Require QR code recognition to be available.
if (![availableCodeTypes containsObject:AVMetadataObjectTypeQRCode]) {
[self setCameraState:qr_scanner::CAMERA_UNAVAILABLE];
[self setCameraState:scanner::CAMERA_UNAVAILABLE];
return;
}
[metadataOutput setMetadataObjectTypes:availableCodeTypes];
_metadataOutput = metadataOutput;
_captureSession = session;
[self setCameraState:qr_scanner::CAMERA_AVAILABLE];
[self setCameraState:scanner::CAMERA_AVAILABLE];
// Setup torchAvailable.
[self setTorchAvailable:[camera hasTorch] &&
[camera isTorchModeSupported:AVCaptureTorchModeOn] &&
......@@ -365,12 +364,12 @@
}
}
#pragma mark notification handlers
#pragma mark - Notification Handlers
- (void)handleAVCaptureSessionRuntimeError:(NSNotification*)notification {
__weak CameraController* weakSelf = self;
dispatch_async(_sessionQueue, ^{
[weakSelf setCameraState:qr_scanner::CAMERA_UNAVAILABLE];
[weakSelf setCameraState:scanner::CAMERA_UNAVAILABLE];
});
}
......@@ -386,15 +385,14 @@
// is backgrounded and foregrounded.
break;
case AVCaptureSessionInterruptionReasonVideoDeviceInUseByAnotherClient:
[weakSelf
setCameraState:qr_scanner::CAMERA_IN_USE_BY_ANOTHER_APPLICATION];
[weakSelf setCameraState:scanner::CAMERA_IN_USE_BY_ANOTHER_APPLICATION];
break;
case AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableWithMultipleForegroundApps:
[weakSelf setCameraState:qr_scanner::MULTIPLE_FOREGROUND_APPS];
[weakSelf setCameraState:scanner::MULTIPLE_FOREGROUND_APPS];
break;
case AVCaptureSessionInterruptionReasonVideoDeviceNotAvailableDueToSystemPressure:
[weakSelf setCameraState:qr_scanner::
CAMERA_UNAVAILABLE_DUE_TO_SYSTEM_PRESSURE];
[weakSelf
setCameraState:scanner::CAMERA_UNAVAILABLE_DUE_TO_SYSTEM_PRESSURE];
break;
case AVCaptureSessionInterruptionReasonAudioDeviceInUseByAnotherClient:
NOTREACHED();
......@@ -408,7 +406,7 @@
dispatch_async(_sessionQueue, ^{
CameraController* strongSelf = weakSelf;
if (strongSelf && [strongSelf.captureSession isRunning]) {
[strongSelf setCameraState:qr_scanner::CAMERA_AVAILABLE];
[strongSelf setCameraState:scanner::CAMERA_AVAILABLE];
}
});
}
......@@ -416,7 +414,7 @@
- (void)handleAVCaptureDeviceWasDisconnected:(NSNotification*)notification {
__weak CameraController* weakSelf = self;
dispatch_async(_sessionQueue, ^{
[weakSelf setCameraState:qr_scanner::CAMERA_UNAVAILABLE];
[weakSelf setCameraState:scanner::CAMERA_UNAVAILABLE];
});
}
......@@ -433,9 +431,9 @@
}
}
#pragma mark property implementation
#pragma mark - Property Implementation
- (void)setCameraState:(qr_scanner::CameraState)state {
- (void)setCameraState:(scanner::CameraState)state {
if (state == _cameraState) {
return;
}
......@@ -468,7 +466,7 @@
});
}
#pragma mark AVCaptureMetadataOutputObjectsDelegate
#pragma mark - AVCaptureMetadataOutputObjectsDelegate
- (void)captureOutput:(AVCaptureOutput*)captureOutput
didOutputMetadataObjects:(NSArray*)metadataObjects
......
......@@ -105,7 +105,7 @@ const CGFloat kViewportBorderShadowRadius = 10.0;
[_viewportBorder setMask:[self viewportBorderMaskWithFrameSize:frameSize]];
}
#pragma mark Private
#pragma mark - Private
// Creates a square mask for the overlay to keep the viewport transparent.
- (CAShapeLayer*)viewportMaskWithFrameSize:(CGSize)frameSize {
......
......@@ -2,15 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_ALERTS_H_
#define IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_ALERTS_H_
#ifndef IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_ALERTS_H_
#define IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_ALERTS_H_
#include "ios/chrome/browser/ui/qr_scanner/camera_controller.h"
#include "ios/chrome/browser/ui/scanner/camera_controller.h"
@class UIAlertAction;
@class UIAlertController;
#import <UIKit/UIKit.h>
namespace qr_scanner {
namespace scanner {
// Block type that takes a UIAlertAction. Blocks of this type will be called
// when the Cancel button of a UIAlertView is pressed.
......@@ -22,6 +21,6 @@ typedef void (^CancelAlertAction)(UIAlertAction* alertAction);
UIAlertController* DialogForCameraState(CameraState state,
CancelAlertAction cancelBlock);
} // namespace qr_scanner
} // namespace scanner
#endif // IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_ALERTS_H_
#endif // IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_ALERTS_H_
......@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/qr_scanner/qr_scanner_alerts.h"
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/scanner/scanner_alerts.h"
#include "base/logging.h"
#include "components/version_info/version_info.h"
......@@ -20,9 +18,9 @@
namespace {
// Returns a "Cancel" UIAlertAction for the given |block|.
UIAlertAction* CancelAction(qr_scanner::CancelAlertAction block) {
UIAlertAction* CancelAction(scanner::CancelAlertAction block) {
NSString* cancelButtonTitle =
l10n_util::GetNSString(IDS_IOS_QR_SCANNER_ALERT_CANCEL);
l10n_util::GetNSString(IDS_IOS_SCANNER_ALERT_CANCEL);
return [UIAlertAction actionWithTitle:cancelButtonTitle
style:UIAlertActionStyleCancel
handler:block];
......@@ -34,7 +32,7 @@ UIAlertAction* CancelAction(qr_scanner::CancelAlertAction block) {
UIAlertController* AlertWithCancelButton(
NSString* title,
NSString* body,
qr_scanner::CancelAlertAction cancelBlock) {
scanner::CancelAlertAction cancelBlock) {
UIAlertController* dialog =
[UIAlertController alertControllerWithTitle:title
message:body
......@@ -54,25 +52,25 @@ UIAlertController* AlertWithCancelButton(
// Returns a UIAlertController to be displayed when the camera state is
// CAMERA_PERMISSION_DENIED.
UIAlertController* CameraPermissionDeniedDialog(
qr_scanner::CancelAlertAction cancelBlock) {
scanner::CancelAlertAction cancelBlock) {
NSURL* settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (![[UIApplication sharedApplication] canOpenURL:settingsURL]) {
// Display a dialog instructing the user how to change the settings.
NSString* dialogTitle = l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE);
NSString* dialogBody = l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_DETAIL);
NSString* dialogTitle =
l10n_util::GetNSString(IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE);
NSString* dialogBody =
l10n_util::GetNSString(IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_DETAIL);
return AlertWithCancelButton(dialogTitle, dialogBody, cancelBlock);
}
// Display a dialog with a link to the Settings app.
NSString* dialogTitle = l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE_GO_TO_SETTINGS);
IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_TITLE_GO_TO_SETTINGS);
NSString* dialogBody = l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_DETAIL_GO_TO_SETTINGS);
IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_DETAIL_GO_TO_SETTINGS);
NSString* settingsButton = l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_CAMERA_PERMISSIONS_HELP_GO_TO_SETTINGS);
IDS_IOS_SCANNER_CAMERA_PERMISSIONS_HELP_GO_TO_SETTINGS);
UIAlertController* dialog =
AlertWithCancelButton(dialogTitle, dialogBody, cancelBlock);
......@@ -94,44 +92,44 @@ UIAlertController* CameraPermissionDeniedDialog(
} // namespace
namespace qr_scanner {
namespace scanner {
UIAlertController* DialogForCameraState(
CameraState state,
qr_scanner::CancelAlertAction cancelBlock) {
scanner::CancelAlertAction cancelBlock) {
NSString* dialogTitle = nil;
NSString* dialogBody = nil;
switch (state) {
case qr_scanner::CAMERA_AVAILABLE:
case qr_scanner::CAMERA_NOT_LOADED:
case scanner::CAMERA_AVAILABLE:
case scanner::CAMERA_NOT_LOADED:
NOTREACHED();
return nil;
case qr_scanner::CAMERA_IN_USE_BY_ANOTHER_APPLICATION:
case scanner::CAMERA_IN_USE_BY_ANOTHER_APPLICATION:
dialogTitle =
l10n_util::GetNSString(IDS_IOS_QR_SCANNER_CAMERA_IN_USE_ALERT_TITLE);
l10n_util::GetNSString(IDS_IOS_SCANNER_CAMERA_IN_USE_ALERT_TITLE);
dialogBody =
l10n_util::GetNSString(IDS_IOS_QR_SCANNER_CAMERA_IN_USE_ALERT_DETAIL);
l10n_util::GetNSString(IDS_IOS_SCANNER_CAMERA_IN_USE_ALERT_DETAIL);
return AlertWithCancelButton(dialogTitle, dialogBody, cancelBlock);
case qr_scanner::MULTIPLE_FOREGROUND_APPS:
case scanner::MULTIPLE_FOREGROUND_APPS:
dialogTitle = l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_MULTIPLE_FOREGROUND_APPS_ALERT_TITLE);
IDS_IOS_SCANNER_MULTIPLE_FOREGROUND_APPS_ALERT_TITLE);
dialogBody = l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_MULTIPLE_FOREGROUND_APPS_ALERT_DETAIL);
IDS_IOS_SCANNER_MULTIPLE_FOREGROUND_APPS_ALERT_DETAIL);
return AlertWithCancelButton(dialogTitle, dialogBody, cancelBlock);
case qr_scanner::CAMERA_PERMISSION_DENIED:
case scanner::CAMERA_PERMISSION_DENIED:
return CameraPermissionDeniedDialog(cancelBlock);
case qr_scanner::CAMERA_UNAVAILABLE_DUE_TO_SYSTEM_PRESSURE:
case qr_scanner::CAMERA_UNAVAILABLE:
case scanner::CAMERA_UNAVAILABLE_DUE_TO_SYSTEM_PRESSURE:
case scanner::CAMERA_UNAVAILABLE:
dialogTitle = l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_CAMERA_UNAVAILABLE_ALERT_TITLE);
IDS_IOS_SCANNER_CAMERA_UNAVAILABLE_ALERT_TITLE);
dialogBody = l10n_util::GetNSString(
IDS_IOS_QR_SCANNER_CAMERA_UNAVAILABLE_ALERT_DETAIL);
IDS_IOS_SCANNER_CAMERA_UNAVAILABLE_ALERT_DETAIL);
return AlertWithCancelButton(dialogTitle, dialogBody, cancelBlock);
}
}
} // namespace qr_scanner
} // namespace scanner
// Copyright 2017 The Chromium Authors. All rights reserved.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_PRESENTING_H_
#define IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_PRESENTING_H_
#ifndef IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_PRESENTING_H_
#define IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_PRESENTING_H_
// QRScannerPresenting contains methods that control how the QR scanner UI is
// ScannerPresenting contains methods that control how a scanner UI is
// dismissed on screen.
@protocol QRScannerPresenting
@protocol ScannerPresenting
// Asks the implementer to dismiss the given |controller| and call the given
// |completion| afterwards.
- (void)dismissQRScannerViewController:(UIViewController*)controller
completion:(void (^)(void))completion;
- (void)dismissScannerViewController:(UIViewController*)controller
completion:(void (^)(void))completion;
@end
#endif // IOS_CHROME_BROWSER_UI_QR_SCANNER_QR_SCANNER_PRESENTING_H_
#endif // IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_PRESENTING_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_TRANSITIONING_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_TRANSITIONING_DELEGATE_H_
#import <UIKit/UIKit.h>
@interface ScannerTransitioningDelegate
: NSObject <UIViewControllerTransitioningDelegate>
@end
#endif // IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_TRANSITIONING_DELEGATE_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/qr_scanner/qr_scanner_transitioning_delegate.h"
#import "ios/chrome/browser/ui/scanner/scanner_transitioning_delegate.h"
#include "base/ios/block_types.h"
......@@ -15,28 +15,28 @@ namespace {
// The default animation duration.
const NSTimeInterval kDefaultDuration = 0.25;
enum QRScannerTransition { PRESENT, DISMISS };
enum ScannerTransition { PRESENT, DISMISS };
} // namespace
// Animates the QR Scanner transition. If initialized with the |PRESENT|
// transition, positions the QR Scanner view below its presenting view
// Animates the Scanner transition. If initialized with the |PRESENT|
// transition, positions the Scanner view below its presenting view
// controller's view in the container view and animates the presenting view to
// slide up. If initialized with the |DISMISS| transition, positions the
// presenting view controller's view above the QR Scanner view in the container
// presenting view controller's view above the Scanner view in the container
// view and animates the presenting view to slide down.
@interface QRScannerTransitionAnimator
: NSObject<UIViewControllerAnimatedTransitioning> {
QRScannerTransition _transition;
@interface ScannerTransitionAnimator
: NSObject <UIViewControllerAnimatedTransitioning> {
ScannerTransition _transition;
}
- (instancetype)initWithTransition:(QRScannerTransition)transition;
- (instancetype)initWithTransition:(ScannerTransition)transition;
@end
@implementation QRScannerTransitionAnimator
@implementation ScannerTransitionAnimator
- (instancetype)initWithTransition:(QRScannerTransition)transition {
- (instancetype)initWithTransition:(ScannerTransition)transition {
self = [super init];
if (self) {
_transition = transition;
......@@ -108,18 +108,18 @@ enum QRScannerTransition { PRESENT, DISMISS };
@end
@implementation QRScannerTransitioningDelegate
@implementation ScannerTransitioningDelegate
- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForPresentedController:(UIViewController*)presented
presentingController:(UIViewController*)presenting
sourceController:(UIViewController*)source {
return [[QRScannerTransitionAnimator alloc] initWithTransition:PRESENT];
animationControllerForPresentedController:(UIViewController*)presented
presentingController:(UIViewController*)presenting
sourceController:(UIViewController*)source {
return [[ScannerTransitionAnimator alloc] initWithTransition:PRESENT];
}
- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForDismissedController:(UIViewController*)dismissed {
return [[QRScannerTransitionAnimator alloc] initWithTransition:DISMISS];
animationControllerForDismissedController:(UIViewController*)dismissed {
return [[ScannerTransitionAnimator alloc] initWithTransition:DISMISS];
}
@end
......@@ -174,7 +174,7 @@ const CGFloat kFlashDuration = 0.5;
}
- (NSString*)caption {
return nil;
return @"";
}
#pragma mark - private methods
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#include "ios/chrome/browser/ui/scanner/camera_controller.h"
#include "ios/chrome/browser/ui/scanner/scanner_view.h"
namespace scannerViewController {
// The reason why the ScannerViewController was dismissed. Used for collecting
// metrics.
enum DismissalReason {
CLOSE_BUTTON,
ERROR_DIALOG,
SCANNED_CODE,
// Not reported. Should be kept last of enum.
IMPOSSIBLY_UNLIKELY_AUTHORIZATION_CHANGE
};
} // namespace scannerViewController
@protocol ScannerPresenting;
// View controller for a generic scanner. This is an abstract class that creates
// the view and camera controller, required for a QR code or Credit Card
// Scanner.
@interface ScannerViewController
: UIViewController <CameraControllerDelegate, ScannerViewDelegate>
// Stores the camera controller for the scanner.
@property(nonatomic, readwrite, strong) CameraController* cameraController;
// Stores the presentation provider.
@property(nonatomic, readwrite, weak) id<ScannerPresenting>
presentationProvider;
- (instancetype)initWithPresentationProvider:
(id<ScannerPresenting>)presentationProvider
cameraController:(CameraController*)cameraController
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithNibName:(NSString*)name
bundle:(NSBundle*)bundle NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)coder NS_UNAVAILABLE;
// Returns a view controller to be presented based on the camera state. Returns
// |self| if the camera is available or an appropriate UIAlertController if
// there was an error loading the camera.
- (UIViewController*)getViewControllerToPresent;
// Builds the scanner view. Must be overridden in the subclass.
- (ScannerView*)buildScannerView;
// Dismiss scanner. Subclass can override to update metrics.
// implementation.
- (void)dismissForReason:(scannerViewController::DismissalReason)reason
withCompletion:(void (^)(void))completion;
- (void)stopReceivingNotifications;
- (void)setTorchMode:(AVCaptureTorchMode)mode;
@end
#endif // IOS_CHROME_BROWSER_UI_SCANNER_SCANNER_VIEW_CONTROLLER_H_
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment