| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cookies_table_model.h" | 5 #include "chrome/browser/cookies_table_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/table_model_observer.h" | 8 #include "app/table_model_observer.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/browser/net/chrome_url_request_context.h" |
| 11 #include "chrome/browser/profile.h" | 12 #include "chrome/browser/profile.h" |
| 12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 13 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
| 14 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 | 17 |
| 17 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 18 // CookiesTableModel, public: | 19 // CookiesTableModel, public: |
| 19 | 20 |
| 20 CookiesTableModel::CookiesTableModel(Profile* profile) | 21 CookiesTableModel::CookiesTableModel(Profile* profile) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 31 int index) { | 32 int index) { |
| 32 DCHECK(index >= 0 && index < RowCount()); | 33 DCHECK(index >= 0 && index < RowCount()); |
| 33 return shown_cookies_.at(index)->second; | 34 return shown_cookies_.at(index)->second; |
| 34 } | 35 } |
| 35 | 36 |
| 36 void CookiesTableModel::RemoveCookies(int start_index, int remove_count) { | 37 void CookiesTableModel::RemoveCookies(int start_index, int remove_count) { |
| 37 if (remove_count <= 0) { | 38 if (remove_count <= 0) { |
| 38 NOTREACHED(); | 39 NOTREACHED(); |
| 39 return; | 40 return; |
| 40 } | 41 } |
| 41 | 42 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 42 net::CookieMonster* monster = | 43 net::CookieMonster* monster = |
| 43 profile_->GetRequestContext()->cookie_store()->GetCookieMonster(); | 44 profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(); |
| 44 | 45 |
| 45 // We need to update the searched results list, the full cookie list, | 46 // We need to update the searched results list, the full cookie list, |
| 46 // and the view. We walk through the search results list (which is what | 47 // and the view. We walk through the search results list (which is what |
| 47 // is displayed) and map these back to the full cookie list. They should | 48 // is displayed) and map these back to the full cookie list. They should |
| 48 // be in the same sort order, and always exist, so we can just walk once. | 49 // be in the same sort order, and always exist, so we can just walk once. |
| 49 // We can't delete any entries from all_cookies_ without invaliding all of | 50 // We can't delete any entries from all_cookies_ without invaliding all of |
| 50 // our pointers after it (which are in shown_cookies), so we go backwards. | 51 // our pointers after it (which are in shown_cookies), so we go backwards. |
| 51 CookiePtrList::iterator first = shown_cookies_.begin() + start_index; | 52 CookiePtrList::iterator first = shown_cookies_.begin() + start_index; |
| 52 CookiePtrList::iterator last = first + remove_count; | 53 CookiePtrList::iterator last = first + remove_count; |
| 53 CookieList::iterator all_it = all_cookies_.end(); | 54 CookieList::iterator all_it = all_cookies_.end(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 const std::string& domain, | 152 const std::string& domain, |
| 152 const net::CookieMonster::CanonicalCookie& cookie, | 153 const net::CookieMonster::CanonicalCookie& cookie, |
| 153 const std::string& filter) { | 154 const std::string& filter) { |
| 154 return domain.find(filter) != std::string::npos || | 155 return domain.find(filter) != std::string::npos || |
| 155 cookie.Name().find(filter) != std::string::npos || | 156 cookie.Name().find(filter) != std::string::npos || |
| 156 cookie.Value().find(filter) != std::string::npos; | 157 cookie.Value().find(filter) != std::string::npos; |
| 157 } | 158 } |
| 158 | 159 |
| 159 void CookiesTableModel::LoadCookies() { | 160 void CookiesTableModel::LoadCookies() { |
| 160 // mmargh mmargh mmargh! | 161 // mmargh mmargh mmargh! |
| 162 |
| 163 // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 161 net::CookieMonster* cookie_monster = | 164 net::CookieMonster* cookie_monster = |
| 162 profile_->GetRequestContext()->cookie_store()->GetCookieMonster(); | 165 profile_->GetRequestContext()->GetCookieStore()->GetCookieMonster(); |
| 166 |
| 163 all_cookies_ = cookie_monster->GetAllCookies(); | 167 all_cookies_ = cookie_monster->GetAllCookies(); |
| 164 DoFilter(); | 168 DoFilter(); |
| 165 } | 169 } |
| 166 | 170 |
| 167 void CookiesTableModel::DoFilter() { | 171 void CookiesTableModel::DoFilter() { |
| 168 std::string utf8_filter = WideToUTF8(filter_); | 172 std::string utf8_filter = WideToUTF8(filter_); |
| 169 bool has_filter = !utf8_filter.empty(); | 173 bool has_filter = !utf8_filter.empty(); |
| 170 | 174 |
| 171 shown_cookies_.clear(); | 175 shown_cookies_.clear(); |
| 172 | 176 |
| 173 CookieList::iterator iter = all_cookies_.begin(); | 177 CookieList::iterator iter = all_cookies_.begin(); |
| 174 for (; iter != all_cookies_.end(); ++iter) { | 178 for (; iter != all_cookies_.end(); ++iter) { |
| 175 if (!has_filter || | 179 if (!has_filter || |
| 176 ContainsFilterText(iter->first, iter->second, utf8_filter)) { | 180 ContainsFilterText(iter->first, iter->second, utf8_filter)) { |
| 177 shown_cookies_.push_back(&*iter); | 181 shown_cookies_.push_back(&*iter); |
| 178 } | 182 } |
| 179 } | 183 } |
| 180 } | 184 } |
| 181 | 185 |
| 182 void CookiesTableModel::UpdateSearchResults(const std::wstring& filter) { | 186 void CookiesTableModel::UpdateSearchResults(const std::wstring& filter) { |
| 183 filter_ = filter; | 187 filter_ = filter; |
| 184 DoFilter(); | 188 DoFilter(); |
| 185 observer_->OnModelChanged(); | 189 observer_->OnModelChanged(); |
| 186 } | 190 } |
| OLD | NEW |