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

Side by Side Diff: chrome/browser/chromeos/extensions/input_method_event_router.cc

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing memory leak in a test. Created 8 years, 4 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 "input_method_event_router.h" 5 #include "input_method_event_router.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 22 matching lines...) Expand all
33 33
34 void ExtensionInputMethodEventRouter::InputMethodChanged( 34 void ExtensionInputMethodEventRouter::InputMethodChanged(
35 input_method::InputMethodManager *manager, 35 input_method::InputMethodManager *manager,
36 bool show_message) { 36 bool show_message) {
37 Profile *profile = ProfileManager::GetDefaultProfile(); 37 Profile *profile = ProfileManager::GetDefaultProfile();
38 extensions::EventRouter *router = profile->GetExtensionEventRouter(); 38 extensions::EventRouter *router = profile->GetExtensionEventRouter();
39 39
40 if (!router->HasEventListener(extensions::event_names::kOnInputMethodChanged)) 40 if (!router->HasEventListener(extensions::event_names::kOnInputMethodChanged))
41 return; 41 return;
42 42
43 ListValue args; 43 scoped_ptr<ListValue> args(new ListValue());
44 StringValue *input_method_name = new StringValue( 44 StringValue *input_method_name = new StringValue(
45 GetInputMethodForXkb(manager->GetCurrentInputMethod().id())); 45 GetInputMethodForXkb(manager->GetCurrentInputMethod().id()));
46 args.Append(input_method_name); 46 args->Append(input_method_name);
47 std::string args_json;
48 base::JSONWriter::Write(&args, &args_json);
49 47
50 // The router will only send the event to extensions that are listening. 48 // The router will only send the event to extensions that are listening.
51 router->DispatchEventToRenderers( 49 router->DispatchEventToRenderers(
52 extensions::event_names::kOnInputMethodChanged, 50 extensions::event_names::kOnInputMethodChanged, args.Pass(), profile,
53 args_json, profile, GURL()); 51 GURL());
54 } 52 }
55 53
56 std::string ExtensionInputMethodEventRouter::GetInputMethodForXkb( 54 std::string ExtensionInputMethodEventRouter::GetInputMethodForXkb(
57 const std::string& xkb_id) { 55 const std::string& xkb_id) {
58 size_t prefix_length = std::string(kXkbPrefix).length(); 56 size_t prefix_length = std::string(kXkbPrefix).length();
59 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); 57 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix);
60 return xkb_id.substr(prefix_length); 58 return xkb_id.substr(prefix_length);
61 } 59 }
62 60
63 } // namespace chromeos 61 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698