| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Defines AutomationExtensionFunction. | |
| 6 | |
| 7 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ | |
| 8 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ | |
| 9 #pragma once | |
| 10 | |
| 11 #include <map> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "chrome/browser/extensions/extension_function.h" | |
| 16 | |
| 17 class RenderViewHost; | |
| 18 class TabContents; | |
| 19 | |
| 20 // An extension function that pipes the extension API call through the | |
| 21 // automation interface, so that extensions can be tested using UITests. | |
| 22 class AutomationExtensionFunction : public AsyncExtensionFunction { | |
| 23 public: | |
| 24 AutomationExtensionFunction(); | |
| 25 | |
| 26 // ExtensionFunction implementation. | |
| 27 virtual void SetArgs(const ListValue* args); | |
| 28 virtual const std::string GetResult(); | |
| 29 virtual bool RunImpl(); | |
| 30 | |
| 31 static ExtensionFunction* Factory(); | |
| 32 | |
| 33 // Enable API automation of selected APIs. Overridden extension API messages | |
| 34 // will be routed to the automation client attached to |api_handler_tab|. | |
| 35 // | |
| 36 // If the list of enabled functions is non-empty, we enable according to the | |
| 37 // list ("*" means enable all, otherwise we enable individual named | |
| 38 // functions). An empty list makes this function a no-op. | |
| 39 // | |
| 40 // Note that all calls to this function are additive. Functions previously | |
| 41 // enabled will remain enabled until you call Disable(). | |
| 42 // | |
| 43 // Calling this function after enabling one or more functions with a | |
| 44 // tab other than the one previously used is an error. | |
| 45 static void Enable(TabContents* api_handler_tab, | |
| 46 const std::vector<std::string>& functions_enabled); | |
| 47 | |
| 48 // Restore the default API function implementations and reset the stored | |
| 49 // API handler. | |
| 50 static void Disable(); | |
| 51 | |
| 52 // Intercepts messages sent from the external host to check if they | |
| 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 | |
| 55 // true, otherwise returns false to indicate the message was not intercepted. | |
| 56 static bool InterceptMessageFromExternalHost(RenderViewHost* view_host, | |
| 57 const std::string& message, | |
| 58 const std::string& origin, | |
| 59 const std::string& target); | |
| 60 | |
| 61 private: | |
| 62 ~AutomationExtensionFunction(); | |
| 63 | |
| 64 // Weak reference, lifetime managed by the ExternalTabContainer instance | |
| 65 // owning the TabContents in question. | |
| 66 static TabContents* api_handler_tab_; | |
| 67 | |
| 68 typedef std::map<int, scoped_refptr<AutomationExtensionFunction> > | |
| 69 PendingFunctionsMap; | |
| 70 static PendingFunctionsMap pending_functions_; | |
| 71 | |
| 72 std::string args_; | |
| 73 std::string json_result_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(AutomationExtensionFunction); | |
| 76 }; | |
| 77 | |
| 78 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ | |
| OLD | NEW |