| 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 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/process/process.h" | 16 #include "base/process/process.h" |
| 17 #include "base/sequenced_task_runner_helpers.h" | 17 #include "base/sequenced_task_runner_helpers.h" |
| 18 #include "chrome/browser/extensions/extension_function_histogram_value.h" | 18 #include "chrome/browser/extensions/extension_function_histogram_value.h" |
| 19 #include "chrome/browser/extensions/extension_info_map.h" | |
| 20 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/common/console_message_level.h" | 21 #include "content/public/common/console_message_level.h" |
| 22 #include "extensions/browser/info_map.h" |
| 23 #include "ipc/ipc_message.h" | 23 #include "ipc/ipc_message.h" |
| 24 | 24 |
| 25 class ChromeRenderMessageFilter; | 25 class ChromeRenderMessageFilter; |
| 26 class ExtensionFunction; | 26 class ExtensionFunction; |
| 27 class ExtensionFunctionDispatcher; | 27 class ExtensionFunctionDispatcher; |
| 28 class UIThreadExtensionFunction; | 28 class UIThreadExtensionFunction; |
| 29 class IOThreadExtensionFunction; | 29 class IOThreadExtensionFunction; |
| 30 class QuotaLimitHeuristic; | |
| 31 | 30 |
| 32 namespace base { | 31 namespace base { |
| 33 class ListValue; | 32 class ListValue; |
| 34 class Value; | 33 class Value; |
| 35 } | 34 } |
| 36 | 35 |
| 37 namespace content { | 36 namespace content { |
| 38 class BrowserContext; | 37 class BrowserContext; |
| 39 class RenderViewHost; | 38 class RenderViewHost; |
| 40 class WebContents; | 39 class WebContents; |
| 41 } | 40 } |
| 42 | 41 |
| 42 namespace extensions { |
| 43 class QuotaLimitHeuristic; |
| 44 } |
| 45 |
| 43 #ifdef NDEBUG | 46 #ifdef NDEBUG |
| 44 #define EXTENSION_FUNCTION_VALIDATE(test) do { \ | 47 #define EXTENSION_FUNCTION_VALIDATE(test) do { \ |
| 45 if (!(test)) { \ | 48 if (!(test)) { \ |
| 46 bad_message_ = true; \ | 49 bad_message_ = true; \ |
| 47 return false; \ | 50 return false; \ |
| 48 } \ | 51 } \ |
| 49 } while (0) | 52 } while (0) |
| 50 #else // NDEBUG | 53 #else // NDEBUG |
| 51 #define EXTENSION_FUNCTION_VALIDATE(test) CHECK(test) | 54 #define EXTENSION_FUNCTION_VALIDATE(test) CHECK(test) |
| 52 #endif // NDEBUG | 55 #endif // NDEBUG |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // invoked once and then cached. | 123 // invoked once and then cached. |
| 121 // | 124 // |
| 122 // Returns false by default. | 125 // Returns false by default. |
| 123 virtual bool ShouldSkipQuotaLimiting() const; | 126 virtual bool ShouldSkipQuotaLimiting() const; |
| 124 | 127 |
| 125 // Optionally adds one or multiple QuotaLimitHeuristic instances suitable for | 128 // Optionally adds one or multiple QuotaLimitHeuristic instances suitable for |
| 126 // this function to |heuristics|. The ownership of the new QuotaLimitHeuristic | 129 // this function to |heuristics|. The ownership of the new QuotaLimitHeuristic |
| 127 // instances is passed to the owner of |heuristics|. | 130 // instances is passed to the owner of |heuristics|. |
| 128 // No quota limiting by default. | 131 // No quota limiting by default. |
| 129 // | 132 // |
| 130 // Only called once per lifetime of the ExtensionsQuotaService. | 133 // Only called once per lifetime of the QuotaService. |
| 131 virtual void GetQuotaLimitHeuristics( | 134 virtual void GetQuotaLimitHeuristics( |
| 132 QuotaLimitHeuristics* heuristics) const {} | 135 extensions::QuotaLimitHeuristics* heuristics) const {} |
| 133 | 136 |
| 134 // Called when the quota limit has been exceeded. The default implementation | 137 // Called when the quota limit has been exceeded. The default implementation |
| 135 // returns an error. | 138 // returns an error. |
| 136 virtual void OnQuotaExceeded(const std::string& violation_error); | 139 virtual void OnQuotaExceeded(const std::string& violation_error); |
| 137 | 140 |
| 138 // Specifies the raw arguments to the function, as a JSON value. | 141 // Specifies the raw arguments to the function, as a JSON value. |
| 139 virtual void SetArgs(const base::ListValue* args); | 142 virtual void SetArgs(const base::ListValue* args); |
| 140 | 143 |
| 141 // Sets a single Value as the results of the function. | 144 // Sets a single Value as the results of the function. |
| 142 void SetResult(base::Value* result); | 145 void SetResult(base::Value* result); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 ipc_sender_ = ipc_sender; | 363 ipc_sender_ = ipc_sender; |
| 361 routing_id_ = routing_id; | 364 routing_id_ = routing_id; |
| 362 } | 365 } |
| 363 | 366 |
| 364 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_weak() const { | 367 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_weak() const { |
| 365 return ipc_sender_; | 368 return ipc_sender_; |
| 366 } | 369 } |
| 367 | 370 |
| 368 int routing_id() const { return routing_id_; } | 371 int routing_id() const { return routing_id_; } |
| 369 | 372 |
| 370 void set_extension_info_map(const ExtensionInfoMap* extension_info_map) { | 373 void set_extension_info_map(const extensions::InfoMap* extension_info_map) { |
| 371 extension_info_map_ = extension_info_map; | 374 extension_info_map_ = extension_info_map; |
| 372 } | 375 } |
| 373 const ExtensionInfoMap* extension_info_map() const { | 376 const extensions::InfoMap* extension_info_map() const { |
| 374 return extension_info_map_.get(); | 377 return extension_info_map_.get(); |
| 375 } | 378 } |
| 376 | 379 |
| 377 protected: | 380 protected: |
| 378 friend struct content::BrowserThread::DeleteOnThread< | 381 friend struct content::BrowserThread::DeleteOnThread< |
| 379 content::BrowserThread::IO>; | 382 content::BrowserThread::IO>; |
| 380 friend class base::DeleteHelper<IOThreadExtensionFunction>; | 383 friend class base::DeleteHelper<IOThreadExtensionFunction>; |
| 381 | 384 |
| 382 virtual ~IOThreadExtensionFunction(); | 385 virtual ~IOThreadExtensionFunction(); |
| 383 | 386 |
| 384 virtual void Destruct() const OVERRIDE; | 387 virtual void Destruct() const OVERRIDE; |
| 385 | 388 |
| 386 virtual void SendResponse(bool success) OVERRIDE; | 389 virtual void SendResponse(bool success) OVERRIDE; |
| 387 | 390 |
| 388 private: | 391 private: |
| 389 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_; | 392 base::WeakPtr<ChromeRenderMessageFilter> ipc_sender_; |
| 390 int routing_id_; | 393 int routing_id_; |
| 391 | 394 |
| 392 scoped_refptr<const ExtensionInfoMap> extension_info_map_; | 395 scoped_refptr<const extensions::InfoMap> extension_info_map_; |
| 393 }; | 396 }; |
| 394 | 397 |
| 395 // Base class for an extension function that runs asynchronously *relative to | 398 // Base class for an extension function that runs asynchronously *relative to |
| 396 // the browser's UI thread*. | 399 // the browser's UI thread*. |
| 397 class AsyncExtensionFunction : public UIThreadExtensionFunction { | 400 class AsyncExtensionFunction : public UIThreadExtensionFunction { |
| 398 public: | 401 public: |
| 399 AsyncExtensionFunction(); | 402 AsyncExtensionFunction(); |
| 400 | 403 |
| 401 protected: | 404 protected: |
| 402 virtual ~AsyncExtensionFunction(); | 405 virtual ~AsyncExtensionFunction(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 423 public: | 426 public: |
| 424 SyncIOThreadExtensionFunction(); | 427 SyncIOThreadExtensionFunction(); |
| 425 | 428 |
| 426 virtual void Run() OVERRIDE; | 429 virtual void Run() OVERRIDE; |
| 427 | 430 |
| 428 protected: | 431 protected: |
| 429 virtual ~SyncIOThreadExtensionFunction(); | 432 virtual ~SyncIOThreadExtensionFunction(); |
| 430 }; | 433 }; |
| 431 | 434 |
| 432 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 435 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| OLD | NEW |