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

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

Issue 2078021: First pass at experimental omnibox API. There are plenty of rough edges and (Closed)
Patch Set: no prefer_keyword Created 10 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/autocomplete/keyword_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_edit.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/app/chrome_dll_resource.h" 12 #include "chrome/app/chrome_dll_resource.h"
13 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 13 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
14 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 14 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
16 #include "chrome/browser/autocomplete/keyword_provider.h" 16 #include "chrome/browser/autocomplete/keyword_provider.h"
17 #include "chrome/browser/command_updater.h" 17 #include "chrome/browser/command_updater.h"
18 #include "chrome/browser/extensions/extension_omnibox_api.h"
18 #include "chrome/browser/metrics/user_metrics.h" 19 #include "chrome/browser/metrics/user_metrics.h"
19 #include "chrome/browser/net/dns_global.h" 20 #include "chrome/browser/net/dns_global.h"
20 #include "chrome/browser/net/url_fixer_upper.h" 21 #include "chrome/browser/net/url_fixer_upper.h"
21 #include "chrome/browser/profile.h" 22 #include "chrome/browser/profile.h"
22 #include "chrome/browser/search_engines/template_url.h" 23 #include "chrome/browser/search_engines/template_url.h"
23 #include "chrome/browser/search_engines/template_url_model.h" 24 #include "chrome/browser/search_engines/template_url_model.h"
24 #include "chrome/common/notification_service.h" 25 #include "chrome/common/notification_service.h"
25 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
26 #include "googleurl/src/gurl.h" 27 #include "googleurl/src/gurl.h"
27 #include "googleurl/src/url_util.h" 28 #include "googleurl/src/url_util.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 paste_and_go_alternate_nav_url_, AutocompletePopupModel::kNoMatch, 259 paste_and_go_alternate_nav_url_, AutocompletePopupModel::kNoMatch,
259 std::wstring()); 260 std::wstring());
260 } 261 }
261 262
262 void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition, 263 void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition,
263 bool for_drop) { 264 bool for_drop) {
264 // Get the URL and transition type for the selected entry. 265 // Get the URL and transition type for the selected entry.
265 AutocompleteMatch match; 266 AutocompleteMatch match;
266 GURL alternate_nav_url; 267 GURL alternate_nav_url;
267 GetInfoForCurrentText(&match, &alternate_nav_url); 268 GetInfoForCurrentText(&match, &alternate_nav_url);
269
270 if (match.template_url && match.template_url->IsExtensionKeyword()) {
271 // Strip the keyword + leading space off the input.
272 size_t prefix_length = match.template_url->keyword().size() + 1;
273 ExtensionOmniboxEventRouter::OnInputEntered(
274 profile_, match.template_url->GetExtensionId(),
275 WideToUTF8(match.fill_into_edit.substr(prefix_length)));
276 view_->RevertAll();
277 return;
278 }
279
268 if (!match.destination_url.is_valid()) 280 if (!match.destination_url.is_valid())
269 return; 281 return;
270 282
271 if (UTF8ToWide(match.destination_url.spec()) == permanent_text_) { 283 if (UTF8ToWide(match.destination_url.spec()) == permanent_text_) {
272 // When the user hit enter on the existing permanent URL, treat it like a 284 // When the user hit enter on the existing permanent URL, treat it like a
273 // reload for scoring purposes. We could detect this by just checking 285 // reload for scoring purposes. We could detect this by just checking
274 // user_input_in_progress_, but it seems better to treat "edits" that end 286 // user_input_in_progress_, but it seems better to treat "edits" that end
275 // up leaving the URL unchanged (e.g. deleting the last character and then 287 // up leaving the URL unchanged (e.g. deleting the last character and then
276 // retyping it) as reloads too. 288 // retyping it) as reloads too.
277 match.transition = PageTransition::RELOAD; 289 match.transition = PageTransition::RELOAD;
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 bool is_keyword_hint = false; 611 bool is_keyword_hint = false;
600 const AutocompleteResult* result = 612 const AutocompleteResult* result =
601 Details<const AutocompleteResult>(details).ptr(); 613 Details<const AutocompleteResult>(details).ptr();
602 const AutocompleteResult::const_iterator match(result->default_match()); 614 const AutocompleteResult::const_iterator match(result->default_match());
603 if (match != result->end()) { 615 if (match != result->end()) {
604 if ((match->inline_autocomplete_offset != std::wstring::npos) && 616 if ((match->inline_autocomplete_offset != std::wstring::npos) &&
605 (match->inline_autocomplete_offset < match->fill_into_edit.length())) { 617 (match->inline_autocomplete_offset < match->fill_into_edit.length())) {
606 inline_autocomplete_text = 618 inline_autocomplete_text =
607 match->fill_into_edit.substr(match->inline_autocomplete_offset); 619 match->fill_into_edit.substr(match->inline_autocomplete_offset);
608 } 620 }
609 // Warm up DNS Prefetch Cache. 621
610 chrome_browser_net::DnsPrefetchUrl(match->destination_url, 622 if (!match->destination_url.SchemeIs(chrome::kExtensionScheme)) {
611 IsPreconnectable(match->type)); 623 // Warm up DNS Prefetch Cache.
624 chrome_browser_net::DnsPrefetchUrl(match->destination_url,
625 IsPreconnectable(match->type));
626 }
627
612 // We could prefetch the alternate nav URL, if any, but because there 628 // We could prefetch the alternate nav URL, if any, but because there
613 // can be many of these as a user types an initial series of characters, 629 // can be many of these as a user types an initial series of characters,
614 // the OS DNS cache could suffer eviction problems for minimal gain. 630 // the OS DNS cache could suffer eviction problems for minimal gain.
615 631
616 is_keyword_hint = popup_->GetKeywordForMatch(*match, &keyword); 632 is_keyword_hint = popup_->GetKeywordForMatch(*match, &keyword);
617 } 633 }
618 634
619 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, is_keyword_hint); 635 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, is_keyword_hint);
620 } 636 }
621 637
(...skipping 21 matching lines...) Expand all
643 AutocompleteMatch* match, 659 AutocompleteMatch* match,
644 GURL* alternate_nav_url) const { 660 GURL* alternate_nav_url) const {
645 if (popup_->IsOpen() || query_in_progress()) { 661 if (popup_->IsOpen() || query_in_progress()) {
646 popup_->InfoForCurrentSelection(match, alternate_nav_url); 662 popup_->InfoForCurrentSelection(match, alternate_nav_url);
647 } else { 663 } else {
648 profile_->GetAutocompleteClassifier()->Classify( 664 profile_->GetAutocompleteClassifier()->Classify(
649 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), match, 665 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), match,
650 alternate_nav_url); 666 alternate_nav_url);
651 } 667 }
652 } 668 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/autocomplete/keyword_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698