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
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_PERMISSIONS_CHIP_PERMISSION_DASHBOARD_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_PERMISSIONS_CHIP_PERMISSION_DASHBOARD_CONTROLLER_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/timer/timer.h"
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "chrome/browser/ui/views/permissions/chip/permission_chip_view.h"
#include "chrome/browser/ui/views/permissions/chip/permission_dashboard_view.h"
#include "content/public/browser/global_routing_id.h"
#include "ui/views/view_tracker.h"
class LocationBarView;
class ChipController;
class ContentSettingImageModel;
class PermissionDashboardController : public PermissionChipView::Observer {
public:
PermissionDashboardController(
LocationBarView* location_bar_view,
PermissionDashboardView* permission_dashboard_view);
~PermissionDashboardController() override;
PermissionDashboardController(const PermissionDashboardController&) = delete;
PermissionDashboardController& operator=(
const PermissionDashboardController&) = delete;
ChipController* request_chip_controller() {
return request_chip_controller_.get();
}
PermissionDashboardView* permission_dashboard_view() {
return permission_dashboard_view_;
}
// This method updates UI based on `ContentSettingImageModel` state. Returns
// `true` if there are user-visible changes, otherwise returns `false`.
bool Update(ContentSettingImageModel* indicator_model,
ContentSettingImageView::Delegate* delegate);
// PermissionChipView::Observer
void OnChipVisibilityChanged(bool is_visible) override;
void OnExpandAnimationEnded() override;
void OnCollapseAnimationEnded() override;
void OnMousePressed() override;
bool is_verbose() const { return is_verbose_; }
// Returns `true` if currently visible verbose indicator should be suppressed
// by e.g. an incoming permission request and `collapse_timer_` will fired if
// running. Return `false` otherwise.
bool SuppressVerboseIndicator();
base::OneShotTimer& get_collapse_timer_for_testing() {
return collapse_timer_;
}
views::View* page_info_for_testing() {
return page_info_bubble_tracker_.view();
}
void ShowPageInfoDialogForTesting() { ShowPageInfoDialog(); }
void DoNotCollapseForTesting() { do_no_collapse_for_testing_ = true; }
private:
void StartCollapseTimer();
void Collapse(bool hide);
void HideIndicators();
void ShowBubble();
void ShowPageInfoDialog();
// Actions executed when the user closes the page info dialog.
void OnPageInfoBubbleClosed(views::Widget::ClosedReason closed_reason,
bool reload_prompt);
void OnIndicatorsChipButtonPressed();
std::u16string GetIndicatorTitle(ContentSettingImageModel* model);
// `LocationBarView` owns this.
raw_ptr<LocationBarView> location_bar_view_ = nullptr;
raw_ptr<PermissionDashboardView> permission_dashboard_view_ = nullptr;
// Currently only Camera and Mic are supported.
raw_ptr<ContentSettingImageModel> content_setting_image_model_ = nullptr;
raw_ptr<ContentSettingImageView::Delegate> delegate_;
std::unique_ptr<ChipController> request_chip_controller_;
// A timer used to collapse indicators after a delay.
base::OneShotTimer collapse_timer_;
bool do_no_collapse_for_testing_ = false;
// A flag that reflects a visual condition of the LHS indicator chip.
// `true` - is used for a verbose state that includes an icon + text. Its
// appearance is accompanied by an expand and collapse animation.
// `false` - is used for a collapsed (not verbose) state that includes only an
// icon. It appears without animation.
bool is_verbose_ = false;
bool blocked_on_system_level_ = false;
content::GlobalRenderFrameHostId main_frame_id_;
views::ViewTracker page_info_bubble_tracker_;
// This is used to check if the PageInfo bubble was showing in the last mouse
// press event. If this is true then PageInfo bubble should not be shown
// again. This flag is necessary because the bubble gets dismissed before the
// button handles the mouse release event.
bool should_suppress_reopening_page_info_ = false;
base::ScopedObservation<PermissionChipView, PermissionChipView::Observer>
observation_{this};
base::WeakPtrFactory<PermissionDashboardController> weak_factory_{this};
};
#endif // CHROME_BROWSER_UI_VIEWS_PERMISSIONS_CHIP_PERMISSION_DASHBOARD_CONTROLLER_H_
|