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