#ifndef CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_
#define CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/shared_impl/scoped_pp_var.h"
#include "v8/include/v8-exception.h"
#include "v8/include/v8-forward.h"
namespace content {
class PepperPluginInstanceImpl;
class V8VarConverter;
class CONTENT_EXPORT PepperTryCatch {
public:
PepperTryCatch(PepperPluginInstanceImpl* instance,
V8VarConverter* var_converter);
virtual ~PepperTryCatch();
virtual void SetException(const char* message) = 0;
virtual bool HasException() = 0;
virtual v8::Local<v8::Context> GetContext() = 0;
v8::Local<v8::Value> ToV8(PP_Var var);
ppapi::ScopedPPVar FromV8(v8::Local<v8::Value> v8_value);
ppapi::ScopedPPVar FromV8Maybe(v8::MaybeLocal<v8::Value> v8_value);
protected:
scoped_refptr<PepperPluginInstanceImpl> instance_;
V8VarConverter* var_converter_;
};
class PepperTryCatchV8 : public PepperTryCatch {
public:
PepperTryCatchV8(PepperPluginInstanceImpl* instance,
V8VarConverter* var_converter,
v8::Isolate* isolate);
PepperTryCatchV8(const PepperTryCatchV8&) = delete;
PepperTryCatchV8& operator=(const PepperTryCatchV8&) = delete;
~PepperTryCatchV8() override;
bool ThrowException();
void ThrowException(const char* message);
PP_Var* exception() { return &exception_; }
void SetException(const char* message) override;
bool HasException() override;
v8::Local<v8::Context> GetContext() override;
private:
PP_Var exception_;
};
class PepperTryCatchVar : public PepperTryCatch {
public:
PepperTryCatchVar(PepperPluginInstanceImpl* instance,
V8VarConverter* var_converter,
PP_Var* exception);
PepperTryCatchVar(const PepperTryCatchVar&) = delete;
PepperTryCatchVar& operator=(const PepperTryCatchVar&) = delete;
~PepperTryCatchVar() override;
void SetException(const char* message) override;
bool HasException() override;
v8::Local<v8::Context> GetContext() override;
private:
v8::HandleScope handle_scope_;
v8::Local<v8::Context> context_;
v8::TryCatch try_catch_;
PP_Var* exception_;
bool exception_is_set_;
};
}
#endif