forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MSC] Added screen capture usage indicator view.
This CL adds a new view to indicate the usage of the new getDisplayMediaSet API (indicating that several screens are captured). Bug: 1300883 Change-Id: Ice0fe91db9a1bdb41a8f3744db667ebc7a73bbf2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3668545 Reviewed-by: Markus Handell <handellm@google.com> Reviewed-by: Avi Drissman <avi@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Simon Hangl <simonha@google.com> Reviewed-by: Ahmed Fakhry <afakhry@chromium.org> Reviewed-by: Elad Alon <eladalon@chromium.org> Cr-Commit-Position: refs/heads/main@{#1036598}
- Loading branch information
Simon Hangl
authored and
Chromium LUCI CQ
committed
Aug 18, 2022
1 parent
26b7d6e
commit add76fe
Showing
24 changed files
with
466 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
c70af15aa5315a4a10452f7abf7fbedb9bf1fd92 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 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 "ash/multi_capture/multi_capture_service_client.h" | ||
|
||
#include "base/logging.h" | ||
|
||
namespace ash { | ||
|
||
MultiCaptureServiceClient::MultiCaptureServiceClient( | ||
mojo::PendingRemote<video_capture::mojom::MultiCaptureService> | ||
multi_capture_service) | ||
: multi_capture_service_(std::move(multi_capture_service)) { | ||
multi_capture_service_->AddObserver( | ||
multi_capture_service_observer_receiver_.BindNewPipeAndPassRemote()); | ||
} | ||
|
||
MultiCaptureServiceClient::~MultiCaptureServiceClient() = default; | ||
|
||
void MultiCaptureServiceClient::AddObserver(Observer* observer) { | ||
observers_.AddObserver(observer); | ||
} | ||
|
||
void MultiCaptureServiceClient::RemoveObserver(Observer* observer) { | ||
observers_.RemoveObserver(observer); | ||
} | ||
|
||
void MultiCaptureServiceClient::MultiCaptureStarted(const std::string& label, | ||
const url::Origin& origin) { | ||
for (Observer& observer : observers_) | ||
observer.MultiCaptureStarted(label, origin); | ||
} | ||
|
||
void MultiCaptureServiceClient::MultiCaptureStopped(const std::string& label) { | ||
for (Observer& observer : observers_) | ||
observer.MultiCaptureStopped(label); | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2022 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 ASH_MULTI_CAPTURE_MULTI_CAPTURE_SERVICE_CLIENT_H_ | ||
#define ASH_MULTI_CAPTURE_MULTI_CAPTURE_SERVICE_CLIENT_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/observer_list.h" | ||
#include "base/observer_list_types.h" | ||
#include "mojo/public/cpp/bindings/receiver.h" | ||
#include "mojo/public/cpp/bindings/remote.h" | ||
#include "services/video_capture/public/mojom/multi_capture_service.mojom.h" | ||
#include "url/origin.h" | ||
|
||
namespace ash { | ||
|
||
// Client of the MultiCaptureService mojo interface. Receives events about | ||
// multi captures being started / stopped and forwards it to ash clients to | ||
// show usage indicators. | ||
class MultiCaptureServiceClient | ||
: public video_capture::mojom::MultiCaptureServiceClient { | ||
public: | ||
class Observer : public base::CheckedObserver { | ||
public: | ||
// Event to inform about a started multi capture. The label is a unique | ||
// identifier that can be used to connect started / stopped events. | ||
// The origin is the capturer's origin. | ||
// TODO(crbug.com/1325750): Consider transferred tracks by either adding | ||
// a MultiCaptureTransferred event or by making sure the label remains | ||
// constant throughout the lifetime of the capture. | ||
virtual void MultiCaptureStarted(const std::string& label, | ||
const url::Origin& origin) = 0; | ||
virtual void MultiCaptureStopped(const std::string& label) = 0; | ||
|
||
protected: | ||
~Observer() override = default; | ||
}; | ||
|
||
explicit MultiCaptureServiceClient( | ||
mojo::PendingRemote<video_capture::mojom::MultiCaptureService> | ||
multi_capture_service); | ||
~MultiCaptureServiceClient() override; | ||
MultiCaptureServiceClient(const MultiCaptureServiceClient&) = delete; | ||
MultiCaptureServiceClient& operator=(const MultiCaptureServiceClient&) = | ||
delete; | ||
|
||
void AddObserver(Observer* observer); | ||
void RemoveObserver(Observer* observer); | ||
|
||
// video_capture::mojom::MultiCaptureService: | ||
void MultiCaptureStarted(const std::string& label, | ||
const url::Origin& origin) override; | ||
void MultiCaptureStopped(const std::string& label) override; | ||
|
||
private: | ||
mojo::Remote<video_capture::mojom::MultiCaptureService> | ||
multi_capture_service_; | ||
mojo::Receiver<video_capture::mojom::MultiCaptureServiceClient> | ||
multi_capture_service_observer_receiver_{this}; | ||
base::ObserverList<Observer> observers_; | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_VIDEO_CAPTURE_MULTI_CAPTURE_SERVICE_CLIENT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2022 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 "ash/system/unified/screen_capture_tray_item_view.h" | ||
|
||
#include "ash/multi_capture/multi_capture_service_client.h" | ||
#include "ash/resources/vector_icons/vector_icons.h" | ||
#include "ash/shell.h" | ||
#include "ash/strings/grit/ash_strings.h" | ||
#include "ash/style/ash_color_provider.h" | ||
#include "ash/system/tray/tray_constants.h" | ||
#include "components/vector_icons/vector_icons.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/gfx/paint_vector_icon.h" | ||
#include "ui/gfx/vector_icon_types.h" | ||
#include "ui/views/controls/image_view.h" | ||
|
||
namespace ash { | ||
|
||
ScreenCaptureTrayItemView::ScreenCaptureTrayItemView(Shelf* shelf) | ||
: TrayItemView(shelf) { | ||
CreateImageView(); | ||
const gfx::VectorIcon* icon = &kSystemTrayRecordingIcon; | ||
image_view()->SetImage(gfx::CreateVectorIcon(gfx::IconDescription( | ||
*icon, kUnifiedTrayIconSize, | ||
AshColorProvider::Get()->GetContentLayerColor( | ||
AshColorProvider::ContentLayerType::kIconColorAlert)))); | ||
|
||
Shell::Get()->multi_capture_service_client()->AddObserver(this); | ||
Refresh(); | ||
} | ||
|
||
ScreenCaptureTrayItemView::~ScreenCaptureTrayItemView() { | ||
Shell::Get()->multi_capture_service_client()->RemoveObserver(this); | ||
} | ||
|
||
const char* ScreenCaptureTrayItemView::GetClassName() const { | ||
return "ScreenCaptureTrayItemView"; | ||
} | ||
|
||
views::View* ScreenCaptureTrayItemView::GetTooltipHandlerForPoint( | ||
const gfx::Point& point) { | ||
return HitTestPoint(point) ? this : nullptr; | ||
} | ||
|
||
std::u16string ScreenCaptureTrayItemView::GetTooltipText( | ||
const gfx::Point& point) const { | ||
return l10n_util::GetStringUTF16(IDS_ASH_ADMIN_SCREEN_CAPTURE); | ||
} | ||
|
||
void ScreenCaptureTrayItemView::Refresh() { | ||
SetVisible(!request_ids_.empty()); | ||
} | ||
|
||
void ScreenCaptureTrayItemView::MultiCaptureStarted(const std::string& label, | ||
const url::Origin& origin) { | ||
request_ids_.insert(label); | ||
Refresh(); | ||
} | ||
|
||
void ScreenCaptureTrayItemView::MultiCaptureStopped(const std::string& label) { | ||
request_ids_.erase(label); | ||
Refresh(); | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2022 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 ASH_SYSTEM_UNIFIED_SCREEN_CAPTURE_TRAY_ITEM_VIEW_H_ | ||
#define ASH_SYSTEM_UNIFIED_SCREEN_CAPTURE_TRAY_ITEM_VIEW_H_ | ||
|
||
#include <string> | ||
|
||
#include "ash/multi_capture/multi_capture_service_client.h" | ||
#include "ash/system/tray/tray_item_view.h" | ||
#include "base/containers/fixed_flat_set.h" | ||
#include "base/memory/weak_ptr.h" | ||
|
||
namespace url { | ||
class Origin; | ||
} | ||
|
||
namespace ash { | ||
|
||
// An indicator shown in UnifiedSystemTray when a web application is using | ||
// screen capturing. | ||
class ASH_EXPORT ScreenCaptureTrayItemView | ||
: public TrayItemView, | ||
public MultiCaptureServiceClient::Observer { | ||
public: | ||
explicit ScreenCaptureTrayItemView(Shelf* shelf); | ||
ScreenCaptureTrayItemView(const ScreenCaptureTrayItemView&) = delete; | ||
ScreenCaptureTrayItemView& operator=(const ScreenCaptureTrayItemView&) = | ||
delete; | ||
~ScreenCaptureTrayItemView() override; | ||
|
||
// views::View: | ||
const char* GetClassName() const override; | ||
views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override; | ||
std::u16string GetTooltipText(const gfx::Point& point) const override; | ||
|
||
// TrayItemView: | ||
void HandleLocaleChange() override {} | ||
|
||
// MultiCaptureServiceClient::Observer: | ||
void MultiCaptureStarted(const std::string& label, | ||
const url::Origin& origin) override; | ||
void MultiCaptureStopped(const std::string& label) override; | ||
|
||
private: | ||
void Refresh(); | ||
|
||
base::flat_set<std::string> request_ids_; | ||
|
||
base::WeakPtrFactory<ScreenCaptureTrayItemView> weak_ptr_factory_{this}; | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_SYSTEM_UNIFIED_SCREEN_CAPTURE_TRAY_ITEM_VIEW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.