Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1033)

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_model.cc

Issue 8983010: Convert WebContents to return a content::NavigationController instead of the implementation. Upda... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
19 #include "content/browser/tab_contents/tab_contents.h" 18 #include "content/browser/tab_contents/tab_contents.h"
20 #include "content/browser/webui/web_ui.h" 19 #include "content/browser/webui/web_ui.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::NavigationEntry; 30 using content::NavigationEntry;
31 using content::SSLStatus; 31 using content::SSLStatus;
32 using content::WebContents; 32 using content::WebContents;
33 33
34 ToolbarModel::ToolbarModel(Browser* browser) 34 ToolbarModel::ToolbarModel(Browser* browser)
35 : browser_(browser), 35 : browser_(browser),
36 input_in_progress_(false) { 36 input_in_progress_(false) {
37 } 37 }
38 38
39 ToolbarModel::~ToolbarModel() { 39 ToolbarModel::~ToolbarModel() {
40 } 40 }
41 41
42 // ToolbarModel Implementation. 42 // ToolbarModel Implementation.
43 string16 ToolbarModel::GetText() const { 43 string16 ToolbarModel::GetText() const {
44 GURL url(chrome::kAboutBlankURL); 44 GURL url(chrome::kAboutBlankURL);
45 std::string languages; // Empty if we don't have a |navigation_controller|. 45 std::string languages; // Empty if we don't have a |navigation_controller|.
46 46
47 NavigationController* navigation_controller = GetNavigationController(); 47 content::NavigationController* navigation_controller =
48 GetNavigationController();
48 if (navigation_controller) { 49 if (navigation_controller) {
49 Profile* profile = 50 Profile* profile =
50 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()); 51 Profile::FromBrowserContext(navigation_controller->GetBrowserContext());
51 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); 52 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
52 NavigationEntry* entry = navigation_controller->GetVisibleEntry(); 53 NavigationEntry* entry = navigation_controller->GetVisibleEntry();
53 if (!ShouldDisplayURL()) { 54 if (!ShouldDisplayURL()) {
54 url = GURL(); 55 url = GURL();
55 } else if (entry) { 56 } else if (entry) {
56 url = entry->GetVirtualURL(); 57 url = entry->GetVirtualURL();
57 } 58 }
58 } 59 }
59 if (url.spec().length() > content::kMaxURLDisplayChars) 60 if (url.spec().length() > content::kMaxURLDisplayChars)
60 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); 61 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":");
61 // 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
62 // 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
63 // the space. 64 // the space.
64 return AutocompleteInput::FormattedStringWithEquivalentMeaning( 65 return AutocompleteInput::FormattedStringWithEquivalentMeaning(
65 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll, 66 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll,
66 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); 67 net::UnescapeRule::NORMAL, NULL, NULL, NULL));
67 } 68 }
68 69
69 bool ToolbarModel::ShouldDisplayURL() const { 70 bool ToolbarModel::ShouldDisplayURL() const {
70 // Note: The order here is important. 71 // Note: The order here is important.
71 // - 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
72 // 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
73 // that case, we should prefer what the WebUI instance says. 74 // that case, we should prefer what the WebUI instance says.
74 // - 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
75 // 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
76 // chrome://newtab's WebUI says. 77 // chrome://newtab's WebUI says.
77 NavigationController* controller = GetNavigationController(); 78 content::NavigationController* controller =
79 GetNavigationController();
78 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL; 80 NavigationEntry* entry = controller ? controller->GetVisibleEntry() : NULL;
79 if (entry) { 81 if (entry) {
80 if (entry->IsViewSourceMode() || 82 if (entry->IsViewSourceMode() ||
81 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) { 83 entry->GetPageType() == content::PAGE_TYPE_INTERSTITIAL) {
82 return true; 84 return true;
83 } 85 }
84 } 86 }
85 87
86 WebContents* web_contents = browser_->GetSelectedWebContents(); 88 WebContents* web_contents = browser_->GetSelectedWebContents();
87 if (web_contents && web_contents->GetWebUIForCurrentState()) 89 if (web_contents && web_contents->GetWebUIForCurrentState())
88 return !web_contents->GetWebUIForCurrentState()->should_hide_url(); 90 return !web_contents->GetWebUIForCurrentState()->should_hide_url();
89 91
90 if (entry && entry->GetURL().SchemeIs(chrome::kExtensionScheme)) 92 if (entry && entry->GetURL().SchemeIs(chrome::kExtensionScheme))
91 return false; 93 return false;
92 94
93 return true; 95 return true;
94 } 96 }
95 97
96 ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { 98 ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const {
97 if (input_in_progress_) // When editing, assume no security style. 99 if (input_in_progress_) // When editing, assume no security style.
98 return NONE; 100 return NONE;
99 101
100 NavigationController* navigation_controller = GetNavigationController(); 102 content::NavigationController* navigation_controller =
103 GetNavigationController();
101 if (!navigation_controller) // We might not have a controller on init. 104 if (!navigation_controller) // We might not have a controller on init.
102 return NONE; 105 return NONE;
103 106
104 NavigationEntry* entry = navigation_controller->GetVisibleEntry(); 107 NavigationEntry* entry = navigation_controller->GetVisibleEntry();
105 if (!entry) 108 if (!entry)
106 return NONE; 109 return NONE;
107 110
108 const SSLStatus& ssl = entry->GetSSL(); 111 const SSLStatus& ssl = entry->GetSSL();
109 switch (ssl.security_style) { 112 switch (ssl.security_style) {
110 case content::SECURITY_STYLE_UNKNOWN: 113 case content::SECURITY_STYLE_UNKNOWN:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 NOTREACHED(); 165 NOTREACHED();
163 return string16(); 166 return string16();
164 } 167 }
165 168
166 return l10n_util::GetStringFUTF16( 169 return l10n_util::GetStringFUTF16(
167 IDS_SECURE_CONNECTION_EV, 170 IDS_SECURE_CONNECTION_EV,
168 UTF8ToUTF16(cert.subject().organization_names[0]), 171 UTF8ToUTF16(cert.subject().organization_names[0]),
169 UTF8ToUTF16(cert.subject().country_name)); 172 UTF8ToUTF16(cert.subject().country_name));
170 } 173 }
171 174
172 NavigationController* ToolbarModel::GetNavigationController() const { 175 content::NavigationController* ToolbarModel::GetNavigationController() const {
173 // This |current_tab| can be NULL during the initialization of the 176 // This |current_tab| can be NULL during the initialization of the
174 // toolbar during window creation (i.e. before any tabs have been added 177 // toolbar during window creation (i.e. before any tabs have been added
175 // to the window). 178 // to the window).
176 WebContents* current_tab = browser_->GetSelectedWebContents(); 179 WebContents* current_tab = browser_->GetSelectedWebContents();
177 return current_tab ? &current_tab->GetController() : NULL; 180 return current_tab ? &current_tab->GetController() : NULL;
178 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698