Chromium Code Reviews| 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> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 v8::Isolate* isolate, | 101 v8::Isolate* isolate, |
| 102 int render_view_id, | 102 int render_view_id, |
| 103 InstantRestrictedID most_visited_item_id) { | 103 InstantRestrictedID most_visited_item_id) { |
| 104 return UTF8ToV8String( | 104 return UTF8ToV8String( |
| 105 isolate, | 105 isolate, |
| 106 base::StringPrintf( | 106 base::StringPrintf( |
| 107 "chrome-search://thumb/%d/%d", render_view_id, most_visited_item_id)); | 107 "chrome-search://thumb/%d/%d", render_view_id, most_visited_item_id)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 v8::Local<v8::String> GenerateThumb2URL(v8::Isolate* isolate, | 110 v8::Local<v8::String> GenerateThumb2URL(v8::Isolate* isolate, |
| 111 const std::string& url) { | 111 const GURL& page_url, |
| 112 return UTF8ToV8String( | 112 const GURL& fallback_thumb_url) { |
| 113 isolate, base::StringPrintf("chrome-search://thumb2/%s", url.c_str())); | 113 return UTF8ToV8String(isolate, |
| 114 base::StringPrintf("chrome-search://thumb2/%s?fb=%s", | |
|
sfiera
2017/03/30 13:40:58
No url-escaping?
Marc Treib
2017/03/30 13:51:03
Nope :-/
Example of what these URLs look like (fr
sfiera
2017/03/30 13:55:19
Ah, so any tile with ?fb= in its URL is probably a
Marc Treib
2017/03/30 14:04:26
Argh, yes - I didn't even notice. Though I think w
| |
| 115 page_url.spec().c_str(), | |
| 116 fallback_thumb_url.spec().c_str())); | |
| 114 } | 117 } |
| 115 | 118 |
| 116 // Populates a Javascript MostVisitedItem object from |mv_item|. | 119 // Populates a Javascript MostVisitedItem object from |mv_item|. |
| 117 // NOTE: Includes "url", "title" and "domain" which are private data, so should | 120 // NOTE: Includes "url", "title" and "domain" which are private data, so should |
| 118 // not be returned to the Instant page. These should be erased before returning | 121 // not be returned to the Instant page. These should be erased before returning |
| 119 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js. | 122 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js. |
| 120 v8::Local<v8::Object> GenerateMostVisitedItem( | 123 v8::Local<v8::Object> GenerateMostVisitedItem( |
| 121 v8::Isolate* isolate, | 124 v8::Isolate* isolate, |
| 122 int render_view_id, | 125 int render_view_id, |
| 123 InstantRestrictedID restricted_id, | 126 InstantRestrictedID restricted_id, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 142 base::string16 title = mv_item.title; | 145 base::string16 title = mv_item.title; |
| 143 if (title.empty()) | 146 if (title.empty()) |
| 144 title = base::UTF8ToUTF16(mv_item.url.spec()); | 147 title = base::UTF8ToUTF16(mv_item.url.spec()); |
| 145 | 148 |
| 146 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 149 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 147 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"), | 150 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"), |
| 148 v8::Int32::New(isolate, render_view_id)); | 151 v8::Int32::New(isolate, render_view_id)); |
| 149 obj->Set(v8::String::NewFromUtf8(isolate, "rid"), | 152 obj->Set(v8::String::NewFromUtf8(isolate, "rid"), |
| 150 v8::Int32::New(isolate, restricted_id)); | 153 v8::Int32::New(isolate, restricted_id)); |
| 151 | 154 |
| 152 // If the suggestion already has a suggested thumbnail, we create an thumbnail | 155 // If the suggestion already has a suggested thumbnail, we create a thumbnail |
| 153 // array with both the local thumbnail and the proposed one. | 156 // URL with both the local thumbnail and the proposed one as a fallback. |
| 154 // Otherwise, we just create an array with the generated one. | 157 // Otherwise, we just pass on the generated one. |
| 155 if (!mv_item.thumbnail.spec().empty()) { | 158 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrl"), |
| 156 v8::Local<v8::Array> thumbs = v8::Array::New(isolate, 2); | 159 mv_item.thumbnail.is_valid() |
| 157 // Note: The "thumb2" source captures a thumbnail on the next visit. | 160 ? GenerateThumb2URL(isolate, mv_item.url, mv_item.thumbnail) |
| 158 thumbs->Set(0, GenerateThumb2URL(isolate, mv_item.url.spec())); | 161 : GenerateThumbnailURL(isolate, render_view_id, restricted_id)); |
| 159 thumbs->Set(1, UTF8ToV8String(isolate, mv_item.thumbnail.spec())); | |
| 160 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrls"), thumbs); | |
| 161 } else { | |
| 162 v8::Local<v8::Array> thumbs = v8::Array::New(isolate, 1); | |
| 163 thumbs->Set(0, | |
| 164 GenerateThumbnailURL(isolate, render_view_id, restricted_id)); | |
| 165 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrls"), thumbs); | |
| 166 } | |
| 167 | 162 |
| 168 // If the suggestion already has a favicon, we populate the element with it. | 163 // If the suggestion already has a favicon, we populate the element with it. |
| 169 if (!mv_item.favicon.spec().empty()) { | 164 if (!mv_item.favicon.spec().empty()) { |
| 170 obj->Set(v8::String::NewFromUtf8(isolate, "faviconUrl"), | 165 obj->Set(v8::String::NewFromUtf8(isolate, "faviconUrl"), |
| 171 UTF8ToV8String(isolate, mv_item.favicon.spec())); | 166 UTF8ToV8String(isolate, mv_item.favicon.spec())); |
| 172 } | 167 } |
| 173 | 168 |
| 174 obj->Set(v8::String::NewFromUtf8(isolate, "tileSource"), | 169 obj->Set(v8::String::NewFromUtf8(isolate, "tileSource"), |
| 175 v8::Integer::New(isolate, static_cast<int>(mv_item.source))); | 170 v8::Integer::New(isolate, static_cast<int>(mv_item.source))); |
| 176 obj->Set(v8::String::NewFromUtf8(isolate, "title"), | 171 obj->Set(v8::String::NewFromUtf8(isolate, "title"), |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1098 ThrowInvalidParameters(args); | 1093 ThrowInvalidParameters(args); |
| 1099 return; | 1094 return; |
| 1100 } | 1095 } |
| 1101 | 1096 |
| 1102 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; | 1097 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; |
| 1103 SearchBox::Get(render_frame) | 1098 SearchBox::Get(render_frame) |
| 1104 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); | 1099 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); |
| 1105 } | 1100 } |
| 1106 | 1101 |
| 1107 } // namespace extensions_v8 | 1102 } // namespace extensions_v8 |
| OLD | NEW |