Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: content/renderer/pepper/pepper_try_catch.h

Issue 614223004: Use the correct v8 context for conversions when calling into the plugin from JS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2171
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ 6 #define CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "content/common/content_export.h" 9 #include "content/common/content_export.h"
10 #include "content/renderer/pepper/v8_var_converter.h" 10 #include "content/renderer/pepper/v8_var_converter.h"
11 #include "ppapi/c/pp_var.h" 11 #include "ppapi/c/pp_var.h"
12 #include "ppapi/shared_impl/scoped_pp_var.h" 12 #include "ppapi/shared_impl/scoped_pp_var.h"
13 #include "v8/include/v8.h" 13 #include "v8/include/v8.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 class PepperPluginInstanceImpl; 17 class PepperPluginInstanceImpl;
18 18
19 // Base class for scripting TryCatch helpers. 19 // Base class for scripting TryCatch helpers.
20 class CONTENT_EXPORT PepperTryCatch { 20 class CONTENT_EXPORT PepperTryCatch {
21 public: 21 public:
22 // PepperTryCatch objects should only be used as stack variables. This object 22 // PepperTryCatch objects should only be used as stack variables. This object
23 // takes a reference on the given PepperPluginInstanceImpl. 23 // takes a reference on the given PepperPluginInstanceImpl.
24 PepperTryCatch(PepperPluginInstanceImpl* instance, 24 PepperTryCatch(PepperPluginInstanceImpl* instance,
25 V8VarConverter::AllowObjectVars convert_objects); 25 V8VarConverter::AllowObjectVars convert_objects);
26 virtual ~PepperTryCatch(); 26 virtual ~PepperTryCatch();
27 27
28 virtual void SetException(const char* message) = 0; 28 virtual void SetException(const char* message) = 0;
29 virtual bool HasException() = 0; 29 virtual bool HasException() = 0;
30 // Gets the plugin context. Virtual so it can be overriden for testing. 30 // Gets the context to execute scripts in.
31 virtual v8::Handle<v8::Context> GetContext(); 31 virtual v8::Handle<v8::Context> GetContext() = 0;
32 32
33 // Convenience functions for doing conversions to/from V8 values and sets an 33 // Convenience functions for doing conversions to/from V8 values and sets an
34 // exception if there is an error in the conversion. 34 // exception if there is an error in the conversion.
35 v8::Handle<v8::Value> ToV8(PP_Var var); 35 v8::Handle<v8::Value> ToV8(PP_Var var);
36 ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value); 36 ppapi::ScopedPPVar FromV8(v8::Handle<v8::Value> v8_value);
37 37
38 protected: 38 protected:
39 // Make sure that |instance_| is alive for the lifetime of PepperTryCatch. 39 // Make sure that |instance_| is alive for the lifetime of PepperTryCatch.
40 // PepperTryCatch is used mostly in Pepper scripting code, where it can be 40 // PepperTryCatch is used mostly in Pepper scripting code, where it can be
41 // possible to enter JavaScript synchronously which can cause the plugin to 41 // possible to enter JavaScript synchronously which can cause the plugin to
(...skipping 17 matching lines...) Expand all
59 v8::Isolate* isolate); 59 v8::Isolate* isolate);
60 virtual ~PepperTryCatchV8(); 60 virtual ~PepperTryCatchV8();
61 61
62 bool ThrowException(); 62 bool ThrowException();
63 void ThrowException(const char* message); 63 void ThrowException(const char* message);
64 PP_Var* exception() { return &exception_; } 64 PP_Var* exception() { return &exception_; }
65 65
66 // PepperTryCatch 66 // PepperTryCatch
67 virtual void SetException(const char* message) OVERRIDE; 67 virtual void SetException(const char* message) OVERRIDE;
68 virtual bool HasException() OVERRIDE; 68 virtual bool HasException() OVERRIDE;
69 virtual v8::Handle<v8::Context> GetContext() OVERRIDE;
69 70
70 private: 71 private:
71 PP_Var exception_; 72 PP_Var exception_;
72 73
73 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchV8); 74 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchV8);
74 }; 75 };
75 76
76 // Catches v8 exceptions and emits a var exception. 77 // Catches v8 exceptions and emits a var exception.
77 class PepperTryCatchVar : public PepperTryCatch { 78 class PepperTryCatchVar : public PepperTryCatch {
78 public: 79 public:
79 // The PP_Var exception will be placed in |exception|. The user of this class 80 // The PP_Var exception will be placed in |exception|. The user of this class
80 // is responsible for managing the lifetime of the exception. It is valid to 81 // is responsible for managing the lifetime of the exception. It is valid to
81 // pass NULL for |exception| in which case no exception will be set. 82 // pass NULL for |exception| in which case no exception will be set.
82 PepperTryCatchVar(PepperPluginInstanceImpl* instance, 83 PepperTryCatchVar(PepperPluginInstanceImpl* instance,
83 PP_Var* exception); 84 PP_Var* exception);
84 virtual ~PepperTryCatchVar(); 85 virtual ~PepperTryCatchVar();
85 86
86 // PepperTryCatch 87 // PepperTryCatch
87 virtual void SetException(const char* message) OVERRIDE; 88 virtual void SetException(const char* message) OVERRIDE;
88 virtual bool HasException() OVERRIDE; 89 virtual bool HasException() OVERRIDE;
90 virtual v8::Handle<v8::Context> GetContext() OVERRIDE;
89 91
90 private: 92 private:
91 // Code which uses PepperTryCatchVar doesn't typically have a HandleScope, 93 // Code which uses PepperTryCatchVar doesn't typically have a HandleScope,
92 // make one for them. Note that this class is always allocated on the stack. 94 // make one for them. Note that this class is always allocated on the stack.
93 v8::HandleScope handle_scope_; 95 v8::HandleScope handle_scope_;
94 96
95 v8::Handle<v8::Context> context_; 97 v8::Handle<v8::Context> context_;
96 98
97 v8::TryCatch try_catch_; 99 v8::TryCatch try_catch_;
98 100
99 PP_Var* exception_; 101 PP_Var* exception_;
100 bool exception_is_set_; 102 bool exception_is_set_;
101 103
102 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar); 104 DISALLOW_COPY_AND_ASSIGN(PepperTryCatchVar);
103 }; 105 };
104 106
105 } // namespace content 107 } // namespace content
106 108
107 #endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_ 109 #endif // CONTENT_RENDERER_PEPPER_PEPPER_TRY_CATCH_H_
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.cc ('k') | content/renderer/pepper/pepper_try_catch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698