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

Side by Side Diff: chrome/browser/ui/gtk/website_settings_popup_gtk.cc

Issue 9732007: Add GTK Website Settings UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "chrome/browser/ui/gtk/website_settings_popup_gtk.h"
6
7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h"
9 #include "base/i18n/rtl.h"
10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/certificate_viewer.h"
13 #include "chrome/browser/page_info_model.h"
14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
16 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
17 #include "chrome/browser/ui/gtk/collected_cookies_gtk.h"
18 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
19 #include "chrome/browser/ui/gtk/gtk_util.h"
20 #include "chrome/browser/ui/gtk/theme_service_gtk.h"
21 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
23 #include "chrome/common/url_constants.h"
24 #include "content/public/browser/cert_store.h"
25 #include "grit/generated_resources.h"
26 #include "grit/locale_settings.h"
27 #include "grit/theme_resources.h"
28 #include "ui/base/gtk/gtk_hig_constants.h"
29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h"
31
32 using content::OpenURLParams;
33
34 WebsiteSettingsPopupGtk::WebsiteSettingsPopupGtk(
35 gfx::NativeWindow parent,
36 Profile* profile,
37 TabContentsWrapper* tab_contents_wrapper,
38 const GURL& url,
39 const SSLStatus& ssl,
40 bool show_history)
41 : website_settings_(NULL),
42 parent_(parent),
43 contents_(NULL),
44 theme_service_(ThemeServiceGtk::GetFrom(profile)),
45 profile_(profile),
46 tab_contents_wrapper_(tab_contents_wrapper) {
47 BrowserWindowGtk* browser_window =
48 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
49 anchor_ = browser_window->
50 GetToolbar()->GetLocationBarView()->location_icon_widget();
51
52 InitContents();
53
54 website_settings_.reset(
55 new WebsiteSettingsModel(this,
56 profile,
57 url,
58 ssl,
59 content::CertStore::GetInstance(),
60 tab_contents_wrapper->content_settings()));
61
62 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ?
63 BubbleGtk::ARROW_LOCATION_TOP_RIGHT :
64 BubbleGtk::ARROW_LOCATION_TOP_LEFT;
65 bubble_ = BubbleGtk::Show(anchor_,
66 NULL, // |rect|
67 contents_,
68 arrow_location,
69 true, // |match_system_theme|
70 true, // |grab_input|
71 theme_service_,
72 this); // |delegate|
73 if (!bubble_) {
74 NOTREACHED();
75 return;
76 }
77 }
78
79 WebsiteSettingsPopupGtk::~WebsiteSettingsPopupGtk() {
80 }
81
82 void WebsiteSettingsPopupGtk::BubbleClosing(BubbleGtk* bubble,
83 bool closed_by_escape) {
84 delete this;
85 }
86
87 void WebsiteSettingsPopupGtk::InitContents() {
88 if (!contents_) {
89 contents_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
90 gtk_container_set_border_width(GTK_CONTAINER(contents_),
91 ui::kContentAreaBorder);
92 } else {
93 gtk_util::RemoveAllChildren(contents_);
94 }
95
96 site_info_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
97 gtk_box_pack_start(GTK_BOX(contents_),
98 CreateSection("Site Information", site_info_contents_),
99 FALSE, FALSE, 0);
100 gtk_box_pack_start(GTK_BOX(contents_),
101 gtk_hseparator_new(),
102 FALSE, FALSE, 0);
103 cookies_section_content_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
104 gtk_box_pack_start(GTK_BOX(contents_),
105 CreateSection("Cookies and Site Data",
106 cookies_section_content_),
107 FALSE, FALSE, 0);
108 gtk_box_pack_start(GTK_BOX(contents_),
109 gtk_hseparator_new(),
110 FALSE, FALSE, 0);
111 permissions_section_content_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
112 gtk_box_pack_start(GTK_BOX(contents_),
113 CreateSection("Permissions", permissions_section_content_),
114 FALSE, FALSE, 0);
115
116 /*
117 GtkWidget* help_link = theme_service_->BuildChromeLinkButton(
118 l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK));
119 GtkWidget* help_link_hbox = gtk_hbox_new(FALSE, 0);
120 // Stick it in an hbox so it doesn't expand to the whole width.
121 gtk_box_pack_start(GTK_BOX(help_link_hbox), help_link, FALSE, FALSE, 0);
122 gtk_box_pack_start(GTK_BOX(contents_), help_link_hbox, FALSE, FALSE, 0);
123 g_signal_connect(help_link, "clicked",
124 G_CALLBACK(OnHelpLinkClickedThunk), this);
125 */
Elliot Glaysher 2012/03/19 19:56:06 Commented out?
markusheintz_ 2012/03/20 20:44:12 removed
126
127 gtk_widget_show_all(contents_);
128 }
129
130 void WebsiteSettingsPopupGtk::ClearContainer(GtkWidget* container) {
131 GList* child = gtk_container_get_children(GTK_CONTAINER(container));
132 while (child) {
133 gtk_container_remove(GTK_CONTAINER(container), GTK_WIDGET(child->data));
134 child = child->next;
135 }
136 }
137
138 void WebsiteSettingsPopupGtk::SetSiteInfo(const std::string site_info) {
139 ClearContainer(site_info_contents_);
140 GtkWidget* label = theme_service_->BuildLabel(site_info,
141 ui::kGdkBlack);
142 GtkWidget* site_info_entry_box = gtk_hbox_new(FALSE, ui::kControlSpacing);
143 gtk_box_pack_start(GTK_BOX(site_info_entry_box), label, FALSE, FALSE, 0);
144 gtk_box_pack_start(GTK_BOX(site_info_contents_), site_info_entry_box, FALSE, F ALSE, 0);
Elliot Glaysher 2012/03/19 19:56:06 nit: lots of 80 col errors in this patch. won't po
markusheintz_ 2012/03/20 20:44:12 Done.
145 gtk_widget_show_all(site_info_contents_);
146 }
147
148 GtkWidget* WebsiteSettingsPopupGtk::CreateSection(std::string section_title,
149 GtkWidget* section_content) {
150 GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
151
152 // Add Section title
153 GtkWidget* title_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
154 gtk_box_pack_start(GTK_BOX(section_box), title_hbox, FALSE, FALSE, 0);
155
156 GtkWidget* label = theme_service_->BuildLabel(section_title,
157 ui::kGdkBlack);
158 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
159 PangoAttrList* attributes = pango_attr_list_new();
160 pango_attr_list_insert(attributes,
161 pango_attr_weight_new(PANGO_WEIGHT_BOLD));
162 gtk_label_set_attributes(GTK_LABEL(label), attributes);
163 pango_attr_list_unref(attributes);
164 gtk_util::SetLabelWidth(label, 400);
165 // Allow linebreaking in the middle of words if necessary, so that extremely
166 // long hostnames (longer than one line) will still be completely shown.
167 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
168 gtk_box_pack_start(GTK_BOX(title_hbox), label, FALSE, FALSE, 0);
169
170 // Add section content
171 gtk_box_pack_start(GTK_BOX(section_box), section_content, FALSE, FALSE, 0);
172 return section_box;
173
174 }
175
176 void WebsiteSettingsPopupGtk::SetCookieInfo(const CookieInfoList& cookie_info_li st) {
177 ClearContainer(cookies_section_content_);
178
179 // Create cookies info rows.
180 for (CookieInfoList::const_iterator it = cookie_info_list.begin();
181 it != cookie_info_list.end();
182 ++it) {
183 GtkWidget* cookies_info = gtk_hbox_new(FALSE, 0);
184
185 GtkWidget* label = theme_service_->BuildLabel(it->text, ui::kGdkBlack);
186 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
187 // PangoAttrList* attributes = pango_attr_list_new();
188 // pango_attr_list_insert(attributes,
189 // pango_attr_weight_new(PANGO_WEIGHT_BOLD));
190 // gtk_label_set_attributes(GTK_LABEL(first_party_cookie_label), attributes) ;
191 // pango_attr_list_unref(attributes);
192 gtk_util::SetLabelWidth(label, 200);
193 // Allow linebreaking in the middle of words if necessary, so that extremely
194 // long hostnames (longer than one line) will still be completely shown.
195 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
196 gtk_box_pack_start(GTK_BOX(cookies_info), label, FALSE, FALSE, 0);
197
198 std::string allowed_count = base::IntToString(it->allowed);
199 std::string blocked_count = base::IntToString(it->blocked);
200 std::string info_str = " (" + allowed_count + " allowed / " + blocked_count + " blocked)";
201 GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack);
202 gtk_label_set_selectable(GTK_LABEL(info), TRUE);
203 gtk_util::SetLabelWidth(info, 200);
204 gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, 0);
205
206 gtk_box_pack_start(GTK_BOX(cookies_section_content_),
207 cookies_info,
208 FALSE, FALSE, 0);
209 }
210
211 // Create links row.
212 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
213
214 GtkWidget* show_cookie_settings_link = theme_service_->BuildChromeLinkButton(
215 "Manage cookie settings");
216 g_signal_connect(show_cookie_settings_link, "clicked",
217 G_CALLBACK(OnCookieSettingsLinkClickedThunk), this);
218 gtk_box_pack_start(GTK_BOX(link_hbox), show_cookie_settings_link,
219 FALSE, FALSE, 0);
220
221 GtkWidget* view_cookies_link = theme_service_->BuildChromeLinkButton(
222 "Show cookies");
223 g_signal_connect(view_cookies_link, "clicked",
224 G_CALLBACK(OnCookiesLinkClickedThunk), this);
225 gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link,
226 FALSE, FALSE, 0);
227
228 gtk_box_pack_start(GTK_BOX(cookies_section_content_), link_hbox, FALSE, FALSE, 0);
229
230 gtk_widget_show_all(cookies_section_content_);
231 }
232
233 void WebsiteSettingsPopupGtk::SetPermissionInfo(
234 const PermissionInfoList& permission_info_list) {
235 ClearContainer(permissions_section_content_);
236
237 for (PermissionInfoList::const_iterator permission =
238 permission_info_list.begin();
239 permission != permission_info_list.end();
240 ++permission) {
241 std::string permission_text;
242 switch (permission->type) {
243 case CONTENT_SETTINGS_TYPE_POPUPS:
244 permission_text = "Popups";
Elliot Glaysher 2012/03/19 19:56:06 shouldn't this be localized?
markusheintz_ 2012/03/20 20:44:12 Done.
245 break;
246 case CONTENT_SETTINGS_TYPE_PLUGINS:
247 permission_text = "Plugins";
248 break;
249 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
250 permission_text = "Location";
251 break;
252 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
253 permission_text = "Notifications";
254 break;
255 default:
256 NOTREACHED();
257 break;
258 }
259 GtkWidget* label = theme_service_->BuildLabel(permission_text,
260 ui::kGdkBlack);
261 gtk_util::SetLabelWidth(label, 280);
262 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
263 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
264
265 GtkWidget* combo_box = gtk_combo_box_new_text();
266 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "ALLOW");
267 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), "BLOCK");
268 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box),
269 permission->setting == CONTENT_SETTING_ALLOW ? 0 : 1);
270 g_signal_connect(combo_box, "changed",
271 G_CALLBACK(OnPermissionChangedThunk), this);
272
273 gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, FALSE, 0);
274
275 gtk_box_pack_start(GTK_BOX(permissions_section_content_), hbox, FALSE,
276 FALSE, 0);
277 }
278
279 GtkWidget* show_content_settings_link = theme_service_->BuildChromeLinkButton(
280 "Manage permission settings");
281 g_signal_connect(show_content_settings_link, "clicked",
282 G_CALLBACK(OnPermissionsSettingsLinkClickedThunk), this);
283 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
284 gtk_box_pack_start(GTK_BOX(link_hbox), show_content_settings_link,
285 FALSE, FALSE, 0);
286
287 gtk_box_pack_start(GTK_BOX(permissions_section_content_), link_hbox,
288 FALSE, FALSE, 0);
289
290 gtk_widget_show_all(permissions_section_content_);
291 }
292
293 void WebsiteSettingsPopupGtk::OnCookiesLinkClicked(GtkWidget* widget) {
294 new CollectedCookiesGtk(GTK_WINDOW(parent_),
295 tab_contents_wrapper_);
296 bubble_->Close();
297 }
298
299 void WebsiteSettingsPopupGtk::OnCookieSettingsLinkClicked(GtkWidget* widget) {
300 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
301 browser->OpenURL(OpenURLParams(
302 GURL(std::string(
303 chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage),
304 content::Referrer(),
305 NEW_FOREGROUND_TAB,
306 content::PAGE_TRANSITION_LINK,
307 false));
308 bubble_->Close();
309 }
310
311 void WebsiteSettingsPopupGtk::OnPermissionsSettingsLinkClicked(
312 GtkWidget* widget) {
313 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
314 browser->OpenURL(OpenURLParams(
315 GURL(std::string(
316 chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage),
317 content::Referrer(),
318 NEW_FOREGROUND_TAB,
319 content::PAGE_TRANSITION_LINK,
320 false));
321 bubble_->Close();
322 }
323
324 void WebsiteSettingsPopupGtk::OnPermissionChanged(GtkWidget* widget) {
325 LOG(ERROR) << " *** OnPermissionChanged";
326 }
327
328 // static
329 void WebsiteSettingsUI::Show(gfx::NativeWindow parent,
330 Profile* profile,
331 TabContentsWrapper* tab_contents_wrapper,
332 const GURL& url,
333 const content::SSLStatus& ssl,
334 bool show_history) {
335 new WebsiteSettingsPopupGtk(parent, profile, tab_contents_wrapper, url, ssl,
336 show_history);
337 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/website_settings_popup_gtk.h ('k') | chrome/browser/ui/website_settings_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698