Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Side by Side Diff: chrome/browser/automation/automation_extension_function.h

Issue 366025: Modifying extension automation so that it is done through a particular... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/automation/automation_extension_function.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
10 #include <string> 10 #include <string>
11 #include <map>
11 12
12 #include "chrome/browser/extensions/extension_function.h" 13 #include "chrome/browser/extensions/extension_function.h"
13 14
14 class RenderViewHost; 15 class RenderViewHost;
16 class TabContents;
15 17
16 // An extension function that pipes the extension API call through the 18 // An extension function that pipes the extension API call through the
17 // automation interface, so that extensions can be tested using UITests. 19 // automation interface, so that extensions can be tested using UITests.
18 class AutomationExtensionFunction : public ExtensionFunction { 20 class AutomationExtensionFunction : public AsyncExtensionFunction {
19 public: 21 public:
20 AutomationExtensionFunction() { } 22 AutomationExtensionFunction() { }
21 23
22 // ExtensionFunction implementation. 24 // ExtensionFunction implementation.
23 virtual void SetArgs(const Value* args); 25 virtual void SetArgs(const Value* args);
24 virtual const std::string GetResult(); 26 virtual const std::string GetResult();
25 virtual const std::string GetError(); 27 virtual bool RunImpl();
26 virtual void Run();
27 28
28 static ExtensionFunction* Factory(); 29 static ExtensionFunction* Factory();
29 30
31 // Enable API automation of selected APIs. Overridden extension API messages
32 // will be routed to the automation client attached to |api_handler_tab|.
33 //
30 // If the list of enabled functions is non-empty, we enable according to the 34 // If the list of enabled functions is non-empty, we enable according to the
31 // list ("*" means enable all, otherwise we enable individual named 35 // list ("*" means enable all, otherwise we enable individual named
32 // functions). If empty, we restore the initial functions. 36 // functions). An empty list makes this function a no-op.
33 // 37 //
34 // Note that all calls to this function, except a call with the empty list, 38 // Note that all calls to this function are additive. Functions previously
35 // are additive. Functions previously enabled will remain enabled until 39 // enabled will remain enabled until you call Disable().
36 // you clear all function forwarding by specifying the empty list. 40 //
37 static void SetEnabled(const std::vector<std::string>& functions_enabled); 41 // Calling this function after enabling one or more functions with a
42 // tab other than the one previously used is an error.
43 static void Enable(TabContents* api_handler_tab,
44 const std::vector<std::string>& functions_enabled);
45
46 // Restore the default API function implementations and reset the stored
47 // API handler.
48 static void Disable();
38 49
39 // Intercepts messages sent from the external host to check if they 50 // Intercepts messages sent from the external host to check if they
40 // are actually responses to extension API calls. If they are, redirects 51 // are actually responses to extension API calls. If they are, redirects
41 // the message to view_host->SendExtensionResponse and returns true, 52 // the message to respond to the pending asynchronous API call and returns
42 // otherwise returns false to indicate the message was not intercepted. 53 // true, otherwise returns false to indicate the message was not intercepted.
43 static bool InterceptMessageFromExternalHost(RenderViewHost* view_host, 54 static bool InterceptMessageFromExternalHost(RenderViewHost* view_host,
44 const std::string& message, 55 const std::string& message,
45 const std::string& origin, 56 const std::string& origin,
46 const std::string& target); 57 const std::string& target);
47 58
48 private: 59 private:
49 ~AutomationExtensionFunction() {} 60 ~AutomationExtensionFunction() {}
50 61
51 static bool enabled_; 62 // Weak reference, lifetime managed by the ExternalTabContainer instance
63 // owning the TabContents in question.
64 static TabContents* api_handler_tab_;
65
66 typedef std::map<int, scoped_refptr<AutomationExtensionFunction> >
67 PendingFunctionsMap;
68 static PendingFunctionsMap pending_functions_;
69
52 std::string args_; 70 std::string args_;
71 std::string json_result_;
72
53 DISALLOW_COPY_AND_ASSIGN(AutomationExtensionFunction); 73 DISALLOW_COPY_AND_ASSIGN(AutomationExtensionFunction);
54 }; 74 };
55 75
56 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_ 76 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/automation/automation_extension_function.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698