| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/renderer/searchbox/searchbox_extension.h" | 5 #include "chrome/renderer/searchbox/searchbox_extension.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 const char kLTRHtmlTextDirection[] = "ltr"; | 64 const char kLTRHtmlTextDirection[] = "ltr"; |
| 65 const char kRTLHtmlTextDirection[] = "rtl"; | 65 const char kRTLHtmlTextDirection[] = "rtl"; |
| 66 | 66 |
| 67 // Converts a V8 value to a string16. | 67 // Converts a V8 value to a string16. |
| 68 base::string16 V8ValueToUTF16(v8::Local<v8::Value> v) { | 68 base::string16 V8ValueToUTF16(v8::Local<v8::Value> v) { |
| 69 v8::String::Value s(v); | 69 v8::String::Value s(v); |
| 70 return base::string16(reinterpret_cast<const base::char16*>(*s), s.length()); | 70 return base::string16(reinterpret_cast<const base::char16*>(*s), s.length()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Returns whether icon NTP is enabled by experiment. | |
| 74 // TODO(huangs): Remove all 3 copies of this routine once Icon NTP launches. | |
| 75 bool IsIconNTPEnabled() { | |
| 76 // Note: It's important to query the field trial state first, to ensure that | |
| 77 // UMA reports the correct group. | |
| 78 const std::string group_name = base::FieldTrialList::FindFullName("IconNTP"); | |
| 79 using base::CommandLine; | |
| 80 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableIconNtp)) | |
| 81 return false; | |
| 82 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableIconNtp)) | |
| 83 return true; | |
| 84 | |
| 85 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); | |
| 86 } | |
| 87 | |
| 88 // Converts string16 to V8 String. | 73 // Converts string16 to V8 String. |
| 89 v8::Local<v8::String> UTF16ToV8String(v8::Isolate* isolate, | 74 v8::Local<v8::String> UTF16ToV8String(v8::Isolate* isolate, |
| 90 const base::string16& s) { | 75 const base::string16& s) { |
| 91 return v8::String::NewFromTwoByte(isolate, | 76 return v8::String::NewFromTwoByte(isolate, |
| 92 reinterpret_cast<const uint16_t*>(s.data()), | 77 reinterpret_cast<const uint16_t*>(s.data()), |
| 93 v8::String::kNormalString, | 78 v8::String::kNormalString, |
| 94 s.size()); | 79 s.size()); |
| 95 } | 80 } |
| 96 | 81 |
| 97 // Converts std::string to V8 String. | 82 // Converts std::string to V8 String. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 167 } |
| 183 | 168 |
| 184 // If the suggestion already has a favicon, we populate the element with it. | 169 // If the suggestion already has a favicon, we populate the element with it. |
| 185 if (!mv_item.favicon.spec().empty()) { | 170 if (!mv_item.favicon.spec().empty()) { |
| 186 obj->Set(v8::String::NewFromUtf8(isolate, "faviconUrl"), | 171 obj->Set(v8::String::NewFromUtf8(isolate, "faviconUrl"), |
| 187 UTF8ToV8String(isolate, mv_item.favicon.spec())); | 172 UTF8ToV8String(isolate, mv_item.favicon.spec())); |
| 188 } | 173 } |
| 189 | 174 |
| 190 obj->Set(v8::String::NewFromUtf8(isolate, "tileSource"), | 175 obj->Set(v8::String::NewFromUtf8(isolate, "tileSource"), |
| 191 v8::Integer::New(isolate, static_cast<int>(mv_item.source))); | 176 v8::Integer::New(isolate, static_cast<int>(mv_item.source))); |
| 192 | |
| 193 if (IsIconNTPEnabled()) { | |
| 194 // Update website http://www.chromium.org/embeddedsearch when we make this | |
| 195 // permanent. | |
| 196 // Large icon size is 48px * window.devicePixelRatio. This is easier to set | |
| 197 // from JS, where IsIconNTPEnabled() is not available. So we add stubs | |
| 198 // here, and let JS fill in details. | |
| 199 obj->Set(v8::String::NewFromUtf8(isolate, "largeIconUrl"), | |
| 200 v8::String::NewFromUtf8(isolate, "chrome-search://large-icon/")); | |
| 201 obj->Set(v8::String::NewFromUtf8(isolate, "fallbackIconUrl"), | |
| 202 v8::String::NewFromUtf8(isolate, "chrome-search://fallback-icon/")); | |
| 203 } | |
| 204 obj->Set(v8::String::NewFromUtf8(isolate, "title"), | 177 obj->Set(v8::String::NewFromUtf8(isolate, "title"), |
| 205 UTF16ToV8String(isolate, title)); | 178 UTF16ToV8String(isolate, title)); |
| 206 obj->Set(v8::String::NewFromUtf8(isolate, "domain"), | 179 obj->Set(v8::String::NewFromUtf8(isolate, "domain"), |
| 207 UTF8ToV8String(isolate, mv_item.url.host())); | 180 UTF8ToV8String(isolate, mv_item.url.host())); |
| 208 obj->Set(v8::String::NewFromUtf8(isolate, "direction"), | 181 obj->Set(v8::String::NewFromUtf8(isolate, "direction"), |
| 209 UTF8ToV8String(isolate, direction)); | 182 UTF8ToV8String(isolate, direction)); |
| 210 obj->Set(v8::String::NewFromUtf8(isolate, "url"), | 183 obj->Set(v8::String::NewFromUtf8(isolate, "url"), |
| 211 UTF8ToV8String(isolate, mv_item.url.spec())); | 184 UTF8ToV8String(isolate, mv_item.url.spec())); |
| 212 return obj; | 185 return obj; |
| 213 } | 186 } |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 ThrowInvalidParameters(args); | 1099 ThrowInvalidParameters(args); |
| 1127 return; | 1100 return; |
| 1128 } | 1101 } |
| 1129 | 1102 |
| 1130 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; | 1103 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; |
| 1131 SearchBox::Get(render_frame) | 1104 SearchBox::Get(render_frame) |
| 1132 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); | 1105 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); |
| 1133 } | 1106 } |
| 1134 | 1107 |
| 1135 } // namespace extensions_v8 | 1108 } // namespace extensions_v8 |
| OLD | NEW |