| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ |
| 6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 typedef scoped_ptr<ResponseActionObject> ResponseAction; | 138 typedef scoped_ptr<ResponseActionObject> ResponseAction; |
| 139 | 139 |
| 140 // Runs the function and returns the action to take when the caller is ready | 140 // Runs the function and returns the action to take when the caller is ready |
| 141 // to respond. | 141 // to respond. |
| 142 // | 142 // |
| 143 // Typical return values might be: | 143 // Typical return values might be: |
| 144 // * RespondNow(NoArguments()) | 144 // * RespondNow(NoArguments()) |
| 145 // * RespondNow(OneArgument(42)) | 145 // * RespondNow(OneArgument(42)) |
| 146 // * RespondNow(ArgumentList(my_result.ToValue())) | 146 // * RespondNow(ArgumentList(my_result.ToValue())) |
| 147 // * RespondNow(Error("Warp core breach")) | 147 // * RespondNow(Error("Warp core breach")) |
| 148 // * RespondNow(Error("Warp core breach on *", GetURL())) |
| 148 // * RespondLater(), then later, | 149 // * RespondLater(), then later, |
| 149 // * Respond(NoArguments()) | 150 // * Respond(NoArguments()) |
| 150 // * ... etc. | 151 // * ... etc. |
| 151 // | 152 // |
| 152 // | 153 // |
| 153 // Callers must call Execute() on the return ResponseAction at some point, | 154 // Callers must call Execute() on the return ResponseAction at some point, |
| 154 // exactly once. | 155 // exactly once. |
| 155 // | 156 // |
| 156 // SyncExtensionFunction and AsyncExtensionFunction implement this in terms | 157 // SyncExtensionFunction and AsyncExtensionFunction implement this in terms |
| 157 // of SyncExtensionFunction::RunSync and AsyncExtensionFunction::RunAsync, | 158 // of SyncExtensionFunction::RunSync and AsyncExtensionFunction::RunAsync, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // the argument to this by hand. Note that use of this function may imply you | 258 // the argument to this by hand. Note that use of this function may imply you |
| 258 // should be using the generated Result struct and ArgumentList. | 259 // should be using the generated Result struct and ArgumentList. |
| 259 ResponseValue TwoArguments(base::Value* arg1, base::Value* arg2); | 260 ResponseValue TwoArguments(base::Value* arg1, base::Value* arg2); |
| 260 // Success, a list of arguments |results| to pass to caller. TAKES OWNERSHIP | 261 // Success, a list of arguments |results| to pass to caller. TAKES OWNERSHIP |
| 261 // -- | 262 // -- |
| 262 // a scoped_ptr<> for convenience, since callers usually get this from the | 263 // a scoped_ptr<> for convenience, since callers usually get this from the |
| 263 // result of a ToValue() call on the generated Result struct. | 264 // result of a ToValue() call on the generated Result struct. |
| 264 ResponseValue ArgumentList(scoped_ptr<base::ListValue> results); | 265 ResponseValue ArgumentList(scoped_ptr<base::ListValue> results); |
| 265 // Error. chrome.runtime.lastError.message will be set to |error|. | 266 // Error. chrome.runtime.lastError.message will be set to |error|. |
| 266 ResponseValue Error(const std::string& error); | 267 ResponseValue Error(const std::string& error); |
| 268 // Error with formatting. Args are processed using |
| 269 // ErrorUtils::FormatErrorMessage, that is, each occurence of * is replaced |
| 270 // by the corresponding |s*|: |
| 271 // Error("Error in *: *", "foo", "bar") <--> // Error("Error in foo: bar"). |
| 272 ResponseValue Error(const std::string& format, const std::string& s1); |
| 273 ResponseValue Error(const std::string& format, |
| 274 const std::string& s1, |
| 275 const std::string& s2); |
| 276 ResponseValue Error(const std::string& format, |
| 277 const std::string& s1, |
| 278 const std::string& s2, |
| 279 const std::string& s3); |
| 267 // Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE(). | 280 // Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE(). |
| 268 ResponseValue BadMessage(); | 281 ResponseValue BadMessage(); |
| 269 | 282 |
| 270 // ResponseActions. | 283 // ResponseActions. |
| 271 // | 284 // |
| 272 // Respond to the extension immediately with |result|. | 285 // Respond to the extension immediately with |result|. |
| 273 ResponseAction RespondNow(ResponseValue result); | 286 ResponseAction RespondNow(ResponseValue result); |
| 274 // Don't respond now, but promise to call Respond() later. | 287 // Don't respond now, but promise to call Respond() later. |
| 275 ResponseAction RespondLater(); | 288 ResponseAction RespondLater(); |
| 276 | 289 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 virtual bool RunSync() = 0; | 580 virtual bool RunSync() = 0; |
| 568 | 581 |
| 569 // ValidationFailure override to match RunSync(). | 582 // ValidationFailure override to match RunSync(). |
| 570 static bool ValidationFailure(SyncIOThreadExtensionFunction* function); | 583 static bool ValidationFailure(SyncIOThreadExtensionFunction* function); |
| 571 | 584 |
| 572 private: | 585 private: |
| 573 virtual ResponseAction Run() OVERRIDE; | 586 virtual ResponseAction Run() OVERRIDE; |
| 574 }; | 587 }; |
| 575 | 588 |
| 576 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ | 589 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ |
| OLD | NEW |