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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
// Copyright 2021 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_PAGE_INFO_PAGE_INFO_MAIN_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_PAGE_INFO_PAGE_INFO_MAIN_VIEW_H_
#include <map>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "chrome/browser/ui/views/page_info/chosen_object_view_observer.h"
#include "chrome/browser/ui/views/page_info/permission_toggle_row_view_observer.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/page_info/core/page_info_types.h"
#include "components/page_info/core/proto/about_this_site_metadata.pb.h"
#include "components/page_info/page_info_ui.h"
#include "device/vr/buildflags/buildflags.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/view.h"
namespace views {
class Label;
class LabelButton;
} // namespace views
class ChromePageInfoUiDelegate;
class ChosenObjectView;
class RichHoverButton;
class PageInfoNavigationHandler;
class PageInfoSecurityContentView;
class PermissionToggleRowView;
class PageInfoHistoryController;
namespace test {
class PageInfoBubbleViewTestApi;
} // namespace test
// The main view of the page info, contains security information, permissions
// and site-related settings.
class PageInfoMainView : public views::View,
public PageInfoUI,
public PermissionToggleRowViewObserver,
public ChosenObjectViewObserver {
METADATA_HEADER(PageInfoMainView, views::View)
public:
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kCookieButtonElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kPrivacyAndSiteDataButtonElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kMainLayoutElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kPermissionsElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kMerchantTrustElementId);
// Container view that fills the bubble width for button rows. Supports
// updating the layout.
class ContainerView : public views::View {
METADATA_HEADER(ContainerView, views::View)
public:
ContainerView();
// Notifies that preferred size changed and updates the layout.
void Update();
};
PageInfoMainView(PageInfo* presenter,
ChromePageInfoUiDelegate* ui_delegate,
PageInfoNavigationHandler* navigation_handler,
PageInfoHistoryController* history_controller,
base::OnceClosure initialized_callback,
bool allow_extended_site_info);
~PageInfoMainView() override;
// PageInfoUI implementations.
void SetPermissionInfo(const PermissionInfoList& permission_info_list,
ChosenObjectInfoList chosen_object_info_list) override;
void SetIdentityInfo(const IdentityInfo& identity_info) override;
void SetPageFeatureInfo(const PageFeatureInfo& info) override;
void SetAdPersonalizationInfo(const AdPersonalizationInfo& info) override;
void SetCookieInfo(const CookiesNewInfo& cookie_info) override;
gfx::Size CalculatePreferredSize(
const views::SizeBounds& available_size) const override;
void ChildPreferredSizeChanged(views::View* child) override;
// PermissionToggleRowViewObserver:
void OnPermissionChanged(const PageInfo::PermissionInfo& permission) override;
// ChosenObjectViewObserver:
void OnChosenObjectDeleted(const PageInfoUI::ChosenObjectInfo& info) override;
int GetVisiblePermissionsCountForTesting() const {
return toggle_rows_.size();
}
const std::vector<raw_ptr<PermissionToggleRowView, VectorExperimental>>&
GetToggleRowsForTesting() const {
return toggle_rows_;
}
protected:
// TODO(olesiamarukhno): Was used for tests, will update it after redesigning
// moves forward.
const std::u16string details_text() const { return details_text_; }
private:
friend class PageInfoBubbleViewDialogBrowserTest;
friend class test::PageInfoBubbleViewTestApi;
// Creates a view with vertical box layout that will used a container for
// other views.
[[nodiscard]] std::unique_ptr<views::View> CreateContainerView();
// Creates bubble header view for this page, contains the title and the close
// button.
[[nodiscard]] std::unique_ptr<views::View> CreateBubbleHeaderView();
// Posts a task to HandleMoreInfoRequestAsync() below.
void HandleMoreInfoRequest(views::View* source);
// Used to asynchronously handle clicks since these calls may cause the
// destruction of the settings view and the base class window still needs to
// be alive to finish handling the mouse or keyboard click.
void HandleMoreInfoRequestAsync(int view_id);
// Makes the permission reset button visible if there is any permission and
// enables it if any permission is in a non-default state. Also updates
// the label depending on the number of visible permissions.
void UpdateResetButton(const PermissionInfoList& permission_info_list);
void OnMerchantTrustDataFetched(
const GURL& url,
std::optional<page_info::MerchantData> merchant_data);
// Creates 'About this site' button that opens a subpage.
[[nodiscard]] std::unique_ptr<views::View> CreateAboutThisSiteButton(
const page_info::proto::SiteInfo& info);
// Creates 'Ad personalization' button that opens a subpage.
[[nodiscard]] std::unique_ptr<views::View> CreateAdPersonalizationButton();
// Creates 'Merchant trust' button.
[[nodiscard]] std::unique_ptr<views::View> CreateMerchantTrustButton(
page_info::MerchantData value);
// Creates 'Merchant trust' button that opens a subpage.
[[nodiscard]] std::unique_ptr<RichHoverButton>
CreateMerchantTrustSubpageButton(page_info::MerchantData value);
// Creates 'Merchant trust' button that opens a side panel.
[[nodiscard]] std::unique_ptr<RichHoverButton>
CreateMerchantTrustLaunchButton(GURL url);
void OpenMerchantTrustSidePanel(const GURL& url);
raw_ptr<PageInfo, AcrossTasksDanglingUntriaged> presenter_;
raw_ptr<ChromePageInfoUiDelegate, AcrossTasksDanglingUntriaged> ui_delegate_;
raw_ptr<PageInfoNavigationHandler> navigation_handler_;
// The raw details of the status of the identity check for this site.
std::u16string details_text_ = std::u16string();
// The button that opens the "Connection" subpage.
raw_ptr<RichHoverButton, AcrossTasksDanglingUntriaged> connection_button_ =
nullptr;
// The view that contains the certificate, cookie, and permissions sections.
raw_ptr<views::View> site_settings_view_ = nullptr;
// The button that opens the "Cookies" subpage.
raw_ptr<RichHoverButton> cookie_button_ = nullptr;
// The button that opens up "Site Settings".
raw_ptr<RichHoverButton> site_settings_link_ = nullptr;
// The view that contains the scroll view with permission rows and the reset
// button, surrounded by separators.
raw_ptr<views::View> permissions_view_ = nullptr;
// The section that contains a separator and buttons with extended site
// information: "About this site" and "Merchant trust". The section is only
// shown when at least of one the buttons is available.
raw_ptr<views::View> extended_site_info_section_ = nullptr;
// "About this site" button that opens a subpage.
raw_ptr<views::View> about_this_site_section_ = nullptr;
// "Merchant trust" button that opens a subpage.
raw_ptr<views::View> merchant_trust_section_ = nullptr;
// The view that contains `SecurityInformationView` and a certificate button.
raw_ptr<PageInfoSecurityContentView, AcrossTasksDanglingUntriaged>
security_content_view_ = nullptr;
// "Ad personalization" button that opens a subpage.
raw_ptr<views::View> ads_personalization_section_ = nullptr;
#if BUILDFLAG(IS_WIN) && BUILDFLAG(ENABLE_VR)
// The view that contains ui related to features on a page, like a presenting
// VR page.
raw_ptr<views::View> page_feature_info_view_ = nullptr;
#endif
// These rows bundle together all the |View|s involved in a single row of the
// permissions section, and keep those views updated when the underlying
// |Permission| changes.
std::vector<raw_ptr<PermissionToggleRowView, VectorExperimental>>
toggle_rows_;
// This map contains rows for permission types that should be updated when
// their usage status is changed. This is needed to avoid recreating the whole
// PageInfo view if only a single permission is changed.
std::map<ContentSettingsType, raw_ptr<PermissionToggleRowView>>
syncable_permission_rows_;
std::vector<raw_ptr<ChosenObjectView, VectorExperimental>>
chosen_object_rows_;
raw_ptr<views::Label> title_ = nullptr;
raw_ptr<views::View> security_container_view_ = nullptr;
raw_ptr<views::LabelButton, AcrossTasksDanglingUntriaged> reset_button_ =
nullptr;
base::WeakPtrFactory<PageInfoMainView> weak_factory_{this};
};
#endif // CHROME_BROWSER_UI_VIEWS_PAGE_INFO_PAGE_INFO_MAIN_VIEW_H_
|