1// Copyright (c) 2010 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_PAGE_INFO_MODEL_H_
6#define CHROME_BROWSER_PAGE_INFO_MODEL_H_
7#pragma once
8
9#include <vector>
10
11#include "base/string16.h"
12#include "chrome/browser/history/history.h"
13#include "content/browser/cancelable_request.h"
14#include "content/browser/tab_contents/navigation_entry.h"
15#include "googleurl/src/gurl.h"
16#include "ui/gfx/image.h"
17
18class PrefService;
19class Profile;
20
21// The model that provides the information that should be displayed in the page
22// info dialog/bubble.
23class PageInfoModel {
24 public:
25  class PageInfoModelObserver {
26   public:
27    virtual ~PageInfoModelObserver() {}
28
29    virtual void ModelChanged() = 0;
30  };
31
32  enum SectionInfoType {
33    SECTION_INFO_IDENTITY = 0,
34    SECTION_INFO_CONNECTION,
35    SECTION_INFO_FIRST_VISIT,
36  };
37
38  // NOTE: ICON_STATE_OK ... ICON_STATE_ERROR must be listed in increasing
39  // order of severity.  Code may depend on this order.
40  enum SectionStateIcon {
41    // No icon.
42    ICON_NONE = -1,
43    // State is OK.
44    ICON_STATE_OK,
45    // For example, if state is OK but contains mixed content.
46    ICON_STATE_WARNING_MINOR,
47    // For example, if content was served over HTTP.
48    ICON_STATE_WARNING_MAJOR,
49    // For example, unverified identity over HTTPS.
50    ICON_STATE_ERROR,
51    // An information icon.
52    ICON_STATE_INFO
53  };
54
55  struct SectionInfo {
56    SectionInfo(SectionStateIcon icon_id,
57                const string16& headline,
58                const string16& description,
59                SectionInfoType type)
60        : icon_id(icon_id),
61          headline(headline),
62          description(description),
63          type(type) {
64    }
65
66    // The overall state of the connection (error, warning, ok).
67    SectionStateIcon icon_id;
68
69    // A single line describing the section, optional.
70    string16 headline;
71
72    // The full description of what this section is.
73    string16 description;
74
75    // The type of SectionInfo we are dealing with, for example: Identity,
76    // Connection, First Visit.
77    SectionInfoType type;
78  };
79
80  PageInfoModel(Profile* profile,
81                const GURL& url,
82                const NavigationEntry::SSLStatus& ssl,
83                bool show_history,
84                PageInfoModelObserver* observer);
85  ~PageInfoModel();
86
87  int GetSectionCount();
88  SectionInfo GetSectionInfo(int index);
89
90  // Returns the native image type for an icon with the given id.
91  gfx::Image* GetIconImage(SectionStateIcon icon_id);
92
93  // Callback from history service with number of visits to url.
94  void OnGotVisitCountToHost(HistoryService::Handle handle,
95                             bool found_visits,
96                             int count,
97                             base::Time first_visit);
98
99 protected:
100  // Testing constructor. DO NOT USE.
101  PageInfoModel();
102
103  // Shared initialization for default and testing constructor.
104  void Init();
105
106  PageInfoModelObserver* observer_;
107
108  std::vector<SectionInfo> sections_;
109
110  // All possible icons that go next to the text descriptions to indicate state.
111  std::vector<gfx::Image*> icons_;
112
113  // Used to request number of visits.
114  CancelableRequestConsumer request_consumer_;
115
116 private:
117  DISALLOW_COPY_AND_ASSIGN(PageInfoModel);
118};
119
120#endif  // CHROME_BROWSER_PAGE_INFO_MODEL_H_
121