#ifndef CHROME_RENDERER_EXTENSIONS_API_APP_HOOKS_DELEGATE_H_
#define CHROME_RENDERER_EXTENSIONS_API_APP_HOOKS_DELEGATE_H_
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "extensions/renderer/bindings/api_binding_hooks_delegate.h"
#include "v8/include/v8.h"
namespace extensions {
class APIRequestHandler;
class Dispatcher;
class IPCMessageSender;
class ScriptContext;
class AppHooksDelegate : public APIBindingHooksDelegate {
public:
AppHooksDelegate(Dispatcher* dispatcher,
APIRequestHandler* request_handler,
IPCMessageSender* ipc_sender);
AppHooksDelegate(const AppHooksDelegate&) = delete;
AppHooksDelegate& operator=(const AppHooksDelegate&) = delete;
~AppHooksDelegate() override;
APIBindingHooks::RequestResult HandleRequest(
const std::string& method_name,
const APISignature* signature,
v8::Local<v8::Context> context,
v8::LocalVector<v8::Value>* arguments,
const APITypeReferenceMap& refs) override;
void InitializeTemplate(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> object_template,
const APITypeReferenceMap& type_refs) override;
bool GetIsInstalled(ScriptContext* script_context) const;
private:
static void IsInstalledGetterCallback(
v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
v8::Local<v8::Value> GetDetails(ScriptContext* script_context) const;
void GetInstallState(ScriptContext* script_context, int request_id);
const char* GetRunningState(ScriptContext* script_context) const;
void OnAppInstallStateResponse(int request_id, const std::string& state);
raw_ptr<Dispatcher> dispatcher_ = nullptr;
raw_ptr<APIRequestHandler> request_handler_ = nullptr;
raw_ptr<IPCMessageSender> ipc_sender_ = nullptr;
base::WeakPtrFactory<AppHooksDelegate> weak_factory_{this};
};
}
#endif