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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_input.cc

Issue 55603002: Move HasHTTPScheme to AutocompleteInput. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/browser/autocomplete/autocomplete_input.h" 5 #include "chrome/browser/autocomplete/autocomplete_input.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/external_protocol/external_protocol_handler.h" 9 #include "chrome/browser/external_protocol/external_protocol_handler.h"
10 #include "chrome/browser/profiles/profile_io_data.h" 10 #include "chrome/browser/profiles/profile_io_data.h"
11 #include "chrome/common/net/url_fixer_upper.h" 11 #include "chrome/common/net/url_fixer_upper.h"
12 #include "content/public/common/url_constants.h" 12 #include "content/public/common/url_constants.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
15 #include "url/url_canon_ip.h" 15 #include "url/url_canon_ip.h"
16 #include "url/url_util.h"
16 17
17 namespace { 18 namespace {
18 19
19 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, 20 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed,
20 size_t* cursor_position) { 21 size_t* cursor_position) {
21 if (*cursor_position == string16::npos) 22 if (*cursor_position == string16::npos)
22 return; 23 return;
23 if (num_leading_chars_removed < *cursor_position) 24 if (num_leading_chars_removed < *cursor_position)
24 *cursor_position -= num_leading_chars_removed; 25 *cursor_position -= num_leading_chars_removed;
25 else 26 else
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 ++num_nonhost_components; 491 ++num_nonhost_components;
491 if (parts.path.is_nonempty()) 492 if (parts.path.is_nonempty())
492 ++num_nonhost_components; 493 ++num_nonhost_components;
493 if (parts.query.is_nonempty()) 494 if (parts.query.is_nonempty())
494 ++num_nonhost_components; 495 ++num_nonhost_components;
495 if (parts.ref.is_nonempty()) 496 if (parts.ref.is_nonempty())
496 ++num_nonhost_components; 497 ++num_nonhost_components;
497 return num_nonhost_components; 498 return num_nonhost_components;
498 } 499 }
499 500
501 // static
502 bool AutocompleteInput::HasHTTPScheme(const string16& input) {
503 std::string utf8_input(UTF16ToUTF8(input));
504 url_parse::Component scheme;
505 if (url_util::FindAndCompareScheme(utf8_input, content::kViewSourceScheme,
506 &scheme))
507 utf8_input.erase(0, scheme.end() + 1);
508 return url_util::FindAndCompareScheme(utf8_input, content::kHttpScheme, NULL);
509 }
510
500 void AutocompleteInput::UpdateText(const string16& text, 511 void AutocompleteInput::UpdateText(const string16& text,
501 size_t cursor_position, 512 size_t cursor_position,
502 const url_parse::Parsed& parts) { 513 const url_parse::Parsed& parts) {
503 DCHECK(cursor_position <= text.length() || cursor_position == string16::npos) 514 DCHECK(cursor_position <= text.length() || cursor_position == string16::npos)
504 << "Text: '" << text << "', cp: " << cursor_position; 515 << "Text: '" << text << "', cp: " << cursor_position;
505 text_ = text; 516 text_ = text;
506 cursor_position_ = cursor_position; 517 cursor_position_ = cursor_position;
507 parts_ = parts; 518 parts_ = parts;
508 } 519 }
509 520
510 void AutocompleteInput::Clear() { 521 void AutocompleteInput::Clear() {
511 text_.clear(); 522 text_.clear();
512 cursor_position_ = string16::npos; 523 cursor_position_ = string16::npos;
513 current_url_ = GURL(); 524 current_url_ = GURL();
514 current_page_classification_ = AutocompleteInput::INVALID_SPEC; 525 current_page_classification_ = AutocompleteInput::INVALID_SPEC;
515 type_ = INVALID; 526 type_ = INVALID;
516 parts_ = url_parse::Parsed(); 527 parts_ = url_parse::Parsed();
517 scheme_.clear(); 528 scheme_.clear();
518 canonicalized_url_ = GURL(); 529 canonicalized_url_ = GURL();
519 prevent_inline_autocomplete_ = false; 530 prevent_inline_autocomplete_ = false;
520 prefer_keyword_ = false; 531 prefer_keyword_ = false;
521 allow_exact_keyword_match_ = false; 532 allow_exact_keyword_match_ = false;
522 matches_requested_ = ALL_MATCHES; 533 matches_requested_ = ALL_MATCHES;
523 } 534 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_input.h ('k') | chrome/browser/autocomplete/autocomplete_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698