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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.cc

Issue 16915006: Convert most of extensions and some other random stuff to using the base namespace for Values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 static const int kOmniboxIconPaddingRight = 0; 67 static const int kOmniboxIconPaddingRight = 0;
68 #endif 68 #endif
69 69
70 scoped_ptr<omnibox::SuggestResult> GetOmniboxDefaultSuggestion( 70 scoped_ptr<omnibox::SuggestResult> GetOmniboxDefaultSuggestion(
71 Profile* profile, 71 Profile* profile,
72 const std::string& extension_id) { 72 const std::string& extension_id) {
73 ExtensionPrefs* prefs = 73 ExtensionPrefs* prefs =
74 ExtensionSystem::Get(profile)->extension_service()->extension_prefs(); 74 ExtensionSystem::Get(profile)->extension_service()->extension_prefs();
75 75
76 scoped_ptr<omnibox::SuggestResult> suggestion; 76 scoped_ptr<omnibox::SuggestResult> suggestion;
77 const DictionaryValue* dict = NULL; 77 const base::DictionaryValue* dict = NULL;
78 if (prefs && prefs->ReadPrefAsDictionary(extension_id, 78 if (prefs && prefs->ReadPrefAsDictionary(extension_id,
79 kOmniboxDefaultSuggestion, 79 kOmniboxDefaultSuggestion,
80 &dict)) { 80 &dict)) {
81 suggestion.reset(new omnibox::SuggestResult); 81 suggestion.reset(new omnibox::SuggestResult);
82 omnibox::SuggestResult::Populate(*dict, suggestion.get()); 82 omnibox::SuggestResult::Populate(*dict, suggestion.get());
83 } 83 }
84 return suggestion.Pass(); 84 return suggestion.Pass();
85 } 85 }
86 86
87 // Tries to set the omnibox default suggestion; returns true on success or 87 // Tries to set the omnibox default suggestion; returns true on success or
(...skipping 17 matching lines...) Expand all
105 105
106 return true; 106 return true;
107 } 107 }
108 108
109 } // namespace 109 } // namespace
110 110
111 // static 111 // static
112 void ExtensionOmniboxEventRouter::OnInputStarted( 112 void ExtensionOmniboxEventRouter::OnInputStarted(
113 Profile* profile, const std::string& extension_id) { 113 Profile* profile, const std::string& extension_id) {
114 scoped_ptr<Event> event(new Event( 114 scoped_ptr<Event> event(new Event(
115 events::kOnInputStarted, make_scoped_ptr(new ListValue()))); 115 events::kOnInputStarted, make_scoped_ptr(new base::ListValue())));
116 event->restrict_to_profile = profile; 116 event->restrict_to_profile = profile;
117 ExtensionSystem::Get(profile)->event_router()-> 117 ExtensionSystem::Get(profile)->event_router()->
118 DispatchEventToExtension(extension_id, event.Pass()); 118 DispatchEventToExtension(extension_id, event.Pass());
119 } 119 }
120 120
121 // static 121 // static
122 bool ExtensionOmniboxEventRouter::OnInputChanged( 122 bool ExtensionOmniboxEventRouter::OnInputChanged(
123 Profile* profile, const std::string& extension_id, 123 Profile* profile, const std::string& extension_id,
124 const std::string& input, int suggest_id) { 124 const std::string& input, int suggest_id) {
125 if (!extensions::ExtensionSystem::Get(profile)->event_router()-> 125 if (!extensions::ExtensionSystem::Get(profile)->event_router()->
126 ExtensionHasEventListener(extension_id, events::kOnInputChanged)) 126 ExtensionHasEventListener(extension_id, events::kOnInputChanged))
127 return false; 127 return false;
128 128
129 scoped_ptr<ListValue> args(new ListValue()); 129 scoped_ptr<base::ListValue> args(new base::ListValue());
130 args->Set(0, Value::CreateStringValue(input)); 130 args->Set(0, Value::CreateStringValue(input));
131 args->Set(1, Value::CreateIntegerValue(suggest_id)); 131 args->Set(1, Value::CreateIntegerValue(suggest_id));
132 132
133 scoped_ptr<Event> event(new Event(events::kOnInputChanged, args.Pass())); 133 scoped_ptr<Event> event(new Event(events::kOnInputChanged, args.Pass()));
134 event->restrict_to_profile = profile; 134 event->restrict_to_profile = profile;
135 ExtensionSystem::Get(profile)->event_router()-> 135 ExtensionSystem::Get(profile)->event_router()->
136 DispatchEventToExtension(extension_id, event.Pass()); 136 DispatchEventToExtension(extension_id, event.Pass());
137 return true; 137 return true;
138 } 138 }
139 139
140 // static 140 // static
141 void ExtensionOmniboxEventRouter::OnInputEntered( 141 void ExtensionOmniboxEventRouter::OnInputEntered(
142 content::WebContents* web_contents, 142 content::WebContents* web_contents,
143 const std::string& extension_id, 143 const std::string& extension_id,
144 const std::string& input, 144 const std::string& input,
145 WindowOpenDisposition disposition) { 145 WindowOpenDisposition disposition) {
146 Profile* profile = 146 Profile* profile =
147 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 147 Profile::FromBrowserContext(web_contents->GetBrowserContext());
148 148
149 const Extension* extension = 149 const Extension* extension =
150 ExtensionSystem::Get(profile)->extension_service()->extensions()-> 150 ExtensionSystem::Get(profile)->extension_service()->extensions()->
151 GetByID(extension_id); 151 GetByID(extension_id);
152 CHECK(extension); 152 CHECK(extension);
153 extensions::TabHelper::FromWebContents(web_contents)-> 153 extensions::TabHelper::FromWebContents(web_contents)->
154 active_tab_permission_granter()->GrantIfRequested(extension); 154 active_tab_permission_granter()->GrantIfRequested(extension);
155 155
156 scoped_ptr<ListValue> args(new ListValue()); 156 scoped_ptr<base::ListValue> args(new base::ListValue());
157 args->Set(0, Value::CreateStringValue(input)); 157 args->Set(0, Value::CreateStringValue(input));
158 if (disposition == NEW_FOREGROUND_TAB) 158 if (disposition == NEW_FOREGROUND_TAB)
159 args->Set(1, Value::CreateStringValue(kForegroundTabDisposition)); 159 args->Set(1, Value::CreateStringValue(kForegroundTabDisposition));
160 else if (disposition == NEW_BACKGROUND_TAB) 160 else if (disposition == NEW_BACKGROUND_TAB)
161 args->Set(1, Value::CreateStringValue(kBackgroundTabDisposition)); 161 args->Set(1, Value::CreateStringValue(kBackgroundTabDisposition));
162 else 162 else
163 args->Set(1, Value::CreateStringValue(kCurrentTabDisposition)); 163 args->Set(1, Value::CreateStringValue(kCurrentTabDisposition));
164 164
165 scoped_ptr<Event> event(new Event(events::kOnInputEntered, args.Pass())); 165 scoped_ptr<Event> event(new Event(events::kOnInputEntered, args.Pass()));
166 event->restrict_to_profile = profile; 166 event->restrict_to_profile = profile;
167 ExtensionSystem::Get(profile)->event_router()-> 167 ExtensionSystem::Get(profile)->event_router()->
168 DispatchEventToExtension(extension_id, event.Pass()); 168 DispatchEventToExtension(extension_id, event.Pass());
169 169
170 content::NotificationService::current()->Notify( 170 content::NotificationService::current()->Notify(
171 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, 171 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED,
172 content::Source<Profile>(profile), 172 content::Source<Profile>(profile),
173 content::NotificationService::NoDetails()); 173 content::NotificationService::NoDetails());
174 } 174 }
175 175
176 // static 176 // static
177 void ExtensionOmniboxEventRouter::OnInputCancelled( 177 void ExtensionOmniboxEventRouter::OnInputCancelled(
178 Profile* profile, const std::string& extension_id) { 178 Profile* profile, const std::string& extension_id) {
179 scoped_ptr<Event> event(new Event( 179 scoped_ptr<Event> event(new Event(
180 events::kOnInputCancelled, make_scoped_ptr(new ListValue()))); 180 events::kOnInputCancelled, make_scoped_ptr(new base::ListValue())));
181 event->restrict_to_profile = profile; 181 event->restrict_to_profile = profile;
182 ExtensionSystem::Get(profile)->event_router()-> 182 ExtensionSystem::Get(profile)->event_router()->
183 DispatchEventToExtension(extension_id, event.Pass()); 183 DispatchEventToExtension(extension_id, event.Pass());
184 } 184 }
185 185
186 OmniboxAPI::OmniboxAPI(Profile* profile) 186 OmniboxAPI::OmniboxAPI(Profile* profile)
187 : profile_(profile), 187 : profile_(profile),
188 url_service_(TemplateURLServiceFactory::GetForProfile(profile)) { 188 url_service_(TemplateURLServiceFactory::GetForProfile(profile)) {
189 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 189 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
190 content::Source<Profile>(profile)); 190 content::Source<Profile>(profile));
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 for (size_t i = 0; i < description_styles.size(); ++i) { 396 for (size_t i = 0; i < description_styles.size(); ++i) {
397 if (description_styles[i].offset > placeholder) 397 if (description_styles[i].offset > placeholder)
398 description_styles[i].offset += replacement.length() - 2; 398 description_styles[i].offset += replacement.length() - 2;
399 } 399 }
400 } 400 }
401 401
402 match->contents.assign(description); 402 match->contents.assign(description);
403 } 403 }
404 404
405 } // namespace extensions 405 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698