| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_NPAPI_GLUE_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_ | 6 #define CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // | 57 // |
| 58 // The instance is necessary because we can have different instances pointing to | 58 // The instance is necessary because we can have different instances pointing to |
| 59 // the same NPObject, and we want to keep their refs separate. | 59 // the same NPObject, and we want to keep their refs separate. |
| 60 // | 60 // |
| 61 // If no ObjectVar currently exists corresponding to the NPObject, one is | 61 // If no ObjectVar currently exists corresponding to the NPObject, one is |
| 62 // created associated with the given module. | 62 // created associated with the given module. |
| 63 // | 63 // |
| 64 // Note: this could easily be changed to take a PP_Instance instead if that | 64 // Note: this could easily be changed to take a PP_Instance instead if that |
| 65 // makes certain calls in the future easier. Currently all callers have a | 65 // makes certain calls in the future easier. Currently all callers have a |
| 66 // PluginInstance so that's what we use here. | 66 // PluginInstance so that's what we use here. |
| 67 CONTENT_EXPORT PP_Var NPObjectToPPVar(PepperPluginInstanceImpl* instance, | 67 CONTENT_EXPORT PP_Var |
| 68 NPObject* object); | 68 NPObjectToPPVar(PepperPluginInstanceImpl* instance, NPObject* object); |
| 69 | 69 |
| 70 // This version creates a default v8::Context rather than using the one from | 70 // This version creates a default v8::Context rather than using the one from |
| 71 // the container of |instance|. It is only for use in unit tests, where we don't | 71 // the container of |instance|. It is only for use in unit tests, where we don't |
| 72 // have a real container for |instance|. | 72 // have a real container for |instance|. |
| 73 CONTENT_EXPORT PP_Var NPObjectToPPVarForTest(PepperPluginInstanceImpl* instance, | 73 CONTENT_EXPORT PP_Var NPObjectToPPVarForTest(PepperPluginInstanceImpl* instance, |
| 74 NPObject* object); | 74 NPObject* object); |
| 75 | 75 |
| 76 // PPResultAndExceptionToNPResult ---------------------------------------------- | 76 // PPResultAndExceptionToNPResult ---------------------------------------------- |
| 77 | 77 |
| 78 // Convenience object for converting a PPAPI call that can throw an exception | 78 // Convenience object for converting a PPAPI call that can throw an exception |
| (...skipping 26 matching lines...) Expand all Loading... |
| 105 // Returns true if an exception has been set. | 105 // Returns true if an exception has been set. |
| 106 bool has_exception() const { return exception_.type != PP_VARTYPE_UNDEFINED; } | 106 bool has_exception() const { return exception_.type != PP_VARTYPE_UNDEFINED; } |
| 107 | 107 |
| 108 // Returns a pointer to the exception. You would pass this to the PPAPI | 108 // Returns a pointer to the exception. You would pass this to the PPAPI |
| 109 // function as the exception parameter. If it is set to non-void, this object | 109 // function as the exception parameter. If it is set to non-void, this object |
| 110 // will take ownership of destroying it. | 110 // will take ownership of destroying it. |
| 111 PP_Var* exception() { return &exception_; } | 111 PP_Var* exception() { return &exception_; } |
| 112 | 112 |
| 113 // Returns true if everything succeeded with no exception. This is valid only | 113 // Returns true if everything succeeded with no exception. This is valid only |
| 114 // after calling SetResult/CheckExceptionForNoResult. | 114 // after calling SetResult/CheckExceptionForNoResult. |
| 115 bool success() const { | 115 bool success() const { return success_; } |
| 116 return success_; | |
| 117 } | |
| 118 | 116 |
| 119 // Call this with the return value of the PPAPI function. It will convert | 117 // Call this with the return value of the PPAPI function. It will convert |
| 120 // the result to the NPVariant output parameter and pass any exception on to | 118 // the result to the NPVariant output parameter and pass any exception on to |
| 121 // the JS engine. It will update the success flag and return it. | 119 // the JS engine. It will update the success flag and return it. |
| 122 bool SetResult(PP_Var result); | 120 bool SetResult(PP_Var result); |
| 123 | 121 |
| 124 // Call this after calling a PPAPI function that could have set the | 122 // Call this after calling a PPAPI function that could have set the |
| 125 // exception. It will pass the exception on to the JS engine and update | 123 // exception. It will pass the exception on to the JS engine and update |
| 126 // the success flag. | 124 // the success flag. |
| 127 // | 125 // |
| 128 // The success flag will be returned. | 126 // The success flag will be returned. |
| 129 bool CheckExceptionForNoResult(); | 127 bool CheckExceptionForNoResult(); |
| 130 | 128 |
| 131 // Call this to ignore any exception. This prevents the DCHECK from failing | 129 // Call this to ignore any exception. This prevents the DCHECK from failing |
| 132 // in the destructor. | 130 // in the destructor. |
| 133 void IgnoreException(); | 131 void IgnoreException(); |
| 134 | 132 |
| 135 private: | 133 private: |
| 136 // Throws the current exception to JS. The exception must be set. | 134 // Throws the current exception to JS. The exception must be set. |
| 137 void ThrowException(); | 135 void ThrowException(); |
| 138 | 136 |
| 139 NPObject* object_var_; // Non-owning ref (see constructor). | 137 NPObject* object_var_; // Non-owning ref (see constructor). |
| 140 NPVariant* np_result_; // Output value, possibly NULL (see constructor). | 138 NPVariant* np_result_; // Output value, possibly NULL (see constructor). |
| 141 PP_Var exception_; // Exception set by the PPAPI call. We own a ref to it. | 139 PP_Var exception_; // Exception set by the PPAPI call. We own a ref to it. |
| 142 bool success_; // See the success() function above. | 140 bool success_; // See the success() function above. |
| 143 bool checked_exception_; // SetResult/CheckExceptionForNoResult was called. | 141 bool checked_exception_; // SetResult/CheckExceptionForNoResult was called. |
| 144 | 142 |
| 145 DISALLOW_COPY_AND_ASSIGN(PPResultAndExceptionToNPResult); | 143 DISALLOW_COPY_AND_ASSIGN(PPResultAndExceptionToNPResult); |
| 146 }; | 144 }; |
| 147 | 145 |
| 148 // PPVarArrayFromNPVariantArray ------------------------------------------------ | 146 // PPVarArrayFromNPVariantArray ------------------------------------------------ |
| 149 | 147 |
| 150 // Converts an array of NPVariants to an array of PP_Var, and scopes the | 148 // Converts an array of NPVariants to an array of PP_Var, and scopes the |
| 151 // ownership of the PP_Var. This is used when converting argument lists from | 149 // ownership of the PP_Var. This is used when converting argument lists from |
| 152 // WebKit to the plugin. | 150 // WebKit to the plugin. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // the exception itself has been stored. | 253 // the exception itself has been stored. |
| 256 bool has_exception_; | 254 bool has_exception_; |
| 257 | 255 |
| 258 // May be null if the consumer isn't interesting in catching exceptions. | 256 // May be null if the consumer isn't interesting in catching exceptions. |
| 259 PP_Var* exception_; | 257 PP_Var* exception_; |
| 260 }; | 258 }; |
| 261 | 259 |
| 262 } // namespace content | 260 } // namespace content |
| 263 | 261 |
| 264 #endif // CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_ | 262 #endif // CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_ |
| OLD | NEW |