| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_ | 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_ |
| 6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_ | 6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 | 13 |
| 14 class Profile; | |
| 15 class ToolbarModelDelegate; | |
| 16 | |
| 17 namespace content { | |
| 18 class NavigationController; | |
| 19 } | |
| 20 | |
| 21 namespace net { | 14 namespace net { |
| 22 class X509Certificate; | 15 class X509Certificate; |
| 23 } | 16 } |
| 24 | 17 |
| 25 // This class is the model used by the toolbar, location bar and autocomplete | 18 // This class is the model used by the toolbar, location bar and autocomplete |
| 26 // edit. It populates its states from the current navigation entry retrieved | 19 // edit. It populates its states from the current navigation entry retrieved |
| 27 // from the navigation controller returned by GetNavigationController(). | 20 // from the navigation controller returned by GetNavigationController(). |
| 28 class ToolbarModel { | 21 class ToolbarModel { |
| 29 public: | 22 public: |
| 30 // TODO(wtc): unify ToolbarModel::SecurityLevel with SecurityStyle. We | 23 // TODO(wtc): unify ToolbarModel::SecurityLevel with SecurityStyle. We |
| 31 // don't need two sets of security UI levels. SECURITY_STYLE_AUTHENTICATED | 24 // don't need two sets of security UI levels. SECURITY_STYLE_AUTHENTICATED |
| 32 // needs to be refined into three levels: warning, standard, and EV. | 25 // needs to be refined into three levels: warning, standard, and EV. |
| 33 enum SecurityLevel { | 26 enum SecurityLevel { |
| 34 NONE = 0, // HTTP/no URL/user is editing | 27 NONE = 0, // HTTP/no URL/user is editing |
| 35 EV_SECURE, // HTTPS with valid EV cert | 28 EV_SECURE, // HTTPS with valid EV cert |
| 36 SECURE, // HTTPS (non-EV) | 29 SECURE, // HTTPS (non-EV) |
| 37 SECURITY_WARNING, // HTTPS, but unable to check certificate revocation | 30 SECURITY_WARNING, // HTTPS, but unable to check certificate revocation |
| 38 // status or with insecure content on the page | 31 // status or with insecure content on the page |
| 39 SECURITY_ERROR, // Attempted HTTPS and failed, page not authenticated | 32 SECURITY_ERROR, // Attempted HTTPS and failed, page not authenticated |
| 40 NUM_SECURITY_LEVELS, | 33 NUM_SECURITY_LEVELS, |
| 41 }; | 34 }; |
| 42 | 35 |
| 43 explicit ToolbarModel(ToolbarModelDelegate* delegate); | 36 virtual ~ToolbarModel() {} |
| 44 ~ToolbarModel(); | |
| 45 | 37 |
| 46 // Returns the text for the current page's URL. This will have been formatted | 38 // Returns the text for the current page's URL. This will have been formatted |
| 47 // for display to the user: | 39 // for display to the user: |
| 48 // - Some characters may be unescaped. | 40 // - Some characters may be unescaped. |
| 49 // - The scheme and/or trailing slash may be dropped. | 41 // - The scheme and/or trailing slash may be dropped. |
| 50 // - if |display_search_urls_as_search_terms| is true, the query will be | 42 // - if |display_search_urls_as_search_terms| is true, the query will be |
| 51 // extracted from search URLs for the user's default search engine and those | 43 // extracted from search URLs for the user's default search engine and those |
| 52 // will be displayed in place of the URL. | 44 // will be displayed in place of the URL. |
| 53 string16 GetText(bool display_search_urls_as_search_terms) const; | 45 virtual string16 GetText(bool display_search_urls_as_search_terms) const = 0; |
| 54 | 46 |
| 55 // Returns the URL of the current navigation entry. | 47 // Returns the URL of the current navigation entry. |
| 56 GURL GetURL() const; | 48 virtual GURL GetURL() const = 0; |
| 57 | 49 |
| 58 // Returns true if a call to GetText(true) would successfully replace the URL | 50 // Returns true if a call to GetText(true) would successfully replace the URL |
| 59 // with search terms. | 51 // with search terms. |
| 60 bool WouldReplaceSearchURLWithSearchTerms() const; | 52 virtual bool WouldReplaceSearchURLWithSearchTerms() const = 0; |
| 61 | 53 |
| 62 // Returns the security level that the toolbar should display. | 54 // Returns the security level that the toolbar should display. |
| 63 SecurityLevel GetSecurityLevel() const; | 55 virtual SecurityLevel GetSecurityLevel() const = 0; |
| 64 | 56 |
| 65 // Returns the resource_id of the icon to show to the left of the address, | 57 // Returns the resource_id of the icon to show to the left of the address, |
| 66 // based on the current URL. This doesn't cover specialized icons while the | 58 // based on the current URL. This doesn't cover specialized icons while the |
| 67 // user is editing; see OmniboxView::GetIcon(). | 59 // user is editing; see OmniboxView::GetIcon(). |
| 68 int GetIcon() const; | 60 virtual int GetIcon() const = 0; |
| 69 | 61 |
| 70 // Returns the name of the EV cert holder. Only call this when the security | 62 // Returns the name of the EV cert holder. Only call this when the security |
| 71 // level is EV_SECURE. | 63 // level is EV_SECURE. |
| 72 string16 GetEVCertName() const; | 64 virtual string16 GetEVCertName() const = 0; |
| 73 | 65 |
| 74 // Returns whether the URL for the current navigation entry should be | 66 // Returns whether the URL for the current navigation entry should be |
| 75 // in the location bar. | 67 // in the location bar. |
| 76 bool ShouldDisplayURL() const; | 68 virtual bool ShouldDisplayURL() const = 0; |
| 77 | 69 |
| 78 // Getter/setter of whether the text in location bar is currently being | 70 // Getter/setter of whether the text in location bar is currently being |
| 79 // edited. | 71 // edited. |
| 80 void set_input_in_progress(bool value) { input_in_progress_ = value; } | 72 virtual void SetInputInProgress(bool value) = 0; |
| 81 bool input_in_progress() const { return input_in_progress_; } | 73 virtual bool GetInputInProgress() const = 0; |
| 82 | 74 |
| 83 // Returns "<organization_name> [<country>]". | 75 protected: |
| 84 static string16 GetEVCertName(const net::X509Certificate& cert); | 76 ToolbarModel() {} |
| 85 | |
| 86 private: | |
| 87 // Returns the navigation controller used to retrieve the navigation entry | |
| 88 // from which the states are retrieved. | |
| 89 // If this returns NULL, default values are used. | |
| 90 content::NavigationController* GetNavigationController() const; | |
| 91 | |
| 92 // Attempt to extract search terms from |url|. Called by GetText if | |
| 93 // |display_search_urls_as_search_terms| is true and by | |
| 94 // WouldReplaceSearchURLWithSearchTerms. | |
| 95 string16 TryToExtractSearchTermsFromURL(const GURL& url) const; | |
| 96 | |
| 97 // Helper method to extract the profile from the navigation controller. | |
| 98 Profile* GetProfile() const; | |
| 99 | |
| 100 ToolbarModelDelegate* delegate_; | |
| 101 | |
| 102 // Whether the text in the location bar is currently being edited. | |
| 103 bool input_in_progress_; | |
| 104 | |
| 105 DISALLOW_IMPLICIT_CONSTRUCTORS(ToolbarModel); | |
| 106 }; | 77 }; |
| 107 | 78 |
| 108 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_ | 79 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_ |
| OLD | NEW |