| OLD | NEW |
| 1 // Copyright 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 COMPONENTS_TOOLBAR_TOOLBAR_MODEL_H_ | 5 #ifndef COMPONENTS_TOOLBAR_TOOLBAR_MODEL_H_ |
| 6 #define COMPONENTS_TOOLBAR_TOOLBAR_MODEL_H_ | 6 #define COMPONENTS_TOOLBAR_TOOLBAR_MODEL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "components/security_state/security_state_model.h" | 14 #include "components/security_state/security_state_model.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace gfx { | 17 namespace gfx { |
| 18 enum class VectorIconId; | 18 enum class VectorIconId; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace net { | |
| 22 class X509Certificate; | |
| 23 } | |
| 24 | |
| 25 // This class is the model used by the toolbar, location bar and autocomplete | 21 // 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 | 22 // edit. It populates its states from the current navigation entry retrieved |
| 27 // from the navigation controller returned by GetNavigationController(). | 23 // from the navigation controller returned by GetNavigationController(). |
| 28 class ToolbarModel { | 24 class ToolbarModel { |
| 29 public: | 25 public: |
| 30 virtual ~ToolbarModel(); | 26 virtual ~ToolbarModel(); |
| 31 | 27 |
| 32 // Returns the text to be displayed in the toolbar for the current page. | |
| 33 // This will have been formatted for display to the user. | |
| 34 // - If the current page's URL is a search URL for the user's default search | |
| 35 // engine, the query will be extracted and returned for display instead | |
| 36 // of the URL. | |
| 37 // - Otherwise, the text will contain the URL returned by GetFormattedURL(). | |
| 38 virtual base::string16 GetText() const = 0; | |
| 39 | |
| 40 // Returns a formatted URL for display in the toolbar. The formatting | 28 // Returns a formatted URL for display in the toolbar. The formatting |
| 41 // includes: | 29 // includes: |
| 42 // - Some characters may be unescaped. | 30 // - Some characters may be unescaped. |
| 43 // - The scheme and/or trailing slash may be dropped. | 31 // - The scheme and/or trailing slash may be dropped. |
| 44 // If |prefix_end| is non-NULL, it is set to the length of the pre-hostname | 32 // If |prefix_end| is non-NULL, it is set to the length of the pre-hostname |
| 45 // portion of the resulting URL. | 33 // portion of the resulting URL. |
| 46 virtual base::string16 GetFormattedURL(size_t* prefix_end) const = 0; | 34 virtual base::string16 GetFormattedURL(size_t* prefix_end) const = 0; |
| 47 | 35 |
| 48 // Returns the URL of the current navigation entry. | 36 // Returns the URL of the current navigation entry. |
| 49 virtual GURL GetURL() const = 0; | 37 virtual GURL GetURL() const = 0; |
| 50 | 38 |
| 51 // Returns true if a call to GetText() would successfully replace the URL | |
| 52 // with search terms. If |ignore_editing| is true, the result reflects the | |
| 53 // underlying state of the page without regard to any user edits that may be | |
| 54 // in progress in the omnibox. | |
| 55 virtual bool WouldPerformSearchTermReplacement(bool ignore_editing) const = 0; | |
| 56 | |
| 57 // Returns the security level that the toolbar should display. If | 39 // Returns the security level that the toolbar should display. If |
| 58 // |ignore_editing| is true, the result reflects the underlying state of the | 40 // |ignore_editing| is true, the result reflects the underlying state of the |
| 59 // page without regard to any user edits that may be in progress in the | 41 // page without regard to any user edits that may be in progress in the |
| 60 // omnibox. | 42 // omnibox. |
| 61 virtual security_state::SecurityStateModel::SecurityLevel GetSecurityLevel( | 43 virtual security_state::SecurityStateModel::SecurityLevel GetSecurityLevel( |
| 62 bool ignore_editing) const = 0; | 44 bool ignore_editing) const = 0; |
| 63 | 45 |
| 64 // Returns true if a call to GetText() would return something other than the | |
| 65 // URL because of search term replacement. | |
| 66 bool WouldReplaceURL() const; | |
| 67 | |
| 68 // Returns the resource_id of the icon to show to the left of the address, | 46 // Returns the resource_id of the icon to show to the left of the address, |
| 69 // based on the current URL. When search term replacement is active, this | 47 // based on the current URL. When search term replacement is active, this |
| 70 // returns a search icon. This doesn't cover specialized icons while the | 48 // returns a search icon. This doesn't cover specialized icons while the |
| 71 // user is editing; see OmniboxView::GetIcon(). | 49 // user is editing; see OmniboxView::GetIcon(). |
| 72 virtual int GetIcon() const = 0; | 50 virtual int GetIcon() const = 0; |
| 73 | 51 |
| 74 // Like GetIcon(), but gets the vector asset ID. | 52 // Like GetIcon(), but gets the vector asset ID. |
| 75 virtual gfx::VectorIconId GetVectorIcon() const = 0; | 53 virtual gfx::VectorIconId GetVectorIcon() const = 0; |
| 76 | 54 |
| 77 // Returns the name of the EV cert holder. This returns an empty string if | 55 // Returns the name of the EV cert holder. This returns an empty string if |
| 78 // the security level is not EV_SECURE. | 56 // the security level is not EV_SECURE. |
| 79 virtual base::string16 GetEVCertName() const = 0; | 57 virtual base::string16 GetEVCertName() const = 0; |
| 80 | 58 |
| 81 // Returns whether the URL for the current navigation entry should be | 59 // Returns whether the URL for the current navigation entry should be |
| 82 // in the location bar. | 60 // in the location bar. |
| 83 virtual bool ShouldDisplayURL() const = 0; | 61 virtual bool ShouldDisplayURL() const = 0; |
| 84 | 62 |
| 85 // Whether the text in the omnibox is currently being edited. | 63 // Whether the text in the omnibox is currently being edited. |
| 86 void set_input_in_progress(bool input_in_progress) { | 64 void set_input_in_progress(bool input_in_progress) { |
| 87 input_in_progress_ = input_in_progress; | 65 input_in_progress_ = input_in_progress; |
| 88 } | 66 } |
| 89 bool input_in_progress() const { return input_in_progress_; } | 67 bool input_in_progress() const { return input_in_progress_; } |
| 90 | 68 |
| 91 // Whether URL replacement should be enabled. | 69 // Whether URL replacement should be enabled. |
| 70 // TODO(treib,pkasting): Remove this. crbug.com/627747 |
| 92 void set_url_replacement_enabled(bool enabled) { | 71 void set_url_replacement_enabled(bool enabled) { |
| 93 url_replacement_enabled_ = enabled; | 72 url_replacement_enabled_ = enabled; |
| 94 } | 73 } |
| 95 bool url_replacement_enabled() const { | 74 bool url_replacement_enabled() const { |
| 96 return url_replacement_enabled_; | 75 return url_replacement_enabled_; |
| 97 } | 76 } |
| 98 | 77 |
| 99 protected: | 78 protected: |
| 100 ToolbarModel(); | 79 ToolbarModel(); |
| 101 | 80 |
| 102 private: | 81 private: |
| 103 bool input_in_progress_; | 82 bool input_in_progress_; |
| 104 bool url_replacement_enabled_; | 83 bool url_replacement_enabled_; |
| 105 | 84 |
| 106 DISALLOW_COPY_AND_ASSIGN(ToolbarModel); | 85 DISALLOW_COPY_AND_ASSIGN(ToolbarModel); |
| 107 }; | 86 }; |
| 108 | 87 |
| 109 #endif // COMPONENTS_TOOLBAR_TOOLBAR_MODEL_H_ | 88 #endif // COMPONENTS_TOOLBAR_TOOLBAR_MODEL_H_ |
| OLD | NEW |