[email protected] | 71675dc7c | 2010-05-14 19:47:28 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | eeba96c | 2009-07-23 22:04:22 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PAGE_INFO_MODEL_H_ |
| 6 | #define CHROME_BROWSER_PAGE_INFO_MODEL_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 8 | |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | b232fc0 | 2009-07-30 22:51:54 | [diff] [blame] | 11 | #include "base/string16.h" |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 12 | #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] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 17 | #ifdef __OBJC__ |
| 18 | @class NSImage; |
| 19 | #else |
| 20 | class NSImage; |
| 21 | #endif // __OBJC__ |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 22 | class PrefService; |
| 23 | class Profile; |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 24 | class SkBitmap; |
| 25 | |
| 26 | #if defined(USE_X11) && !defined(TOOLKIT_VIEWS) |
| 27 | typedef struct _GdkPixbuf GdkPixbuf; |
| 28 | #endif |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 29 | |
| 30 | // The model that provides the information that should be displayed in the page |
[email protected] | ba96f8a | 2010-08-26 09:00:00 | [diff] [blame] | 31 | // info dialog/bubble. |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 32 | class PageInfoModel { |
| 33 | public: |
| 34 | class PageInfoModelObserver { |
[email protected] | 46ebf064 | 2010-07-24 02:47:40 | [diff] [blame] | 35 | public: |
[email protected] | 46ebf064 | 2010-07-24 02:47:40 | [diff] [blame] | 36 | virtual ~PageInfoModelObserver() {} |
[email protected] | 440cb53 | 2010-09-30 17:32:28 | [diff] [blame] | 37 | |
| 38 | virtual void ModelChanged() = 0; |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 39 | }; |
| 40 | |
[email protected] | ba96f8a | 2010-08-26 09:00:00 | [diff] [blame] | 41 | enum SectionInfoType { |
| 42 | SECTION_INFO_IDENTITY = 0, |
| 43 | SECTION_INFO_CONNECTION, |
| 44 | SECTION_INFO_FIRST_VISIT, |
| 45 | }; |
| 46 | |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 47 | // 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] | c45ea217 | 2010-09-10 13:22:05 | [diff] [blame] | 61 | // For example, if state is OK but contains mixed content. |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 62 | ICON_STATE_WARNING_MINOR, |
[email protected] | c45ea217 | 2010-09-10 13:22:05 | [diff] [blame] | 63 | // For example, if content was served over HTTP. |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 64 | ICON_STATE_WARNING_MAJOR, |
[email protected] | 740ea16 | 2010-08-27 09:28:24 | [diff] [blame] | 65 | // For example, unverified identity over HTTPS. |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 66 | ICON_STATE_ERROR, |
| 67 | // An information icon. |
| 68 | ICON_STATE_INFO |
[email protected] | 740ea16 | 2010-08-27 09:28:24 | [diff] [blame] | 69 | }; |
| 70 | |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 71 | struct SectionInfo { |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 72 | SectionInfo(SectionStateIcon icon_id, |
[email protected] | b232fc0 | 2009-07-30 22:51:54 | [diff] [blame] | 73 | const string16& title, |
[email protected] | ba96f8a | 2010-08-26 09:00:00 | [diff] [blame] | 74 | const string16& headline, |
| 75 | const string16& description, |
| 76 | SectionInfoType type) |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 77 | : icon_id(icon_id), |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 78 | title(title), |
[email protected] | ba96f8a | 2010-08-26 09:00:00 | [diff] [blame] | 79 | headline(headline), |
| 80 | description(description), |
| 81 | type(type) { |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | 740ea16 | 2010-08-27 09:28:24 | [diff] [blame] | 84 | // The overall state of the connection (error, warning, ok). |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 85 | SectionStateIcon icon_id; |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 86 | |
| 87 | // The title of the section. |
[email protected] | b232fc0 | 2009-07-30 22:51:54 | [diff] [blame] | 88 | string16 title; |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 89 | |
| 90 | // A single line describing the section, optional. |
[email protected] | ba96f8a | 2010-08-26 09:00:00 | [diff] [blame] | 91 | string16 headline; |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 92 | |
| 93 | // The full description of what this section is. |
[email protected] | b232fc0 | 2009-07-30 22:51:54 | [diff] [blame] | 94 | string16 description; |
[email protected] | ba96f8a | 2010-08-26 09:00:00 | [diff] [blame] | 95 | |
| 96 | // The type of SectionInfo we are dealing with, for example: Identity, |
| 97 | // Connection, First Visit. |
| 98 | SectionInfoType type; |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | PageInfoModel(Profile* profile, |
| 102 | const GURL& url, |
| 103 | const NavigationEntry::SSLStatus& ssl, |
| 104 | bool show_history, |
| 105 | PageInfoModelObserver* observer); |
[email protected] | 601858c0 | 2010-09-01 17:08:20 | [diff] [blame] | 106 | ~PageInfoModel(); |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 107 | |
| 108 | int GetSectionCount(); |
| 109 | SectionInfo GetSectionInfo(int index); |
| 110 | |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 111 | // Returns the native image type for an icon with the given id. |
| 112 | ImageType GetIconImage(SectionStateIcon icon_id); |
| 113 | |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 114 | // 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] | 71675dc7c | 2010-05-14 19:47:28 | [diff] [blame] | 122 | protected: |
| 123 | // Testing constructor. DO NOT USE. |
[email protected] | 601858c0 | 2010-09-01 17:08:20 | [diff] [blame] | 124 | PageInfoModel(); |
[email protected] | 71675dc7c | 2010-05-14 19:47:28 | [diff] [blame] | 125 | |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 126 | // 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] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 134 | PageInfoModelObserver* observer_; |
| 135 | |
| 136 | std::vector<SectionInfo> sections_; |
| 137 | |
[email protected] | 7fef9717a | 2010-10-02 19:08:44 | [diff] [blame^] | 138 | // All possible icons that go next to the text descriptions to indicate state. |
| 139 | std::vector<ImageType> icons_; |
| 140 | |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 141 | // Used to request number of visits. |
| 142 | CancelableRequestConsumer request_consumer_; |
| 143 | |
[email protected] | 71675dc7c | 2010-05-14 19:47:28 | [diff] [blame] | 144 | private: |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 145 | DISALLOW_COPY_AND_ASSIGN(PageInfoModel); |
| 146 | }; |
| 147 | |
[email protected] | eeba96c | 2009-07-23 22:04:22 | [diff] [blame] | 148 | #endif // CHROME_BROWSER_PAGE_INFO_MODEL_H_ |