Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Unified Diff: chrome/renderer/searchbox/searchbox.cc

Issue 13375003: Fixing iframe jank in the local omnibox popup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Include missing file. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/searchbox/searchbox.cc
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index 9245eab13fabaaaf17c134f29f0b3af298270232..cfb793027d7faf4811735255ee52cbce6caded48 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -22,37 +22,6 @@ namespace {
// Size of the results cache.
const size_t kMaxInstantAutocompleteResultItemCacheSize = 100;
-// The HTML returned when an invalid or unknown restricted ID is requested.
-const char kInvalidSuggestionHtml[] =
- "<div style=\"background:red\">invalid rid %d</div>";
-
-// Checks if the input color is in valid range.
-bool IsColorValid(int color) {
- return color >= 0 && color <= 0xffffff;
-}
-
-// If |url| starts with |prefix|, removes |prefix|.
-void StripPrefix(string16* url, const string16& prefix) {
- if (StartsWith(*url, prefix, true))
- url->erase(0, prefix.length());
-}
-
-// Removes leading "http://" or "http://www." from |url| unless |userInput|
-// starts with those prefixes.
-void StripURLPrefixes(string16* url, const string16& userInput) {
- string16 trimmedUserInput;
- TrimWhitespace(userInput, TRIM_TRAILING, &trimmedUserInput);
- if (StartsWith(*url, trimmedUserInput, true))
- return;
-
- StripPrefix(url, ASCIIToUTF16(chrome::kHttpScheme) + ASCIIToUTF16("://"));
-
- if (StartsWith(*url, trimmedUserInput, true))
- return;
-
- StripPrefix(url, ASCIIToUTF16("www."));
-}
-
} // namespace
SearchBox::SearchBox(content::RenderView* render_view)
@@ -394,88 +363,3 @@ bool SearchBox::GetMostVisitedItemWithID(
return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id,
item);
}
-
-bool SearchBox::GenerateDataURLForSuggestionRequest(const GURL& request_url,
- GURL* data_url) const {
- DCHECK(data_url);
-
- // The origin URL is required so that the iframe knows what origin to post
- // messages to.
- WebKit::WebView* webview = render_view()->GetWebView();
- if (!webview)
- return false;
- GURL embedder_url(webview->mainFrame()->document().url());
- GURL embedder_origin = embedder_url.GetOrigin();
- if (!embedder_origin.is_valid())
- return false;
-
- DCHECK(StartsWithASCII(request_url.path(), "/", true));
- std::string restricted_id_str = request_url.path().substr(1);
-
- InstantRestrictedID restricted_id = 0;
- DCHECK_EQ(sizeof(InstantRestrictedID), sizeof(int));
- if (!base::StringToInt(restricted_id_str, &restricted_id))
- return false;
-
- std::string response_html;
- InstantAutocompleteResult result;
- if (autocomplete_results_cache_.GetItemWithRestrictedID(
- restricted_id, &result)) {
- std::string template_html =
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_OMNIBOX_RESULT).as_string();
-
- DCHECK(IsColorValid(autocomplete_results_style_.url_color));
- DCHECK(IsColorValid(autocomplete_results_style_.title_color));
-
- string16 contents;
- if (result.search_query.empty()) {
- contents = result.destination_url;
- FormatURLForDisplay(&contents);
- } else {
- contents = result.search_query;
- }
-
- // First, HTML-encode the text so that '&', '<' and such lose their special
- // meaning. Next, URL-encode the text because it will be inserted into
- // "data:" URIs; thus '%' and such lose their special meaning.
- std::string encoded_contents = net::EscapeQueryParamValue(
- net::EscapeForHTML(UTF16ToUTF8(contents)), false);
- std::string encoded_description = net::EscapeQueryParamValue(
- net::EscapeForHTML(UTF16ToUTF8(result.description)), false);
-
- response_html = base::StringPrintf(
- template_html.c_str(),
- embedder_origin.spec().c_str(),
- UTF16ToUTF8(omnibox_font_).c_str(),
- omnibox_font_size_,
- autocomplete_results_style_.url_color,
- autocomplete_results_style_.title_color,
- encoded_contents.c_str(),
- encoded_description.c_str());
- } else {
- response_html = base::StringPrintf(kInvalidSuggestionHtml, restricted_id);
- }
-
- *data_url = GURL("data:text/html;charset=utf-8," + response_html);
- return true;
-}
-
-void SearchBox::SetInstantAutocompleteResultStyle(
- const InstantAutocompleteResultStyle& style) {
- if (IsColorValid(style.url_color) && IsColorValid(style.title_color))
- autocomplete_results_style_ = style;
-}
-
-void SearchBox::FormatURLForDisplay(string16* url) const {
- StripURLPrefixes(url, query());
-
- string16 trimmedUserInput;
- TrimWhitespace(query(), TRIM_LEADING, &trimmedUserInput);
- if (EndsWith(*url, trimmedUserInput, true))
- return;
-
- // Strip a lone trailing slash.
- if (EndsWith(*url, ASCIIToUTF16("/"), true))
- url->erase(url->length() - 1, 1);
-}

Powered by Google App Engine
This is Rietveld 408576698