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

Side by Side Diff: chrome/browser/dom_ui/new_tab_ui.cc

Issue 42566: Fixes crash in new tab page when searching from a field other than the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/dom_ui/new_tab_ui.h" 7 #include "chrome/browser/dom_ui/new_tab_ui.h"
8 8
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 } 537 }
538 const TemplateURLRef* url_ref = template_url->url(); 538 const TemplateURLRef* url_ref = template_url->url();
539 if (!url_ref || !url_ref->SupportsReplacement()) { 539 if (!url_ref || !url_ref->SupportsReplacement()) {
540 NOTREACHED(); 540 NOTREACHED();
541 return; 541 return;
542 } 542 }
543 GURL url = url_ref->ReplaceSearchTerms(*template_url, search, 543 GURL url = url_ref->ReplaceSearchTerms(*template_url, search,
544 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); 544 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring());
545 545
546 if (url.is_valid()) { 546 if (url.is_valid()) {
547 // Load the URL.
548 dom_ui_->web_contents()->OpenURL(url, GURL(), CURRENT_TAB,
549 PageTransition::LINK);
550
551 // Record the user action 547 // Record the user action
552 std::vector<const TemplateURL*> urls = 548 std::vector<const TemplateURL*> urls =
553 template_url_model_->GetTemplateURLs(); 549 template_url_model_->GetTemplateURLs();
554 sort(urls.begin(), urls.end(), TemplateURLSortByUsage); 550 sort(urls.begin(), urls.end(), TemplateURLSortByUsage);
555 ListValue urls_value; 551 ListValue urls_value;
556 int item_number = 0; 552 int item_number = 0;
557 for (size_t i = 0; 553 for (size_t i = 0;
558 i < std::min<size_t>(urls.size(), kSearchURLs); ++i) { 554 i < std::min<size_t>(urls.size(), kSearchURLs); ++i) {
559 if (urls[i]->usage_count() == 0) 555 if (urls[i]->usage_count() == 0)
560 break; // The remainder would be no good. 556 break; // The remainder would be no good.
561 557
562 const TemplateURLRef* urlref = urls[i]->url(); 558 const TemplateURLRef* urlref = urls[i]->url();
563 if (!urlref) 559 if (!urlref)
564 continue; 560 continue;
565 561
566 if (urls[i] == template_url) { 562 if (urls[i] == template_url) {
567 UserMetrics::RecordComputedAction( 563 UserMetrics::RecordComputedAction(
568 StringPrintf(L"NTP_SearchURL%d", item_number), 564 StringPrintf(L"NTP_SearchURL%d", item_number),
569 dom_ui_->GetProfile()); 565 dom_ui_->GetProfile());
570 break; 566 break;
571 } 567 }
572 568
573 item_number++; 569 item_number++;
574 } 570 }
571
572 // Load the URL.
573 dom_ui_->web_contents()->OpenURL(url, GURL(), CURRENT_TAB,
574 PageTransition::LINK);
575 // We've been deleted.
576 return;
575 } 577 }
576 } 578 }
577 579
578 void TemplateURLHandler::OnTemplateURLModelChanged() { 580 void TemplateURLHandler::OnTemplateURLModelChanged() {
579 // We've loaded some template URLs. Send them to the page. 581 // We've loaded some template URLs. Send them to the page.
580 std::vector<const TemplateURL*> urls = template_url_model_->GetTemplateURLs(); 582 std::vector<const TemplateURL*> urls = template_url_model_->GetTemplateURLs();
581 sort(urls.begin(), urls.end(), TemplateURLSortByUsage); 583 sort(urls.begin(), urls.end(), TemplateURLSortByUsage);
582 ListValue urls_value; 584 ListValue urls_value;
583 for (size_t i = 0; i < std::min<size_t>(urls.size(), kSearchURLs); ++i) { 585 for (size_t i = 0; i < std::min<size_t>(urls.size(), kSearchURLs); ++i) {
584 if (urls[i]->usage_count() == 0) 586 if (urls[i]->usage_count() == 0)
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 #endif 1064 #endif
1063 1065
1064 NewTabHTMLSource* html_source = new NewTabHTMLSource(); 1066 NewTabHTMLSource* html_source = new NewTabHTMLSource();
1065 1067
1066 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 1068 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
1067 NewRunnableMethod(&chrome_url_data_manager, 1069 NewRunnableMethod(&chrome_url_data_manager,
1068 &ChromeURLDataManager::AddDataSource, 1070 &ChromeURLDataManager::AddDataSource,
1069 html_source)); 1071 html_source));
1070 } 1072 }
1071 } 1073 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698