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
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_QUICK_INSERT_QUICK_INSERT_CLIENT_H_
#define ASH_QUICK_INSERT_QUICK_INSERT_CLIENT_H_
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "ash/ash_export.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/quick_insert/quick_insert_category.h"
#include "ash/quick_insert/quick_insert_search_result.h"
#include "ash/quick_insert/quick_insert_web_paste_target.h"
#include "base/files/file.h"
#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "ui/base/ime/text_input_client.h"
class SkBitmap;
namespace favicon {
class FaviconService;
}
namespace gfx {
class Size;
}
namespace history {
class HistoryService;
}
namespace network {
class SharedURLLoaderFactory;
} // namespace network
namespace ash {
// Lets QuickInsertController in Ash to communicate with the browser.
class ASH_EXPORT QuickInsertClient {
public:
using CrosSearchResultsCallback = base::RepeatingCallback<void(
AppListSearchResultType result_type,
std::vector<QuickInsertSearchResult> results)>;
using ShowEditorCallback =
base::OnceCallback<void(std::optional<std::string> preset_query_id,
std::optional<std::string> freeform_text)>;
using ShowLobsterCallback =
base::OnceCallback<void(std::optional<std::string> query)>;
using SuggestedEditorResultsCallback =
base::OnceCallback<void(std::vector<QuickInsertSearchResult>)>;
using RecentFilesCallback =
base::OnceCallback<void(std::vector<QuickInsertSearchResult>)>;
using FetchFileThumbnailCallback =
base::OnceCallback<void(const SkBitmap* bitmap, base::File::Error error)>;
// Gets the SharedURLLoaderFactory to use for Quick Insert network requests,
// e.g. to fetch assets. This is the loader factory for the active profile,
// not the global browser process one.
virtual scoped_refptr<network::SharedURLLoaderFactory>
GetSharedURLLoaderFactory() = 0;
// Starts a search using the CrOS Search API
// (`app_list::SearchEngine::StartSearch`).
virtual void StartCrosSearch(const std::u16string& query,
std::optional<QuickInsertCategory> category,
CrosSearchResultsCallback callback) = 0;
// Stops a search using the CrOS Search API
// (`app_list::SearchEngine::StopQuery`).
virtual void StopCrosQuery() = 0;
// Whether this device is eligble for editor.
virtual bool IsEligibleForEditor() = 0;
// Caches the current input field context and returns a callback to show
// Editor. If Editor is not available, this returns a null callback.
virtual ShowEditorCallback CacheEditorContext() = 0;
virtual ShowLobsterCallback CacheLobsterContext(
ui::TextInputClient* text_input_client) = 0;
virtual void GetSuggestedEditorResults(
SuggestedEditorResultsCallback callback) = 0;
virtual void GetRecentLocalFileResults(size_t max_files,
base::TimeDelta now_delta,
RecentFilesCallback callback) = 0;
virtual void GetRecentDriveFileResults(size_t max_files,
RecentFilesCallback callback) = 0;
virtual void FetchFileThumbnail(const base::FilePath& path,
const gfx::Size& size,
FetchFileThumbnailCallback callback) = 0;
// SAFETY: The returned `do_paste` MUST be called synchronously. Calling it
// after a delay, such as in a different task, may result in use-after-frees.
virtual std::optional<QuickInsertWebPasteTarget> GetWebPasteTarget() = 0;
// Make an announcement via an offscreen live region.
virtual void Announce(std::u16string_view message) = 0;
virtual history::HistoryService* GetHistoryService() = 0;
virtual favicon::FaviconService* GetFaviconService() = 0;
protected:
QuickInsertClient();
virtual ~QuickInsertClient();
};
} // namespace ash
#endif // ASH_QUICK_INSERT_QUICK_INSERT_CLIENT_H_
|