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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 return source_process_id_; | 288 return source_process_id_; |
289 } | 289 } |
290 | 290 |
291 protected: | 291 protected: |
292 friend struct ExtensionFunctionDeleteTraits; | 292 friend struct ExtensionFunctionDeleteTraits; |
293 | 293 |
294 // ResponseValues. | 294 // ResponseValues. |
295 // | 295 // |
296 // Success, no arguments to pass to caller. | 296 // Success, no arguments to pass to caller. |
297 ResponseValue NoArguments(); | 297 ResponseValue NoArguments(); |
| 298 // Success, a single argument |arg| to pass to caller. TAKES OWNERSHIP - a |
| 299 // raw pointer for convenience, since callers usually construct the argument |
| 300 // to this by hand. |
| 301 ResponseValue OneArgument(base::Value* arg); |
298 // Success, a single argument |arg| to pass to caller. | 302 // Success, a single argument |arg| to pass to caller. |
299 ResponseValue OneArgument(std::unique_ptr<base::Value> arg); | 303 ResponseValue OneArgument(std::unique_ptr<base::Value> arg); |
300 // Success, two arguments |arg1| and |arg2| to pass to caller. | 304 // Success, two arguments |arg1| and |arg2| to pass to caller. TAKES |
301 // Note that use of this function may imply you | 305 // OWNERSHIP - raw pointers for convenience, since callers usually construct |
| 306 // the argument to this by hand. Note that use of this function may imply you |
302 // should be using the generated Result struct and ArgumentList. | 307 // should be using the generated Result struct and ArgumentList. |
303 ResponseValue TwoArguments(std::unique_ptr<base::Value> arg1, | 308 ResponseValue TwoArguments(base::Value* arg1, base::Value* arg2); |
304 std::unique_ptr<base::Value> arg2); | 309 // Success, a list of arguments |results| to pass to caller. TAKES OWNERSHIP |
305 // Success, a list of arguments |results| to pass to caller. | |
306 // - a std::unique_ptr<> for convenience, since callers usually get this from | 310 // - a std::unique_ptr<> for convenience, since callers usually get this from |
307 // the result of a Create(...) call on the generated Results struct. For | 311 // the |
308 // example, alarms::Get::Results::Create(alarm). | 312 // result of a Create(...) call on the generated Results struct, for example, |
| 313 // alarms::Get::Results::Create(alarm). |
309 ResponseValue ArgumentList(std::unique_ptr<base::ListValue> results); | 314 ResponseValue ArgumentList(std::unique_ptr<base::ListValue> results); |
310 // Error. chrome.runtime.lastError.message will be set to |error|. | 315 // Error. chrome.runtime.lastError.message will be set to |error|. |
311 ResponseValue Error(const std::string& error); | 316 ResponseValue Error(const std::string& error); |
312 // Error with formatting. Args are processed using | 317 // Error with formatting. Args are processed using |
313 // ErrorUtils::FormatErrorMessage, that is, each occurence of * is replaced | 318 // ErrorUtils::FormatErrorMessage, that is, each occurence of * is replaced |
314 // by the corresponding |s*|: | 319 // by the corresponding |s*|: |
315 // Error("Error in *: *", "foo", "bar") <--> Error("Error in foo: bar"). | 320 // Error("Error in *: *", "foo", "bar") <--> Error("Error in foo: bar"). |
316 ResponseValue Error(const std::string& format, const std::string& s1); | 321 ResponseValue Error(const std::string& format, const std::string& s1); |
317 ResponseValue Error(const std::string& format, | 322 ResponseValue Error(const std::string& format, |
318 const std::string& s1, | 323 const std::string& s1, |
319 const std::string& s2); | 324 const std::string& s2); |
320 ResponseValue Error(const std::string& format, | 325 ResponseValue Error(const std::string& format, |
321 const std::string& s1, | 326 const std::string& s1, |
322 const std::string& s2, | 327 const std::string& s2, |
323 const std::string& s3); | 328 const std::string& s3); |
324 // Error with a list of arguments |args| to pass to caller. | 329 // Error with a list of arguments |args| to pass to caller. TAKES OWNERSHIP. |
325 // Using this ResponseValue indicates something is wrong with the API. | 330 // Using this ResponseValue indicates something is wrong with the API. |
326 // It shouldn't be possible to have both an error *and* some arguments. | 331 // It shouldn't be possible to have both an error *and* some arguments. |
327 // Some legacy APIs do rely on it though, like webstorePrivate. | 332 // Some legacy APIs do rely on it though, like webstorePrivate. |
328 ResponseValue ErrorWithArguments(std::unique_ptr<base::ListValue> args, | 333 ResponseValue ErrorWithArguments(std::unique_ptr<base::ListValue> args, |
329 const std::string& error); | 334 const std::string& error); |
330 // Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE(), | 335 // Bad message. A ResponseValue equivalent to EXTENSION_FUNCTION_VALIDATE(), |
331 // so this will actually kill the renderer and not respond at all. | 336 // so this will actually kill the renderer and not respond at all. |
332 ResponseValue BadMessage(); | 337 ResponseValue BadMessage(); |
333 | 338 |
334 // ResponseActions. | 339 // ResponseActions. |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 private: | 682 private: |
678 // If you're hitting a compile error here due to "final" - great! You're | 683 // If you're hitting a compile error here due to "final" - great! You're |
679 // doing the right thing, you just need to extend IOThreadExtensionFunction | 684 // doing the right thing, you just need to extend IOThreadExtensionFunction |
680 // instead of SyncIOExtensionFunction. | 685 // instead of SyncIOExtensionFunction. |
681 ResponseAction Run() final; | 686 ResponseAction Run() final; |
682 | 687 |
683 DISALLOW_COPY_AND_ASSIGN(SyncIOThreadExtensionFunction); | 688 DISALLOW_COPY_AND_ASSIGN(SyncIOThreadExtensionFunction); |
684 }; | 689 }; |
685 | 690 |
686 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ | 691 #endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_H_ |
OLD | NEW |