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

Side by Side Diff: chrome/browser/custom_home_pages_table_model.cc

Issue 26887002: Fix crash when drag moving URLs in chrome://settings/startup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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) 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/custom_home_pages_table_model.h" 5 #include "chrome/browser/custom_home_pages_table_model.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 /** 90 /**
91 * Move a number of existing entries to a new position, reordering the table. 91 * Move a number of existing entries to a new position, reordering the table.
92 * 92 *
93 * We determine the range of elements affected by the move, save the moved 93 * We determine the range of elements affected by the move, save the moved
94 * elements, compact the remaining ones, and re-insert moved elements. 94 * elements, compact the remaining ones, and re-insert moved elements.
95 * Expects |index_list| to be ordered ascending. 95 * Expects |index_list| to be ordered ascending.
96 */ 96 */
97 void CustomHomePagesTableModel::MoveURLs(int insert_before, 97 void CustomHomePagesTableModel::MoveURLs(int insert_before,
98 const std::vector<int>& index_list) { 98 const std::vector<int>& index_list) {
99 DCHECK(!index_list.empty());
100 DCHECK(insert_before >= 0 && insert_before <= RowCount()); 99 DCHECK(insert_before >= 0 && insert_before <= RowCount());
101 100
101 // This is a bug. This should be a DCHECK, but under circumstances, the JS can
102 // get confused and pass us an empty list of selected indices to drag move.
Dan Beam 2013/10/14 18:08:07 Are you sure it's the WebUI's fault? This can only
103 // See http://crbug.com/302284.
104 if (index_list.empty())
Dan Beam 2013/10/14 18:08:07 NOTREACHED();
105 return;
106
102 // The range of elements that needs to be reshuffled is [ |first|, |last| ). 107 // The range of elements that needs to be reshuffled is [ |first|, |last| ).
103 int first = std::min(insert_before, index_list.front()); 108 int first = std::min(insert_before, index_list.front());
104 int last = std::max(insert_before, index_list.back() + 1); 109 int last = std::max(insert_before, index_list.back() + 1);
105 110
106 // Save the dragged elements. Also, adjust insertion point if it is before a 111 // Save the dragged elements. Also, adjust insertion point if it is before a
107 // dragged element. 112 // dragged element.
108 std::vector<Entry> moved_entries; 113 std::vector<Entry> moved_entries;
109 for (size_t i = 0; i < index_list.size(); ++i) { 114 for (size_t i = 0; i < index_list.size(); ++i) {
110 moved_entries.push_back(entries_[index_list[i]]); 115 moved_entries.push_back(entries_[index_list[i]]);
111 if (index_list[i] == insert_before) 116 if (index_list[i] == insert_before)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 return NULL; 269 return NULL;
265 } 270 }
266 271
267 string16 CustomHomePagesTableModel::FormattedURL(int row) const { 272 string16 CustomHomePagesTableModel::FormattedURL(int row) const {
268 std::string languages = 273 std::string languages =
269 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); 274 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
270 string16 url = net::FormatUrl(entries_[row].url, languages); 275 string16 url = net::FormatUrl(entries_[row].url, languages);
271 url = base::i18n::GetDisplayStringInLTRDirectionality(url); 276 url = base::i18n::GetDisplayStringInLTRDirectionality(url);
272 return url; 277 return url;
273 } 278 }
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