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

Unified Diff: extensions/browser/api/execute_code_function.h

Issue 2630753003: Separate validation failures from other failures in ExecuteCodeFunction. (Closed)
Patch Set: address comments Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/execute_code_function.h
diff --git a/extensions/browser/api/execute_code_function.h b/extensions/browser/api/execute_code_function.h
index dbf8639e9ff06378db37fc269e8c8c7b1364b5f7..13df3dd544b41588db6843e5ca9dffbca7f72eb8 100644
--- a/extensions/browser/api/execute_code_function.h
+++ b/extensions/browser/api/execute_code_function.h
@@ -6,6 +6,7 @@
#define EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_H_
#include "base/macros.h"
+#include "base/optional.h"
#include "extensions/browser/extension_function.h"
#include "extensions/browser/script_executor.h"
#include "extensions/common/api/extension_types.h"
@@ -27,8 +28,23 @@ class ExecuteCodeFunction : public AsyncExtensionFunction {
bool HasPermission() override;
bool RunAsync() override;
- // Initialize |details_| if it hasn't already been.
- virtual bool Init() = 0;
+ enum InitResult {
+ // ExtensionFunction validation failure.
+ // Warning: Validation failures kill the renderer and should only be used
+ // for circumstances that should never happen.
+ VALIDATION_FAILURE,
+ // Failure other than validation.
+ // Failures return an error to the extension function and should be used
+ // when an error situation occurs: e.g. trying to execute script during
+ // browser shutdown.
+ FAILURE,
+ SUCCESS
+ };
+
+ // Initializes |details_| and other variables if they haven't already been.
+ // Returns whether or not it succeeded. Failure can be tolerable (FAILURE), or
+ // fatal (VALIDATION_FAILURE).
+ virtual InitResult Init() = 0;
virtual bool ShouldInsertCSS() const = 0;
virtual bool CanExecuteScriptOnPage() = 0;
virtual ScriptExecutor* GetScriptExecutor() = 0;
@@ -48,8 +64,20 @@ class ExecuteCodeFunction : public AsyncExtensionFunction {
const HostID& host_id() const { return host_id_; }
void set_host_id(const HostID& host_id) { host_id_ = host_id; }
+ InitResult set_init_result(InitResult init_result) {
+ init_result_ = init_result;
+ return init_result_.value();
+ }
+ InitResult set_init_result_error(const std::string& error) {
+ init_error_ = error;
+ return set_init_result(FAILURE);
+ }
+
// The injection details.
std::unique_ptr<api::extension_types::InjectDetails> details_;
+ base::Optional<InitResult> init_result_;
+ // Set iff |init_result_| == FAILURE, holds the error string.
+ base::Optional<std::string> init_error_;
private:
// Retrieves the file url for the given |extension_path| and optionally
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_constants.cc ('k') | extensions/browser/api/execute_code_function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698