summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/ui/webui/chromeos/camera/camera_ui.cc
blob: 8a40f0cbdba1781f377471f680c9b85c4059793c (plain)
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
// 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.

#include "chrome/browser/ui/webui/chromeos/camera/camera_ui.h"

#include <utility>

#include "base/bind.h"
#include "base/feature_list.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/system_web_app_manager.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h"
#include "chrome/grit/camera_resources.h"
#include "chrome/grit/camera_resources_map.h"
#include "chromeos/constants/chromeos_features.h"
#include "content/public/browser/web_ui_data_source.h"
#include "mojo/public/js/grit/mojo_bindings_resources.h"

namespace chromeos {

namespace {

content::WebUIDataSource* CreateCameraUIHTMLSource() {
  content::WebUIDataSource* source =
      content::WebUIDataSource::Create(chrome::kChromeUICameraHost);

  // Add all settings resources.
  for (size_t i = 0; i < kCameraResourcesSize; ++i) {
    source->AddResourcePath(kCameraResources[i].name,
                            kCameraResources[i].value);
  }

  // Add WebUI version of the CCA browser proxy.
  source->AddResourcePath("src/js/browser_proxy/browser_proxy.js",
                          IDR_CAMERA_WEBUI_BROWSER_PROXY);

  // Add mojom-lite files under expected paths.
  source->AddResourcePath("src/js/mojo/image_capture.mojom-lite.js",
                          IDR_CAMERA_IMAGE_CAPTURE_MOJOM_LITE_JS);
  source->AddResourcePath("src/js/mojo/camera_common.mojom-lite.js",
                          IDR_CAMERA_CAMERA_COMMON_MOJOM_LITE_JS);
  source->AddResourcePath("src/js/mojo/camera_metadata.mojom-lite.js",
                          IDR_CAMERA_CAMERA_METADATA_MOJOM_LITE_JS);
  source->AddResourcePath("src/js/mojo/camera_metadata_tags.mojom-lite.js",
                          IDR_CAMERA_CAMERA_METADATA_TAGS_MOJOM_LITE_JS);
  source->AddResourcePath("src/js/mojo/camera_app.mojom-lite.js",
                          IDR_CAMERA_APP_MOJOM_LITE_JS);
  source->AddResourcePath("src/js/mojo/mojo_bindings_lite.js",
                          IDR_MOJO_MOJO_BINDINGS_LITE_JS);

  // Add System Web App resources.
  source->AddResourcePath("pwa.html", IDR_PWA_HTML);

  source->UseStringsJs();

  return source;
}

}  // namespace

///////////////////////////////////////////////////////////////////////////////
//
// CameraUI
//
///////////////////////////////////////////////////////////////////////////////

CameraUI::CameraUI(content::WebUI* web_ui) : ui::MojoWebUIController(web_ui) {
  Profile* profile = Profile::FromWebUI(web_ui);

  // Set up the data source.
  content::WebUIDataSource* source = CreateCameraUIHTMLSource();
  content::WebUIDataSource::Add(profile, source);
}

CameraUI::~CameraUI() = default;

// static
bool CameraUI::IsEnabled() {
  return web_app::SystemWebAppManager::IsAppEnabled(
      web_app::SystemAppType::CAMERA);
}

}  // namespace chromeos