summaryrefslogtreecommitdiffstats
path: root/chrome/browser/page_info_model.h
blob: 3e6b96270376bd542e62fe505b4900122d6f1a61 (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
126
127
128
129
// Copyright (c) 2010 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 "gfx/native_widget_types.h"
#include "base/string16.h"
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "googleurl/src/gurl.h"

class PrefService;
class Profile;

// The model that provides the information that should be displayed in the page
// info dialog/bubble.
class PageInfoModel {
 public:
  class PageInfoModelObserver {
   public:
    virtual ~PageInfoModelObserver() {}

    virtual void ModelChanged() = 0;
  };

  enum SectionInfoType {
    SECTION_INFO_IDENTITY = 0,
    SECTION_INFO_CONNECTION,
    SECTION_INFO_FIRST_VISIT,
  };

  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
  };

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

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

    // The title of the section.
    string16 title;

    // 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 NavigationEntry::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::NativeImage 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);

  static void RegisterPrefs(PrefService* prefs);

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

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

  // Wrapper for ResourceBundle::GetNativeImage() so that Mac can retain its
  // icons.
  gfx::NativeImage GetBitmapNamed(int resource_id);

  PageInfoModelObserver* observer_;

  std::vector<SectionInfo> sections_;

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

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

 private:
  DISALLOW_COPY_AND_ASSIGN(PageInfoModel);
};

#endif  // CHROME_BROWSER_PAGE_INFO_MODEL_H_