Commit 1710969d authored by manuk's avatar manuk Committed by Commit Bot

Omnibox: Disable Paste & Go for clipboard contents over 32KB

Opening omnibox context menu when clipboard contains over 32K characters caused chrome to freeze up for ~1 minute.
Other performance issues remain outside of the 'is paste & go allowed' checking and large clipboard sizes (.5 - 1 million characters) still cause freezing for ~10 seconds.

Bug: 277732
Change-Id: I7d130ef4e1668f6e73b2c670143ed69f7309cc6d
Reviewed-on: https://chromium-review.googlesource.com/1089193
Commit-Queue: manuk hovanesian <manukh@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565622}
parent 073e1952
...@@ -444,6 +444,9 @@ bool OmniboxEditModel::CanPasteAndGo(const base::string16& text) const { ...@@ -444,6 +444,9 @@ bool OmniboxEditModel::CanPasteAndGo(const base::string16& text) const {
if (!client_->IsPasteAndGoEnabled()) if (!client_->IsPasteAndGoEnabled())
return false; return false;
if (text.length() > kMaxPasteAndGoTextLength)
return false;
AutocompleteMatch match; AutocompleteMatch match;
ClassifyString(text, &match, nullptr); ClassifyString(text, &match, nullptr);
return match.destination_url.is_valid(); return match.destination_url.is_valid();
...@@ -622,17 +625,12 @@ void OmniboxEditModel::OpenMatch(AutocompleteMatch match, ...@@ -622,17 +625,12 @@ void OmniboxEditModel::OpenMatch(AutocompleteMatch match,
fake_single_entry_result.AppendMatches(input_, fake_single_entry_matches); fake_single_entry_result.AppendMatches(input_, fake_single_entry_matches);
OmniboxLog log( OmniboxLog log(
input_.from_omnibox_focus() ? base::string16() : input_text, input_.from_omnibox_focus() ? base::string16() : input_text,
just_deleted_text_, just_deleted_text_, input_.type(), popup_open,
input_.type(), dropdown_ignored ? 0 : index, disposition, !pasted_text.empty(),
popup_open, SessionID::InvalidValue(), // don't know tab ID; set later if appropriate
dropdown_ignored ? 0 : index, ClassifyPage(), elapsed_time_since_user_first_modified_omnibox,
disposition, match.allowed_to_be_default_match ? match.inline_autocompletion.length()
!pasted_text.empty(), : base::string16::npos,
SessionID::InvalidValue(), // don't know tab ID; set later if appropriate
ClassifyPage(),
elapsed_time_since_user_first_modified_omnibox,
match.allowed_to_be_default_match ? match.inline_autocompletion.length() :
base::string16::npos,
elapsed_time_since_last_change_to_default_match, elapsed_time_since_last_change_to_default_match,
dropdown_ignored ? fake_single_entry_result : result()); dropdown_ignored ? fake_single_entry_result : result());
DCHECK(dropdown_ignored || DCHECK(dropdown_ignored ||
......
...@@ -81,6 +81,11 @@ class OmniboxEditModel { ...@@ -81,6 +81,11 @@ class OmniboxEditModel {
const AutocompleteInput autocomplete_input; const AutocompleteInput autocomplete_input;
}; };
// This is a mirror of content::kMaxURLDisplayChars because ios cannot depend
// on content. If clipboard contains more than kMaxPasteAndGoTextLength
// characters, then the paste & go option will be disabled.
static const size_t kMaxPasteAndGoTextLength = 32 * 1024;
OmniboxEditModel(OmniboxView* view, OmniboxEditModel(OmniboxView* view,
OmniboxEditController* controller, OmniboxEditController* controller,
std::unique_ptr<OmniboxClient> client); std::unique_ptr<OmniboxClient> client);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stddef.h> #include <stddef.h>
#include <memory> #include <memory>
#include <string>
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
...@@ -260,3 +261,16 @@ TEST_F(OmniboxEditModelTest, GenerateMatchesFromFullFormattedUrl) { ...@@ -260,3 +261,16 @@ TEST_F(OmniboxEditModelTest, GenerateMatchesFromFullFormattedUrl) {
AutocompleteMatch match = model()->OmniboxEditModel::CurrentMatch(nullptr); AutocompleteMatch match = model()->OmniboxEditModel::CurrentMatch(nullptr);
EXPECT_EQ(AutocompleteMatchType::URL_WHAT_YOU_TYPED, match.type); EXPECT_EQ(AutocompleteMatchType::URL_WHAT_YOU_TYPED, match.type);
} }
TEST_F(OmniboxEditModelTest, DisablePasteAndGoForLongTexts) {
EXPECT_TRUE(model()->OmniboxEditModel::CanPasteAndGo(
base::ASCIIToUTF16("short text")));
base::string16 almost_long_text = base::ASCIIToUTF16(
std::string(OmniboxEditModel::kMaxPasteAndGoTextLength, '.'));
EXPECT_TRUE(model()->OmniboxEditModel::CanPasteAndGo(almost_long_text));
base::string16 long_text = base::ASCIIToUTF16(
std::string(OmniboxEditModel::kMaxPasteAndGoTextLength + 1, '.'));
EXPECT_FALSE(model()->OmniboxEditModel::CanPasteAndGo(long_text));
}
...@@ -61,6 +61,10 @@ TestOmniboxClient::CreateOmniboxNavigationObserver( ...@@ -61,6 +61,10 @@ TestOmniboxClient::CreateOmniboxNavigationObserver(
return nullptr; return nullptr;
} }
bool TestOmniboxClient::IsPasteAndGoEnabled() const {
return true;
}
const SessionID& TestOmniboxClient::GetSessionID() const { const SessionID& TestOmniboxClient::GetSessionID() const {
return session_id_; return session_id_;
} }
......
...@@ -34,6 +34,7 @@ class TestOmniboxClient : public OmniboxClient { ...@@ -34,6 +34,7 @@ class TestOmniboxClient : public OmniboxClient {
const base::string16& text, const base::string16& text,
const AutocompleteMatch& match, const AutocompleteMatch& match,
const AutocompleteMatch& alternate_nav_match) override; const AutocompleteMatch& alternate_nav_match) override;
bool IsPasteAndGoEnabled() const override;
const SessionID& GetSessionID() const override; const SessionID& GetSessionID() const override;
const AutocompleteSchemeClassifier& GetSchemeClassifier() const override; const AutocompleteSchemeClassifier& GetSchemeClassifier() const override;
AutocompleteClassifier* GetAutocompleteClassifier() override; AutocompleteClassifier* GetAutocompleteClassifier() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment