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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_ 6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/strings/string16.h" 12 #include "url/gurl.h" 13 14 namespace net { 15 class X509Certificate; 16 } 17 18 // This class is the model used by the toolbar, location bar and autocomplete 19 // edit. It populates its states from the current navigation entry retrieved 20 // from the navigation controller returned by GetNavigationController(). 21 class ToolbarModel { 22 public: 23 // TODO(wtc): unify ToolbarModel::SecurityLevel with SecurityStyle. We 24 // don't need two sets of security UI levels. SECURITY_STYLE_AUTHENTICATED 25 // needs to be refined into three levels: warning, standard, and EV. 26 enum SecurityLevel { 27 #define DEFINE_TOOLBAR_MODEL_SECURITY_LEVEL(name,value) name = value, 28 #include "chrome/browser/ui/toolbar/toolbar_model_security_level_list.h" 29 #undef DEFINE_TOOLBAR_MODEL_SECURITY_LEVEL 30 }; 31 32 virtual ~ToolbarModel(); 33 34 // Returns the text for the current page's URL. This will have been formatted 35 // for display to the user: 36 // - Some characters may be unescaped. 37 // - The scheme and/or trailing slash may be dropped. 38 // - If the current page's URL is a search URL for the user's default search 39 // engine, the query will be extracted and returned for display instead 40 // of the URL. 41 virtual base::string16 GetText() const = 0; 42 43 // Some search URLs bundle a special "corpus" param that we can extract and 44 // display next to users' search terms in cases where we'd show the search 45 // terms instead of the URL anyway. For example, a Google image search might 46 // show the corpus "Images:" plus a search string. This is only used on 47 // mobile. 48 virtual base::string16 GetCorpusNameForMobile() const = 0; 49 50 // Returns the URL of the current navigation entry. 51 virtual GURL GetURL() const = 0; 52 53 // Returns true if a call to GetText() would successfully replace the URL 54 // with search terms. If |ignore_editing| is true, the result reflects the 55 // underlying state of the page without regard to any user edits that may be 56 // in progress in the omnibox. 57 virtual bool WouldPerformSearchTermReplacement(bool ignore_editing) const = 0; 58 59 // Returns true if a call to GetText() would return something other than the 60 // URL because of either search term replacement or URL omission in favor of 61 // the origin chip. 62 bool WouldReplaceURL() const; 63 64 // Returns the security level that the toolbar should display. If 65 // |ignore_editing| is true, the result reflects the underlying state of the 66 // page without regard to any user edits that may be in progress in the 67 // omnibox. 68 virtual SecurityLevel GetSecurityLevel(bool ignore_editing) const = 0; 69 70 // Returns the resource_id of the icon to show to the left of the address, 71 // based on the current URL. When search term replacement is active, this 72 // returns a search icon. This doesn't cover specialized icons while the 73 // user is editing; see OmniboxView::GetIcon(). 74 virtual int GetIcon() const = 0; 75 76 // As |GetIcon()|, but returns the icon only taking into account the security 77 // |level| given, ignoring search term replacement state. 78 virtual int GetIconForSecurityLevel(SecurityLevel level) const = 0; 79 80 // Returns the name of the EV cert holder. Only call this when the security 81 // level is EV_SECURE. 82 virtual base::string16 GetEVCertName() const = 0; 83 84 // Returns whether the URL for the current navigation entry should be 85 // in the location bar. 86 virtual bool ShouldDisplayURL() const = 0; 87 88 // Whether the text in the omnibox is currently being edited. 89 void set_input_in_progress(bool input_in_progress) { 90 input_in_progress_ = input_in_progress; 91 } 92 bool input_in_progress() const { return input_in_progress_; } 93 94 // Whether URL replacement should be enabled. 95 void set_url_replacement_enabled(bool enabled) { 96 url_replacement_enabled_ = enabled; 97 } 98 bool url_replacement_enabled() const { 99 return url_replacement_enabled_; 100 } 101 102 protected: 103 ToolbarModel(); 104 105 private: 106 // Returns true if a call to GetText() would return an empty string instead of 107 // the URL that would have otherwise been displayed because the host/origin is 108 // instead being displayed in the origin chip. This returns false when we 109 // wouldn't have displayed a URL to begin with (e.g. for the NTP). 110 virtual bool WouldOmitURLDueToOriginChip() const = 0; 111 112 bool input_in_progress_; 113 bool url_replacement_enabled_; 114 115 DISALLOW_COPY_AND_ASSIGN(ToolbarModel); 116 }; 117 118 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_ 119