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

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

Issue 2961103002: [Extensions Bindings] Add an ExceptionHandler class (Closed)
Patch Set: jbroman's 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.
35 void SetHandlerForContext(v8::Local<v8::Context> context,
36 v8::Local<v8::Function> handler);
37
38 private:
39 // Returns the custom handler for the given |context|, or an empty handle if
40 // no custom handle exists.
41 v8::Local<v8::Function> GetCustomHandler(v8::Local<v8::Context> context);
42
43 binding::AddConsoleError add_console_error_;
44
45 binding::RunJSFunction run_js_;
46
47 DISALLOW_COPY_AND_ASSIGN(ExceptionHandler);
48 };
49
50 } // namespace extensions
51
52 #endif // EXTENSIONS_RENDERER_BINDINGS_EXCEPTION_HANDLER
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698