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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.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 "chrome/browser/extensions/api/omnibox/omnibox_api.h" 5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const char kSuggestionDescriptionStylesRaw[] = "descriptionStylesRaw"; 44 const char kSuggestionDescriptionStylesRaw[] = "descriptionStylesRaw";
45 const char kDescriptionStylesType[] = "type"; 45 const char kDescriptionStylesType[] = "type";
46 const char kDescriptionStylesOffset[] = "offset"; 46 const char kDescriptionStylesOffset[] = "offset";
47 const char kDescriptionStylesLength[] = "length"; 47 const char kDescriptionStylesLength[] = "length";
48 48
49 } // namespace 49 } // namespace
50 50
51 // static 51 // static
52 void ExtensionOmniboxEventRouter::OnInputStarted( 52 void ExtensionOmniboxEventRouter::OnInputStarted(
53 Profile* profile, const std::string& extension_id) { 53 Profile* profile, const std::string& extension_id) {
54 profile->GetExtensionEventRouter()->DispatchEventToExtension( 54 scoped_ptr<ListValue> event_args(new ListValue());
55 extension_id, events::kOnInputStarted, "[]", profile, GURL()); 55 profile->GetExtensionEventRouter()->DispatchEventToExtension(extension_id,
56 events::kOnInputStarted, event_args.Pass(), profile, GURL());
56 } 57 }
57 58
58 // static 59 // static
59 bool ExtensionOmniboxEventRouter::OnInputChanged( 60 bool ExtensionOmniboxEventRouter::OnInputChanged(
60 Profile* profile, const std::string& extension_id, 61 Profile* profile, const std::string& extension_id,
61 const std::string& input, int suggest_id) { 62 const std::string& input, int suggest_id) {
62 if (!profile->GetExtensionEventRouter()->ExtensionHasEventListener( 63 if (!profile->GetExtensionEventRouter()->ExtensionHasEventListener(
63 extension_id, events::kOnInputChanged)) 64 extension_id, events::kOnInputChanged))
64 return false; 65 return false;
65 66
66 ListValue args; 67 scoped_ptr<ListValue> args(new ListValue());
67 args.Set(0, Value::CreateStringValue(input)); 68 args->Set(0, Value::CreateStringValue(input));
68 args.Set(1, Value::CreateIntegerValue(suggest_id)); 69 args->Set(1, Value::CreateIntegerValue(suggest_id));
69 std::string json_args;
70 base::JSONWriter::Write(&args, &json_args);
71 70
72 profile->GetExtensionEventRouter()->DispatchEventToExtension( 71 profile->GetExtensionEventRouter()->DispatchEventToExtension(
73 extension_id, events::kOnInputChanged, json_args, profile, GURL()); 72 extension_id, events::kOnInputChanged, args.Pass(), profile, GURL());
74 return true; 73 return true;
75 } 74 }
76 75
77 // static 76 // static
78 void ExtensionOmniboxEventRouter::OnInputEntered( 77 void ExtensionOmniboxEventRouter::OnInputEntered(
79 TabContents* tab_contents, 78 TabContents* tab_contents,
80 const std::string& extension_id, 79 const std::string& extension_id,
81 const std::string& input) { 80 const std::string& input) {
82 Profile* profile = tab_contents->profile(); 81 Profile* profile = tab_contents->profile();
83 82
84 const Extension* extension = 83 const Extension* extension =
85 ExtensionSystem::Get(profile)->extension_service()->extensions()-> 84 ExtensionSystem::Get(profile)->extension_service()->extensions()->
86 GetByID(extension_id); 85 GetByID(extension_id);
87 CHECK(extension); 86 CHECK(extension);
88 tab_contents->extension_tab_helper()->active_tab_permission_manager()-> 87 tab_contents->extension_tab_helper()->active_tab_permission_manager()->
89 GrantIfRequested(extension); 88 GrantIfRequested(extension);
90 89
91 ListValue args; 90 scoped_ptr<ListValue> args(new ListValue());
92 args.Set(0, Value::CreateStringValue(input)); 91 args->Set(0, Value::CreateStringValue(input));
93 std::string json_args;
94 base::JSONWriter::Write(&args, &json_args);
95 92
96 profile->GetExtensionEventRouter()->DispatchEventToExtension( 93 profile->GetExtensionEventRouter()->DispatchEventToExtension(
97 extension_id, events::kOnInputEntered, json_args, profile, GURL()); 94 extension_id, events::kOnInputEntered, args.Pass(), profile, GURL());
98 95
99 content::NotificationService::current()->Notify( 96 content::NotificationService::current()->Notify(
100 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, 97 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED,
101 content::Source<Profile>(profile), 98 content::Source<Profile>(profile),
102 content::NotificationService::NoDetails()); 99 content::NotificationService::NoDetails());
103 } 100 }
104 101
105 // static 102 // static
106 void ExtensionOmniboxEventRouter::OnInputCancelled( 103 void ExtensionOmniboxEventRouter::OnInputCancelled(
107 Profile* profile, const std::string& extension_id) { 104 Profile* profile, const std::string& extension_id) {
105 scoped_ptr<ListValue> args(new ListValue());
108 profile->GetExtensionEventRouter()->DispatchEventToExtension( 106 profile->GetExtensionEventRouter()->DispatchEventToExtension(
109 extension_id, events::kOnInputCancelled, "[]", profile, GURL()); 107 extension_id, events::kOnInputCancelled, args.Pass(), profile, GURL());
110 } 108 }
111 109
112 bool OmniboxSendSuggestionsFunction::RunImpl() { 110 bool OmniboxSendSuggestionsFunction::RunImpl() {
113 ExtensionOmniboxSuggestions suggestions; 111 ExtensionOmniboxSuggestions suggestions;
114 ListValue* suggestions_value; 112 ListValue* suggestions_value;
115 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); 113 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id));
116 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); 114 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value));
117 115
118 suggestions.suggestions.resize(suggestions_value->GetSize()); 116 suggestions.suggestions.resize(suggestions_value->GetSize());
119 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { 117 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 for (size_t i = 0; i < description_styles.size(); ++i) { 301 for (size_t i = 0; i < description_styles.size(); ++i) {
304 if (description_styles[i].offset > placeholder) 302 if (description_styles[i].offset > placeholder)
305 description_styles[i].offset += replacement.length() - 2; 303 description_styles[i].offset += replacement.length() - 2;
306 } 304 }
307 } 305 }
308 306
309 match->contents.assign(description); 307 match->contents.assign(description);
310 } 308 }
311 309
312 } // namespace extensions 310 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.cc ('k') | chrome/browser/extensions/api/proxy/proxy_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698