| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/toolbar/toolbar_model.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete.h" | 8 #include "chrome/browser/autocomplete/autocomplete.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 9 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ssl/ssl_error_info.h" | 12 #include "chrome/browser/ssl/ssl_error_info.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "content/browser/cert_store.h" | 17 #include "content/browser/cert_store.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 19 #include "content/browser/webui/web_ui.h" | 19 #include "content/browser/webui/web_ui.h" |
| 20 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/ssl_status.h" | 22 #include "content/public/browser/ssl_status.h" |
| 23 #include "content/public/common/content_constants.h" | 23 #include "content/public/common/content_constants.h" |
| 24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
| 26 #include "net/base/cert_status_flags.h" | 26 #include "net/base/cert_status_flags.h" |
| 27 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 | 29 |
| 30 using content::NavigationController; |
| 30 using content::NavigationEntry; | 31 using content::NavigationEntry; |
| 31 using content::SSLStatus; | 32 using content::SSLStatus; |
| 32 using content::WebContents; | 33 using content::WebContents; |
| 33 | 34 |
| 34 ToolbarModel::ToolbarModel(Browser* browser) | 35 ToolbarModel::ToolbarModel(Browser* browser) |
| 35 : browser_(browser), | 36 : browser_(browser), |
| 36 input_in_progress_(false) { | 37 input_in_progress_(false) { |
| 37 } | 38 } |
| 38 | 39 |
| 39 ToolbarModel::~ToolbarModel() { | 40 ToolbarModel::~ToolbarModel() { |
| 40 } | 41 } |
| 41 | 42 |
| 42 // ToolbarModel Implementation. | 43 // ToolbarModel Implementation. |
| 43 string16 ToolbarModel::GetText() const { | 44 string16 ToolbarModel::GetText() const { |
| 44 GURL url(chrome::kAboutBlankURL); | 45 GURL url(chrome::kAboutBlankURL); |
| 45 std::string languages; // Empty if we don't have a |navigation_controller|. | 46 std::string languages; // Empty if we don't have a |navigation_controller|. |
| 46 | 47 |
| 47 content::NavigationController* navigation_controller = | 48 NavigationController* navigation_controller = GetNavigationController(); |
| 48 GetNavigationController(); | |
| 49 if (navigation_controller) { | 49 if (navigation_controller) { |
| 50 Profile* profile = | 50 Profile* profile = |
| 51 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()); | 51 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()); |
| 52 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 52 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 53 NavigationEntry* entry = navigation_controller->GetVisibleEntry(); | 53 NavigationEntry* entry = navigation_controller->GetVisibleEntry(); |
| 54 if (!ShouldDisplayURL()) { | 54 if (!ShouldDisplayURL()) { |
| 55 url = GURL(); | 55 url = GURL(); |
| 56 } else if (entry) { | 56 } else if (entry) { |
| 57 url = entry->GetVirtualURL(); | 57 url = entry->GetVirtualURL(); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 if (url.spec().length() > content::kMaxURLDisplayChars) | 60 if (url.spec().length() > content::kMaxURLDisplayChars) |
| 61 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); | 61 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); |
| 62 // Note that we can't unescape spaces here, because if the user copies this | 62 // Note that we can't unescape spaces here, because if the user copies this |
| 63 // and pastes it into another program, that program may think the URL ends at | 63 // and pastes it into another program, that program may think the URL ends at |
| 64 // the space. | 64 // the space. |
| 65 return AutocompleteInput::FormattedStringWithEquivalentMeaning( | 65 return AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 66 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll, | 66 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll, |
| 67 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); | 67 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool ToolbarModel::ShouldDisplayURL() const { | 70 bool ToolbarModel::ShouldDisplayURL() const { |
| 71 // Note: The order here is important. | 71 // Note: The order here is important. |
| 72 // - The WebUI test must come before the extension scheme test because there | 72 // - The WebUI test must come before the extension scheme test because there |
| 73 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In | 73 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In |
| 74 // that case, we should prefer what the WebUI instance says. | 74 // that case, we should prefer what the WebUI instance says. |
| 75 // - The view-source test must come before the WebUI test because of the case | 75 // - The view-source test must come before the WebUI test because of the case |
| 76 // of view-source:chrome://newtab, which should display its URL despite what | 76 // of view-source:chrome://newtab, which should display its URL despite what |
| 77 // chrome://newtab's WebUI says. | 77 // chrome://newtab's WebUI says. |
| 78 content::NavigationController* controller = | 78 NavigationController* controller = GetNavigationController(); |
| 79 GetNavigationController(); | |
| 80 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL; | 79 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL; |
| 81 if (entry) { | 80 if (entry) { |
| 82 if (entry->IsViewSourceMode() || | 81 if (entry->IsViewSourceMode() || |
| 83 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { | 82 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { |
| 84 return true; | 83 return true; |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 | 86 |
| 88 WebContents* web_contents = browser_->GetSelectedWebContents(); | 87 WebContents* web_contents = browser_->GetSelectedWebContents(); |
| 89 if (web_contents && web_contents->GetWebUIForCurrentState()) | 88 if (web_contents && web_contents->GetWebUIForCurrentState()) |
| 90 return !web_contents->GetWebUIForCurrentState()->should_hide_url(); | 89 return !web_contents->GetWebUIForCurrentState()->should_hide_url(); |
| 91 | 90 |
| 92 if (entry && entry->GetURL().SchemeIs(chrome::kExtensionScheme)) | 91 if (entry && entry->GetURL().SchemeIs(chrome::kExtensionScheme)) |
| 93 return false; | 92 return false; |
| 94 | 93 |
| 95 return true; | 94 return true; |
| 96 } | 95 } |
| 97 | 96 |
| 98 ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { | 97 ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { |
| 99 if (input_in_progress_) // When editing, assume no security style. | 98 if (input_in_progress_) // When editing, assume no security style. |
| 100 return NONE; | 99 return NONE; |
| 101 | 100 |
| 102 content::NavigationController* navigation_controller = | 101 NavigationController* navigation_controller = GetNavigationController(); |
| 103 GetNavigationController(); | |
| 104 if (!navigation_controller) // We might not have a controller on init. | 102 if (!navigation_controller) // We might not have a controller on init. |
| 105 return NONE; | 103 return NONE; |
| 106 | 104 |
| 107 NavigationEntry* entry = navigation_controller->GetVisibleEntry(); | 105 NavigationEntry* entry = navigation_controller->GetVisibleEntry(); |
| 108 if (!entry) | 106 if (!entry) |
| 109 return NONE; | 107 return NONE; |
| 110 | 108 |
| 111 const SSLStatus& ssl = entry->GetSSL(); | 109 const SSLStatus& ssl = entry->GetSSL(); |
| 112 switch (ssl.security_style) { | 110 switch (ssl.security_style) { |
| 113 case content::SECURITY_STYLE_UNKNOWN: | 111 case content::SECURITY_STYLE_UNKNOWN: |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 NOTREACHED(); | 163 NOTREACHED(); |
| 166 return string16(); | 164 return string16(); |
| 167 } | 165 } |
| 168 | 166 |
| 169 return l10n_util::GetStringFUTF16( | 167 return l10n_util::GetStringFUTF16( |
| 170 IDS_SECURE_CONNECTION_EV, | 168 IDS_SECURE_CONNECTION_EV, |
| 171 UTF8ToUTF16(cert.subject().organization_names[0]), | 169 UTF8ToUTF16(cert.subject().organization_names[0]), |
| 172 UTF8ToUTF16(cert.subject().country_name)); | 170 UTF8ToUTF16(cert.subject().country_name)); |
| 173 } | 171 } |
| 174 | 172 |
| 175 content::NavigationController* ToolbarModel::GetNavigationController() const { | 173 NavigationController* ToolbarModel::GetNavigationController() const { |
| 176 // This |current_tab| can be NULL during the initialization of the | 174 // This |current_tab| can be NULL during the initialization of the |
| 177 // toolbar during window creation (i.e. before any tabs have been added | 175 // toolbar during window creation (i.e. before any tabs have been added |
| 178 // to the window). | 176 // to the window). |
| 179 WebContents* current_tab = browser_->GetSelectedWebContents(); | 177 WebContents* current_tab = browser_->GetSelectedWebContents(); |
| 180 return current_tab ? ¤t_tab->GetController() : NULL; | 178 return current_tab ? ¤t_tab->GetController() : NULL; |
| 181 } | 179 } |
| OLD | NEW |