#include "components/omnibox/browser/clipboard_provider.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_provider_client.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/page_classification_functions.h"
#include "components/omnibox/browser/verbatim_match.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/open_from_clipboard/clipboard_recent_content.h"
#include "components/search_engines/template_url_service.h"
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/url_formatter.h"
#include "third_party/metrics_proto/omnibox_focus_type.pb.h"
#include "third_party/omnibox_proto/groups.pb.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_util.h"
#if !BUILDFLAG(IS_IOS)
#include "ui/base/clipboard/clipboard.h"
#endif
namespace …
ClipboardProvider::ClipboardProvider(AutocompleteProviderClient* client,
AutocompleteProviderListener* listener,
ClipboardRecentContent* clipboard_content)
: … { … }
ClipboardProvider::~ClipboardProvider() { … }
void ClipboardProvider::Start(const AutocompleteInput& input,
bool minimal_changes) { … }
void ClipboardProvider::Stop(bool clear_cached_results,
bool due_to_user_inactivity) { … }
void ClipboardProvider::DeleteMatch(const AutocompleteMatch& match) { … }
void ClipboardProvider::AddProviderInfo(ProvidersInfo* provider_info) const { … }
void ClipboardProvider::AddCreatedMatchWithTracking(
const AutocompleteInput& input,
AutocompleteMatch match,
const base::TimeDelta clipboard_contents_age) { … }
bool ClipboardProvider::TemplateURLSupportsTextSearch() { … }
bool ClipboardProvider::TemplateURLSupportsImageSearch() { … }
void ClipboardProvider::CheckClipboardContent(const AutocompleteInput& input) { … }
void ClipboardProvider::OnReceiveClipboardContent(
const AutocompleteInput& input,
base::TimeDelta clipboard_contents_age,
std::set<ClipboardContentType> matched_types) { … }
std::optional<AutocompleteMatch> ClipboardProvider::CreateURLMatch(
const AutocompleteInput& input,
bool* read_clipboard_content) { … }
std::optional<AutocompleteMatch> ClipboardProvider::CreateTextMatch(
const AutocompleteInput& input,
bool* read_clipboard_content) { … }
bool ClipboardProvider::CreateImageMatch(const AutocompleteInput& input) { … }
void ClipboardProvider::CreateImageMatchCallback(
const AutocompleteInput& input,
const base::TimeDelta clipboard_contents_age,
std::optional<gfx::Image> optional_image) { … }
void ClipboardProvider::AddImageMatchCallback(
const AutocompleteInput& input,
const base::TimeDelta clipboard_contents_age,
std::optional<AutocompleteMatch> match) { … }
AutocompleteMatch ClipboardProvider::NewBlankURLMatch() { … }
AutocompleteMatch ClipboardProvider::NewClipboardURLMatch(GURL url) { … }
AutocompleteMatch ClipboardProvider::NewBlankTextMatch() { … }
std::optional<AutocompleteMatch> ClipboardProvider::NewClipboardTextMatch(
std::u16string text) { … }
AutocompleteMatch ClipboardProvider::NewBlankImageMatch() { … }
void ClipboardProvider::NewClipboardImageMatch(
std::optional<gfx::Image> optional_image,
ClipboardImageMatchCallback callback) { … }
void ClipboardProvider::UpdateClipboardMatchWithContent(
AutocompleteMatch* match,
ClipboardMatchCallback callback) { … }
scoped_refptr<base::RefCountedMemory> ClipboardProvider::EncodeClipboardImage(
gfx::ImageSkia image_skia) { … }
void ClipboardProvider::ConstructImageMatchCallback(
ClipboardImageMatchCallback callback,
scoped_refptr<base::RefCountedMemory> image_bytes) { … }
void ClipboardProvider::OnReceiveURLForMatchWithContent(
ClipboardMatchCallback callback,
AutocompleteMatch* match,
std::optional<GURL> optional_gurl) { … }
void ClipboardProvider::OnReceiveTextForMatchWithContent(
ClipboardMatchCallback callback,
AutocompleteMatch* match,
std::optional<std::u16string> optional_text) { … }
void ClipboardProvider::OnReceiveImageForMatchWithContent(
ClipboardMatchCallback callback,
AutocompleteMatch* match,
std::optional<gfx::Image> optional_image) { … }
void ClipboardProvider::OnReceiveImageMatchForMatchWithContent(
ClipboardMatchCallback callback,
AutocompleteMatch* match,
std::optional<AutocompleteMatch> optional_match) { … }
void ClipboardProvider::UpdateClipboardURLContent(const GURL& url,
AutocompleteMatch* match) { … }
bool ClipboardProvider::UpdateClipboardTextContent(const std::u16string& text,
AutocompleteMatch* match) { … }