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

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: virtual Created 7 years, 8 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
« no previous file with comments | « chrome/renderer/searchbox/searchbox.h ('k') | chrome/renderer/searchbox/searchbox_extension.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/searchbox/searchbox.cc
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index b48c383b1131ee5dd151337fb4e9f8fe36c0657b..2483b30b6bf7e6d8d4f2cb8fa48d8e583f45cc18 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -4,7 +4,6 @@
#include "chrome/renderer/searchbox/searchbox.h"
-#include "base/metrics/field_trial.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_switches.h"
@@ -25,37 +24,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)
@@ -424,112 +392,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);
-
- if (!ShouldUseIframes())
- return false;
-
- // 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);
-}
-
-// static
-bool SearchBox::ShouldUseIframes() {
- // TODO(shishir): All the code below is just temporary and needs to be removed
- // once support for ShadowDom is removed.
-
- // The following is hacky. But given the short lifespan of this code
- // and the amount of code that would need to be moved/copied for this change,
- // it's probably worth it.
- static const char kInstantExtendedFieldTrialName[] = "InstantExtended";
- static const char kIframesEnabledFlagWithValue[] = "iframe:1";
- std::string trial_flags =
- base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName);
- std::vector<std::string> flags;
- Tokenize(trial_flags, " ", &flags);
- for (size_t i = 0; i < flags.size(); ++i) {
- if (flags[i] == kIframesEnabledFlagWithValue)
- return true;
- }
- return false;
-}
« no previous file with comments | « chrome/renderer/searchbox/searchbox.h ('k') | chrome/renderer/searchbox/searchbox_extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698