OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Support utilities for the JSON automation interface used by PyAuto. | 5 // Support utilities for the JSON automation interface used by PyAuto. |
6 | 6 |
7 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_ | 7 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_ |
8 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_ | 8 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
| 13 class AutomationProvider; |
| 14 class Browser; |
| 15 class DictionaryValue; |
| 16 class TabContents; |
13 class Value; | 17 class Value; |
14 class AutomationProvider; | |
15 | 18 |
16 namespace IPC { | 19 namespace IPC { |
17 class Message; | 20 class Message; |
18 } | 21 } |
19 | 22 |
20 // Helper to ensure we always send a reply message for JSON automation requests. | 23 // Helper to ensure we always send a reply message for JSON automation requests. |
21 class AutomationJSONReply { | 24 class AutomationJSONReply { |
22 public: | 25 public: |
23 // Creates a new reply object for the IPC message |reply_message| for | 26 // Creates a new reply object for the IPC message |reply_message| for |
24 // |provider|. The caller is expected to call SendSuccess() or SendError() | 27 // |provider|. The caller is expected to call SendSuccess() or SendError() |
25 // before destroying this object. | 28 // before destroying this object. |
26 AutomationJSONReply(AutomationProvider* provider, | 29 AutomationJSONReply(AutomationProvider* provider, |
27 IPC::Message* reply_message); | 30 IPC::Message* reply_message); |
28 | 31 |
29 ~AutomationJSONReply(); | 32 ~AutomationJSONReply(); |
30 | 33 |
31 // Send a success reply along with data contained in |value|. | 34 // Send a success reply along with data contained in |value|. |
32 // An empty message will be sent if |value| is NULL. | 35 // An empty message will be sent if |value| is NULL. |
33 void SendSuccess(const Value* value); | 36 void SendSuccess(const Value* value); |
34 | 37 |
35 // Send an error reply along with error message |error_message|. | 38 // Send an error reply along with error message |error_message|. |
36 void SendError(const std::string& error_message); | 39 void SendError(const std::string& error_message); |
37 | 40 |
38 private: | 41 private: |
39 AutomationProvider* provider_; | 42 AutomationProvider* provider_; |
40 IPC::Message* message_; | 43 IPC::Message* message_; |
41 }; | 44 }; |
42 | 45 |
| 46 // Gets the browser specified by the given dictionary |args|. 'windex' should |
| 47 // refer to the index of the browser. Returns true on success and sets |
| 48 // |browser|. Otherwise, |error| will be set. |
| 49 bool GetBrowserFromJSONArgs(DictionaryValue* args, |
| 50 Browser** browser, |
| 51 std::string* error); |
| 52 |
| 53 // Gets the tab specified by the given dictionary |args|. 'windex' should |
| 54 // refer to the index of the parent browser, and 'tab_index' should refer |
| 55 // to the index of the tab in that browser. Returns true on success and sets |
| 56 // |tab|. Otherwise, |error| will be set. |
| 57 bool GetTabFromJSONArgs(DictionaryValue* args, |
| 58 TabContents** tab, |
| 59 std::string* error); |
| 60 |
| 61 // Gets the browser and tab specified by the given dictionary |args|. 'windex' |
| 62 // should refer to the index of the browser, and 'tab_index' should refer |
| 63 // to the index of the tab in that browser. Returns true on success and sets |
| 64 // |browser| and |tab|. Otherwise, |error| will be set. |
| 65 bool GetBrowserAndTabFromJSONArgs(DictionaryValue* args, |
| 66 Browser** browser, |
| 67 TabContents** tab, |
| 68 std::string* error); |
| 69 |
43 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_ | 70 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_ |
OLD | NEW |