File: ambient_video_view.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (87 lines) | stat: -rw-r--r-- 3,260 bytes parent folder | download | duplicates (5)
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
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/ambient/ui/ambient_video_view.h"

#include <string_view>

#include "ash/ambient/ambient_ui_settings.h"
#include "ash/ambient/metrics/ambient_metrics.h"
#include "ash/ambient/ui/ambient_slideshow_peripheral_ui.h"
#include "ash/ambient/ui/ambient_view_ids.h"
#include "ash/public/cpp/ambient/ambient_ui_model.h"
#include "ash/public/cpp/ash_web_view.h"
#include "ash/public/cpp/ash_web_view_factory.h"
#include "ash/webui/personalization_app/mojom/personalization_app.mojom-shared.h"
#include "base/check.h"
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/strings/strcat.h"

#include "base/time/time.h"
#include "net/base/url_util.h"
#include "ui/views/layout/fill_layout.h"
#include "url/gurl.h"
#include "url/url_constants.h"

namespace ash {

namespace {

constexpr std::string_view kAmbientVideoFileQueryParam = "video_file";

// Apply the same jitter interval to the peripheral elements as the slideshow
// theme does (which applies jitter each time the photo switches).
constexpr base::TimeDelta kPeripheralUiJitterPeriod = kPhotoRefreshInterval;

GURL BuildFileUrl(const base::FilePath& file_path) {
  return GURL(base::StrCat(
      {url::kFileScheme, url::kStandardSchemeSeparator, file_path.value()}));
}

}  // namespace

AmbientVideoView::AmbientVideoView(std::string_view video_file,
                                   const base::FilePath& html_path,
                                   AmbientVideo video,
                                   AmbientViewDelegate* view_delegate)
    : video_(video),
      peripheral_ui_(
          std::make_unique<AmbientSlideshowPeripheralUi>(view_delegate)) {
  DCHECK(!video_file.empty());
  DCHECK(!html_path.empty());
  DCHECK(AshWebViewFactory::Get());
  SetUseDefaultFillLayout(true);
  AshWebView::InitParams web_view_params;
  // Disables wake locks so the video doesn't stop the device from going to
  // sleep.
  web_view_params.enable_wake_locks = false;
  ash_web_view_ =
      AddChildView(AshWebViewFactory::Get()->Create(web_view_params));
  ash_web_view_->SetID(kAmbientVideoWebView);
  ash_web_view_->SetUseDefaultFillLayout(true);
  GURL ambient_video_url = net::AppendQueryParameter(
      BuildFileUrl(html_path), kAmbientVideoFileQueryParam, video_file);
  ash_web_view_->Navigate(ambient_video_url);

  AddChildViewRaw(peripheral_ui_.get());
  peripheral_ui_->UpdateLeftPaddingToMatchBottom();
  // Update details label to empty string as details info is not shown for
  // ambient video.
  peripheral_ui_->UpdateImageDetails(u"", u"");
  peripheral_ui_jitter_timer_.Start(
      FROM_HERE, kPeripheralUiJitterPeriod, peripheral_ui_.get(),
      &AmbientSlideshowPeripheralUi::UpdateGlanceableInfoPosition);
}

AmbientVideoView::~AmbientVideoView() {
  AmbientUiSettings ui_settings(
      personalization_app::mojom::AmbientTheme::kVideo, video_);
  ambient::RecordAmbientModeVideoSessionStatus(ash_web_view_.get(),
                                               ui_settings);
  ambient::RecordAmbientModeVideoSmoothness(ash_web_view_.get(), ui_settings);
}

}  // namespace ash