OLD | NEW |
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 // Implements AutomationExtensionFunction. | 5 // Implements AutomationExtensionFunction. |
6 | 6 |
7 #include "chrome/browser/automation/automation_extension_function.h" | 7 #include "chrome/browser/automation/automation_extension_function.h" |
8 | 8 |
9 #include "base/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "chrome/browser/automation/extension_automation_constants.h" | 11 #include "chrome/browser/automation/extension_automation_constants.h" |
12 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 12 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
13 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
14 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 14 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
15 | 15 |
16 bool AutomationExtensionFunction::enabled_ = false; | 16 bool AutomationExtensionFunction::enabled_ = false; |
17 | 17 |
18 void AutomationExtensionFunction::SetArgs(const Value* args) { | 18 void AutomationExtensionFunction::SetArgs(const Value* args) { |
19 JSONWriter::Write(args, false, &args_); | 19 base::JSONWriter::Write(args, false, &args_); |
20 } | 20 } |
21 | 21 |
22 const std::string AutomationExtensionFunction::GetResult() { | 22 const std::string AutomationExtensionFunction::GetResult() { |
23 // Our API result passing is done through InterceptMessageFromExternalHost | 23 // Our API result passing is done through InterceptMessageFromExternalHost |
24 return ""; | 24 return ""; |
25 } | 25 } |
26 | 26 |
27 const std::string AutomationExtensionFunction::GetError() { | 27 const std::string AutomationExtensionFunction::GetError() { |
28 // Our API result passing is done through InterceptMessageFromExternalHost | 28 // Our API result passing is done through InterceptMessageFromExternalHost |
29 return ""; | 29 return ""; |
30 } | 30 } |
31 | 31 |
32 void AutomationExtensionFunction::Run() { | 32 void AutomationExtensionFunction::Run() { |
33 namespace keys = extension_automation_constants; | 33 namespace keys = extension_automation_constants; |
34 | 34 |
35 // We are being driven through automation, so we send the extension API | 35 // We are being driven through automation, so we send the extension API |
36 // request over to the automation host. We do this before decoding the | 36 // request over to the automation host. We do this before decoding the |
37 // 'args' JSON, otherwise we'd be decoding it only to encode it again. | 37 // 'args' JSON, otherwise we'd be decoding it only to encode it again. |
38 DictionaryValue message_to_host; | 38 DictionaryValue message_to_host; |
39 message_to_host.SetString(keys::kAutomationNameKey, name_); | 39 message_to_host.SetString(keys::kAutomationNameKey, name_); |
40 message_to_host.SetString(keys::kAutomationArgsKey, args_); | 40 message_to_host.SetString(keys::kAutomationArgsKey, args_); |
41 message_to_host.SetInteger(keys::kAutomationRequestIdKey, request_id_); | 41 message_to_host.SetInteger(keys::kAutomationRequestIdKey, request_id_); |
42 message_to_host.SetBoolean(keys::kAutomationHasCallbackKey, has_callback_); | 42 message_to_host.SetBoolean(keys::kAutomationHasCallbackKey, has_callback_); |
43 | 43 |
44 std::string message; | 44 std::string message; |
45 JSONWriter::Write(&message_to_host, false, &message); | 45 base::JSONWriter::Write(&message_to_host, false, &message); |
46 dispatcher()->render_view_host_->delegate()->ProcessExternalHostMessage( | 46 dispatcher()->render_view_host_->delegate()->ProcessExternalHostMessage( |
47 message, keys::kAutomationOrigin, keys::kAutomationRequestTarget); | 47 message, keys::kAutomationOrigin, keys::kAutomationRequestTarget); |
48 } | 48 } |
49 | 49 |
50 ExtensionFunction* AutomationExtensionFunction::Factory() { | 50 ExtensionFunction* AutomationExtensionFunction::Factory() { |
51 return new AutomationExtensionFunction(); | 51 return new AutomationExtensionFunction(); |
52 } | 52 } |
53 | 53 |
54 void AutomationExtensionFunction::SetEnabled(bool enabled) { | 54 void AutomationExtensionFunction::SetEnabled(bool enabled) { |
55 if (enabled) { | 55 if (enabled) { |
(...skipping 19 matching lines...) Expand all Loading... |
75 RenderViewHost* view_host, | 75 RenderViewHost* view_host, |
76 const std::string& message, | 76 const std::string& message, |
77 const std::string& origin, | 77 const std::string& origin, |
78 const std::string& target) { | 78 const std::string& target) { |
79 namespace keys = extension_automation_constants; | 79 namespace keys = extension_automation_constants; |
80 | 80 |
81 if (origin == keys::kAutomationOrigin && | 81 if (origin == keys::kAutomationOrigin && |
82 target == keys::kAutomationResponseTarget) { | 82 target == keys::kAutomationResponseTarget) { |
83 // This is an extension API response being sent back via postMessage, | 83 // This is an extension API response being sent back via postMessage, |
84 // so redirect it. | 84 // so redirect it. |
85 scoped_ptr<Value> message_value(JSONReader::Read(message, false)); | 85 scoped_ptr<Value> message_value(base::JSONReader::Read(message, false)); |
86 DCHECK(message_value->IsType(Value::TYPE_DICTIONARY)); | 86 DCHECK(message_value->IsType(Value::TYPE_DICTIONARY)); |
87 if (message_value->IsType(Value::TYPE_DICTIONARY)) { | 87 if (message_value->IsType(Value::TYPE_DICTIONARY)) { |
88 DictionaryValue* message_dict = | 88 DictionaryValue* message_dict = |
89 reinterpret_cast<DictionaryValue*>(message_value.get()); | 89 reinterpret_cast<DictionaryValue*>(message_value.get()); |
90 | 90 |
91 int request_id = -1; | 91 int request_id = -1; |
92 bool got_value = message_dict->GetInteger(keys::kAutomationRequestIdKey, | 92 bool got_value = message_dict->GetInteger(keys::kAutomationRequestIdKey, |
93 &request_id); | 93 &request_id); |
94 DCHECK(got_value); | 94 DCHECK(got_value); |
95 if (got_value) { | 95 if (got_value) { |
(...skipping 10 matching lines...) Expand all Loading... |
106 // functions, we should use that instead. | 106 // functions, we should use that instead. |
107 view_host->SendExtensionResponse(request_id, success, | 107 view_host->SendExtensionResponse(request_id, success, |
108 response, error); | 108 response, error); |
109 return true; | 109 return true; |
110 } | 110 } |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 return false; | 114 return false; |
115 } | 115 } |
OLD | NEW |