blob: 04a7a2df29b439e28f56a2621b4b41cc7f01c1a1 [file] [log] [blame]
[email protected]71675dc7c2010-05-14 19:47:281// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]4d677202009-07-19 07:37:122// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]eeba96c2009-07-23 22:04:225#ifndef CHROME_BROWSER_PAGE_INFO_MODEL_H_
6#define CHROME_BROWSER_PAGE_INFO_MODEL_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]4d677202009-07-19 07:37:128
[email protected]4d677202009-07-19 07:37:129#include <vector>
10
[email protected]b232fc02009-07-30 22:51:5411#include "base/string16.h"
[email protected]4d677202009-07-19 07:37:1212#include "chrome/browser/cancelable_request.h"
13#include "chrome/browser/history/history.h"
14#include "chrome/browser/tab_contents/navigation_entry.h"
15#include "googleurl/src/gurl.h"
16
[email protected]7fef9717a2010-10-02 19:08:4417#ifdef __OBJC__
18@class NSImage;
19#else
20class NSImage;
21#endif // __OBJC__
[email protected]4d677202009-07-19 07:37:1222class PrefService;
23class Profile;
[email protected]7fef9717a2010-10-02 19:08:4424class SkBitmap;
25
26#if defined(USE_X11) && !defined(TOOLKIT_VIEWS)
27typedef struct _GdkPixbuf GdkPixbuf;
28#endif
[email protected]4d677202009-07-19 07:37:1229
30// The model that provides the information that should be displayed in the page
[email protected]ba96f8a2010-08-26 09:00:0031// info dialog/bubble.
[email protected]4d677202009-07-19 07:37:1232class PageInfoModel {
33 public:
34 class PageInfoModelObserver {
[email protected]46ebf0642010-07-24 02:47:4035 public:
[email protected]46ebf0642010-07-24 02:47:4036 virtual ~PageInfoModelObserver() {}
[email protected]440cb532010-09-30 17:32:2837
38 virtual void ModelChanged() = 0;
[email protected]4d677202009-07-19 07:37:1239 };
40
[email protected]ba96f8a2010-08-26 09:00:0041 enum SectionInfoType {
42 SECTION_INFO_IDENTITY = 0,
43 SECTION_INFO_CONNECTION,
44 SECTION_INFO_FIRST_VISIT,
45 };
46
[email protected]7fef9717a2010-10-02 19:08:4447 // TODO(rsesek): Extract this information out to gfx::NativeImage.
48#if defined(OS_MACOSX)
49 typedef NSImage* ImageType;
50#elif defined(USE_X11) && !defined(TOOLKIT_VIEWS)
51 typedef GdkPixbuf* ImageType;
52#else
53 typedef const SkBitmap* ImageType;
54#endif
55
56 enum SectionStateIcon {
57 // No icon.
58 ICON_NONE = -1,
59 // State is OK.
60 ICON_STATE_OK,
[email protected]c45ea2172010-09-10 13:22:0561 // For example, if state is OK but contains mixed content.
[email protected]7fef9717a2010-10-02 19:08:4462 ICON_STATE_WARNING_MINOR,
[email protected]c45ea2172010-09-10 13:22:0563 // For example, if content was served over HTTP.
[email protected]7fef9717a2010-10-02 19:08:4464 ICON_STATE_WARNING_MAJOR,
[email protected]740ea162010-08-27 09:28:2465 // For example, unverified identity over HTTPS.
[email protected]7fef9717a2010-10-02 19:08:4466 ICON_STATE_ERROR,
67 // An information icon.
68 ICON_STATE_INFO
[email protected]740ea162010-08-27 09:28:2469 };
70
[email protected]4d677202009-07-19 07:37:1271 struct SectionInfo {
[email protected]7fef9717a2010-10-02 19:08:4472 SectionInfo(SectionStateIcon icon_id,
[email protected]b232fc02009-07-30 22:51:5473 const string16& title,
[email protected]ba96f8a2010-08-26 09:00:0074 const string16& headline,
75 const string16& description,
76 SectionInfoType type)
[email protected]7fef9717a2010-10-02 19:08:4477 : icon_id(icon_id),
[email protected]4d677202009-07-19 07:37:1278 title(title),
[email protected]ba96f8a2010-08-26 09:00:0079 headline(headline),
80 description(description),
81 type(type) {
[email protected]4d677202009-07-19 07:37:1282 }
83
[email protected]740ea162010-08-27 09:28:2484 // The overall state of the connection (error, warning, ok).
[email protected]7fef9717a2010-10-02 19:08:4485 SectionStateIcon icon_id;
[email protected]4d677202009-07-19 07:37:1286
87 // The title of the section.
[email protected]b232fc02009-07-30 22:51:5488 string16 title;
[email protected]4d677202009-07-19 07:37:1289
90 // A single line describing the section, optional.
[email protected]ba96f8a2010-08-26 09:00:0091 string16 headline;
[email protected]4d677202009-07-19 07:37:1292
93 // The full description of what this section is.
[email protected]b232fc02009-07-30 22:51:5494 string16 description;
[email protected]ba96f8a2010-08-26 09:00:0095
96 // The type of SectionInfo we are dealing with, for example: Identity,
97 // Connection, First Visit.
98 SectionInfoType type;
[email protected]4d677202009-07-19 07:37:1299 };
100
101 PageInfoModel(Profile* profile,
102 const GURL& url,
103 const NavigationEntry::SSLStatus& ssl,
104 bool show_history,
105 PageInfoModelObserver* observer);
[email protected]601858c02010-09-01 17:08:20106 ~PageInfoModel();
[email protected]4d677202009-07-19 07:37:12107
108 int GetSectionCount();
109 SectionInfo GetSectionInfo(int index);
110
[email protected]7fef9717a2010-10-02 19:08:44111 // Returns the native image type for an icon with the given id.
112 ImageType GetIconImage(SectionStateIcon icon_id);
113
[email protected]4d677202009-07-19 07:37:12114 // Callback from history service with number of visits to url.
115 void OnGotVisitCountToHost(HistoryService::Handle handle,
116 bool found_visits,
117 int count,
118 base::Time first_visit);
119
120 static void RegisterPrefs(PrefService* prefs);
121
[email protected]71675dc7c2010-05-14 19:47:28122 protected:
123 // Testing constructor. DO NOT USE.
[email protected]601858c02010-09-01 17:08:20124 PageInfoModel();
[email protected]71675dc7c2010-05-14 19:47:28125
[email protected]7fef9717a2010-10-02 19:08:44126 // Shared initialization for default and testing constructor.
127 void Init();
128
129 // Gets the native image resource of the given id from the ResourceBundle.
130 // Mac only: image is owned by caller. On other platforms, the image is owned
131 // by the shared ResourceBundle.
132 ImageType GetBitmapNamed(int resource_id);
133
[email protected]4d677202009-07-19 07:37:12134 PageInfoModelObserver* observer_;
135
136 std::vector<SectionInfo> sections_;
137
[email protected]7fef9717a2010-10-02 19:08:44138 // All possible icons that go next to the text descriptions to indicate state.
139 std::vector<ImageType> icons_;
140
[email protected]4d677202009-07-19 07:37:12141 // Used to request number of visits.
142 CancelableRequestConsumer request_consumer_;
143
[email protected]71675dc7c2010-05-14 19:47:28144 private:
[email protected]4d677202009-07-19 07:37:12145 DISALLOW_COPY_AND_ASSIGN(PageInfoModel);
146};
147
[email protected]eeba96c2009-07-23 22:04:22148#endif // CHROME_BROWSER_PAGE_INFO_MODEL_H_