Chromium Code Reviews| Index: content/renderer/pepper/pepper_try_catch.h |
| diff --git a/content/renderer/pepper/pepper_try_catch.h b/content/renderer/pepper/pepper_try_catch.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a9f78a311e044e8fb0e82001a14b5bb2b9428ec2 |
| --- /dev/null |
| +++ b/content/renderer/pepper/pepper_try_catch.h |
| @@ -0,0 +1,91 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ |
| +#define CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "ppapi/c/pp_var.h" |
| +#include "ppapi/shared_impl/scoped_pp_var.h" |
| +#include "v8/include/v8.h" |
| + |
| +namespace content { |
| + |
| +class PepperPluginInstanceImpl; |
| + |
| +// Base class for scripting TryCatch helpers. |
| +class PepperTryCatch { |
| + public: |
| + PepperTryCatch(PepperPluginInstanceImpl* instance, |
| + bool convert_objects); |
| + virtual ~PepperTryCatch(); |
| + |
| + virtual void SetException(const char* message) = 0; |
| + // Gets the plugin context. Virtual so it can be overriden for testing. |
| + virtual v8::Handle<v8::Context> GetContext(); |
| + |
| + // Convenience functions for doing conversions to/from V8 values and sets an |
| + // exception if there is an error in the conversion. |
| + v8::Handle<v8::Value> ToV8(PP_Var var); |
| + ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value); |
| + |
| + protected: |
| + PepperPluginInstanceImpl* instance_; |
| + |
| + // Whether To/FromV8 should convert object vars. If set to false, an exception |
| + // should be set if they are encountered during conversion. |
| + bool convert_objects_; |
| +}; |
| + |
| +// Catches var exceptions and emits a v8 exception. |
| +class PepperTryCatchV8 : public PepperTryCatch { |
| + public: |
| + PepperTryCatchV8(PepperPluginInstanceImpl* instance, |
| + bool convert_objects, |
| + v8::Isolate* isolate); |
| + virtual ~PepperTryCatchV8(); |
| + |
| + bool HasException(); |
| + bool ThrowException(); |
| + void ThrowException(const char* message); |
| + PP_Var* exception() { return &exception_; } |
| + |
| + // PepperTryCatch |
| + virtual void SetException(const char* message) OVERRIDE; |
| + |
| + private: |
| + PP_Var exception_; |
|
dmichael (off chromium)
2014/07/30 19:34:14
It looks like using scoped_refptr<StringVar> might
raymes
2014/08/06 03:22:52
Done.
raymes
2014/08/06 03:29:56
Actually this won't work. We want to be able to pa
dmichael (off chromium)
2014/08/06 15:41:45
Ah, I see. Thanks for explaining.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(PepperTryCatchV8); |
| +}; |
| + |
| +// Catches v8 exceptions and emits a var exception. |
| +class PepperTryCatchVar : public PepperTryCatch { |
| + public: |
| + // The PP_Var exception will be placed in |exception|. |
| + PepperTryCatchVar(PepperPluginInstanceImpl* instance, |
| + bool convert_objects, |
| + PP_Var* exception); |
|
dmichael (off chromium)
2014/07/30 19:34:14
ScopedPPVar*, maybe?
Otherwise the user of Pepper
raymes
2014/08/06 03:22:52
This class is mainly used to provide an exception
|
| + virtual ~PepperTryCatchVar(); |
| + |
| + bool HasException(); |
| + |
| + // PepperTryCatch |
| + virtual void SetException(const char* message) OVERRIDE; |
| + |
| + private: |
| + // We typically don't have a HandleScope when using PepperTryCatchVar. |
|
dmichael (off chromium)
2014/07/30 19:34:14
Maybe a clearer wording would be:
// Code which us
raymes
2014/08/06 03:22:52
Done, I reworded the comment! I think it makes the
|
| + v8::HandleScope handle_scope_; |
| + |
| + v8::TryCatch try_catch_; |
| + |
| + PP_Var* exception_; |
| + bool exception_is_set_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ |