#ifndef CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_DEVELOPER_PRIVATE_DEVELOPER_PRIVATE_API_H_
#include "base/memory/raw_ptr.h"
#include "chrome/browser/extensions/api/developer_private/developer_private_event_router.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/pref_types.h"
#include "extensions/buildflags/buildflags.h"
#include "ui/base/clipboard/file_info.h"
static_assert(BUILDFLAG(ENABLE_EXTENSIONS_CORE));
class Profile;
namespace extensions {
inline constexpr PrefMap kPrefAcknowledgeSafetyCheckWarningReason = {
"ack_safety_check_warning_reason", PrefType::kInteger,
PrefScope::kExtensionSpecific};
class EventRouter;
class DeveloperPrivateAPI : public BrowserContextKeyedAPI,
public EventRouter::Observer {
public:
using UnpackedRetryId = std::string;
static BrowserContextKeyedAPIFactory<DeveloperPrivateAPI>*
GetFactoryInstance();
static DeveloperPrivateAPI* Get(content::BrowserContext* context);
explicit DeveloperPrivateAPI(content::BrowserContext* context);
DeveloperPrivateAPI(const DeveloperPrivateAPI&) = delete;
DeveloperPrivateAPI& operator=(const DeveloperPrivateAPI&) = delete;
~DeveloperPrivateAPI() override;
UnpackedRetryId AddUnpackedPath(content::WebContents* web_contents,
const base::FilePath& path);
base::FilePath GetUnpackedPath(content::WebContents* web_contents,
const UnpackedRetryId& id) const;
void SetDraggedFile(content::WebContents* web_contents,
const ui::FileInfo& file);
ui::FileInfo GetDraggedFile(content::WebContents* web_contents) const;
void Shutdown() override;
void OnListenerAdded(const EventListenerInfo& details) override;
void OnListenerRemoved(const EventListenerInfo& details) override;
DeveloperPrivateEventRouter* developer_private_event_router() {
return developer_private_event_router_.get();
}
const base::FilePath& last_unpacked_directory() const {
return last_unpacked_directory_;
}
private:
class WebContentsTracker;
using IdToPathMap = std::map<UnpackedRetryId, base::FilePath>;
struct WebContentsData {
WebContentsData();
WebContentsData(const WebContentsData&) = delete;
WebContentsData& operator=(const WebContentsData&) = delete;
~WebContentsData();
WebContentsData(WebContentsData&& other);
IdToPathMap allowed_unpacked_paths;
ui::FileInfo dragged_file;
};
friend class BrowserContextKeyedAPIFactory<DeveloperPrivateAPI>;
static const char* service_name() { return "DeveloperPrivateAPI"; }
static const bool kServiceRedirectedInIncognito = true;
static const bool kServiceIsNULLWhileTesting = true;
void RegisterNotifications();
const WebContentsData* GetWebContentsData(
content::WebContents* web_contents) const;
WebContentsData* GetOrCreateWebContentsData(
content::WebContents* web_contents);
raw_ptr<Profile> profile_;
base::FilePath last_unpacked_directory_;
std::map<content::WebContents*, WebContentsData> web_contents_data_;
std::unique_ptr<DeveloperPrivateEventRouter> developer_private_event_router_;
base::WeakPtrFactory<DeveloperPrivateAPI> weak_factory_{this};
};
template <>
void BrowserContextKeyedAPIFactory<
DeveloperPrivateAPI>::DeclareFactoryDependencies();
}
#endif