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