| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // Defines AutomationExtensionFunction. | 5 // Defines AutomationExtensionFunction. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ | 7 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ |
| 8 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ | 8 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "chrome/browser/extensions/extension_function.h" | 15 #include "chrome/browser/extensions/extension_function.h" |
| 16 | 16 |
| 17 class RenderViewHost; | 17 class RenderViewHost; |
| 18 class TabContents; | 18 class TabContents; |
| 19 | 19 |
| 20 // An extension function that pipes the extension API call through the | 20 // An extension function that pipes the extension API call through the |
| 21 // automation interface, so that extensions can be tested using UITests. | 21 // automation interface, so that extensions can be tested using UITests. |
| 22 class AutomationExtensionFunction : public AsyncExtensionFunction { | 22 class AutomationExtensionFunction : public AsyncExtensionFunction { |
| 23 public: | 23 public: |
| 24 AutomationExtensionFunction() { } | 24 AutomationExtensionFunction(); |
| 25 | 25 |
| 26 // ExtensionFunction implementation. | 26 // ExtensionFunction implementation. |
| 27 virtual void SetArgs(const ListValue* args); | 27 virtual void SetArgs(const ListValue* args); |
| 28 virtual const std::string GetResult(); | 28 virtual const std::string GetResult(); |
| 29 virtual bool RunImpl(); | 29 virtual bool RunImpl(); |
| 30 | 30 |
| 31 static ExtensionFunction* Factory(); | 31 static ExtensionFunction* Factory(); |
| 32 | 32 |
| 33 // Enable API automation of selected APIs. Overridden extension API messages | 33 // Enable API automation of selected APIs. Overridden extension API messages |
| 34 // will be routed to the automation client attached to |api_handler_tab|. | 34 // will be routed to the automation client attached to |api_handler_tab|. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 52 // Intercepts messages sent from the external host to check if they | 52 // Intercepts messages sent from the external host to check if they |
| 53 // are actually responses to extension API calls. If they are, redirects | 53 // are actually responses to extension API calls. If they are, redirects |
| 54 // the message to respond to the pending asynchronous API call and returns | 54 // the message to respond to the pending asynchronous API call and returns |
| 55 // true, otherwise returns false to indicate the message was not intercepted. | 55 // true, otherwise returns false to indicate the message was not intercepted. |
| 56 static bool InterceptMessageFromExternalHost(RenderViewHost* view_host, | 56 static bool InterceptMessageFromExternalHost(RenderViewHost* view_host, |
| 57 const std::string& message, | 57 const std::string& message, |
| 58 const std::string& origin, | 58 const std::string& origin, |
| 59 const std::string& target); | 59 const std::string& target); |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 ~AutomationExtensionFunction() {} | 62 ~AutomationExtensionFunction(); |
| 63 | 63 |
| 64 // Weak reference, lifetime managed by the ExternalTabContainer instance | 64 // Weak reference, lifetime managed by the ExternalTabContainer instance |
| 65 // owning the TabContents in question. | 65 // owning the TabContents in question. |
| 66 static TabContents* api_handler_tab_; | 66 static TabContents* api_handler_tab_; |
| 67 | 67 |
| 68 typedef std::map<int, scoped_refptr<AutomationExtensionFunction> > | 68 typedef std::map<int, scoped_refptr<AutomationExtensionFunction> > |
| 69 PendingFunctionsMap; | 69 PendingFunctionsMap; |
| 70 static PendingFunctionsMap pending_functions_; | 70 static PendingFunctionsMap pending_functions_; |
| 71 | 71 |
| 72 std::string args_; | 72 std::string args_; |
| 73 std::string json_result_; | 73 std::string json_result_; |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(AutomationExtensionFunction); | 75 DISALLOW_COPY_AND_ASSIGN(AutomationExtensionFunction); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ | 78 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ |
| OLD | NEW |