Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tab in 'attribution internals' with budget consumption visualization #5

Open
wants to merge 26 commits into
base: cu-ara
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ void CreateAndAddOverviewDataSource(Profile* profile) {
source->AddResourcePath(kArcTracingUiJsPath, IDR_ARC_TRACING_UI_JS);
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources 'self';");
"script-src chrome://resources 'self' 'unsafe-inline' https://d3js.org/;");


base::Value::Dict localized_strings;
const std::string& app_locale = g_browser_process->GetApplicationLocale();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void CreateAndAddPowerControlDataSource(Profile* profile) {
source->AddResourcePath(kArcTracingUiJsPath, IDR_ARC_TRACING_UI_JS);
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources 'self';");
"script-src chrome://resources 'self' 'unsafe-inline' https://d3js.org/;");

base::Value::Dict localized_strings;
const std::string& app_locale = g_browser_process->GetApplicationLocale();
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/webui/ash/cros_components_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CrosComponentsUI : public content::WebUIController {

source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources 'self' 'unsafe-inline';");
"script-src chrome://resources 'self' 'unsafe-inline' https://d3js.org/;");

source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::TrustedTypes,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/webui/conflicts/conflicts_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void CreateAndAddConflictsUIHTMLSource(Profile* profile) {
profile, chrome::kChromeUIConflictsHost);
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources 'self';");
"script-src chrome://resources 'self' 'unsafe-inline' https://d3js.org/;");

source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::TrustedTypes,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/webui/interstitials/interstitial_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ std::string InterstitialHTMLSource::GetContentSecurityPolicy(
const network::mojom::CSPDirectiveName directive) {
if (directive == network::mojom::CSPDirectiveName::ScriptSrc) {
// 'unsafe-inline' is added to script-src.
return "script-src chrome://resources 'self' 'unsafe-inline';";
return "script-src chrome://resources 'self' 'unsafe-inline' https://d3js.org/;";
} else if (directive == network::mojom::CSPDirectiveName::StyleSrc) {
return "style-src 'self' 'unsafe-inline';";
} else if (directive == network::mojom::CSPDirectiveName::ImgSrc) {
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/ui/webui/nacl_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void CreateAndAddNaClUIHTMLSource(Profile* profile) {
profile, chrome::kChromeUINaClHost);
source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src chrome://resources 'self';");
"script-src chrome://resources 'self' 'unsafe-inline' https://d3js.org/;");

source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::TrustedTypes,
"trusted-types polymer-html-literal "
Expand Down
2 changes: 1 addition & 1 deletion chrome/test/base/ash/web_ui_browser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class MockWebUIDataSource : public content::URLDataSource {
std::string GetContentSecurityPolicy(
const network::mojom::CSPDirectiveName directive) override {
if (directive == network::mojom::CSPDirectiveName::ScriptSrc) {
return "script-src chrome://resources 'self';";
return "script-src chrome://resources 'self' 'unsafe-inline' https://d3js.org/;";
} else if (directive ==
network::mojom::CSPDirectiveName::RequireTrustedTypesFor ||
directive == network::mojom::CSPDirectiveName::TrustedTypes) {
Expand Down
2 changes: 2 additions & 0 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ source_set("browser") {
"attribution_reporting/store_source_result_internal.h",
"attribution_reporting/stored_source.cc",
"attribution_reporting/stored_source.h",
"attribution_reporting/stored_filter.cc",
"attribution_reporting/stored_filter.h",
"audio/audio_service.cc",
"background_fetch/background_fetch_context.cc",
"background_fetch/background_fetch_context.h",
Expand Down
18 changes: 18 additions & 0 deletions content/browser/attribution_reporting/attribution_internals.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ struct WebUISource {
Attributability attributability;
};

struct WebUIFilter {
uint64 id;
uint64 time;
uint64 epoch;
double consumed_budget;
double initial_budget;
url.mojom.Origin destination_origin;
url.mojom.Origin source_origin;
uint64 source_time;
};

struct WebUIRegistration {
double time;
url.mojom.Origin context_origin;
Expand Down Expand Up @@ -169,6 +180,10 @@ interface Observer {
// Called when the sources in storage changed, indicating that the observer
// should call `Handler::GetActiveSources()`.
OnSourcesChanged();

// Called when the filters in storage changed, indicating that the observer
// should call `Handler::GetFilters()`.
OnFiltersChanged();

// Called when the reports in storage changed, indicating that the observer
// should call `Handler::GetReports()`.
Expand Down Expand Up @@ -207,6 +222,9 @@ interface Handler {
// due to reaching policy limits.
GetActiveSources() => (array<WebUISource> sources);

// Returns all filters contained in storage
GetFilters() => (array<WebUIFilter> filters);

// Returns all reports contained in storage, including those that are actively
// being sent.
GetReports() => (array<WebUIReport> reports);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <utility>
#include <vector>

#include "base/logging.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/command_line.h"
Expand Down Expand Up @@ -44,6 +45,7 @@
#include "content/browser/attribution_reporting/send_result.h"
#include "content/browser/attribution_reporting/storable_source.h"
#include "content/browser/attribution_reporting/stored_source.h"
#include "content/browser/attribution_reporting/stored_filter.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/web_contents.h"
Expand Down Expand Up @@ -96,6 +98,27 @@ attribution_internals::mojom::WebUISourcePtr WebUISource(
source.debug_cookie_set(), attributability);
}

void ForwardFiltersToWebUI(
attribution_internals::mojom::Handler::GetFiltersCallback web_ui_callback,
std::vector<StoredFilter> filters) {
std::vector<attribution_internals::mojom::WebUIFilterPtr> web_ui_filters;
web_ui_filters.reserve(filters.size());

for (const StoredFilter& filter : filters) {
web_ui_filters.push_back(attribution_internals::mojom::WebUIFilter::New(
filter.id(),
filter.time(),
filter.epoch(),
filter.consumed_budget(),
filter.initial_budget(),
filter.destination_origin(),
filter.source_origin(),
filter.source_time()));
}

std::move(web_ui_callback).Run(std::move(web_ui_filters));
}

void ForwardSourcesToWebUI(
attribution_internals::mojom::Handler::GetActiveSourcesCallback
web_ui_callback,
Expand Down Expand Up @@ -277,6 +300,18 @@ void AttributionInternalsHandlerImpl::GetActiveSources(
}
}

void AttributionInternalsHandlerImpl::GetFilters(
attribution_internals::mojom::Handler::GetFiltersCallback callback) {
LOG(INFO) << " #### #### content/browser/attribution_reporting/attribution_internals_handler_impl.cc: GetFilters";
if (AttributionManager* manager =
AttributionManager::FromWebContents(web_ui_->GetWebContents())) {
manager->GetFiltersForWebUI(
base::BindOnce(&ForwardFiltersToWebUI, std::move(callback)));
} else {
std::move(callback).Run({});
}
}

void AttributionInternalsHandlerImpl::GetReports(
attribution_internals::mojom::Handler::GetReportsCallback callback) {
if (AttributionManager* manager =
Expand Down Expand Up @@ -317,6 +352,10 @@ void AttributionInternalsHandlerImpl::OnSourcesChanged() {
observer_->OnSourcesChanged();
}

void AttributionInternalsHandlerImpl::OnFiltersChanged() {
observer_->OnFiltersChanged();
}

void AttributionInternalsHandlerImpl::OnReportsChanged() {
observer_->OnReportsChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class AttributionInternalsHandlerImpl
void GetActiveSources(
attribution_internals::mojom::Handler::GetActiveSourcesCallback callback)
override;
void GetFilters(attribution_internals::mojom::Handler::GetFiltersCallback
callback) override;
void GetReports(attribution_internals::mojom::Handler::GetReportsCallback
callback) override;
void SendReports(const std::vector<AttributionReport::Id>& ids,
Expand All @@ -59,6 +61,7 @@ class AttributionInternalsHandlerImpl
private:
// AttributionObserver:
void OnSourcesChanged() override;
void OnFiltersChanged() override;
void OnReportsChanged() override;
void OnSourceHandled(
const StorableSource& source,
Expand Down
4 changes: 4 additions & 0 deletions content/browser/attribution_reporting/attribution_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BrowserContext;
class BrowsingDataFilterBuilder;
class StorableSource;
class StoredSource;
class StoredFilter;
class WebContents;

struct GlobalRenderFrameHostId;
Expand Down Expand Up @@ -70,6 +71,9 @@ class CONTENT_EXPORT AttributionManager : public AttributionDataModel {
virtual void GetActiveSourcesForWebUI(
base::OnceCallback<void(std::vector<StoredSource>)> callback) = 0;

virtual void GetFiltersForWebUI(
base::OnceCallback<void(std::vector<StoredFilter>)> callback) = 0;

// Get all pending reports that are currently stored in this partition. Used
// for populating WebUI and simulator.
virtual void GetPendingReportsForInternalUse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "content/browser/attribution_reporting/storable_source.h"
#include "content/browser/attribution_reporting/store_source_result.h"
#include "content/browser/attribution_reporting/stored_source.h"
#include "content/browser/attribution_reporting/stored_filter.h"
#include "content/browser/browsing_data/browsing_data_filter_builder_impl.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/attribution_data_model.h"
Expand Down Expand Up @@ -921,6 +922,14 @@ void AttributionManagerImpl::GetActiveSourcesForWebUI(
.Then(std::move(callback));
}

// Called when a filter is applied to the sources, to notify observers.
void AttributionManagerImpl::GetFiltersForWebUI(
base::OnceCallback<void(std::vector<StoredFilter>)> callback) {
LOG(INFO) << "#### #### AttributionManagerImpl::GetFiltersForWebUI";
attribution_storage_.AsyncCall(&AttributionStorage::GetFilters)
.Then(std::move(callback));
}

// TODO(apaseltiner): Consider `OnUserVisibleTaskStarted()` here, since this is
// used by the internals UI, which is user-visible.
void AttributionManagerImpl::GetPendingReportsForInternalUse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class CONTENT_EXPORT AttributionManagerImpl
GlobalRenderFrameHostId render_frame_id) override;
void GetActiveSourcesForWebUI(
base::OnceCallback<void(std::vector<StoredSource>)> callback) override;
void GetFiltersForWebUI(
base::OnceCallback<void(std::vector<StoredFilter>)> callback) override;
void GetPendingReportsForInternalUse(
int limit,
base::OnceCallback<void(std::vector<AttributionReport>)> callback)
Expand Down
3 changes: 3 additions & 0 deletions content/browser/attribution_reporting/attribution_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class AttributionObserver : public base::CheckedObserver {
// Called when sources in storage change.
virtual void OnSourcesChanged() {}

// Called when filters in storage change.
virtual void OnFiltersChanged() {}

// Called when reports in storage change.
virtual void OnReportsChanged() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "components/attribution_reporting/suitable_origin.h"
#include "content/browser/attribution_reporting/common_source_info.h"
#include "content/browser/attribution_reporting/stored_source.h"
#include "content/browser/attribution_reporting/stored_filter.h"
#include "net/http/http_request_headers.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "url/gurl.h"
Expand Down
1 change: 1 addition & 0 deletions content/browser/attribution_reporting/attribution_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "content/browser/attribution_reporting/attribution_info.h"
#include "content/browser/attribution_reporting/attribution_reporting.mojom.h"
#include "content/browser/attribution_reporting/stored_source.h"
#include "content/browser/attribution_reporting/stored_filter.h"
#include "content/common/content_export.h"
#include "third_party/abseil-cpp/absl/types/variant.h"

Expand Down
2 changes: 2 additions & 0 deletions content/browser/attribution_reporting/attribution_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CreateReportResult;
class StorableSource;
class StoreSourceResult;
class StoredSource;
class StoredFilter;

// This class provides an interface for persisting attribution data to
// disk, and performing queries on it. AttributionStorage should initialize
Expand Down Expand Up @@ -83,6 +84,7 @@ class AttributionStorage {
// a negative number for no limit.
virtual std::vector<StoredSource> GetActiveSources(int limit = -1) = 0;

virtual std::vector<StoredFilter> GetFilters() = 0;
// Returns all distinct reporting origins for the
// Browsing Data Model. Partial data will still be returned
// in the event of an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "content/browser/attribution_reporting/attribution_trigger.h"
#include "content/browser/attribution_reporting/privacy_math.h"
#include "content/browser/attribution_reporting/stored_source.h"
#include "content/browser/attribution_reporting/stored_filter.h"
#include "services/network/public/cpp/trigger_verification.h"

namespace content {
Expand Down
Loading