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

Side by Side Diff: chrome/browser/extensions/extension_input_ime_api.cc

Issue 9590002: JSONWriter cleanup: integrate pretty print into write options. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflict 7. Created 8 years, 9 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) 2012 The Chromium Authors. All rights reserved. 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 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/extensions/extension_input_ime_api.h" 5 #include "chrome/browser/extensions/extension_input_ime_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 153 }
154 154
155 virtual void OnActivate(const std::string& engine_id) { 155 virtual void OnActivate(const std::string& engine_id) {
156 if (profile_ == NULL || extension_id_.empty()) 156 if (profile_ == NULL || extension_id_.empty())
157 return; 157 return;
158 158
159 ListValue args; 159 ListValue args;
160 args.Append(Value::CreateStringValue(engine_id)); 160 args.Append(Value::CreateStringValue(engine_id));
161 161
162 std::string json_args; 162 std::string json_args;
163 base::JSONWriter::Write(&args, false, &json_args); 163 base::JSONWriter::Write(&args, &json_args);
164 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 164 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
165 extension_id_, events::kOnActivate, json_args, profile_, GURL()); 165 extension_id_, events::kOnActivate, json_args, profile_, GURL());
166 } 166 }
167 167
168 virtual void OnDeactivated(const std::string& engine_id) { 168 virtual void OnDeactivated(const std::string& engine_id) {
169 if (profile_ == NULL || extension_id_.empty()) 169 if (profile_ == NULL || extension_id_.empty())
170 return; 170 return;
171 171
172 ListValue args; 172 ListValue args;
173 args.Append(Value::CreateStringValue(engine_id)); 173 args.Append(Value::CreateStringValue(engine_id));
174 174
175 std::string json_args; 175 std::string json_args;
176 base::JSONWriter::Write(&args, false, &json_args); 176 base::JSONWriter::Write(&args, &json_args);
177 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 177 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
178 extension_id_, events::kOnDeactivated, json_args, profile_, GURL()); 178 extension_id_, events::kOnDeactivated, json_args, profile_, GURL());
179 } 179 }
180 180
181 virtual void OnFocus(const InputMethodEngine::InputContext& context) { 181 virtual void OnFocus(const InputMethodEngine::InputContext& context) {
182 if (profile_ == NULL || extension_id_.empty()) 182 if (profile_ == NULL || extension_id_.empty())
183 return; 183 return;
184 184
185 DictionaryValue* dict = new DictionaryValue(); 185 DictionaryValue* dict = new DictionaryValue();
186 dict->SetInteger("contextID", context.id); 186 dict->SetInteger("contextID", context.id);
187 dict->SetString("type", context.type); 187 dict->SetString("type", context.type);
188 188
189 ListValue args; 189 ListValue args;
190 args.Append(dict); 190 args.Append(dict);
191 191
192 std::string json_args; 192 std::string json_args;
193 base::JSONWriter::Write(&args, false, &json_args); 193 base::JSONWriter::Write(&args, &json_args);
194 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 194 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
195 extension_id_, events::kOnFocus, json_args, profile_, GURL()); 195 extension_id_, events::kOnFocus, json_args, profile_, GURL());
196 } 196 }
197 197
198 virtual void OnBlur(int context_id) { 198 virtual void OnBlur(int context_id) {
199 if (profile_ == NULL || extension_id_.empty()) 199 if (profile_ == NULL || extension_id_.empty())
200 return; 200 return;
201 201
202 ListValue args; 202 ListValue args;
203 args.Append(Value::CreateIntegerValue(context_id)); 203 args.Append(Value::CreateIntegerValue(context_id));
204 204
205 std::string json_args; 205 std::string json_args;
206 base::JSONWriter::Write(&args, false, &json_args); 206 base::JSONWriter::Write(&args, &json_args);
207 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 207 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
208 extension_id_, events::kOnBlur, json_args, profile_, GURL()); 208 extension_id_, events::kOnBlur, json_args, profile_, GURL());
209 } 209 }
210 210
211 virtual void OnInputContextUpdate( 211 virtual void OnInputContextUpdate(
212 const InputMethodEngine::InputContext& context) { 212 const InputMethodEngine::InputContext& context) {
213 if (profile_ == NULL || extension_id_.empty()) 213 if (profile_ == NULL || extension_id_.empty())
214 return; 214 return;
215 215
216 DictionaryValue* dict = new DictionaryValue(); 216 DictionaryValue* dict = new DictionaryValue();
217 dict->SetInteger("contextID", context.id); 217 dict->SetInteger("contextID", context.id);
218 dict->SetString("type", context.type); 218 dict->SetString("type", context.type);
219 219
220 ListValue args; 220 ListValue args;
221 args.Append(dict); 221 args.Append(dict);
222 222
223 std::string json_args; 223 std::string json_args;
224 base::JSONWriter::Write(&args, false, &json_args); 224 base::JSONWriter::Write(&args, &json_args);
225 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 225 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
226 extension_id_, events::kOnInputContextUpdate, json_args, profile_, 226 extension_id_, events::kOnInputContextUpdate, json_args, profile_,
227 GURL()); 227 GURL());
228 } 228 }
229 229
230 virtual void OnKeyEvent(const std::string& engine_id, 230 virtual void OnKeyEvent(const std::string& engine_id,
231 const InputMethodEngine::KeyboardEvent& event, 231 const InputMethodEngine::KeyboardEvent& event,
232 chromeos::input_method::KeyEventHandle* key_data) { 232 chromeos::input_method::KeyEventHandle* key_data) {
233 if (profile_ == NULL || extension_id_.empty()) 233 if (profile_ == NULL || extension_id_.empty())
234 return; 234 return;
235 235
236 std::string request_id = 236 std::string request_id =
237 ExtensionInputImeEventRouter::GetInstance()->AddRequest(engine_id, 237 ExtensionInputImeEventRouter::GetInstance()->AddRequest(engine_id,
238 key_data); 238 key_data);
239 239
240 DictionaryValue* dict = new DictionaryValue(); 240 DictionaryValue* dict = new DictionaryValue();
241 dict->SetString("type", event.type); 241 dict->SetString("type", event.type);
242 dict->SetString("requestId", request_id); 242 dict->SetString("requestId", request_id);
243 dict->SetString("key", event.key); 243 dict->SetString("key", event.key);
244 dict->SetBoolean("altKey", event.alt_key); 244 dict->SetBoolean("altKey", event.alt_key);
245 dict->SetBoolean("ctrlKey", event.ctrl_key); 245 dict->SetBoolean("ctrlKey", event.ctrl_key);
246 dict->SetBoolean("shiftKey", event.shift_key); 246 dict->SetBoolean("shiftKey", event.shift_key);
247 247
248 ListValue args; 248 ListValue args;
249 args.Append(Value::CreateStringValue(engine_id)); 249 args.Append(Value::CreateStringValue(engine_id));
250 args.Append(dict); 250 args.Append(dict);
251 251
252 std::string json_args; 252 std::string json_args;
253 base::JSONWriter::Write(&args, false, &json_args); 253 base::JSONWriter::Write(&args, &json_args);
254 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 254 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
255 extension_id_, events::kOnKeyEvent, json_args, profile_, GURL()); 255 extension_id_, events::kOnKeyEvent, json_args, profile_, GURL());
256 } 256 }
257 257
258 virtual void OnCandidateClicked( 258 virtual void OnCandidateClicked(
259 const std::string& engine_id, 259 const std::string& engine_id,
260 int candidate_id, 260 int candidate_id,
261 chromeos::InputMethodEngine::MouseButtonEvent button) { 261 chromeos::InputMethodEngine::MouseButtonEvent button) {
262 if (profile_ == NULL || extension_id_.empty()) 262 if (profile_ == NULL || extension_id_.empty())
263 return; 263 return;
(...skipping 11 matching lines...) Expand all
275 break; 275 break;
276 276
277 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: 277 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT:
278 // Default to left. 278 // Default to left.
279 default: 279 default:
280 args.Append(Value::CreateStringValue("left")); 280 args.Append(Value::CreateStringValue("left"));
281 break; 281 break;
282 } 282 }
283 283
284 std::string json_args; 284 std::string json_args;
285 base::JSONWriter::Write(&args, false, &json_args); 285 base::JSONWriter::Write(&args, &json_args);
286 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 286 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
287 extension_id_, events::kOnCandidateClicked, json_args, profile_, 287 extension_id_, events::kOnCandidateClicked, json_args, profile_,
288 GURL()); 288 GURL());
289 } 289 }
290 290
291 virtual void OnMenuItemActivated(const std::string& engine_id, 291 virtual void OnMenuItemActivated(const std::string& engine_id,
292 const std::string& menu_id) { 292 const std::string& menu_id) {
293 if (profile_ == NULL || extension_id_.empty()) 293 if (profile_ == NULL || extension_id_.empty())
294 return; 294 return;
295 295
296 ListValue args; 296 ListValue args;
297 args.Append(Value::CreateStringValue(engine_id)); 297 args.Append(Value::CreateStringValue(engine_id));
298 args.Append(Value::CreateStringValue(menu_id)); 298 args.Append(Value::CreateStringValue(menu_id));
299 299
300 std::string json_args; 300 std::string json_args;
301 base::JSONWriter::Write(&args, false, &json_args); 301 base::JSONWriter::Write(&args, &json_args);
302 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 302 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
303 extension_id_, events::kOnMenuItemActivated, json_args, profile_, 303 extension_id_, events::kOnMenuItemActivated, json_args, profile_,
304 GURL()); 304 GURL());
305 } 305 }
306 306
307 private: 307 private:
308 Profile* profile_; 308 Profile* profile_;
309 std::string extension_id_; 309 std::string extension_id_;
310 std::string engine_id_; 310 std::string engine_id_;
311 311
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 824
825 bool handled = false; 825 bool handled = false;
826 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); 826 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled));
827 827
828 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled( 828 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled(
829 extension_id(), request_id_str, handled); 829 extension_id(), request_id_str, handled);
830 830
831 return true; 831 return true;
832 } 832 }
833 #endif 833 #endif
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_idle_api.cc ('k') | chrome/browser/extensions/extension_input_ui_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698