Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef EXTENSIONS_RENDERER_BINDINGS_EXCEPTION_HANDLER | |
| 6 #define EXTENSIONS_RENDERER_BINDINGS_EXCEPTION_HANDLER | |
| 7 | |
| 8 #include <string> | |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/optional.h" | |
| 14 #include "extensions/renderer/bindings/api_binding_types.h" | |
| 15 #include "v8/include/v8.h" | |
| 16 | |
| 17 namespace extensions { | |
| 18 | |
| 19 // A class to handle uncaught exceptions encountered in the bindings system | |
| 20 // while running untrusted code, such as exceptions thrown during callback | |
| 21 // execution or event handling. | |
| 22 class ExceptionHandler { | |
| 23 public: | |
| 24 ExceptionHandler(const binding::AddConsoleError& add_console_error, | |
| 25 const binding::RunJSFunction& run_js); | |
| 26 ~ExceptionHandler(); | |
| 27 | |
| 28 // Handles an exception in the given |context|. |message| is a message to | |
| 29 // prefix the error message with, e.g. "Exception in response to foo". | |
| 30 // The |try_catch| is the TryCatch that caught the exception. | |
| 31 void HandleException(v8::Local<v8::Context> context, | |
| 32 const std::string& message, | |
| 33 const v8::TryCatch& try_catch); | |
| 34 | |
| 35 // Sets a custom handler for the given context, which will be notified of | |
| 36 // exceptions thrown. | |
| 37 void SetHandlerForContext(v8::Local<v8::Context> context, | |
|
Devlin
2017/06/29 01:36:01
Note: This isn't actually used in this CL (though
| |
| 38 v8::Local<v8::Function> handler); | |
| 39 | |
| 40 // Notifies the ExceptionHandler that the given |context| should be | |
| 41 // invalidated. | |
| 42 void InvalidateContext(v8::Local<v8::Context> context); | |
| 43 | |
| 44 private: | |
| 45 // Returns the custom handler for the given |context|, or an empty handle if | |
| 46 // no custom handle exists. | |
| 47 v8::Local<v8::Function> GetCustomHandler(v8::Local<v8::Context> context); | |
| 48 | |
| 49 using CustomHandlerList = | |
| 50 std::vector<std::pair<v8::Global<v8::Context>, v8::Global<v8::Function>>>; | |
|
jbroman
2017/06/30 18:35:31
This seems to roughly re-implement PerContextData
Devlin
2017/07/06 16:49:22
Brevity :) It was actually quite a bit shorter th
jbroman
2017/07/06 21:09:18
I think I mildly prefer the PerContextData version
| |
| 51 CustomHandlerList custom_handlers_; | |
| 52 | |
| 53 binding::AddConsoleError add_console_error_; | |
| 54 | |
| 55 binding::RunJSFunction run_js_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(ExceptionHandler); | |
| 58 }; | |
| 59 | |
| 60 } // namespace extensions | |
| 61 | |
| 62 #endif // EXTENSIONS_RENDERER_BINDINGS_EXCEPTION_HANDLER | |
| OLD | NEW |