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

Side by Side Diff: chrome/browser/automation/extension_port_container.cc

Issue 316016: Move the json-related files into a separate json directory. This hopefully al... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months 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
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 #include "chrome/browser/automation/extension_port_container.h" 5 #include "chrome/browser/automation/extension_port_container.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/automation/automation_provider.h" 11 #include "chrome/browser/automation/automation_provider.h"
12 #include "chrome/browser/automation/extension_automation_constants.h" 12 #include "chrome/browser/automation/extension_automation_constants.h"
13 #include "chrome/browser/chrome_thread.h" 13 #include "chrome/browser/chrome_thread.h"
14 #include "chrome/browser/extensions/extension_message_service.h" 14 #include "chrome/browser/extensions/extension_message_service.h"
15 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
16 #include "chrome/browser/renderer_host/render_process_host.h" 16 #include "chrome/browser/renderer_host/render_process_host.h"
17 #include "chrome/browser/renderer_host/render_view_host.h" 17 #include "chrome/browser/renderer_host/render_view_host.h"
18 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
19 #include "chrome/common/render_messages.h" 19 #include "chrome/common/render_messages.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 void ExtensionPortContainer::SendConnectionResponse(int connection_id, 86 void ExtensionPortContainer::SendConnectionResponse(int connection_id,
87 int port_id) { 87 int port_id) {
88 // Compose the reply message. 88 // Compose the reply message.
89 scoped_ptr<DictionaryValue> msg_dict(new DictionaryValue()); 89 scoped_ptr<DictionaryValue> msg_dict(new DictionaryValue());
90 msg_dict->SetInteger(ext::kAutomationRequestIdKey, ext::CHANNEL_OPENED); 90 msg_dict->SetInteger(ext::kAutomationRequestIdKey, ext::CHANNEL_OPENED);
91 msg_dict->SetInteger(ext::kAutomationConnectionIdKey, connection_id); 91 msg_dict->SetInteger(ext::kAutomationConnectionIdKey, connection_id);
92 msg_dict->SetInteger(ext::kAutomationPortIdKey, port_id); 92 msg_dict->SetInteger(ext::kAutomationPortIdKey, port_id);
93 93
94 std::string msg_json; 94 std::string msg_json;
95 JSONWriter::Write(msg_dict.get(), false, &msg_json); 95 base::JSONWriter::Write(msg_dict.get(), false, &msg_json);
96 96
97 PostResponseToExternalPort(msg_json); 97 PostResponseToExternalPort(msg_json);
98 } 98 }
99 99
100 bool ExtensionPortContainer::Send(IPC::Message *message) { 100 bool ExtensionPortContainer::Send(IPC::Message *message) {
101 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); 101 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
102 102
103 IPC_BEGIN_MESSAGE_MAP(ExtensionPortContainer, *message) 103 IPC_BEGIN_MESSAGE_MAP(ExtensionPortContainer, *message)
104 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, 104 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
105 OnExtensionMessageInvoke) 105 OnExtensionMessageInvoke)
(...skipping 28 matching lines...) Expand all
134 134
135 void ExtensionPortContainer::OnExtensionHandleMessage( 135 void ExtensionPortContainer::OnExtensionHandleMessage(
136 const std::string& message, int source_port_id) { 136 const std::string& message, int source_port_id) {
137 // Compose the reply message and fire it away. 137 // Compose the reply message and fire it away.
138 DictionaryValue msg_dict; 138 DictionaryValue msg_dict;
139 msg_dict.SetInteger(ext::kAutomationRequestIdKey, ext::POST_MESSAGE); 139 msg_dict.SetInteger(ext::kAutomationRequestIdKey, ext::POST_MESSAGE);
140 msg_dict.SetInteger(ext::kAutomationPortIdKey, port_id_); 140 msg_dict.SetInteger(ext::kAutomationPortIdKey, port_id_);
141 msg_dict.SetString(ext::kAutomationMessageDataKey, message); 141 msg_dict.SetString(ext::kAutomationMessageDataKey, message);
142 142
143 std::string msg_json; 143 std::string msg_json;
144 JSONWriter::Write(&msg_dict, false, &msg_json); 144 base::JSONWriter::Write(&msg_dict, false, &msg_json);
145 145
146 PostMessageToExternalPort(msg_json); 146 PostMessageToExternalPort(msg_json);
147 } 147 }
148 148
149 void ExtensionPortContainer::OnExtensionPortDisconnected(int source_port_id) { 149 void ExtensionPortContainer::OnExtensionPortDisconnected(int source_port_id) {
150 // Compose the disconnect message and fire it away. 150 // Compose the disconnect message and fire it away.
151 DictionaryValue msg_dict; 151 DictionaryValue msg_dict;
152 msg_dict.SetInteger(ext::kAutomationRequestIdKey, ext::CHANNEL_CLOSED); 152 msg_dict.SetInteger(ext::kAutomationRequestIdKey, ext::CHANNEL_CLOSED);
153 msg_dict.SetInteger(ext::kAutomationPortIdKey, port_id_); 153 msg_dict.SetInteger(ext::kAutomationPortIdKey, port_id_);
154 154
155 std::string msg_json; 155 std::string msg_json;
156 JSONWriter::Write(&msg_dict, false, &msg_json); 156 base::JSONWriter::Write(&msg_dict, false, &msg_json);
157 157
158 PostMessageToExternalPort(msg_json); 158 PostMessageToExternalPort(msg_json);
159 } 159 }
160 160
161 bool ExtensionPortContainer::InterceptMessageFromExternalHost( 161 bool ExtensionPortContainer::InterceptMessageFromExternalHost(
162 const std::string& message, const std::string& origin, 162 const std::string& message, const std::string& origin,
163 const std::string& target, AutomationProvider* automation, 163 const std::string& target, AutomationProvider* automation,
164 RenderViewHost *view_host, int tab_handle) { 164 RenderViewHost *view_host, int tab_handle) {
165 if (target != ext::kAutomationPortRequestTarget) 165 if (target != ext::kAutomationPortRequestTarget)
166 return false; 166 return false;
167 167
168 if (origin != ext::kAutomationOrigin) { 168 if (origin != ext::kAutomationOrigin) {
169 // TODO(siggi): Should we block the message on wrong origin? 169 // TODO(siggi): Should we block the message on wrong origin?
170 LOG(WARNING) << "Wrong origin on automation port message " << origin; 170 LOG(WARNING) << "Wrong origin on automation port message " << origin;
171 } 171 }
172 172
173 scoped_ptr<Value> message_value(JSONReader::Read(message, false)); 173 scoped_ptr<Value> message_value(base::JSONReader::Read(message, false));
174 DCHECK(message_value->IsType(Value::TYPE_DICTIONARY)); 174 DCHECK(message_value->IsType(Value::TYPE_DICTIONARY));
175 if (!message_value->IsType(Value::TYPE_DICTIONARY)) 175 if (!message_value->IsType(Value::TYPE_DICTIONARY))
176 return true; 176 return true;
177 177
178 DictionaryValue* message_dict = 178 DictionaryValue* message_dict =
179 reinterpret_cast<DictionaryValue*>(message_value.get()); 179 reinterpret_cast<DictionaryValue*>(message_value.get());
180 180
181 int command = -1; 181 int command = -1;
182 bool got_value = message_dict->GetInteger(ext::kAutomationRequestIdKey, 182 bool got_value = message_dict->GetInteger(ext::kAutomationRequestIdKey,
183 &command); 183 &command);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // This will delete the port and notify the other end of the disconnect. 246 // This will delete the port and notify the other end of the disconnect.
247 automation->RemovePortContainer(port); 247 automation->RemovePortContainer(port);
248 } 248 }
249 } else { 249 } else {
250 // We don't expect other messages here. 250 // We don't expect other messages here.
251 NOTREACHED(); 251 NOTREACHED();
252 } 252 }
253 253
254 return true; 254 return true;
255 } 255 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider.cc ('k') | chrome/browser/bookmarks/bookmark_storage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698