Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/page_info_model.h

Issue 3560004: Refactor the code for loading icons into the PageInfoModel. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: cleanup Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/page_info_window_gtk.cc ('k') | chrome/browser/page_info_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PAGE_INFO_MODEL_H_ 5 #ifndef CHROME_BROWSER_PAGE_INFO_MODEL_H_
6 #define CHROME_BROWSER_PAGE_INFO_MODEL_H_ 6 #define CHROME_BROWSER_PAGE_INFO_MODEL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "chrome/browser/cancelable_request.h" 12 #include "chrome/browser/cancelable_request.h"
13 #include "chrome/browser/history/history.h" 13 #include "chrome/browser/history/history.h"
14 #include "chrome/browser/tab_contents/navigation_entry.h" 14 #include "chrome/browser/tab_contents/navigation_entry.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 16
17 #ifdef __OBJC__
18 @class NSImage;
19 #else
20 class NSImage;
21 #endif // __OBJC__
17 class PrefService; 22 class PrefService;
18 class Profile; 23 class Profile;
24 class SkBitmap;
25
26 #if defined(USE_X11) && !defined(TOOLKIT_VIEWS)
27 typedef struct _GdkPixbuf GdkPixbuf;
28 #endif
19 29
20 // The model that provides the information that should be displayed in the page 30 // The model that provides the information that should be displayed in the page
21 // info dialog/bubble. 31 // info dialog/bubble.
22 class PageInfoModel { 32 class PageInfoModel {
23 public: 33 public:
24 class PageInfoModelObserver { 34 class PageInfoModelObserver {
25 public: 35 public:
26 virtual ~PageInfoModelObserver() {} 36 virtual ~PageInfoModelObserver() {}
27 37
28 virtual void ModelChanged() = 0; 38 virtual void ModelChanged() = 0;
29 }; 39 };
30 40
31 enum SectionInfoType { 41 enum SectionInfoType {
32 SECTION_INFO_IDENTITY = 0, 42 SECTION_INFO_IDENTITY = 0,
33 SECTION_INFO_CONNECTION, 43 SECTION_INFO_CONNECTION,
34 SECTION_INFO_FIRST_VISIT, 44 SECTION_INFO_FIRST_VISIT,
35 }; 45 };
36 46
37 enum SectionInfoState { 47 // TODO(rsesek): Extract this information out to gfx::NativeImage.
38 SECTION_STATE_OK = 0, 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,
39 // For example, if state is OK but contains mixed content. 61 // For example, if state is OK but contains mixed content.
40 SECTION_STATE_WARNING_MINOR, 62 ICON_STATE_WARNING_MINOR,
41 // For example, if content was served over HTTP. 63 // For example, if content was served over HTTP.
42 SECTION_STATE_WARNING_MAJOR, 64 ICON_STATE_WARNING_MAJOR,
43 // For example, unverified identity over HTTPS. 65 // For example, unverified identity over HTTPS.
44 SECTION_STATE_ERROR, 66 ICON_STATE_ERROR,
67 // An information icon.
68 ICON_STATE_INFO
45 }; 69 };
46 70
47 struct SectionInfo { 71 struct SectionInfo {
48 SectionInfo(SectionInfoState state, 72 SectionInfo(SectionStateIcon icon_id,
49 const string16& title, 73 const string16& title,
50 const string16& headline, 74 const string16& headline,
51 const string16& description, 75 const string16& description,
52 SectionInfoType type) 76 SectionInfoType type)
53 : state(state), 77 : icon_id(icon_id),
54 title(title), 78 title(title),
55 headline(headline), 79 headline(headline),
56 description(description), 80 description(description),
57 type(type) { 81 type(type) {
58 } 82 }
59 83
60 // The overall state of the connection (error, warning, ok). 84 // The overall state of the connection (error, warning, ok).
61 SectionInfoState state; 85 SectionStateIcon icon_id;
62 86
63 // The title of the section. 87 // The title of the section.
64 string16 title; 88 string16 title;
65 89
66 // A single line describing the section, optional. 90 // A single line describing the section, optional.
67 string16 headline; 91 string16 headline;
68 92
69 // The full description of what this section is. 93 // The full description of what this section is.
70 string16 description; 94 string16 description;
71 95
72 // The type of SectionInfo we are dealing with, for example: Identity, 96 // The type of SectionInfo we are dealing with, for example: Identity,
73 // Connection, First Visit. 97 // Connection, First Visit.
74 SectionInfoType type; 98 SectionInfoType type;
75 }; 99 };
76 100
77 PageInfoModel(Profile* profile, 101 PageInfoModel(Profile* profile,
78 const GURL& url, 102 const GURL& url,
79 const NavigationEntry::SSLStatus& ssl, 103 const NavigationEntry::SSLStatus& ssl,
80 bool show_history, 104 bool show_history,
81 PageInfoModelObserver* observer); 105 PageInfoModelObserver* observer);
82 ~PageInfoModel(); 106 ~PageInfoModel();
83 107
84 int GetSectionCount(); 108 int GetSectionCount();
85 SectionInfo GetSectionInfo(int index); 109 SectionInfo GetSectionInfo(int index);
86 110
111 // Returns the native image type for an icon with the given id.
112 ImageType GetIconImage(SectionStateIcon icon_id);
113
87 // Callback from history service with number of visits to url. 114 // Callback from history service with number of visits to url.
88 void OnGotVisitCountToHost(HistoryService::Handle handle, 115 void OnGotVisitCountToHost(HistoryService::Handle handle,
89 bool found_visits, 116 bool found_visits,
90 int count, 117 int count,
91 base::Time first_visit); 118 base::Time first_visit);
92 119
93 static void RegisterPrefs(PrefService* prefs); 120 static void RegisterPrefs(PrefService* prefs);
94 121
95 protected: 122 protected:
96 // Testing constructor. DO NOT USE. 123 // Testing constructor. DO NOT USE.
97 PageInfoModel(); 124 PageInfoModel();
98 125
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
99 PageInfoModelObserver* observer_; 134 PageInfoModelObserver* observer_;
100 135
101 std::vector<SectionInfo> sections_; 136 std::vector<SectionInfo> sections_;
102 137
138 // All possible icons that go next to the text descriptions to indicate state.
139 std::vector<ImageType> icons_;
140
103 // Used to request number of visits. 141 // Used to request number of visits.
104 CancelableRequestConsumer request_consumer_; 142 CancelableRequestConsumer request_consumer_;
105 143
106 private: 144 private:
107 DISALLOW_COPY_AND_ASSIGN(PageInfoModel); 145 DISALLOW_COPY_AND_ASSIGN(PageInfoModel);
108 }; 146 };
109 147
110 #endif // CHROME_BROWSER_PAGE_INFO_MODEL_H_ 148 #endif // CHROME_BROWSER_PAGE_INFO_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/gtk/page_info_window_gtk.cc ('k') | chrome/browser/page_info_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698