chromium/chrome/browser/enterprise/connectors/analysis/content_analysis_delegate.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/enterprise/connectors/analysis/content_analysis_delegate.h"

#include <algorithm>
#include <memory>
#include <numeric>
#include <string>
#include <utility>

#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_dialog.h"
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_features.h"
#include "chrome/browser/enterprise/connectors/analysis/files_request_handler.h"
#include "chrome/browser/enterprise/connectors/analysis/page_print_analysis_request.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router.h"
#include "chrome/browser/file_util_service.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/binary_upload_service.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/file_analysis_request.h"
#include "chrome/browser/safe_browsing/download_protection/check_client_download_request.h"
#include "chrome/grit/generated_resources.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "components/enterprise/common/files_scan_data.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/enterprise/connectors/core/analysis_settings.h"
#include "components/policy/core/common/chrome_schema.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/url_matcher/url_matcher.h"
#include "content/public/browser/web_contents.h"
#include "crypto/secure_hash.h"
#include "crypto/sha2.h"
#include "net/base/mime_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_types.h"

#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_sdk_manager.h"  // nogncheck
#endif

BinaryUploadService;

namespace enterprise_connectors {

namespace {

// Global pointer of factory function (RepeatingCallback) used to create
// instances of ContentAnalysisDelegate in tests.  !is_null() only in tests.
ContentAnalysisDelegate::Factory* GetFactoryStorage() {}

bool* UIEnabledStorage() {}

ContentAnalysisDelegate::OnAckAllRequestsCallback* OnAckAllRequestsStorage() {}

void OnContentAnalysisComplete(
    std::unique_ptr<FilesScanData> files_scan_data,
    ContentAnalysisDelegate::ForFilesCompletionCallback callback,
    const ContentAnalysisDelegate::Data& data,
    ContentAnalysisDelegate::Result& result) {}

void OnPathsExpanded(
    base::WeakPtr<content::WebContents> web_contents,
    safe_browsing::DeepScanAccessPoint access_point,
    ContentAnalysisDelegate::Data data,
    std::unique_ptr<FilesScanData> files_scan_data,
    ContentAnalysisDelegate::ForFilesCompletionCallback callback) {}

}  // namespace

StringAnalysisRequest::StringAnalysisRequest(
    CloudOrLocalAnalysisSettings settings,
    std::string text,
    BinaryUploadService::ContentAnalysisCallback callback)
    :{}

StringAnalysisRequest::~StringAnalysisRequest() {}

void StringAnalysisRequest::GetRequestData(DataCallback callback) {}

ContentAnalysisDelegate::Data::Data() = default;
ContentAnalysisDelegate::Data::Data(Data&& other) = default;
ContentAnalysisDelegate::Data& ContentAnalysisDelegate::Data::operator=(
    ContentAnalysisDelegate::Data&& other) = default;
ContentAnalysisDelegate::Data::~Data() = default;

void ContentAnalysisDelegate::Data::AddClipboardData(
    const content::ClipboardPasteData& clipboard_paste_data) {}

ContentAnalysisDelegate::Result::Result() = default;
ContentAnalysisDelegate::Result::Result(Result&& other) = default;
ContentAnalysisDelegate::Result::~Result() = default;

ContentAnalysisDelegate::~ContentAnalysisDelegate() = default;

void ContentAnalysisDelegate::BypassWarnings(
    std::optional<std::u16string> user_justification) {}

void ContentAnalysisDelegate::Cancel(bool warning) {}

std::optional<std::u16string> ContentAnalysisDelegate::GetCustomMessage()
    const {}

std::optional<GURL> ContentAnalysisDelegate::GetCustomLearnMoreUrl() const {}

std::optional<std::vector<std::pair<gfx::Range, GURL>>>
ContentAnalysisDelegate::GetCustomRuleMessageRanges() const {}

bool ContentAnalysisDelegate::BypassRequiresJustification() const {}

std::u16string ContentAnalysisDelegate::GetBypassJustificationLabel() const {}

std::optional<std::u16string>
ContentAnalysisDelegate::OverrideCancelButtonText() const {}

// static
bool ContentAnalysisDelegate::IsEnabled(Profile* profile,
                                        GURL url,
                                        Data* data,
                                        AnalysisConnector connector) {}

// static
void ContentAnalysisDelegate::CreateForWebContents(
    content::WebContents* web_contents,
    Data data,
    CompletionCallback callback,
    safe_browsing::DeepScanAccessPoint access_point) {}

// static
void ContentAnalysisDelegate::CreateForFilesInWebContents(
    content::WebContents* web_contents,
    Data data,
    ForFilesCompletionCallback callback,
    safe_browsing::DeepScanAccessPoint access_point) {}

// static
void ContentAnalysisDelegate::SetFactoryForTesting(Factory factory) {}

// static
void ContentAnalysisDelegate::ResetFactoryForTesting() {}

// static
void ContentAnalysisDelegate::DisableUIForTesting() {}

// TODO(b/283067315): Add this to all the test TearDown()s.
// static
void ContentAnalysisDelegate::EnableUIAfterTesting() {}

// static
void ContentAnalysisDelegate::SetOnAckAllRequestsCallbackForTesting(
    OnAckAllRequestsCallback callback) {}

void ContentAnalysisDelegate::SetPageWarningForTesting(
    ContentAnalysisResponse page_response) {}

ContentAnalysisDelegate::ContentAnalysisDelegate(
    content::WebContents* web_contents,
    Data data,
    CompletionCallback callback,
    safe_browsing::DeepScanAccessPoint access_point)
    :{}

void ContentAnalysisDelegate::StringRequestCallback(
    BinaryUploadService::Result result,
    ContentAnalysisResponse response) {}

void ContentAnalysisDelegate::ImageRequestCallback(
    BinaryUploadService::Result result,
    ContentAnalysisResponse response) {}

void ContentAnalysisDelegate::FilesRequestCallback(
    std::vector<RequestHandlerResult> results) {}

FilesRequestHandler*
ContentAnalysisDelegate::GetFilesRequestHandlerForTesting() {}

bool ContentAnalysisDelegate::ShowFinalResultInDialog() {}

bool ContentAnalysisDelegate::CancelDialog() {}

void ContentAnalysisDelegate::PageRequestCallback(
    BinaryUploadService::Result result,
    ContentAnalysisResponse response) {}

ContentAnalysisDelegate::UploadDataStatus
ContentAnalysisDelegate::UploadData() {}

bool ContentAnalysisDelegate::IsFailClosed(UploadDataStatus upload_data_status,
                                           bool should_allow_by_default) {}

bool ContentAnalysisDelegate::ShouldFailOpenWithoutLocalClient(
    bool should_allow_by_default) {}

void ContentAnalysisDelegate::PrepareTextRequest() {}

bool ContentAnalysisDelegate::ShouldNotUploadLargePage(size_t page_size) {}

void ContentAnalysisDelegate::PrepareImageRequest() {}

void ContentAnalysisDelegate::PreparePageRequest() {}

// This method only prepares requests for print and paste events. File events
// are handled by
// chrome/browser/enterprise/connectors/analysis/files_request_handler.h
void ContentAnalysisDelegate::PrepareRequest(
    AnalysisConnector connector,
    BinaryUploadService::Request* request) {}

void ContentAnalysisDelegate::FillAllResultsWith(bool status) {}

BinaryUploadService* ContentAnalysisDelegate::GetBinaryUploadService() {}

void ContentAnalysisDelegate::UploadTextForDeepScanning(
    std::unique_ptr<BinaryUploadService::Request> request) {}

void ContentAnalysisDelegate::UploadImageForDeepScanning(
    std::unique_ptr<BinaryUploadService::Request> request) {}

void ContentAnalysisDelegate::UploadPageForDeepScanning(
    std::unique_ptr<BinaryUploadService::Request> request) {}

bool ContentAnalysisDelegate::UpdateDialog() {}

void ContentAnalysisDelegate::MaybeCompleteScanRequest() {}

void ContentAnalysisDelegate::RunCallback() {}

void ContentAnalysisDelegate::UpdateFinalResult(
    FinalContentAnalysisResult result,
    const std::string& tag,
    const ContentAnalysisResponse::Result::TriggeredRule::CustomRuleMessage&
        custom_rule_message) {}

void ContentAnalysisDelegate::AckAllRequests() {}

void ContentAnalysisDelegate::FinishLargeDataRequestEarly(
    std::unique_ptr<safe_browsing::BinaryUploadService::Request> request,
    safe_browsing::BinaryUploadService::Result result) {}

std::string ContentAnalysisDelegate::GetContentTransferMethod() const {}

}  // namespace enterprise_connectors