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

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/ui/browser_list.h"
14 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
15 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
16 #include "chrome/browser/ui/gtk/collected_cookies_gtk.h"
17 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
18 #include "chrome/browser/ui/gtk/gtk_util.h"
19 #include "chrome/browser/ui/gtk/theme_service_gtk.h"
20 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
22 #include "chrome/common/url_constants.h"
23 #include "grit/generated_resources.h"
24 #include "grit/locale_settings.h"
25 #include "grit/theme_resources.h"
26 #include "ui/base/gtk/gtk_hig_constants.h"
27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h"
29
30 using content::OpenURLParams;
31
32 WebsiteSettingsPopupGtk::WebsiteSettingsPopupGtk(
33 gfx::NativeWindow parent,
34 Profile* profile,
35 TabContentsWrapper* tab_contents_wrapper)
36 : parent_(parent),
37 contents_(NULL),
38 theme_service_(ThemeServiceGtk::GetFrom(profile)),
39 profile_(profile),
40 tab_contents_wrapper_(tab_contents_wrapper) {
41 BrowserWindowGtk* browser_window =
42 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
43 anchor_ = browser_window->
44 GetToolbar()->GetLocationBarView()->location_icon_widget();
45
46 InitContents();
47
48 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ?
49 BubbleGtk::ARROW_LOCATION_TOP_RIGHT :
50 BubbleGtk::ARROW_LOCATION_TOP_LEFT;
51 bubble_ = BubbleGtk::Show(anchor_,
52 NULL, // |rect|
53 contents_,
54 arrow_location,
55 true, // |match_system_theme|
56 true, // |grab_input|
57 theme_service_,
58 this); // |delegate|
59 if (!bubble_) {
60 NOTREACHED();
61 return;
62 }
63 }
64
65 WebsiteSettingsPopupGtk::~WebsiteSettingsPopupGtk() {
66 DCHECK(!delegate_);
67 }
68
69 void WebsiteSettingsPopupGtk::SetDelegate(WebsiteSettingsUIDelegate* delegate) {
70 delegate_ = delegate;
71 }
72
73 void WebsiteSettingsPopupGtk::BubbleClosing(BubbleGtk* bubble,
74 bool closed_by_escape) {
75 if (delegate_)
76 delegate_->OnUIClosing();
77 }
78
79 void WebsiteSettingsPopupGtk::InitContents() {
80 if (!contents_) {
81 contents_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
82 gtk_container_set_border_width(GTK_CONTAINER(contents_),
83 ui::kContentAreaBorder);
84 } else {
85 gtk_util::RemoveAllChildren(contents_);
86 }
87
88 site_info_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
89 std::string title = UTF16ToUTF8(
90 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE));
91 gtk_box_pack_start(GTK_BOX(contents_),
92 CreateSection(title, site_info_contents_),
93 FALSE, FALSE, 0);
94 gtk_box_pack_start(GTK_BOX(contents_),
95 gtk_hseparator_new(),
96 FALSE, FALSE, 0);
97 cookies_section_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
98 title = UTF16ToUTF8(
99 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA));
100 gtk_box_pack_start(GTK_BOX(contents_),
101 CreateSection(title,
102 cookies_section_contents_),
103 FALSE, FALSE, 0);
104 gtk_box_pack_start(GTK_BOX(contents_),
105 gtk_hseparator_new(),
106 FALSE, FALSE, 0);
107 permissions_section_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
108 title = UTF16ToUTF8(
109 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS));
110 gtk_box_pack_start(GTK_BOX(contents_),
111 CreateSection(title,
112 permissions_section_contents_),
113 FALSE, FALSE, 0);
114
115 gtk_widget_show_all(contents_);
116 }
117
118 void WebsiteSettingsPopupGtk::ClearContainer(GtkWidget* container) {
119 GList* child = gtk_container_get_children(GTK_CONTAINER(container));
120 while (child) {
121 gtk_container_remove(GTK_CONTAINER(container), GTK_WIDGET(child->data));
122 child = child->next;
123 }
124 }
125
126 void WebsiteSettingsPopupGtk::SetSiteInfo(const std::string site_info) {
127 DCHECK(site_info_contents_);
128 ClearContainer(site_info_contents_);
129 GtkWidget* label = theme_service_->BuildLabel(site_info,
130 ui::kGdkBlack);
131 GtkWidget* site_info_entry_box = gtk_hbox_new(FALSE, ui::kControlSpacing);
132 gtk_box_pack_start(GTK_BOX(site_info_entry_box), label, FALSE, FALSE, 0);
133 gtk_box_pack_start(GTK_BOX(site_info_contents_), site_info_entry_box, FALSE,
134 FALSE, 0);
135 gtk_widget_show_all(site_info_contents_);
136 }
137
138 GtkWidget* WebsiteSettingsPopupGtk::CreateSection(std::string section_title,
139 GtkWidget* section_content) {
140 GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
141
142 // Add Section title
143 GtkWidget* title_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
144 gtk_box_pack_start(GTK_BOX(section_box), title_hbox, FALSE, FALSE, 0);
145
146 GtkWidget* label = theme_service_->BuildLabel(section_title,
147 ui::kGdkBlack);
148 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
149 PangoAttrList* attributes = pango_attr_list_new();
150 pango_attr_list_insert(attributes,
151 pango_attr_weight_new(PANGO_WEIGHT_BOLD));
152 gtk_label_set_attributes(GTK_LABEL(label), attributes);
153 pango_attr_list_unref(attributes);
154 gtk_util::SetLabelWidth(label, 400);
155
156 // Add section content
157 if (delegate_)
158 delegate_->OnSitePermissionChanged(CONTENT_SETTINGS_TYPE_DEFAULT,
159 CONTENT_SETTING_DEFAULT);
160 gtk_box_pack_start(GTK_BOX(section_box), section_content, FALSE, FALSE, 0);
161 return section_box;
162
163 }
164
165 void WebsiteSettingsPopupGtk::SetCookieInfo(
166 const CookieInfoList& cookie_info_list) {
167 DCHECK(cookies_section_contents_);
168 ClearContainer(cookies_section_contents_);
169
170 // Create cookies info rows.
171 for (CookieInfoList::const_iterator it = cookie_info_list.begin();
172 it != cookie_info_list.end();
173 ++it) {
174 GtkWidget* cookies_info = gtk_hbox_new(FALSE, 0);
175
176 GtkWidget* label = theme_service_->BuildLabel(it->text, ui::kGdkBlack);
177 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
178 gtk_util::SetLabelWidth(label, 200);
179 // Allow linebreaking in the middle of words if necessary, so that extremely
180 // long hostnames (longer than one line) will still be completely shown.
181 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
182 gtk_box_pack_start(GTK_BOX(cookies_info), label, FALSE, FALSE, 0);
183
184 std::string allowed_count = base::IntToString(it->allowed);
185 std::string blocked_count = base::IntToString(it->blocked);
186 // TODO(markusheintz): Add a localized label here once we decided how this
187 // information should be displayed.
188 std::string info_str = " (" + allowed_count + " allowed / "
189 + blocked_count + " blocked)";
190
191 GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack);
192 gtk_label_set_selectable(GTK_LABEL(info), TRUE);
193 gtk_util::SetLabelWidth(info, 200);
Elliot Glaysher 2012/03/20 23:46:19 Can you get away without manually setting the widt
markusheintz_ 2012/03/21 10:54:24 Yes. removed.
194 gtk_box_pack_start(GTK_BOX(cookies_info), info, FALSE, FALSE, 0);
195
196 gtk_box_pack_start(GTK_BOX(cookies_section_contents_),
197 cookies_info,
198 FALSE, FALSE, 0);
199 }
200
201 // Create row with links for cookie settings and for the cookies dialog.
202 GtkWidget* link_hbox = gtk_hbox_new(TRUE, 0);
203
204 GtkWidget* show_cookie_settings_link = theme_service_->BuildChromeLinkButton(
205 UTF16ToUTF8(l10n_util::GetStringUTF16(
206 IDS_WEBSITE_SETTINGS_SHOW_SITE_DATA_SETTINGS)));
207 g_signal_connect(show_cookie_settings_link, "clicked",
208 G_CALLBACK(OnCookieSettingsLinkClickedThunk), this);
209 gtk_box_pack_start(GTK_BOX(link_hbox), show_cookie_settings_link,
210 if (delegate_)
211 delegate_->OnSitePermissionChanged(CONTENT_SETTINGS_TYPE_DEFAULT,
212 CONTENT_SETTING_DEFAULT);
213 TRUE, FALSE, 0);
214
215 GtkWidget* view_cookies_link = theme_service_->BuildChromeLinkButton(
216 UTF16ToUTF8(l10n_util::GetStringUTF16(
217 IDS_WEBSITE_SETTINGS_SHOW_SITE_DATA)));
218 g_signal_connect(view_cookies_link, "clicked",
219 G_CALLBACK(OnCookiesLinkClickedThunk), this);
220 gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link,
221 TRUE, FALSE, 0);
222
223 gtk_box_pack_start(GTK_BOX(cookies_section_contents_), link_hbox,
224 TRUE, FALSE, 0);
225
226 gtk_widget_show_all(cookies_section_contents_);
227 }
228
229 void WebsiteSettingsPopupGtk::SetPermissionInfo(
230 const PermissionInfoList& permission_info_list) {
231 DCHECK(permissions_section_contents_);
232 ClearContainer(permissions_section_contents_);
233
234 for (PermissionInfoList::const_iterator permission =
235 permission_info_list.begin();
236 permission != permission_info_list.end();
237 ++permission) {
238 std::string permission_text;
239 switch (permission->type) {
240 case CONTENT_SETTINGS_TYPE_POPUPS:
241 permission_text = UTF16ToUTF8(
242 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_POPUPS));
243 break;
244 case CONTENT_SETTINGS_TYPE_PLUGINS:
245 permission_text = UTF16ToUTF8(
246 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_PLUGINS));
247 break;
248 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
249 permission_text = UTF16ToUTF8(
250 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_LOCATION));
251 break;
252 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
253 permission_text = UTF16ToUTF8(
254 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS));
Elliot Glaysher 2012/03/20 23:46:19 GetStringUTF8. Also in the rest of the file.
markusheintz_ 2012/03/21 10:54:24 Done.
255 break;
256 default:
257 NOTREACHED();
258 break;
259 }
260 GtkWidget* label = theme_service_->BuildLabel(permission_text,
261 ui::kGdkBlack);
262 gtk_util::SetLabelWidth(label, 280);
263 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
264 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
265
266 GtkWidget* combo_box = gtk_combo_box_new_text();
267 std::string permission_str = UTF16ToUTF8(
268 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_ALLOW));
269 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), permission_str.c_str());
270 permission_str = UTF16ToUTF8(
271 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_PERMISSION_BLOCK));
272 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), permission_str.c_str());
273 gtk_combo_box_set_active(
274 GTK_COMBO_BOX(combo_box),
275 permission->setting == CONTENT_SETTING_ALLOW ? 0 : 1);
276 g_signal_connect(combo_box, "changed",
277 G_CALLBACK(OnPermissionChangedThunk), this);
278 g_signal_connect(combo_box, "notify::popup-shown",
279 G_CALLBACK(OnComboBoxShownThunk), this);
280 gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, FALSE, 0);
281
282 gtk_box_pack_start(GTK_BOX(permissions_section_contents_), hbox, FALSE,
283 FALSE, 0);
284 }
285
286 GtkWidget* show_content_settings_link = theme_service_->BuildChromeLinkButton(
287 UTF16ToUTF8(l10n_util::GetStringUTF16(
288 IDS_WEBSITE_SETTINGS_SHOW_PERMISSION_SETTINGS)));
289 g_signal_connect(show_content_settings_link, "clicked",
290 G_CALLBACK(OnPermissionsSettingsLinkClickedThunk), this);
291 GtkWidget* link_hbox = gtk_hbox_new(FALSE, 0);
292 gtk_box_pack_start(GTK_BOX(link_hbox), show_content_settings_link,
293 FALSE, FALSE, 0);
294
295 gtk_box_pack_start(GTK_BOX(permissions_section_contents_), link_hbox,
296 FALSE, FALSE, 0);
297
298 gtk_widget_show_all(permissions_section_contents_);
299 }
300
301 void WebsiteSettingsPopupGtk::OnComboBoxShown(GtkWidget* widget,
302 GParamSpec* property) {
303 // GtkComboBox grabs the keyboard and pointer when it displays its popup,
304 // which steals the grabs that BubbleGtk had installed. When the popup is
305 // hidden, we notify BubbleGtk so it can try to reacquire the grabs
306 // (otherwise, GTK won't activate our widgets when the user clicks in them).
307 gboolean popup_shown = FALSE;
308 g_object_get(G_OBJECT(GTK_COMBO_BOX(widget)), "popup-shown", &popup_shown,
309 NULL);
310 if (!popup_shown)
311 bubble_->HandlePointerAndKeyboardUngrabbedByContent();
312 }
313
314 void WebsiteSettingsPopupGtk::OnCookiesLinkClicked(GtkWidget* widget) {
315 new CollectedCookiesGtk(GTK_WINDOW(parent_),
316 tab_contents_wrapper_);
317 bubble_->Close();
318 }
319
320 void WebsiteSettingsPopupGtk::OnCookieSettingsLinkClicked(GtkWidget* widget) {
321 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
322 browser->OpenURL(OpenURLParams(
323 GURL(std::string(
324 chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage),
325 content::Referrer(),
326 NEW_FOREGROUND_TAB,
327 content::PAGE_TRANSITION_LINK,
328 false));
329 bubble_->Close();
330 }
331
332 void WebsiteSettingsPopupGtk::OnPermissionsSettingsLinkClicked(
333 GtkWidget* widget) {
334 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
Elliot Glaysher 2012/03/20 23:46:19 May want to get this from BrowserWindow that you h
markusheintz_ 2012/03/21 10:54:24 Done.
335 browser->OpenURL(OpenURLParams(
336 GURL(std::string(
337 chrome::kChromeUISettingsURL) + chrome::kContentSettingsSubPage),
338 content::Referrer(),
339 NEW_FOREGROUND_TAB,
340 content::PAGE_TRANSITION_LINK,
341 false));
342 bubble_->Close();
343 }
344
345 void WebsiteSettingsPopupGtk::OnPermissionChanged(GtkWidget* widget) {
346 // TODO(markusheintz): Implement once the backend (|WebsiteSettingsUIDelegate|
347 // implmentation which is the |WebsiteSettings| class) provides support for
348 // this.
349 }
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