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

Side by Side Diff: extensions/renderer/bindings/exception_handler.h

Issue 2961103002: [Extensions Bindings] Add an ExceptionHandler class (Closed)
Patch Set: rebase + nits Created 3 years, 5 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
(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
10 #include "base/macros.h"
11 #include "base/optional.h"
12 #include "extensions/renderer/bindings/api_binding_types.h"
13 #include "v8/include/v8.h"
14
15 namespace extensions {
16
17 // A class to handle uncaught exceptions encountered in the bindings system
18 // while running untrusted code, such as exceptions thrown during callback
19 // execution or event handling.
20 class ExceptionHandler {
21 public:
22 ExceptionHandler(const binding::AddConsoleError& add_console_error,
23 const binding::RunJSFunction& run_js);
24 ~ExceptionHandler();
25
26 // Handles an exception in the given |context|. |message| is a message to
27 // prefix the error message with, e.g. "Exception in response to foo".
28 // The |try_catch| is the TryCatch that caught the exception.
29 void HandleException(v8::Local<v8::Context> context,
30 const std::string& message,
31 v8::TryCatch* try_catch);
32
33 // Sets a custom handler for the given context, which will be notified of
34 // exceptions thrown. This is only allowed to be called while the context is
35 // valid.
36 void SetHandlerForContext(v8::Local<v8::Context> context,
37 v8::Local<v8::Function> handler);
38
39 private:
40 // Returns the custom handler for the given |context|, or an empty handle if
41 // no custom handle exists.
42 v8::Local<v8::Function> GetCustomHandler(v8::Local<v8::Context> context);
43
44 binding::AddConsoleError add_console_error_;
45
46 binding::RunJSFunction run_js_;
47
48 DISALLOW_COPY_AND_ASSIGN(ExceptionHandler);
49 };
50
51 } // namespace extensions
52
53 #endif // EXTENSIONS_RENDERER_BINDINGS_EXCEPTION_HANDLER
OLDNEW
« no previous file with comments | « extensions/renderer/bindings/declarative_event_unittest.cc ('k') | extensions/renderer/bindings/exception_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698