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

Side by Side Diff: extensions/renderer/api_last_error.h

Issue 2947463002: [Extensions Bindings] Add a bindings/ subdirectory under renderer (Closed)
Patch Set: . Created 3 years, 6 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_API_LAST_ERROR_H_
6 #define EXTENSIONS_RENDERER_API_LAST_ERROR_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "v8/include/v8.h"
13
14 namespace extensions {
15
16 // Handles creating and clearing a 'lastError' property to hold the last error
17 // set by an extension API function.
18 class APILastError {
19 public:
20 // Returns the object the 'lastError' property should be exposed on for the
21 // given context.
22 using GetParent =
23 base::Callback<v8::Local<v8::Object>(v8::Local<v8::Context>)>;
24 // Adds an error message to the context's console.
25 using AddConsoleError =
26 base::Callback<void(v8::Local<v8::Context>, const std::string& error)>;
27
28 APILastError(const GetParent& get_parent,
29 const AddConsoleError& add_console_error);
30 APILastError(APILastError&& other);
31 ~APILastError();
32
33 // Sets the last error for the given |context| to |error|.
34 void SetError(v8::Local<v8::Context> context, const std::string& error);
35
36 // Clears the last error in the given |context|. If |report_if_unchecked| is
37 // true and the developer didn't check the error, this throws an exception.
38 void ClearError(v8::Local<v8::Context> context, bool report_if_unchecked);
39
40 // Returns true if the given context has an active error.
41 bool HasError(v8::Local<v8::Context> context);
42
43 private:
44 GetParent get_parent_;
45
46 AddConsoleError add_console_error_;
47
48 DISALLOW_COPY_AND_ASSIGN(APILastError);
49 };
50
51 } // namespace extensions
52
53 #endif // EXTENSIONS_RENDERER_API_LAST_ERROR_H_
OLDNEW
« no previous file with comments | « extensions/renderer/api_invocation_errors_unittest.cc ('k') | extensions/renderer/api_last_error.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698