1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170

ash / webui / camera_app_ui / camera_app_ui_delegate.h [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WEBUI_CAMERA_APP_UI_CAMERA_APP_UI_DELEGATE_H_
#define ASH_WEBUI_CAMERA_APP_UI_CAMERA_APP_UI_DELEGATE_H_

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "ash/webui/camera_app_ui/ocr.mojom-forward.h"
#include "ash/webui/camera_app_ui/pdf_builder.mojom-forward.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"

namespace content {
class BrowserContext;
class WebContents;
class WebUIDataSource;
}  // namespace content

namespace media_device_salt {
class MediaDeviceSaltService;
}  // namespace media_device_salt

namespace ash {

class ProgressivePdf {
 public:
  virtual ~ProgressivePdf() = default;

  // Adds a new page to the PDF at `page_index`. If a page at `page_index`
  // already exists, it will be replaced.
  virtual void NewPage(const std::vector<uint8_t>& jpg,
                       uint32_t page_index) = 0;

  // Deletes the page of the PDF at `page_index`.
  virtual void DeletePage(uint32_t page_index) = 0;

  // Returns the PDF produced by the preceding operations.
  virtual void Save(base::OnceCallback<void(const std::vector<uint8_t>&)>) = 0;
};
// A delegate which exposes browser functionality from //chrome to the camera
// app ui page handler.
class CameraAppUIDelegate {
 public:
  enum class FileMonitorResult {
    // The file is deleted.
    kDeleted = 0,

    // The request is canceled since there is another monitor request.
    kCanceled = 1,

    // Fails to monitor the file due to errors.
    kError = 2,
  };

  enum class StorageMonitorStatus {
    // Storage has enough space to operate CCA functions.
    kNormal = 0,

    // Storage is getting low, display warning to users.
    kLow = 1,

    // Storage is almost full. Should stop ongoing recording and don't allow new
    // recording.
    kCriticallyLow = 2,

    // Monitoring got canceled since there is another monitor request.
    kCanceled = 3,

    // Monitoring get errors.
    kError = 4,
  };

  struct WifiConfig {
    WifiConfig();
    WifiConfig(const WifiConfig&);
    WifiConfig& operator=(const WifiConfig&);
    ~WifiConfig();

    std::string ssid;
    std::string security;
    std::optional<std::string> password;
    std::optional<std::string> eap_method;
    std::optional<std::string> eap_phase2_method;
    std::optional<std::string> eap_identity;
    std::optional<std::string> eap_anonymous_identity;
  };

  virtual ~CameraAppUIDelegate() = default;

  // Takes a WebUIDataSource, and adds load time data into it.
  virtual void PopulateLoadTimeData(content::WebUIDataSource* source) = 0;

  // Checks if the logging consent option is enabled.
  virtual bool IsMetricsAndCrashReportingEnabled() = 0;

  // Opens the file in Downloads folder by its |name| in gallery.
  virtual void OpenFileInGallery(const std::string& name) = 0;

  // Opens the native chrome feedback dialog scoped to chrome://camera-app and
  // show |placeholder| in the description field.
  virtual void OpenFeedbackDialog(const std::string& placeholder) = 0;

  // Gets the file path in ARC file system by given file |name|.
  virtual std::string GetFilePathInArcByName(const std::string& name) = 0;

  // Opens the dev tools window.
  virtual void OpenDevToolsWindow(content::WebContents* web_contents) = 0;

  // Monitors deletion of the file by its |name|. The |callback| might be
  // triggered when the file is deleted, or when the monitor is canceled, or
  // when error occurs.
  virtual void MonitorFileDeletion(
      const std::string& name,
      base::OnceCallback<void(FileMonitorResult)> callback) = 0;

  // Maybe triggers HaTS survey for the camera app if all the conditions match.
  virtual void MaybeTriggerSurvey() = 0;

  // Start monitor storage status, |monitor_callback| will be called at initial
  // time and every time the status is changed.
  virtual void StartStorageMonitor(
      base::RepeatingCallback<void(StorageMonitorStatus)> monitor_callback) = 0;

  // Stop ongoing storage monitoring, if there is one, otherwise no-ops.
  virtual void StopStorageMonitor() = 0;

  // Open "Storage management" page in system's Settings app.
  virtual void OpenStorageManagement() = 0;

  // Gets the file path by given file |name|.
  virtual base::FilePath GetFilePathByName(const std::string& name) = 0;

  // Returns a service that provides persistent salts for generating media
  // device IDs. Can be null if the embedder does not support persistent salts.
  virtual media_device_salt::MediaDeviceSaltService* GetMediaDeviceSaltService(
      content::BrowserContext* context) = 0;

  // Opens a Wi-Fi connection dialog based on the given information.
  virtual void OpenWifiDialog(WifiConfig wifi_config) = 0;

  // Gets the system language of the current profile.
  virtual std::string GetSystemLanguage() = 0;

  // Returns the first page of a PDF as a JPEG.
  virtual void RenderPdfAsJpeg(
      const std::vector<uint8_t>& pdf,
      base::OnceCallback<void(const std::vector<uint8_t>&)> callback) = 0;

  // Performs OCR on the image and returns the OCR result.
  virtual void PerformOcr(
      base::span<const uint8_t> jpeg_data,
      base::OnceCallback<void(camera_app::mojom::OcrResultPtr)> callback) = 0;

  // Creates a PDF and provides operations to add and delete pages, and save the
  // searchified PDF.
  virtual void CreatePdfBuilder(
      mojo::PendingReceiver<camera_app::mojom::PdfBuilder>) = 0;
};

}  // namespace ash

#endif  // ASH_WEBUI_CAMERA_APP_UI_CAMERA_APP_UI_DELEGATE_H_