- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / toolbar / toolbar_model.h
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 |allow_search_term_replacement| is true, the query will be extracted
39   //     from search URLs for the user's default search engine and will be
40   //     displayed in place of the URL.
41   virtual string16 GetText(bool allow_search_term_replacement) 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 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(true) 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 the security level that the toolbar should display.  If
60   // |ignore_editing| is true, the result reflects the underlying state of the
61   // page without regard to any user edits that may be in progress in the
62   // omnibox.
63   virtual SecurityLevel GetSecurityLevel(bool ignore_editing) const = 0;
64
65   // 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
67   // user is editing; see OmniboxView::GetIcon().
68   virtual int GetIcon() const = 0;
69
70   // Returns the name of the EV cert holder.  Only call this when the security
71   // level is EV_SECURE.
72   virtual string16 GetEVCertName() const = 0;
73
74   // Returns whether the URL for the current navigation entry should be
75   // in the location bar.
76   virtual bool ShouldDisplayURL() const = 0;
77
78   // Whether the text in the omnibox is currently being edited.
79   void set_input_in_progress(bool input_in_progress) {
80     input_in_progress_ = input_in_progress;
81   }
82   bool input_in_progress() const { return input_in_progress_; }
83
84   // Whether search term replacement should be enabled.
85   void set_search_term_replacement_enabled(bool enabled) {
86     search_term_replacement_enabled_ = enabled;
87   }
88   bool search_term_replacement_enabled() const {
89     return search_term_replacement_enabled_;
90   }
91
92  protected:
93   ToolbarModel()
94       : input_in_progress_(false),
95         search_term_replacement_enabled_(true) {}
96
97  private:
98   bool input_in_progress_;
99   bool search_term_replacement_enabled_;
100
101   DISALLOW_COPY_AND_ASSIGN(ToolbarModel);
102 };
103
104 #endif  // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_MODEL_H_