summaryrefslogtreecommitdiffstats
path: root/chrome/browser/page_info_model.h
blob: eb05dc1f6dbb9cf5d0260372585a22b61d5bc1d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PAGE_INFO_MODEL_H_
#define CHROME_BROWSER_PAGE_INFO_MODEL_H_
#pragma once

#include <vector>

#include "base/string16.h"
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/history/history.h"
#include "googleurl/src/gurl.h"
#include "ui/gfx/image/image.h"

class PageInfoModelObserver;
class Profile;

namespace content {
struct SSLStatus;
}

// The model that provides the information that should be displayed in the page
// info dialog/bubble.
class PageInfoModel {
 public:
  enum SectionInfoType {
    SECTION_INFO_IDENTITY = 0,
    SECTION_INFO_CONNECTION,
    SECTION_INFO_FIRST_VISIT,
    SECTION_INFO_INTERNAL_PAGE,  // Used for chrome:// pages, etc.
  };

  // NOTE: ICON_STATE_OK ... ICON_STATE_ERROR must be listed in increasing
  // order of severity.  Code may depend on this order.
  enum SectionStateIcon {
    // No icon.
    ICON_NONE = -1,
    // State is OK.
    ICON_STATE_OK,
    // For example, if state is OK but contains mixed content.
    ICON_STATE_WARNING_MINOR,
    // For example, if content was served over HTTP.
    ICON_STATE_WARNING_MAJOR,
    // For example, unverified identity over HTTPS.
    ICON_STATE_ERROR,
    // An information icon.
    ICON_STATE_INFO,
    // Icon for internal pages.
    ICON_STATE_INTERNAL_PAGE,
  };

  struct SectionInfo {
    SectionInfo(SectionStateIcon icon_id,
                const string16& headline,
                const string16& description,
                SectionInfoType type)
        : icon_id(icon_id),
          headline(headline),
          description(description),
          type(type) {
    }

    // The overall state of the connection (error, warning, ok).
    SectionStateIcon icon_id;

    // A single line describing the section, optional.
    string16 headline;

    // The full description of what this section is.
    string16 description;

    // The type of SectionInfo we are dealing with, for example: Identity,
    // Connection, First Visit.
    SectionInfoType type;
  };

  PageInfoModel(Profile* profile,
                const GURL& url,
                const content::SSLStatus& ssl,
                bool show_history,
                PageInfoModelObserver* observer);
  ~PageInfoModel();

  int GetSectionCount();
  SectionInfo GetSectionInfo(int index);

  // Returns the native image type for an icon with the given id.
  gfx::Image* GetIconImage(SectionStateIcon icon_id);

  // Callback from history service with number of visits to url.
  void OnGotVisitCountToHost(HistoryService::Handle handle,
                             bool found_visits,
                             int count,
                             base::Time first_visit);

  // Returns the label for the "Certificate Information", if needed.
  string16 GetCertificateLabel() const;

 protected:
  // Testing constructor. DO NOT USE.
  PageInfoModel();

  // Shared initialization for default and testing constructor.
  void Init();

  PageInfoModelObserver* observer_;

  std::vector<SectionInfo> sections_;

  // All possible icons that go next to the text descriptions to indicate state.
  std::vector<gfx::Image*> icons_;

  // Used to request number of visits.
  CancelableRequestConsumer request_consumer_;

  // Label for "Certificate Information", if needed.
  string16 certificate_label_;

 private:
  DISALLOW_COPY_AND_ASSIGN(PageInfoModel);
};

#endif  // CHROME_BROWSER_PAGE_INFO_MODEL_H_