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/navigation_controller.h" | 18 #include "content/browser/tab_contents/navigation_controller.h" |
19 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
20 #include "content/browser/webui/web_ui.h" | 20 #include "content/browser/webui/web_ui.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::NavigationEntry; |
30 using content::SSLStatus; | 31 using content::SSLStatus; |
31 | 32 |
32 ToolbarModel::ToolbarModel(Browser* browser) | 33 ToolbarModel::ToolbarModel(Browser* browser) |
33 : browser_(browser), | 34 : browser_(browser), |
34 input_in_progress_(false) { | 35 input_in_progress_(false) { |
35 } | 36 } |
36 | 37 |
37 ToolbarModel::~ToolbarModel() { | 38 ToolbarModel::~ToolbarModel() { |
38 } | 39 } |
39 | 40 |
40 // ToolbarModel Implementation. | 41 // ToolbarModel Implementation. |
41 string16 ToolbarModel::GetText() const { | 42 string16 ToolbarModel::GetText() const { |
42 GURL url(chrome::kAboutBlankURL); | 43 GURL url(chrome::kAboutBlankURL); |
43 std::string languages; // Empty if we don't have a |navigation_controller|. | 44 std::string languages; // Empty if we don't have a |navigation_controller|. |
44 | 45 |
45 NavigationController* navigation_controller = GetNavigationController(); | 46 NavigationController* navigation_controller = GetNavigationController(); |
46 if (navigation_controller) { | 47 if (navigation_controller) { |
47 Profile* profile = | 48 Profile* profile = |
48 Profile::FromBrowserContext(navigation_controller->browser_context()); | 49 Profile::FromBrowserContext(navigation_controller->browser_context()); |
49 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 50 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
50 content::NavigationEntry* entry = navigation_controller->GetVisibleEntry(); | 51 NavigationEntry* entry = navigation_controller->GetVisibleEntry(); |
51 if (!ShouldDisplayURL()) { | 52 if (!ShouldDisplayURL()) { |
52 url = GURL(); | 53 url = GURL(); |
53 } else if (entry) { | 54 } else if (entry) { |
54 url = entry->GetVirtualURL(); | 55 url = entry->GetVirtualURL(); |
55 } | 56 } |
56 } | 57 } |
57 if (url.spec().length() > content::kMaxURLDisplayChars) | 58 if (url.spec().length() > content::kMaxURLDisplayChars) |
58 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); | 59 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); |
59 // Note that we can't unescape spaces here, because if the user copies this | 60 // Note that we can't unescape spaces here, because if the user copies this |
60 // and pastes it into another program, that program may think the URL ends at | 61 // and pastes it into another program, that program may think the URL ends at |
61 // the space. | 62 // the space. |
62 return AutocompleteInput::FormattedStringWithEquivalentMeaning( | 63 return AutocompleteInput::FormattedStringWithEquivalentMeaning( |
63 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll, | 64 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll, |
64 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); | 65 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); |
65 } | 66 } |
66 | 67 |
67 bool ToolbarModel::ShouldDisplayURL() const { | 68 bool ToolbarModel::ShouldDisplayURL() const { |
68 // Note: The order here is important. | 69 // Note: The order here is important. |
69 // - The WebUI test must come before the extension scheme test because there | 70 // - The WebUI test must come before the extension scheme test because there |
70 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In | 71 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In |
71 // that case, we should prefer what the WebUI instance says. | 72 // that case, we should prefer what the WebUI instance says. |
72 // - The view-source test must come before the WebUI test because of the case | 73 // - The view-source test must come before the WebUI test because of the case |
73 // of view-source:chrome://newtab, which should display its URL despite what | 74 // of view-source:chrome://newtab, which should display its URL despite what |
74 // chrome://newtab's WebUI says. | 75 // chrome://newtab's WebUI says. |
75 NavigationController* controller = GetNavigationController(); | 76 NavigationController* controller = GetNavigationController(); |
76 content::NavigationEntry* entry = | 77 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL; |
77 controller ? controller->GetVisibleEntry() : NULL; | |
78 if (entry) { | 78 if (entry) { |
79 if (entry->IsViewSourceMode() || | 79 if (entry->IsViewSourceMode() || |
80 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { | 80 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { |
81 return true; | 81 return true; |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 TabContents* tab_contents = browser_->GetSelectedTabContents(); | 85 TabContents* tab_contents = browser_->GetSelectedTabContents(); |
86 if (tab_contents && tab_contents->GetWebUIForCurrentState()) | 86 if (tab_contents && tab_contents->GetWebUIForCurrentState()) |
87 return !tab_contents->GetWebUIForCurrentState()->should_hide_url(); | 87 return !tab_contents->GetWebUIForCurrentState()->should_hide_url(); |
88 | 88 |
89 if (entry && entry->GetURL().SchemeIs(chrome::kExtensionScheme)) | 89 if (entry && entry->GetURL().SchemeIs(chrome::kExtensionScheme)) |
90 return false; | 90 return false; |
91 | 91 |
92 return true; | 92 return true; |
93 } | 93 } |
94 | 94 |
95 ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { | 95 ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { |
96 if (input_in_progress_) // When editing, assume no security style. | 96 if (input_in_progress_) // When editing, assume no security style. |
97 return NONE; | 97 return NONE; |
98 | 98 |
99 NavigationController* navigation_controller = GetNavigationController(); | 99 NavigationController* navigation_controller = GetNavigationController(); |
100 if (!navigation_controller) // We might not have a controller on init. | 100 if (!navigation_controller) // We might not have a controller on init. |
101 return NONE; | 101 return NONE; |
102 | 102 |
103 content::NavigationEntry* entry = navigation_controller->GetVisibleEntry(); | 103 NavigationEntry* entry = navigation_controller->GetVisibleEntry(); |
104 if (!entry) | 104 if (!entry) |
105 return NONE; | 105 return NONE; |
106 | 106 |
107 const SSLStatus& ssl = entry->GetSSL(); | 107 const SSLStatus& ssl = entry->GetSSL(); |
108 switch (ssl.security_style) { | 108 switch (ssl.security_style) { |
109 case content::SECURITY_STYLE_UNKNOWN: | 109 case content::SECURITY_STYLE_UNKNOWN: |
110 case content::SECURITY_STYLE_UNAUTHENTICATED: | 110 case content::SECURITY_STYLE_UNAUTHENTICATED: |
111 return NONE; | 111 return NONE; |
112 | 112 |
113 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: | 113 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 UTF8ToUTF16(cert.subject().country_name)); | 168 UTF8ToUTF16(cert.subject().country_name)); |
169 } | 169 } |
170 | 170 |
171 NavigationController* ToolbarModel::GetNavigationController() const { | 171 NavigationController* ToolbarModel::GetNavigationController() const { |
172 // This |current_tab| can be NULL during the initialization of the | 172 // This |current_tab| can be NULL during the initialization of the |
173 // toolbar during window creation (i.e. before any tabs have been added | 173 // toolbar during window creation (i.e. before any tabs have been added |
174 // to the window). | 174 // to the window). |
175 TabContents* current_tab = browser_->GetSelectedTabContents(); | 175 TabContents* current_tab = browser_->GetSelectedTabContents(); |
176 return current_tab ? ¤t_tab->GetController() : NULL; | 176 return current_tab ? ¤t_tab->GetController() : NULL; |
177 } | 177 } |
OLD | NEW |