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