| OLD | NEW |
| 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/page_info_model.h" | 5 #include "chrome/browser/page_info_model.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/cert_store.h" | 13 #include "chrome/browser/cert_store.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ssl/ssl_error_info.h" | 15 #include "chrome/browser/ssl/ssl_error_info.h" |
| 16 #include "chrome/browser/ssl/ssl_manager.h" | 16 #include "chrome/browser/ssl/ssl_manager.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 19 #include "net/base/cert_status_flags.h" | 19 #include "net/base/cert_status_flags.h" |
| 20 #include "net/base/ssl_connection_status_flags.h" | 20 #include "net/base/ssl_connection_status_flags.h" |
| 21 #include "net/base/ssl_cipher_suite_names.h" | 21 #include "net/base/ssl_cipher_suite_names.h" |
| 22 #include "net/base/x509_certificate.h" | 22 #include "net/base/x509_certificate.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 25 | 25 |
| 26 #if defined(OS_MACOSX) | |
| 27 #include "base/mac/mac_util.h" | |
| 28 #endif | |
| 29 | |
| 30 PageInfoModel::PageInfoModel(Profile* profile, | 26 PageInfoModel::PageInfoModel(Profile* profile, |
| 31 const GURL& url, | 27 const GURL& url, |
| 32 const NavigationEntry::SSLStatus& ssl, | 28 const NavigationEntry::SSLStatus& ssl, |
| 33 bool show_history, | 29 bool show_history, |
| 34 PageInfoModelObserver* observer) | 30 PageInfoModelObserver* observer) |
| 35 : observer_(observer) { | 31 : observer_(observer) { |
| 36 Init(); | 32 Init(); |
| 37 | 33 |
| 38 SectionStateIcon icon_id = ICON_STATE_OK; | 34 SectionStateIcon icon_id = ICON_STATE_OK; |
| 39 string16 headline; | 35 string16 headline; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 HistoryService* history = profile->GetHistoryService( | 269 HistoryService* history = profile->GetHistoryService( |
| 274 Profile::EXPLICIT_ACCESS); | 270 Profile::EXPLICIT_ACCESS); |
| 275 if (show_history && history) { | 271 if (show_history && history) { |
| 276 history->GetVisitCountToHost( | 272 history->GetVisitCountToHost( |
| 277 url, | 273 url, |
| 278 &request_consumer_, | 274 &request_consumer_, |
| 279 NewCallback(this, &PageInfoModel::OnGotVisitCountToHost)); | 275 NewCallback(this, &PageInfoModel::OnGotVisitCountToHost)); |
| 280 } | 276 } |
| 281 } | 277 } |
| 282 | 278 |
| 283 PageInfoModel::~PageInfoModel() { | |
| 284 #if defined(OS_MACOSX) | |
| 285 // Release the NSImages. | |
| 286 for (std::vector<gfx::NativeImage>::iterator it = icons_.begin(); | |
| 287 it != icons_.end(); ++it) { | |
| 288 base::mac::NSObjectRelease(*it); | |
| 289 } | |
| 290 #endif | |
| 291 } | |
| 292 | |
| 293 int PageInfoModel::GetSectionCount() { | 279 int PageInfoModel::GetSectionCount() { |
| 294 return sections_.size(); | 280 return sections_.size(); |
| 295 } | 281 } |
| 296 | 282 |
| 297 PageInfoModel::SectionInfo PageInfoModel::GetSectionInfo(int index) { | 283 PageInfoModel::SectionInfo PageInfoModel::GetSectionInfo(int index) { |
| 298 DCHECK(index < static_cast<int>(sections_.size())); | 284 DCHECK(index < static_cast<int>(sections_.size())); |
| 299 return sections_[index]; | 285 return sections_[index]; |
| 300 } | 286 } |
| 301 | 287 |
| 302 gfx::NativeImage PageInfoModel::GetIconImage(SectionStateIcon icon_id) { | 288 gfx::Image* PageInfoModel::GetIconImage(SectionStateIcon icon_id) { |
| 303 if (icon_id == ICON_NONE) | 289 if (icon_id == ICON_NONE) |
| 304 return NULL; | 290 return NULL; |
| 305 // The bubble uses new, various icons. | 291 // The bubble uses new, various icons. |
| 306 return icons_[icon_id]; | 292 return icons_[icon_id]; |
| 307 } | 293 } |
| 308 | 294 |
| 309 void PageInfoModel::OnGotVisitCountToHost(HistoryService::Handle handle, | 295 void PageInfoModel::OnGotVisitCountToHost(HistoryService::Handle handle, |
| 310 bool found_visits, | 296 bool found_visits, |
| 311 int count, | 297 int count, |
| 312 base::Time first_visit) { | 298 base::Time first_visit) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 343 observer_->ModelChanged(); | 329 observer_->ModelChanged(); |
| 344 } | 330 } |
| 345 | 331 |
| 346 PageInfoModel::PageInfoModel() : observer_(NULL) { | 332 PageInfoModel::PageInfoModel() : observer_(NULL) { |
| 347 Init(); | 333 Init(); |
| 348 } | 334 } |
| 349 | 335 |
| 350 void PageInfoModel::Init() { | 336 void PageInfoModel::Init() { |
| 351 // Loads the icons into the vector. The order must match the SectionStateIcon | 337 // Loads the icons into the vector. The order must match the SectionStateIcon |
| 352 // enum. | 338 // enum. |
| 353 icons_.push_back(GetBitmapNamed(IDR_PAGEINFO_GOOD)); | 339 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 354 icons_.push_back(GetBitmapNamed(IDR_PAGEINFO_WARNING_MINOR)); | 340 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_GOOD)); |
| 355 icons_.push_back(GetBitmapNamed(IDR_PAGEINFO_WARNING_MAJOR)); | 341 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_WARNING_MINOR)); |
| 356 icons_.push_back(GetBitmapNamed(IDR_PAGEINFO_BAD)); | 342 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_WARNING_MAJOR)); |
| 357 icons_.push_back(GetBitmapNamed(IDR_PAGEINFO_INFO)); | 343 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_BAD)); |
| 344 icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_INFO)); |
| 358 } | 345 } |
| 359 | |
| 360 gfx::NativeImage PageInfoModel::GetBitmapNamed(int resource_id) { | |
| 361 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 362 gfx::NativeImage image = rb.GetNativeImageNamed(resource_id); | |
| 363 #if defined(OS_MACOSX) | |
| 364 // Unlike other platforms, the Mac ResourceBundle does not keep a shared image | |
| 365 // cache. These are released in the dtor. | |
| 366 base::mac::NSObjectRetain(image); | |
| 367 #endif | |
| 368 return image; | |
| 369 } | |
| OLD | NEW |