diff options
-rw-r--r-- | apps/shell/browser/api/shell/shell_api.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/chrome_extension_function.cc | 12 | ||||
-rw-r--r-- | chrome/browser/extensions/chrome_extension_function.h | 6 | ||||
-rw-r--r-- | extensions/browser/api/runtime/runtime_api.cc | 2 | ||||
-rw-r--r-- | extensions/browser/api/storage/storage_api.cc | 7 | ||||
-rw-r--r-- | extensions/browser/extension_function.cc | 27 | ||||
-rw-r--r-- | extensions/browser/extension_function.h | 43 |
7 files changed, 74 insertions, 25 deletions
diff --git a/apps/shell/browser/api/shell/shell_api.cc b/apps/shell/browser/api/shell/shell_api.cc index c985025..c108b0f 100644 --- a/apps/shell/browser/api/shell/shell_api.cc +++ b/apps/shell/browser/api/shell/shell_api.cc @@ -53,7 +53,7 @@ ShellCreateWindowFunction::~ShellCreateWindowFunction() { ExtensionFunction::ResponseAction ShellCreateWindowFunction::Run() { scoped_ptr<CreateWindow::Params> params(CreateWindow::Params::Create(*args_)); - EXTENSION_FUNCTION_VALIDATE_TYPESAFE(params.get()); + EXTENSION_FUNCTION_VALIDATE(params.get()); // Convert "main.html" to "chrome-extension:/<id>/main.html". GURL url = GetExtension()->GetResourceURL(params->url); diff --git a/chrome/browser/extensions/chrome_extension_function.cc b/chrome/browser/extensions/chrome_extension_function.cc index f9c7f28..0f5a503 100644 --- a/chrome/browser/extensions/chrome_extension_function.cc +++ b/chrome/browser/extensions/chrome_extension_function.cc @@ -119,6 +119,12 @@ ExtensionFunction::ResponseAction ChromeAsyncExtensionFunction::Run() { return RunAsync() ? RespondLater() : RespondNow(Error(error_)); } +// static +bool ChromeAsyncExtensionFunction::ValidationFailure( + ChromeAsyncExtensionFunction* function) { + return false; +} + ChromeSyncExtensionFunction::ChromeSyncExtensionFunction() { } @@ -128,3 +134,9 @@ ExtensionFunction::ResponseAction ChromeSyncExtensionFunction::Run() { return RespondNow(RunSync() ? MultipleArguments(results_.get()) : Error(error_)); } + +// static +bool ChromeSyncExtensionFunction::ValidationFailure( + ChromeSyncExtensionFunction* function) { + return false; +} diff --git a/chrome/browser/extensions/chrome_extension_function.h b/chrome/browser/extensions/chrome_extension_function.h index 6536a76..dc35815 100644 --- a/chrome/browser/extensions/chrome_extension_function.h +++ b/chrome/browser/extensions/chrome_extension_function.h @@ -74,6 +74,9 @@ class ChromeAsyncExtensionFunction : public ChromeUIThreadExtensionFunction { // Deprecated, see AsyncExtensionFunction::RunAsync. virtual bool RunAsync() = 0; + // ValidationFailure override to match RunAsync(). + static bool ValidationFailure(ChromeAsyncExtensionFunction* function); + private: virtual ResponseAction Run() OVERRIDE; }; @@ -90,6 +93,9 @@ class ChromeSyncExtensionFunction : public ChromeUIThreadExtensionFunction { // Deprecated, see SyncExtensionFunction::RunSync. virtual bool RunSync() = 0; + // ValidationFailure override to match RunSync(). + static bool ValidationFailure(ChromeSyncExtensionFunction* function); + private: virtual ResponseAction Run() OVERRIDE; }; diff --git a/extensions/browser/api/runtime/runtime_api.cc b/extensions/browser/api/runtime/runtime_api.cc index 942c3a60d..9dc3feb 100644 --- a/extensions/browser/api/runtime/runtime_api.cc +++ b/extensions/browser/api/runtime/runtime_api.cc @@ -427,7 +427,7 @@ void RuntimeGetBackgroundPageFunction::OnPageLoaded(ExtensionHost* host) { ExtensionFunction::ResponseAction RuntimeSetUninstallURLFunction::Run() { std::string url_string; - EXTENSION_FUNCTION_VALIDATE_TYPESAFE(args_->GetString(0, &url_string)); + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string)); GURL url(url_string); if (!url.is_valid()) { diff --git a/extensions/browser/api/storage/storage_api.cc b/extensions/browser/api/storage/storage_api.cc index 012fe41..1023236 100644 --- a/extensions/browser/api/storage/storage_api.cc +++ b/extensions/browser/api/storage/storage_api.cc @@ -40,13 +40,12 @@ bool SettingsFunction::ShouldSkipQuotaLimiting() const { ExtensionFunction::ResponseAction SettingsFunction::Run() { std::string settings_namespace_string; - EXTENSION_FUNCTION_VALIDATE_TYPESAFE( - args_->GetString(0, &settings_namespace_string)); + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &settings_namespace_string)); args_->Remove(0, NULL); settings_namespace_ = settings_namespace::FromString(settings_namespace_string); - EXTENSION_FUNCTION_VALIDATE_TYPESAFE(settings_namespace_ != - settings_namespace::INVALID); + EXTENSION_FUNCTION_VALIDATE(settings_namespace_ != + settings_namespace::INVALID); StorageFrontend* frontend = StorageFrontend::Get(browser_context()); if (!frontend->IsStorageEnabled(settings_namespace_)) { diff --git a/extensions/browser/extension_function.cc b/extensions/browser/extension_function.cc index 470ae55..ff7d544 100644 --- a/extensions/browser/extension_function.cc +++ b/extensions/browser/extension_function.cc @@ -227,12 +227,18 @@ ExtensionFunction::ResponseValue ExtensionFunction::BadMessage() { ExtensionFunction::ResponseAction ExtensionFunction::RespondNow( ResponseValue result) { - return scoped_ptr<ResponseActionObject>(new RespondNowAction( + return ResponseAction(new RespondNowAction( result.Pass(), base::Bind(&ExtensionFunction::SendResponse, this))); } ExtensionFunction::ResponseAction ExtensionFunction::RespondLater() { - return scoped_ptr<ResponseActionObject>(new RespondLaterAction()); + return ResponseAction(new RespondLaterAction()); +} + +// static +ExtensionFunction::ResponseAction ExtensionFunction::ValidationFailure( + ExtensionFunction* function) { + return function->RespondNow(function->BadMessage()); } void ExtensionFunction::Respond(ResponseValue result) { @@ -364,6 +370,12 @@ ExtensionFunction::ResponseAction AsyncExtensionFunction::Run() { return RunAsync() ? RespondLater() : RespondNow(Error(error_)); } +// static +bool AsyncExtensionFunction::ValidationFailure( + AsyncExtensionFunction* function) { + return false; +} + SyncExtensionFunction::SyncExtensionFunction() { } @@ -375,6 +387,11 @@ ExtensionFunction::ResponseAction SyncExtensionFunction::Run() { : Error(error_)); } +// static +bool SyncExtensionFunction::ValidationFailure(SyncExtensionFunction* function) { + return false; +} + SyncIOThreadExtensionFunction::SyncIOThreadExtensionFunction() { } @@ -385,3 +402,9 @@ ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { return RespondNow(RunSync() ? MultipleArguments(results_.get()) : Error(error_)); } + +// static +bool SyncIOThreadExtensionFunction::ValidationFailure( + SyncIOThreadExtensionFunction* function) { + return false; +} diff --git a/extensions/browser/extension_function.h b/extensions/browser/extension_function.h index 259b86a..9f8cb71 100644 --- a/extensions/browser/extension_function.h +++ b/extensions/browser/extension_function.h @@ -44,28 +44,23 @@ class ExtensionMessageFilter; class QuotaLimitHeuristic; } -#define EXTENSION_FUNCTION_VALIDATE(test) \ - EXTENSION_FUNCTION_VALIDATE_INTERNAL(test, false) - -#define EXTENSION_FUNCTION_VALIDATE_TYPESAFE(test) \ - EXTENSION_FUNCTION_VALIDATE_INTERNAL(test, RespondNow(BadMessage())) - #ifdef NDEBUG -#define EXTENSION_FUNCTION_VALIDATE_INTERNAL(test, failure) \ - do { \ - if (!(test)) { \ - bad_message_ = true; \ - return (failure); \ - } \ +#define EXTENSION_FUNCTION_VALIDATE(test) \ + do { \ + if (!(test)) { \ + bad_message_ = true; \ + return ValidationFailure(this); \ + } \ } while (0) #else // NDEBUG -#define EXTENSION_FUNCTION_VALIDATE_INTERNAL(test, failure) CHECK(test) +#define EXTENSION_FUNCTION_VALIDATE(test) CHECK(test) #endif // NDEBUG -#define EXTENSION_FUNCTION_ERROR(error) do { \ - error_ = error; \ - bad_message_ = true; \ - return false; \ +#define EXTENSION_FUNCTION_ERROR(error) \ + do { \ + error_ = error; \ + bad_message_ = true; \ + return ValidationFailure(this); \ } while (0) // Declares a callable extension function with the given |name|. You must also @@ -259,6 +254,11 @@ class ExtensionFunction // Don't respond now, but promise to call Respond() later. ResponseAction RespondLater(); + // This is the return value of the EXTENSION_FUNCTION_VALIDATE macro, which + // needs to work from Run(), RunAsync(), and RunSync(). The former of those + // has a different return type (ResponseAction) than the latter two (bool). + static ResponseAction ValidationFailure(ExtensionFunction* function); + // If RespondLater() was used, functions must at some point call Respond() // with |result| as their result. void Respond(ResponseValue result); @@ -498,6 +498,9 @@ class AsyncExtensionFunction : public UIThreadExtensionFunction { // to respond immediately with an error. virtual bool RunAsync() = 0; + // ValidationFailure override to match RunAsync(). + static bool ValidationFailure(AsyncExtensionFunction* function); + private: virtual ResponseAction Run() OVERRIDE; }; @@ -522,6 +525,9 @@ class SyncExtensionFunction : public UIThreadExtensionFunction { // immediately with success, false to respond immediately with an error. virtual bool RunSync() = 0; + // ValidationFailure override to match RunSync(). + static bool ValidationFailure(SyncExtensionFunction* function); + private: virtual ResponseAction Run() OVERRIDE; }; @@ -540,6 +546,9 @@ class SyncIOThreadExtensionFunction : public IOThreadExtensionFunction { // error. virtual bool RunSync() = 0; + // ValidationFailure override to match RunSync(). + static bool ValidationFailure(SyncIOThreadExtensionFunction* function); + private: virtual ResponseAction Run() OVERRIDE; }; |