Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 } | 37 } |
| 38 | 38 |
| 39 namespace content { | 39 namespace content { |
| 40 class RenderViewHost; | 40 class RenderViewHost; |
| 41 } | 41 } |
| 42 | 42 |
| 43 namespace extensions { | 43 namespace extensions { |
| 44 class WindowController; | 44 class WindowController; |
| 45 } | 45 } |
| 46 | 46 |
| 47 #ifdef NDEBUG | |
| 47 #define EXTENSION_FUNCTION_VALIDATE(test) do { \ | 48 #define EXTENSION_FUNCTION_VALIDATE(test) do { \ |
| 48 if (!(test)) { \ | 49 if (!(test)) { \ |
| 49 bad_message_ = true; \ | 50 bad_message_ = true; \ |
| 50 return false; \ | 51 return false; \ |
| 51 } \ | 52 } \ |
| 52 } while (0) | 53 } while (0) |
| 54 #else // NDEBUG | |
| 55 #define EXTENSION_FUNCTION_VALIDATE(test) CHECK(test) | |
| 56 #endif // NDEBUG | |
| 53 | 57 |
| 54 #define EXTENSION_FUNCTION_ERROR(error) do { \ | 58 #define EXTENSION_FUNCTION_ERROR(error) do { \ |
| 55 error_ = error; \ | 59 error_ = error; \ |
| 56 bad_message_ = true; \ | 60 bad_message_ = true; \ |
| 57 return false; \ | 61 return false; \ |
| 58 } while (0) | 62 } while (0) |
| 59 | 63 |
| 60 #define DECLARE_EXTENSION_FUNCTION_NAME(name) \ | 64 #define DECLARE_EXTENSION_FUNCTION_NAME(name) \ |
| 61 public: static const char* function_name() { return name; } | 65 public: static const char* function_name() { return name; } |
| 62 | 66 |
| 63 // Traits that describe how ExtensionFunction should be deleted. This just calls | 67 // Traits that describe how ExtensionFunction should be deleted. This just calls |
| 64 // the virtual "Destruct" method on ExtensionFunction, allowing derived classes | 68 // the virtual "Destruct" method on ExtensionFunction, allowing derived classes |
| 65 // to override the behavior. | 69 // to override the behavior. |
| 66 struct ExtensionFunctionDeleteTraits { | 70 struct ExtensionFunctionDeleteTraits { |
| 67 public: | 71 public: |
| 68 static void Destruct(const ExtensionFunction* x); | 72 static void Destruct(const ExtensionFunction* x); |
| 69 }; | 73 }; |
| 70 | 74 |
| 71 // Abstract base class for extension functions the ExtensionFunctionDispatcher | 75 // Abstract base class for extension functions the ExtensionFunctionDispatcher |
| 72 // knows how to dispatch to. | 76 // knows how to dispatch to. |
| 73 class ExtensionFunction | 77 class ExtensionFunction |
| 74 : public base::RefCountedThreadSafe<ExtensionFunction, | 78 : public base::RefCountedThreadSafe<ExtensionFunction, |
| 75 ExtensionFunctionDeleteTraits> { | 79 ExtensionFunctionDeleteTraits> { |
| 76 public: | 80 public: |
| 77 ExtensionFunction(); | 81 ExtensionFunction(); |
| 78 | 82 |
| 79 virtual UIThreadExtensionFunction* AsUIThreadExtensionFunction(); | 83 virtual UIThreadExtensionFunction* AsUIThreadExtensionFunction(); |
| 80 virtual IOThreadExtensionFunction* AsIOThreadExtensionFunction(); | 84 virtual IOThreadExtensionFunction* AsIOThreadExtensionFunction(); |
| 81 | 85 |
| 86 // Returns true if the function permission to run. | |
|
Aaron Boodman
2012/07/31 14:53:43
^has
not at google - send to devlin
2012/07/31 15:09:05
Done.
| |
| 87 // | |
| 88 // The default implementation is to check the Extension's permissions against | |
| 89 // what this function requires to run, but some APIs may require finer | |
| 90 // grained control, such as tabs.executeScript being allowed for active tabs. | |
| 91 // | |
| 92 // This will be run after the function has been set up but before Run(). | |
| 93 virtual bool HasPermission(); | |
|
Aaron Boodman
2012/07/31 14:53:43
Neat.
| |
| 94 | |
| 82 // Execute the API. Clients should initialize the ExtensionFunction using | 95 // Execute the API. Clients should initialize the ExtensionFunction using |
| 83 // SetArgs(), set_request_id(), and the other setters before calling this | 96 // SetArgs(), set_request_id(), and the other setters before calling this |
| 84 // method. Derived classes should be ready to return GetResultList() and | 97 // method. Derived classes should be ready to return GetResultList() and |
| 85 // GetError() before returning from this function. | 98 // GetError() before returning from this function. |
| 86 // Note that once Run() returns, dispatcher() can be NULL, so be sure to | 99 // Note that once Run() returns, dispatcher() can be NULL, so be sure to |
| 87 // NULL-check. | 100 // NULL-check. |
| 88 virtual void Run(); | 101 virtual void Run(); |
| 89 | 102 |
| 90 // Gets whether quota should be applied to this individual function | 103 // Gets whether quota should be applied to this individual function |
| 91 // invocation. This is different to GetQuotaLimitHeuristics which is only | 104 // invocation. This is different to GetQuotaLimitHeuristics which is only |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 public: | 443 public: |
| 431 SyncIOThreadExtensionFunction(); | 444 SyncIOThreadExtensionFunction(); |
| 432 | 445 |
| 433 virtual void Run() OVERRIDE; | 446 virtual void Run() OVERRIDE; |
| 434 | 447 |
| 435 protected: | 448 protected: |
| 436 virtual ~SyncIOThreadExtensionFunction(); | 449 virtual ~SyncIOThreadExtensionFunction(); |
| 437 }; | 450 }; |
| 438 | 451 |
| 439 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 452 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| OLD | NEW |