OLD | NEW |
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/string16.h" | 10 #include "base/string16.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
88 // false on failure. | 88 // false on failure. |
89 bool SetOmniboxDefaultSuggestion(Profile* profile, | 89 bool SetOmniboxDefaultSuggestion( |
90 const std::string& extension_id, | 90 Profile* profile, |
91 const omnibox::SuggestResult& suggestion) { | 91 const std::string& extension_id, |
| 92 const omnibox::DefaultSuggestResult& suggestion) { |
92 ExtensionPrefs* prefs = | 93 ExtensionPrefs* prefs = |
93 ExtensionSystem::Get(profile)->extension_service()->extension_prefs(); | 94 ExtensionSystem::Get(profile)->extension_service()->extension_prefs(); |
94 if (!prefs) | 95 if (!prefs) |
95 return false; | 96 return false; |
96 | 97 |
97 scoped_ptr<base::DictionaryValue> dict = suggestion.ToValue(); | 98 scoped_ptr<base::DictionaryValue> dict = suggestion.ToValue(); |
98 // A default suggestion should not have the content field set. | 99 // Add the content field so that the dictionary can be used to populate an |
99 dict->Remove(kSuggestionContent, NULL); | 100 // omnibox::SuggestResult. |
| 101 dict->SetWithoutPathExpansion(kSuggestionContent, new base::StringValue("")); |
100 prefs->UpdateExtensionPref(extension_id, | 102 prefs->UpdateExtensionPref(extension_id, |
101 kOmniboxDefaultSuggestion, | 103 kOmniboxDefaultSuggestion, |
102 dict.release()); | 104 dict.release()); |
103 | 105 |
104 return true; | 106 return true; |
105 } | 107 } |
106 | 108 |
107 } // namespace | 109 } // namespace |
108 | 110 |
109 // static | 111 // static |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 for (size_t i = 0; i < description_styles.size(); ++i) { | 396 for (size_t i = 0; i < description_styles.size(); ++i) { |
395 if (description_styles[i].offset > placeholder) | 397 if (description_styles[i].offset > placeholder) |
396 description_styles[i].offset += replacement.length() - 2; | 398 description_styles[i].offset += replacement.length() - 2; |
397 } | 399 } |
398 } | 400 } |
399 | 401 |
400 match->contents.assign(description); | 402 match->contents.assign(description); |
401 } | 403 } |
402 | 404 |
403 } // namespace extensions | 405 } // namespace extensions |
OLD | NEW |