OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer/searchbox_extension.h" | 5 #include "chrome/renderer/searchbox_extension.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 // } | 286 // } |
287 // static | 287 // static |
288 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( | 288 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( |
289 const v8::Arguments& args) { | 289 const v8::Arguments& args) { |
290 std::vector<std::string> suggestions; | 290 std::vector<std::string> suggestions; |
291 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; | 291 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; |
292 | 292 |
293 if (args.Length() && args[0]->IsArray()) { | 293 if (args.Length() && args[0]->IsArray()) { |
294 // For backwards compatibility, also accept an array of strings. | 294 // For backwards compatibility, also accept an array of strings. |
295 // TODO(tonyg): Remove this when it is confirmed to be unused. | 295 // TODO(tonyg): Remove this when it is confirmed to be unused. |
296 v8::Array* suggestions_array = v8::Array::Cast(*args[0]); | 296 v8::Local<v8::Array> suggestions_array = |
| 297 v8::Local<v8::Array>::Cast(args[0]); |
297 uint32_t length = suggestions_array->Length(); | 298 uint32_t length = suggestions_array->Length(); |
298 for (uint32_t i = 0; i < length; i++) { | 299 for (uint32_t i = 0; i < length; i++) { |
299 std::string suggestion = *v8::String::Utf8Value( | 300 std::string suggestion = *v8::String::Utf8Value( |
300 suggestions_array->Get(v8::Integer::New(i))->ToString()); | 301 suggestions_array->Get(v8::Integer::New(i))->ToString()); |
301 if (!suggestion.length()) continue; | 302 if (!suggestion.length()) continue; |
302 suggestions.push_back(suggestion); | 303 suggestions.push_back(suggestion); |
303 } | 304 } |
304 } else if (args.Length() && args[0]->IsObject()) { | 305 } else if (args.Length() && args[0]->IsObject()) { |
305 // Standard version, object argument. | 306 // Standard version, object argument. |
306 v8::Object* suggestion_json = static_cast<v8::Object*>(*args[0]); | 307 v8::Local<v8::Object> suggestion_json = |
| 308 v8::Local<v8::Object>::Cast(args[0]); |
307 v8::Local<v8::Value> suggestions_field = | 309 v8::Local<v8::Value> suggestions_field = |
308 suggestion_json->Get(v8::String::New("suggestions")); | 310 suggestion_json->Get(v8::String::New("suggestions")); |
309 | 311 |
310 if (suggestions_field->IsArray()) { | 312 if (suggestions_field->IsArray()) { |
311 v8::Local<v8::Array> suggestions_array = | 313 v8::Local<v8::Array> suggestions_array = |
312 suggestions_field.As<v8::Array>(); | 314 suggestions_field.As<v8::Array>(); |
313 | 315 |
314 uint32_t length = suggestions_array->Length(); | 316 uint32_t length = suggestions_array->Length(); |
315 for (uint32_t i = 0; i < length; i++) { | 317 for (uint32_t i = 0; i < length; i++) { |
316 v8::Local<v8::Value> suggestion_value = | 318 v8::Local<v8::Value> suggestion_value = |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 428 |
427 return supports_searchbox_api || supports_deprecated_api; | 429 return supports_searchbox_api || supports_deprecated_api; |
428 } | 430 } |
429 | 431 |
430 // static | 432 // static |
431 v8::Extension* SearchBoxExtension::Get() { | 433 v8::Extension* SearchBoxExtension::Get() { |
432 return new SearchBoxExtensionWrapper(); | 434 return new SearchBoxExtensionWrapper(); |
433 } | 435 } |
434 | 436 |
435 } // namespace extensions_v8 | 437 } // namespace extensions_v8 |
OLD | NEW |