| OLD | NEW | 
|---|
|  | (Empty) | 
| 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 |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #include "chrome/browser/toolbar_model.h" |  | 
| 6 |  | 
| 7 #include "base/utf_string_conversions.h" |  | 
| 8 #include "chrome/browser/autocomplete/autocomplete.h" |  | 
| 9 #include "chrome/browser/autocomplete/autocomplete_edit.h" |  | 
| 10 #include "chrome/browser/cert_store.h" |  | 
| 11 #include "chrome/browser/prefs/pref_service.h" |  | 
| 12 #include "chrome/browser/profile.h" |  | 
| 13 #include "chrome/browser/ssl/ssl_error_info.h" |  | 
| 14 #include "chrome/browser/tab_contents/navigation_controller.h" |  | 
| 15 #include "chrome/browser/tab_contents/navigation_entry.h" |  | 
| 16 #include "chrome/browser/tab_contents/tab_contents.h" |  | 
| 17 #include "chrome/browser/ui/browser.h" |  | 
| 18 #include "chrome/common/chrome_constants.h" |  | 
| 19 #include "chrome/common/pref_names.h" |  | 
| 20 #include "chrome/common/url_constants.h" |  | 
| 21 #include "grit/generated_resources.h" |  | 
| 22 #include "grit/theme_resources.h" |  | 
| 23 #include "net/base/cert_status_flags.h" |  | 
| 24 #include "net/base/net_util.h" |  | 
| 25 |  | 
| 26 ToolbarModel::ToolbarModel(Browser* browser) |  | 
| 27     : browser_(browser), |  | 
| 28       input_in_progress_(false) { |  | 
| 29 } |  | 
| 30 |  | 
| 31 ToolbarModel::~ToolbarModel() { |  | 
| 32 } |  | 
| 33 |  | 
| 34 // ToolbarModel Implementation. |  | 
| 35 std::wstring ToolbarModel::GetText() const { |  | 
| 36   GURL url(chrome::kAboutBlankURL); |  | 
| 37   std::string languages;  // Empty if we don't have a |navigation_controller|. |  | 
| 38 |  | 
| 39   NavigationController* navigation_controller = GetNavigationController(); |  | 
| 40   if (navigation_controller) { |  | 
| 41     languages = navigation_controller->profile()->GetPrefs()->GetString( |  | 
| 42         prefs::kAcceptLanguages); |  | 
| 43     NavigationEntry* entry = navigation_controller->GetActiveEntry(); |  | 
| 44     if (!navigation_controller->tab_contents()->ShouldDisplayURL()) { |  | 
| 45       // Explicitly hide the URL for this tab. |  | 
| 46       url = GURL(); |  | 
| 47     } else if (entry) { |  | 
| 48       url = entry->virtual_url(); |  | 
| 49     } |  | 
| 50   } |  | 
| 51   if (url.spec().length() > chrome::kMaxURLDisplayChars) |  | 
| 52     url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); |  | 
| 53   // Note that we can't unescape spaces here, because if the user copies this |  | 
| 54   // and pastes it into another program, that program may think the URL ends at |  | 
| 55   // the space. |  | 
| 56   return AutocompleteInput::FormattedStringWithEquivalentMeaning(url, |  | 
| 57       UTF16ToWideHack(net::FormatUrl(url, languages, net::kFormatUrlOmitAll, |  | 
| 58                                      UnescapeRule::NORMAL, NULL, NULL, NULL))); |  | 
| 59 } |  | 
| 60 |  | 
| 61 ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { |  | 
| 62   if (input_in_progress_)  // When editing, assume no security style. |  | 
| 63     return NONE; |  | 
| 64 |  | 
| 65   NavigationController* navigation_controller = GetNavigationController(); |  | 
| 66   if (!navigation_controller)  // We might not have a controller on init. |  | 
| 67     return NONE; |  | 
| 68 |  | 
| 69   NavigationEntry* entry = navigation_controller->GetActiveEntry(); |  | 
| 70   if (!entry) |  | 
| 71     return NONE; |  | 
| 72 |  | 
| 73   const NavigationEntry::SSLStatus& ssl = entry->ssl(); |  | 
| 74   switch (ssl.security_style()) { |  | 
| 75     case SECURITY_STYLE_UNKNOWN: |  | 
| 76     case SECURITY_STYLE_UNAUTHENTICATED: |  | 
| 77       return NONE; |  | 
| 78 |  | 
| 79     case SECURITY_STYLE_AUTHENTICATION_BROKEN: |  | 
| 80       return SECURITY_ERROR; |  | 
| 81 |  | 
| 82     case SECURITY_STYLE_AUTHENTICATED: |  | 
| 83       if (ssl.displayed_insecure_content()) |  | 
| 84         return SECURITY_WARNING; |  | 
| 85       if (net::IsCertStatusError(ssl.cert_status())) { |  | 
| 86         DCHECK_EQ(ssl.cert_status() & net::CERT_STATUS_ALL_ERRORS, |  | 
| 87                   net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION); |  | 
| 88         return SECURITY_WARNING; |  | 
| 89       } |  | 
| 90       if ((ssl.cert_status() & net::CERT_STATUS_IS_EV) && |  | 
| 91           CertStore::GetSharedInstance()->RetrieveCert(ssl.cert_id(), NULL)) |  | 
| 92         return EV_SECURE; |  | 
| 93       return SECURE; |  | 
| 94 |  | 
| 95     default: |  | 
| 96       NOTREACHED(); |  | 
| 97       return NONE; |  | 
| 98   } |  | 
| 99 } |  | 
| 100 |  | 
| 101 int ToolbarModel::GetIcon() const { |  | 
| 102   static int icon_ids[NUM_SECURITY_LEVELS] = { |  | 
| 103     IDR_OMNIBOX_HTTP, |  | 
| 104     IDR_OMNIBOX_HTTPS_VALID, |  | 
| 105     IDR_OMNIBOX_HTTPS_VALID, |  | 
| 106     IDR_OMNIBOX_HTTPS_WARNING, |  | 
| 107     IDR_OMNIBOX_HTTPS_INVALID, |  | 
| 108   }; |  | 
| 109   DCHECK(arraysize(icon_ids) == NUM_SECURITY_LEVELS); |  | 
| 110   return icon_ids[GetSecurityLevel()]; |  | 
| 111 } |  | 
| 112 |  | 
| 113 std::wstring ToolbarModel::GetEVCertName() const { |  | 
| 114   DCHECK_EQ(GetSecurityLevel(), EV_SECURE); |  | 
| 115   scoped_refptr<net::X509Certificate> cert; |  | 
| 116   // Note: Navigation controller and active entry are guaranteed non-NULL or |  | 
| 117   // the security level would be NONE. |  | 
| 118   CertStore::GetSharedInstance()->RetrieveCert( |  | 
| 119       GetNavigationController()->GetActiveEntry()->ssl().cert_id(), &cert); |  | 
| 120   return SSLManager::GetEVCertName(*cert); |  | 
| 121 } |  | 
| 122 |  | 
| 123 NavigationController* ToolbarModel::GetNavigationController() const { |  | 
| 124   // This |current_tab| can be NULL during the initialization of the |  | 
| 125   // toolbar during window creation (i.e. before any tabs have been added |  | 
| 126   // to the window). |  | 
| 127   TabContents* current_tab = browser_->GetSelectedTabContents(); |  | 
| 128   return current_tab ? ¤t_tab->controller() : NULL; |  | 
| 129 } |  | 
| OLD | NEW | 
|---|