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

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