| 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/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 bool require_content) { | 159 bool require_content) { |
| 160 if (!value.GetString(kSuggestionContent, &content) && require_content) | 160 if (!value.GetString(kSuggestionContent, &content) && require_content) |
| 161 return false; | 161 return false; |
| 162 | 162 |
| 163 if (!value.GetString(kSuggestionDescription, &description)) | 163 if (!value.GetString(kSuggestionDescription, &description)) |
| 164 return false; | 164 return false; |
| 165 | 165 |
| 166 description_styles.clear(); | 166 description_styles.clear(); |
| 167 if (value.HasKey(kSuggestionDescriptionStyles)) { | 167 if (value.HasKey(kSuggestionDescriptionStyles)) { |
| 168 // This version comes from the extension. | 168 // This version comes from the extension. |
| 169 ListValue* styles = NULL; | 169 const ListValue* styles = NULL; |
| 170 if (!value.GetList(kSuggestionDescriptionStyles, &styles) || | 170 if (!value.GetList(kSuggestionDescriptionStyles, &styles) || |
| 171 !ReadStylesFromValue(*styles)) { | 171 !ReadStylesFromValue(*styles)) { |
| 172 return false; | 172 return false; |
| 173 } | 173 } |
| 174 } else if (value.HasKey(kSuggestionDescriptionStylesRaw)) { | 174 } else if (value.HasKey(kSuggestionDescriptionStylesRaw)) { |
| 175 // This version comes from ToValue(), which we use to persist to disk. | 175 // This version comes from ToValue(), which we use to persist to disk. |
| 176 ListValue* styles = NULL; | 176 const ListValue* styles = NULL; |
| 177 if (!value.GetList(kSuggestionDescriptionStylesRaw, &styles) || | 177 if (!value.GetList(kSuggestionDescriptionStylesRaw, &styles) || |
| 178 styles->empty()) { | 178 styles->empty()) { |
| 179 return false; | 179 return false; |
| 180 } | 180 } |
| 181 for (size_t i = 0; i < styles->GetSize(); ++i) { | 181 for (size_t i = 0; i < styles->GetSize(); ++i) { |
| 182 base::DictionaryValue* style = NULL; | 182 base::DictionaryValue* style = NULL; |
| 183 int offset, type; | 183 int offset, type; |
| 184 if (!styles->GetDictionary(i, &style)) | 184 if (!styles->GetDictionary(i, &style)) |
| 185 return false; | 185 return false; |
| 186 if (!style->GetInteger(kDescriptionStylesType, &type)) | 186 if (!style->GetInteger(kDescriptionStylesType, &type)) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 for (size_t i = 0; i < description_styles.size(); ++i) { | 303 for (size_t i = 0; i < description_styles.size(); ++i) { |
| 304 if (description_styles[i].offset > placeholder) | 304 if (description_styles[i].offset > placeholder) |
| 305 description_styles[i].offset += replacement.length() - 2; | 305 description_styles[i].offset += replacement.length() - 2; |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 | 308 |
| 309 match->contents.assign(description); | 309 match->contents.assign(description); |
| 310 } | 310 } |
| 311 | 311 |
| 312 } // namespace extensions | 312 } // namespace extensions |
| OLD | NEW |