Skip to content

Commit

Permalink
[site data] Create PageSpecificSiteDataDialog
Browse files Browse the repository at this point in the history
When the feature is enabled, show PageSpecificSiteDataDialog instead of
CollectedCookiesView. PageSpecificSiteDataDialog is empty for now.

After showing the web modal, the widget ref is needed to store is as the
user data for the current web contents. Update contrained_window API to
return the widget.

Bug: 1344787
Change-Id: I8afb136c3c3227d1301090db1c4af85194023afc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3805330
Commit-Queue: Olesia Marukhno <olesiamarukhno@google.com>
Reviewed-by: Theodore Olsauskas-Warren <sauski@google.com>
Reviewed-by: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1031430}
  • Loading branch information
Olesia Marukhno authored and Chromium LUCI CQ committed Aug 4, 2022
1 parent 5c605dd commit 998ff19
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 18 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Expand Up @@ -4887,6 +4887,8 @@ static_library("ui") {
"views/side_search/unified_side_search_controller.cc",
"views/side_search/unified_side_search_controller.h",
"views/side_search/unified_side_search_helper.cc",
"views/site_data/page_specific_site_data_dialog.cc",
"views/site_data/page_specific_site_data_dialog.h",
"views/ssl_client_certificate_selector.cc",
"views/ssl_client_certificate_selector.h",
"views/status_bubble_views.cc",
Expand Down
37 changes: 25 additions & 12 deletions chrome/browser/ui/views/collected_cookies_views.cc
Expand Up @@ -15,6 +15,7 @@
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/cookie_info_view.h"
#include "chrome/browser/ui/views/site_data/page_specific_site_data_dialog.h"
#include "chrome/grit/generated_resources.h"
#include "components/browsing_data/content/cookie_helper.h"
#include "components/browsing_data/content/database_helper.h"
Expand All @@ -26,6 +27,7 @@
#include "components/content_settings/browser/page_specific_content_settings.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/page_info/core/features.h"
#include "components/strings/grit/components_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
Expand Down Expand Up @@ -134,12 +136,12 @@ class CollectedCookiesViews::WebContentsUserData
tracker_.view()->GetWidget()->CloseNow();
}

static CollectedCookiesViews* GetDialog(content::WebContents* web_contents) {
static views::View* GetDialogView(content::WebContents* web_contents) {
WebContentsUserData* handle = static_cast<WebContentsUserData*>(
web_contents->GetUserData(UserDataKey()));
if (!handle)
return nullptr;
return handle->GetCollectedCookiesViews();
return handle->GetDialogView();
}

static void Create(content::WebContents* web_contents) {
Expand All @@ -153,15 +155,24 @@ class CollectedCookiesViews::WebContentsUserData
explicit WebContentsUserData(content::WebContents* web_contents)
: content::WebContentsUserData<
CollectedCookiesViews::WebContentsUserData>(*web_contents) {
// Owned by its Widget
CollectedCookiesViews* const dialog =
new CollectedCookiesViews(web_contents);
tracker_.SetView(dialog);
// TODO(crbug.com/1344787): Provide a public interface to show cookies
// dialog independent on the actual implementation, not tied to any views
// class.
if (base::FeatureList::IsEnabled(page_info::kPageSpecificSiteDataDialog)) {
views::Widget* widget = ShowPageSpecificSiteDataDialog(web_contents);
tracker_.SetView(widget->GetRootView());
} else {
// CollectedCookiesViews is DialogDelegateView and it's owned by its
// widget. It created the widget in the constructor using
// `ShowWebModalDialogViews()`. It will be destroyed when its widget is
// destroyed.
CollectedCookiesViews* const dialog =
new CollectedCookiesViews(web_contents);
tracker_.SetView(dialog);
}
}

CollectedCookiesViews* GetCollectedCookiesViews() {
return static_cast<CollectedCookiesViews*>(tracker_.view());
}
views::View* GetDialogView() { return tracker_.view(); }

views::ViewTracker tracker_;

Expand Down Expand Up @@ -322,8 +333,8 @@ CollectedCookiesViews::~CollectedCookiesViews() {
// static
void CollectedCookiesViews::CreateAndShowForWebContents(
content::WebContents* web_contents) {
CollectedCookiesViews* instance =
CollectedCookiesViews::WebContentsUserData::GetDialog(web_contents);
views::View* const instance =
CollectedCookiesViews::WebContentsUserData::GetDialogView(web_contents);
if (!instance) {
CollectedCookiesViews::WebContentsUserData::Create(web_contents);
return;
Expand All @@ -345,7 +356,9 @@ void CollectedCookiesViews::CreateAndShowForWebContents(

CollectedCookiesViews* CollectedCookiesViews::GetDialogForTesting(
content::WebContents* web_contents) {
return CollectedCookiesViews::WebContentsUserData::GetDialog(web_contents);
CHECK(!base::FeatureList::IsEnabled(page_info::kPageSpecificSiteDataDialog));
return static_cast<CollectedCookiesViews*>(
CollectedCookiesViews::WebContentsUserData::GetDialogView(web_contents));
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/views/site_data/OWNERS
@@ -0,0 +1,2 @@
olesiamarukhno@google.com
sauski@google.com
@@ -0,0 +1,21 @@
// 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 "chrome/browser/ui/views/site_data/page_specific_site_data_dialog.h"

#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/dialog_model.h"

// static
views::Widget* ShowPageSpecificSiteDataDialog(
content::WebContents* web_contents) {
auto builder = ui::DialogModel::Builder();
builder.SetTitle(
l10n_util::GetStringUTF16(IDS_COLLECTED_COOKIES_DIALOG_TITLE));
// TODO(crbug.com/1344787): Build the rest of the dialog. Add action handling.
// Remove the dialog from WebContentsUserData when destroyed.
return constrained_window::ShowWebModal(builder.Build(), web_contents);
}
19 changes: 19 additions & 0 deletions chrome/browser/ui/views/site_data/page_specific_site_data_dialog.h
@@ -0,0 +1,19 @@
// 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 CHROME_BROWSER_UI_VIEWS_SITE_DATA_PAGE_SPECIFIC_SITE_DATA_DIALOG_H_
#define CHROME_BROWSER_UI_VIEWS_SITE_DATA_PAGE_SPECIFIC_SITE_DATA_DIALOG_H_

namespace views {
class Widget;
} // namespace views

namespace content {
class WebContents;
} // namespace content

views::Widget* ShowPageSpecificSiteDataDialog(
content::WebContents* web_contents);

#endif // CHROME_BROWSER_UI_VIEWS_SITE_DATA_PAGE_SPECIFIC_SITE_DATA_DIALOG_H_
6 changes: 3 additions & 3 deletions components/constrained_window/constrained_window_views.cc
Expand Up @@ -267,9 +267,9 @@ void ShowBrowserModal(std::unique_ptr<ui::DialogModel> dialog_model,
->Show();
}

void ShowWebModal(std::unique_ptr<ui::DialogModel> dialog_model,
content::WebContents* web_contents) {
constrained_window::ShowWebModalDialogViews(
views::Widget* ShowWebModal(std::unique_ptr<ui::DialogModel> dialog_model,
content::WebContents* web_contents) {
return constrained_window::ShowWebModalDialogViews(
views::BubbleDialogModelHost::CreateModal(std::move(dialog_model),
ui::MODAL_TYPE_CHILD)
.release(),
Expand Down
6 changes: 3 additions & 3 deletions components/constrained_window/constrained_window_views.h
Expand Up @@ -92,9 +92,9 @@ views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog,
void ShowBrowserModal(std::unique_ptr<ui::DialogModel> dialog_model,
gfx::NativeWindow parent);

// Shows a web/tab-modal dialog based on `dialog_model`.
void ShowWebModal(std::unique_ptr<ui::DialogModel> dialog_model,
content::WebContents* web_contents);
// Shows a web/tab-modal dialog based on `dialog_model` and returns its widget.
views::Widget* ShowWebModal(std::unique_ptr<ui::DialogModel> dialog_model,
content::WebContents* web_contents);

} // namespace constrained_window

Expand Down

0 comments on commit 998ff19

Please sign in to comment.