Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / automation / automation_provider_json.h
blob428fa4dc1aef518fae29c0413ae9257aa82ca8d0
1 // Copyright (c) 2012 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.
5 // Support utilities for the JSON automation interface used by PyAuto.
7 #ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_
8 #define CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_
10 #include <string>
12 #include "base/compiler_specific.h"
13 #include "chrome/common/automation_constants.h"
15 class AutomationProvider;
16 class Browser;
17 class Profile;
19 namespace base {
20 class DictionaryValue;
21 class Value;
24 namespace content {
25 class RenderViewHost;
26 class WebContents;
29 namespace extensions {
30 class Extension;
33 namespace IPC {
34 class Message;
37 // Helper to ensure we always send a reply message for JSON automation requests.
38 class AutomationJSONReply {
39 public:
40 // Creates a new reply object for the IPC message |reply_message| for
41 // |provider|. The caller is expected to call SendSuccess() or SendError()
42 // before destroying this object.
43 AutomationJSONReply(AutomationProvider* provider,
44 IPC::Message* reply_message);
46 ~AutomationJSONReply();
48 // Send a success reply along with data contained in |value|.
49 // An empty message will be sent if |value| is NULL.
50 void SendSuccess(const base::Value* value);
52 // Send an error reply along with error message |error_message|.
53 void SendError(const std::string& error_message);
55 private:
56 AutomationProvider* provider_;
57 IPC::Message* message_;
60 // Gets the browser specified by the given dictionary |args|. |args| should
61 // contain a key 'windex' which refers to the index of the browser. Returns
62 // true on success and sets |browser|. Otherwise, |error| will be set.
63 bool GetBrowserFromJSONArgs(base::DictionaryValue* args,
64 Browser** browser,
65 std::string* error) WARN_UNUSED_RESULT;
67 // Gets the tab specified by the given dictionary |args|. |args| should
68 // contain a key 'windex' which refers to the index of the parent browser,
69 // and a key 'tab_index' which refers to the index of the tab in that browser.
70 // Returns true on success and sets |tab|. Otherwise, |error| will be set.
71 bool GetTabFromJSONArgs(base::DictionaryValue* args,
72 content::WebContents** tab,
73 std::string* error) WARN_UNUSED_RESULT;
75 // Gets the browser and tab specified by the given dictionary |args|. |args|
76 // should contain a key 'windex' which refers to the index of the browser and
77 // a key 'tab_index' which refers to the index of the tab in that browser.
78 // Returns true on success and sets |browser| and |tab|. Otherwise, |error|
79 // will be set.
80 bool GetBrowserAndTabFromJSONArgs(base::DictionaryValue* args,
81 Browser** browser,
82 content::WebContents** tab,
83 std::string* error) WARN_UNUSED_RESULT;
85 // Gets the render view specified by the given dictionary |args|. |args|
86 // should contain a key 'view_id' which refers to an automation ID for the
87 // render view. Returns true on success and sets |rvh|. Otherwise, |error|
88 // will be set.
89 bool GetRenderViewFromJSONArgs(
90 base::DictionaryValue* args,
91 Profile* profile,
92 content::RenderViewHost** rvh,
93 std::string* error) WARN_UNUSED_RESULT;
95 // Gets the extension specified by the given dictionary |args|. |args|
96 // should contain the given key which refers to an extension ID. Returns
97 // true on success and sets |extension|. Otherwise, |error| will be set.
98 // The retrieved extension may be disabled or crashed.
99 bool GetExtensionFromJSONArgs(
100 base::DictionaryValue* args,
101 const std::string& key,
102 Profile* profile,
103 const extensions::Extension** extension,
104 std::string* error) WARN_UNUSED_RESULT;
106 // Gets the enabled extension specified by the given dictionary |args|. |args|
107 // should contain the given key which refers to an extension ID. Returns
108 // true on success and sets |extension|. Otherwise, |error| will be set.
109 // The retrieved extension will not be disabled or crashed.
110 bool GetEnabledExtensionFromJSONArgs(
111 base::DictionaryValue* args,
112 const std::string& key,
113 Profile* profile,
114 const extensions::Extension** extension,
115 std::string* error) WARN_UNUSED_RESULT;
117 #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_JSON_H_