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" |
(...skipping 16 matching lines...) Expand all Loading... |
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::NavigationController; |
31 using content::NavigationEntry; | 31 using content::NavigationEntry; |
32 using content::SSLStatus; | 32 using content::SSLStatus; |
33 using content::WebContents; | 33 using content::WebContents; |
34 | 34 |
35 ToolbarModel::ToolbarModel(Browser* browser) | 35 ToolbarModel::ToolbarModel(Browser* browser) |
36 : browser_(browser), | 36 : browser_(browser), |
| 37 web_contents_(NULL), |
37 input_in_progress_(false) { | 38 input_in_progress_(false) { |
38 } | 39 } |
39 | 40 |
| 41 ToolbarModel::ToolbarModel(WebContents* web_contents) |
| 42 : browser_(NULL), |
| 43 web_contents_(web_contents), |
| 44 input_in_progress_(false) { |
| 45 } |
| 46 |
40 ToolbarModel::~ToolbarModel() { | 47 ToolbarModel::~ToolbarModel() { |
41 } | 48 } |
42 | 49 |
43 // ToolbarModel Implementation. | 50 // ToolbarModel Implementation. |
44 string16 ToolbarModel::GetText() const { | 51 string16 ToolbarModel::GetText() const { |
45 GURL url(chrome::kAboutBlankURL); | 52 GURL url(chrome::kAboutBlankURL); |
46 std::string languages; // Empty if we don't have a |navigation_controller|. | 53 std::string languages; // Empty if we don't have a |navigation_controller|. |
47 | 54 |
48 NavigationController* navigation_controller = GetNavigationController(); | 55 NavigationController* navigation_controller = GetNavigationController(); |
49 if (navigation_controller) { | 56 if (navigation_controller) { |
(...skipping 27 matching lines...) Expand all Loading... |
77 // chrome://newtab's WebUI says. | 84 // chrome://newtab's WebUI says. |
78 NavigationController* controller = GetNavigationController(); | 85 NavigationController* controller = GetNavigationController(); |
79 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL; | 86 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL; |
80 if (entry) { | 87 if (entry) { |
81 if (entry->IsViewSourceMode() || | 88 if (entry->IsViewSourceMode() || |
82 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { | 89 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { |
83 return true; | 90 return true; |
84 } | 91 } |
85 } | 92 } |
86 | 93 |
87 WebContents* web_contents = browser_->GetSelectedWebContents(); | 94 WebContents* web_contents = GetSelectedWebContents(); |
88 if (web_contents && web_contents->GetWebUIForCurrentState()) | 95 if (web_contents && web_contents->GetWebUIForCurrentState()) |
89 return !web_contents->GetWebUIForCurrentState()->ShouldHideURL(); | 96 return !web_contents->GetWebUIForCurrentState()->ShouldHideURL(); |
90 | 97 |
91 if (entry && entry->GetURL().SchemeIs(chrome::kExtensionScheme)) | 98 if (entry && entry->GetURL().SchemeIs(chrome::kExtensionScheme)) |
92 return false; | 99 return false; |
93 | 100 |
94 return true; | 101 return true; |
95 } | 102 } |
96 | 103 |
97 ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { | 104 ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 return l10n_util::GetStringFUTF16( | 174 return l10n_util::GetStringFUTF16( |
168 IDS_SECURE_CONNECTION_EV, | 175 IDS_SECURE_CONNECTION_EV, |
169 UTF8ToUTF16(cert.subject().organization_names[0]), | 176 UTF8ToUTF16(cert.subject().organization_names[0]), |
170 UTF8ToUTF16(cert.subject().country_name)); | 177 UTF8ToUTF16(cert.subject().country_name)); |
171 } | 178 } |
172 | 179 |
173 NavigationController* ToolbarModel::GetNavigationController() const { | 180 NavigationController* ToolbarModel::GetNavigationController() const { |
174 // This |current_tab| can be NULL during the initialization of the | 181 // This |current_tab| can be NULL during the initialization of the |
175 // toolbar during window creation (i.e. before any tabs have been added | 182 // toolbar during window creation (i.e. before any tabs have been added |
176 // to the window). | 183 // to the window). |
177 WebContents* current_tab = browser_->GetSelectedWebContents(); | 184 WebContents* current_tab = GetSelectedWebContents(); |
178 return current_tab ? ¤t_tab->GetController() : NULL; | 185 return current_tab ? ¤t_tab->GetController() : NULL; |
179 } | 186 } |
| 187 |
| 188 WebContents* ToolbarModel::GetSelectedWebContents() const { |
| 189 if (browser_) |
| 190 return browser_->GetSelectedWebContents(); |
| 191 return web_contents_; |
| 192 } |
OLD | NEW |