| 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 #include <string> |
| 10 #include <vector> |
| 9 | 11 |
| 10 #include "base/command_line.h" | |
| 11 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 12 #include "base/json/string_escape.h" | 13 #include "base/json/string_escape.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/metrics/field_trial.h" | |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/common/search/instant_types.h" | 19 #include "chrome/common/search/instant_types.h" |
| 20 #include "chrome/common/search/ntp_logging_events.h" | 20 #include "chrome/common/search/ntp_logging_events.h" |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "chrome/grit/renderer_resources.h" | 22 #include "chrome/grit/renderer_resources.h" |
| 23 #include "chrome/renderer/searchbox/searchbox.h" | 23 #include "chrome/renderer/searchbox/searchbox.h" |
| 24 #include "components/crx_file/id_util.h" | 24 #include "components/crx_file/id_util.h" |
| 25 #include "components/ntp_tiles/ntp_tile_source.h" | 25 #include "components/ntp_tiles/ntp_tile_source.h" |
| 26 #include "content/public/renderer/render_frame.h" | 26 #include "content/public/renderer/render_frame.h" |
| 27 #include "content/public/renderer/render_view.h" | 27 #include "content/public/renderer/render_view.h" |
| 28 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 28 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 29 #include "third_party/WebKit/public/web/WebDocument.h" | 29 #include "third_party/WebKit/public/web/WebDocument.h" |
| 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 31 #include "third_party/WebKit/public/web/WebScriptSource.h" | 31 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 32 #include "third_party/WebKit/public/web/WebView.h" | 32 #include "third_party/WebKit/public/web/WebView.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 34 #include "ui/base/ui_base_switches.h" | |
| 35 #include "ui/base/window_open_disposition.h" | 34 #include "ui/base/window_open_disposition.h" |
| 36 #include "ui/events/keycodes/keyboard_codes.h" | 35 #include "ui/events/keycodes/keyboard_codes.h" |
| 37 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 38 #include "url/url_constants.h" | 37 #include "url/url_constants.h" |
| 39 #include "v8/include/v8.h" | 38 #include "v8/include/v8.h" |
| 40 | 39 |
| 41 namespace { | 40 namespace { |
| 42 | 41 |
| 43 const char kCSSBackgroundImageFormat[] = "-webkit-image-set(" | 42 const char kCSSBackgroundImageFormat[] = "-webkit-image-set(" |
| 44 "url(chrome-search://theme/IDR_THEME_NTP_BACKGROUND?%s) 1x, " | 43 "url(chrome-search://theme/IDR_THEME_NTP_BACKGROUND?%s) 1x, " |
| (...skipping 18 matching lines...) Expand all Loading... |
| 63 | 62 |
| 64 const char kLTRHtmlTextDirection[] = "ltr"; | 63 const char kLTRHtmlTextDirection[] = "ltr"; |
| 65 const char kRTLHtmlTextDirection[] = "rtl"; | 64 const char kRTLHtmlTextDirection[] = "rtl"; |
| 66 | 65 |
| 67 // Converts a V8 value to a string16. | 66 // Converts a V8 value to a string16. |
| 68 base::string16 V8ValueToUTF16(v8::Local<v8::Value> v) { | 67 base::string16 V8ValueToUTF16(v8::Local<v8::Value> v) { |
| 69 v8::String::Value s(v); | 68 v8::String::Value s(v); |
| 70 return base::string16(reinterpret_cast<const base::char16*>(*s), s.length()); | 69 return base::string16(reinterpret_cast<const base::char16*>(*s), s.length()); |
| 71 } | 70 } |
| 72 | 71 |
| 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. | 72 // Converts string16 to V8 String. |
| 89 v8::Local<v8::String> UTF16ToV8String(v8::Isolate* isolate, | 73 v8::Local<v8::String> UTF16ToV8String(v8::Isolate* isolate, |
| 90 const base::string16& s) { | 74 const base::string16& s) { |
| 91 return v8::String::NewFromTwoByte(isolate, | 75 return v8::String::NewFromTwoByte(isolate, |
| 92 reinterpret_cast<const uint16_t*>(s.data()), | 76 reinterpret_cast<const uint16_t*>(s.data()), |
| 93 v8::String::kNormalString, | 77 v8::String::kNormalString, |
| 94 s.size()); | 78 s.size()); |
| 95 } | 79 } |
| 96 | 80 |
| 97 // Converts std::string to V8 String. | 81 // Converts std::string to V8 String. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 166 } |
| 183 | 167 |
| 184 // If the suggestion already has a favicon, we populate the element with it. | 168 // If the suggestion already has a favicon, we populate the element with it. |
| 185 if (!mv_item.favicon.spec().empty()) { | 169 if (!mv_item.favicon.spec().empty()) { |
| 186 obj->Set(v8::String::NewFromUtf8(isolate, "faviconUrl"), | 170 obj->Set(v8::String::NewFromUtf8(isolate, "faviconUrl"), |
| 187 UTF8ToV8String(isolate, mv_item.favicon.spec())); | 171 UTF8ToV8String(isolate, mv_item.favicon.spec())); |
| 188 } | 172 } |
| 189 | 173 |
| 190 obj->Set(v8::String::NewFromUtf8(isolate, "tileSource"), | 174 obj->Set(v8::String::NewFromUtf8(isolate, "tileSource"), |
| 191 v8::Integer::New(isolate, static_cast<int>(mv_item.source))); | 175 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"), | 176 obj->Set(v8::String::NewFromUtf8(isolate, "title"), |
| 205 UTF16ToV8String(isolate, title)); | 177 UTF16ToV8String(isolate, title)); |
| 206 obj->Set(v8::String::NewFromUtf8(isolate, "domain"), | 178 obj->Set(v8::String::NewFromUtf8(isolate, "domain"), |
| 207 UTF8ToV8String(isolate, mv_item.url.host())); | 179 UTF8ToV8String(isolate, mv_item.url.host())); |
| 208 obj->Set(v8::String::NewFromUtf8(isolate, "direction"), | 180 obj->Set(v8::String::NewFromUtf8(isolate, "direction"), |
| 209 UTF8ToV8String(isolate, direction)); | 181 UTF8ToV8String(isolate, direction)); |
| 210 obj->Set(v8::String::NewFromUtf8(isolate, "url"), | 182 obj->Set(v8::String::NewFromUtf8(isolate, "url"), |
| 211 UTF8ToV8String(isolate, mv_item.url.spec())); | 183 UTF8ToV8String(isolate, mv_item.url.spec())); |
| 212 return obj; | 184 return obj; |
| 213 } | 185 } |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 ThrowInvalidParameters(args); | 1098 ThrowInvalidParameters(args); |
| 1127 return; | 1099 return; |
| 1128 } | 1100 } |
| 1129 | 1101 |
| 1130 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; | 1102 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; |
| 1131 SearchBox::Get(render_frame) | 1103 SearchBox::Get(render_frame) |
| 1132 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); | 1104 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); |
| 1133 } | 1105 } |
| 1134 | 1106 |
| 1135 } // namespace extensions_v8 | 1107 } // namespace extensions_v8 |
| OLD | NEW |