page_info_model.h revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_PAGE_INFO_MODEL_H_ 6#define CHROME_BROWSER_PAGE_INFO_MODEL_H_ 7#pragma once 8 9#include <vector> 10 11#include "gfx/native_widget_types.h" 12#include "base/string16.h" 13#include "chrome/browser/cancelable_request.h" 14#include "chrome/browser/history/history.h" 15#include "chrome/browser/tab_contents/navigation_entry.h" 16#include "googleurl/src/gurl.h" 17 18class PrefService; 19class Profile; 20 21// The model that provides the information that should be displayed in the page 22// info dialog/bubble. 23class PageInfoModel { 24 public: 25 class PageInfoModelObserver { 26 public: 27 virtual ~PageInfoModelObserver() {} 28 29 virtual void ModelChanged() = 0; 30 }; 31 32 enum SectionInfoType { 33 SECTION_INFO_IDENTITY = 0, 34 SECTION_INFO_CONNECTION, 35 SECTION_INFO_FIRST_VISIT, 36 }; 37 38 enum SectionStateIcon { 39 // No icon. 40 ICON_NONE = -1, 41 // State is OK. 42 ICON_STATE_OK, 43 // For example, if state is OK but contains mixed content. 44 ICON_STATE_WARNING_MINOR, 45 // For example, if content was served over HTTP. 46 ICON_STATE_WARNING_MAJOR, 47 // For example, unverified identity over HTTPS. 48 ICON_STATE_ERROR, 49 // An information icon. 50 ICON_STATE_INFO 51 }; 52 53 struct SectionInfo { 54 SectionInfo(SectionStateIcon icon_id, 55 const string16& title, 56 const string16& headline, 57 const string16& description, 58 SectionInfoType type) 59 : icon_id(icon_id), 60 title(title), 61 headline(headline), 62 description(description), 63 type(type) { 64 } 65 66 // The overall state of the connection (error, warning, ok). 67 SectionStateIcon icon_id; 68 69 // The title of the section. 70 string16 title; 71 72 // A single line describing the section, optional. 73 string16 headline; 74 75 // The full description of what this section is. 76 string16 description; 77 78 // The type of SectionInfo we are dealing with, for example: Identity, 79 // Connection, First Visit. 80 SectionInfoType type; 81 }; 82 83 PageInfoModel(Profile* profile, 84 const GURL& url, 85 const NavigationEntry::SSLStatus& ssl, 86 bool show_history, 87 PageInfoModelObserver* observer); 88 ~PageInfoModel(); 89 90 int GetSectionCount(); 91 SectionInfo GetSectionInfo(int index); 92 93 // Returns the native image type for an icon with the given id. 94 gfx::NativeImage GetIconImage(SectionStateIcon icon_id); 95 96 // Callback from history service with number of visits to url. 97 void OnGotVisitCountToHost(HistoryService::Handle handle, 98 bool found_visits, 99 int count, 100 base::Time first_visit); 101 102 static void RegisterPrefs(PrefService* prefs); 103 104 protected: 105 // Testing constructor. DO NOT USE. 106 PageInfoModel(); 107 108 // Shared initialization for default and testing constructor. 109 void Init(); 110 111 // Wrapper for ResourceBundle::GetNativeImage() so that Mac can retain its 112 // icons. 113 gfx::NativeImage GetBitmapNamed(int resource_id); 114 115 PageInfoModelObserver* observer_; 116 117 std::vector<SectionInfo> sections_; 118 119 // All possible icons that go next to the text descriptions to indicate state. 120 std::vector<gfx::NativeImage> icons_; 121 122 // Used to request number of visits. 123 CancelableRequestConsumer request_consumer_; 124 125 private: 126 DISALLOW_COPY_AND_ASSIGN(PageInfoModel); 127}; 128 129#endif // CHROME_BROWSER_PAGE_INFO_MODEL_H_ 130