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

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

Issue 10163002: Add tabs UI to WebsiteSettingsUI (GTK only). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove string changes from CL again. 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/ui/gtk/website_settings_popup_gtk.h" 5 #include "chrome/browser/ui/gtk/website_settings_popup_gtk.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 14 matching lines...) Expand all
25 #include "grit/locale_settings.h" 25 #include "grit/locale_settings.h"
26 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
27 #include "ui/base/gtk/gtk_hig_constants.h" 27 #include "ui/base/gtk/gtk_hig_constants.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 30
31 using content::OpenURLParams; 31 using content::OpenURLParams;
32 32
33 namespace { 33 namespace {
34 34
35 // The background color of the tabs if a theme other than the native GTK theme
36 // is selected.
37 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xff, 0xff, 0xff);
38
35 std::string PermissionTypeToString(ContentSettingsType type) { 39 std::string PermissionTypeToString(ContentSettingsType type) {
36 switch (type) { 40 switch (type) {
37 case CONTENT_SETTINGS_TYPE_POPUPS: 41 case CONTENT_SETTINGS_TYPE_POPUPS:
38 return l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TYPE_POPUPS); 42 return l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TYPE_POPUPS);
39 case CONTENT_SETTINGS_TYPE_PLUGINS: 43 case CONTENT_SETTINGS_TYPE_PLUGINS:
40 return l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TYPE_PLUGINS); 44 return l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TYPE_PLUGINS);
41 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 45 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
42 return l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TYPE_LOCATION); 46 return l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TYPE_LOCATION);
43 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 47 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
44 return l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS); 48 return l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS);
(...skipping 22 matching lines...) Expand all
67 WebsiteSettingsPopupGtk::WebsiteSettingsPopupGtk( 71 WebsiteSettingsPopupGtk::WebsiteSettingsPopupGtk(
68 gfx::NativeWindow parent, 72 gfx::NativeWindow parent,
69 Profile* profile, 73 Profile* profile,
70 TabContentsWrapper* tab_contents_wrapper) 74 TabContentsWrapper* tab_contents_wrapper)
71 : parent_(parent), 75 : parent_(parent),
72 contents_(NULL), 76 contents_(NULL),
73 theme_service_(ThemeServiceGtk::GetFrom(profile)), 77 theme_service_(ThemeServiceGtk::GetFrom(profile)),
74 profile_(profile), 78 profile_(profile),
75 tab_contents_wrapper_(tab_contents_wrapper), 79 tab_contents_wrapper_(tab_contents_wrapper),
76 browser_(NULL), 80 browser_(NULL),
77 site_info_contents_(NULL), 81 header_box_(NULL),
78 cookies_section_contents_(NULL), 82 cookies_section_contents_(NULL),
79 permissions_section_contents_(NULL), 83 permissions_section_contents_(NULL),
80 presenter_(NULL) { 84 presenter_(NULL) {
81 BrowserWindowGtk* browser_window = 85 BrowserWindowGtk* browser_window =
82 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent); 86 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent);
83 browser_ = browser_window->browser(); 87 browser_ = browser_window->browser();
84 anchor_ = browser_window-> 88 anchor_ = browser_window->
85 GetToolbar()->GetLocationBarView()->location_icon_widget(); 89 GetToolbar()->GetLocationBarView()->location_icon_widget();
86 90
87 InitContents(); 91 InitContents();
(...skipping 30 matching lines...) Expand all
118 122
119 void WebsiteSettingsPopupGtk::InitContents() { 123 void WebsiteSettingsPopupGtk::InitContents() {
120 if (!contents_) { 124 if (!contents_) {
121 contents_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); 125 contents_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
122 gtk_container_set_border_width(GTK_CONTAINER(contents_), 126 gtk_container_set_border_width(GTK_CONTAINER(contents_),
123 ui::kContentAreaBorder); 127 ui::kContentAreaBorder);
124 } else { 128 } else {
125 gtk_util::RemoveAllChildren(contents_); 129 gtk_util::RemoveAllChildren(contents_);
126 } 130 }
127 131
128 site_info_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing); 132 // Create popup header.
129 std::string title = 133 header_box_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
130 l10n_util::GetStringUTF8(IDS_PAGE_INFO_SITE_INFO_TITLE); 134 gtk_box_pack_start(GTK_BOX(contents_), header_box_, FALSE, FALSE, 0);
131 gtk_box_pack_start(GTK_BOX(contents_), 135
132 CreateSection(title, site_info_contents_), 136 // Create the container for the contents of the permissions tab.
133 FALSE, FALSE, 0); 137 GtkWidget* permission_tab_contents = gtk_vbox_new(FALSE, ui::kControlSpacing);
134 gtk_box_pack_start(GTK_BOX(contents_), 138 gtk_container_set_border_width(GTK_CONTAINER(permission_tab_contents), 10);
135 gtk_hseparator_new(),
136 FALSE, FALSE, 0);
137 cookies_section_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing); 139 cookies_section_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
138 title = l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA); 140 std::string title = l10n_util::GetStringUTF8(
139 gtk_box_pack_start(GTK_BOX(contents_), 141 IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA);
142 gtk_box_pack_start(GTK_BOX(permission_tab_contents),
140 CreateSection(title, 143 CreateSection(title,
141 cookies_section_contents_), 144 cookies_section_contents_),
142 FALSE, FALSE, 0); 145 FALSE, FALSE, 0);
143 gtk_box_pack_start(GTK_BOX(contents_), 146 gtk_box_pack_start(GTK_BOX(permission_tab_contents),
144 gtk_hseparator_new(), 147 gtk_hseparator_new(),
145 FALSE, FALSE, 0); 148 FALSE, FALSE, 0);
146 permissions_section_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing); 149 permissions_section_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
147 title = l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS); 150 title = l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS);
148 gtk_box_pack_start(GTK_BOX(contents_), 151 gtk_box_pack_start(GTK_BOX(permission_tab_contents),
149 CreateSection(title, 152 CreateSection(title,
150 permissions_section_contents_), 153 permissions_section_contents_),
151 FALSE, FALSE, 0); 154 FALSE, FALSE, 0);
152 155
156 // Create the container for the contents of the identity tab.
157 GtkWidget* info_tab = gtk_vbox_new(FALSE, ui::kControlSpacing);
158 identity_tab_contents_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
159 gtk_container_set_border_width(GTK_CONTAINER(identity_tab_contents_), 10);
160 gtk_box_pack_start(GTK_BOX(info_tab),
161 identity_tab_contents_,
162 FALSE, FALSE, 0);
163
164 // Create tab container and add all tabs.
165 GtkWidget* notebook = gtk_notebook_new();
166 if (theme_service_->UsingNativeTheme())
167 gtk_widget_modify_bg(notebook, GTK_STATE_NORMAL, NULL);
168 else
169 gtk_widget_modify_bg(notebook, GTK_STATE_NORMAL, &kBackgroundColor);
170
171 GtkWidget* label = theme_service_->BuildLabel(
172 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS),
173 ui::kGdkBlack);
174 gtk_widget_show(label);
175 gtk_notebook_append_page(
176 GTK_NOTEBOOK(notebook), permission_tab_contents, label);
177
178 label = theme_service_->BuildLabel(
179 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TAB_LABEL_IDENTITY),
180 ui::kGdkBlack);
181 gtk_widget_show(label);
182 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), info_tab, label);
183
184 gtk_box_pack_start(GTK_BOX(contents_), notebook, FALSE, FALSE, 0);
153 gtk_widget_show_all(contents_); 185 gtk_widget_show_all(contents_);
154 } 186 }
155 187
156 void WebsiteSettingsPopupGtk::ClearContainer(GtkWidget* container) { 188 void WebsiteSettingsPopupGtk::ClearContainer(GtkWidget* container) {
157 GList* child = gtk_container_get_children(GTK_CONTAINER(container)); 189 GList* child = gtk_container_get_children(GTK_CONTAINER(container));
158 while (child) { 190 while (child) {
159 gtk_container_remove(GTK_CONTAINER(container), GTK_WIDGET(child->data)); 191 gtk_container_remove(GTK_CONTAINER(container), GTK_WIDGET(child->data));
160 child = child->next; 192 child = child->next;
161 } 193 }
162 } 194 }
163 195
164 void WebsiteSettingsPopupGtk::SetSiteInfo(const std::string& site_info) {
165 DCHECK(site_info_contents_);
166 ClearContainer(site_info_contents_);
167 GtkWidget* label = theme_service_->BuildLabel(site_info,
168 ui::kGdkBlack);
169 GtkWidget* site_info_entry_box = gtk_hbox_new(FALSE, ui::kControlSpacing);
170 gtk_box_pack_start(GTK_BOX(site_info_entry_box), label, FALSE, FALSE, 0);
171 gtk_box_pack_start(GTK_BOX(site_info_contents_), site_info_entry_box, FALSE,
172 FALSE, 0);
173 gtk_widget_show_all(site_info_contents_);
174 }
175
176 GtkWidget* WebsiteSettingsPopupGtk::CreateSection(std::string section_title, 196 GtkWidget* WebsiteSettingsPopupGtk::CreateSection(std::string section_title,
177 GtkWidget* section_content) { 197 GtkWidget* section_content) {
178 GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing); 198 GtkWidget* section_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
179 199
180 // Add Section title 200 // Add Section title
181 GtkWidget* title_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); 201 GtkWidget* title_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
182 202
183 GtkWidget* label = theme_service_->BuildLabel(section_title, 203 GtkWidget* label = theme_service_->BuildLabel(section_title,
184 ui::kGdkBlack); 204 ui::kGdkBlack);
185 gtk_label_set_selectable(GTK_LABEL(label), TRUE); 205 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
(...skipping 16 matching lines...) Expand all
202 void WebsiteSettingsPopupGtk::SetCookieInfo( 222 void WebsiteSettingsPopupGtk::SetCookieInfo(
203 const CookieInfoList& cookie_info_list) { 223 const CookieInfoList& cookie_info_list) {
204 DCHECK(cookies_section_contents_); 224 DCHECK(cookies_section_contents_);
205 ClearContainer(cookies_section_contents_); 225 ClearContainer(cookies_section_contents_);
206 226
207 // Create cookies info rows. 227 // Create cookies info rows.
208 for (CookieInfoList::const_iterator it = cookie_info_list.begin(); 228 for (CookieInfoList::const_iterator it = cookie_info_list.begin();
209 it != cookie_info_list.end(); 229 it != cookie_info_list.end();
210 ++it) { 230 ++it) {
211 GtkWidget* cookies_info = gtk_hbox_new(FALSE, 0); 231 GtkWidget* cookies_info = gtk_hbox_new(FALSE, 0);
212 232 GtkWidget* label = CreateTextLabel(it->cookie_source, 200);
213 GtkWidget* label = theme_service_->BuildLabel(it->cookie_source,
214 ui::kGdkBlack);
215 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
216 gtk_util::SetLabelWidth(label, 200);
217 // Allow linebreaking in the middle of words if necessary, so that extremely
218 // long hostnames (longer than one line) will still be completely shown.
219 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
220 gtk_box_pack_start(GTK_BOX(cookies_info), label, FALSE, FALSE, 0); 233 gtk_box_pack_start(GTK_BOX(cookies_info), label, FALSE, FALSE, 0);
221 234
222 std::string allowed_count = base::IntToString(it->allowed); 235 std::string allowed_count = base::IntToString(it->allowed);
223 std::string blocked_count = base::IntToString(it->blocked); 236 std::string blocked_count = base::IntToString(it->blocked);
224 // TODO(markusheintz): Add a localized label here once we decided how this 237 // TODO(markusheintz): Add a localized label here once we decided how this
225 // information should be displayed. 238 // information should be displayed.
226 std::string info_str = " (" + allowed_count + " allowed / " 239 std::string info_str = " (" + allowed_count + " allowed / "
227 + blocked_count + " blocked)"; 240 + blocked_count + " blocked)";
228 241
229 GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack); 242 GtkWidget* info = theme_service_->BuildLabel(info_str, ui::kGdkBlack);
(...skipping 14 matching lines...) Expand all
244 G_CALLBACK(OnCookiesLinkClickedThunk), this); 257 G_CALLBACK(OnCookiesLinkClickedThunk), this);
245 gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link, 258 gtk_box_pack_start(GTK_BOX(link_hbox), view_cookies_link,
246 FALSE, FALSE, 0); 259 FALSE, FALSE, 0);
247 260
248 gtk_box_pack_start(GTK_BOX(cookies_section_contents_), link_hbox, 261 gtk_box_pack_start(GTK_BOX(cookies_section_contents_), link_hbox,
249 TRUE, FALSE, 0); 262 TRUE, FALSE, 0);
250 263
251 gtk_widget_show_all(cookies_section_contents_); 264 gtk_widget_show_all(cookies_section_contents_);
252 } 265 }
253 266
267 GtkWidget* WebsiteSettingsPopupGtk::CreateTextLabel(const std::string& text,
268 int width) {
269 GtkWidget* label = theme_service_->BuildLabel(text, ui::kGdkBlack);
270 gtk_util::SetLabelWidth(label, width);
271 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
272 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR);
273 return label;
274 }
275
276 void WebsiteSettingsPopupGtk::SetIdentityInfo(
277 const IdentityInfo& identity_info) {
278 // Create popup header.
279 DCHECK(header_box_);
280 ClearContainer(header_box_);
281
282 GtkWidget* identity_label = theme_service_->BuildLabel(
283 identity_info.site_identity, ui::kGdkBlack);
284 gtk_label_set_selectable(GTK_LABEL(identity_label), TRUE);
285 PangoAttrList* attributes = pango_attr_list_new();
286 pango_attr_list_insert(attributes,
287 pango_attr_weight_new(PANGO_WEIGHT_BOLD));
288 gtk_label_set_attributes(GTK_LABEL(identity_label), attributes);
289 pango_attr_list_unref(attributes);
290 gtk_util::SetLabelWidth(identity_label, 400);
291 gtk_box_pack_start(GTK_BOX(header_box_), identity_label, FALSE, FALSE, 0);
292
293 std::string identity_status_text;
294 switch (identity_info.identity_status) {
295 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT:
296 case WebsiteSettings::SITE_IDENTITY_STATUS_DNSSEC_CERT:
297 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT:
298 identity_status_text =
299 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_VERIFIED);
300 break;
301 default:
302 identity_status_text =
303 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_IDENTITY_NOT_VERIFIED);
304 break;
305 }
306 GtkWidget* status_label = CreateTextLabel(identity_status_text, 400);
307 gtk_box_pack_start(
308 GTK_BOX(header_box_), status_label, FALSE, FALSE, 0);
309 gtk_widget_show_all(header_box_);
310
311 // Create identity tab contents.
312 DCHECK(identity_tab_contents_);
313 ClearContainer(identity_tab_contents_);
314
315 // Create identity section.
316 GtkWidget* identity_description =
317 CreateTextLabel(identity_info.identity_status_description, 300);
318 GtkWidget* identity_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
319 gtk_box_pack_start(GTK_BOX(identity_box), identity_description, FALSE, FALSE,
320 0);
321
322 // Create connection section.
323 GtkWidget* connection_description =
324 CreateTextLabel(identity_info.connection_status_description, 300);
325 GtkWidget* connection_box = gtk_vbox_new(FALSE, ui::kControlSpacing);
326 gtk_box_pack_start(GTK_BOX(connection_box), connection_description, FALSE,
327 FALSE, 0);
328
329 // Add to contents.
330 gtk_box_pack_start(
331 GTK_BOX(identity_tab_contents_), CreateSection(
332 l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_TITEL_IDENTITY),
333 identity_box),
334 TRUE,
335 FALSE,
336 0);
337 gtk_box_pack_start(GTK_BOX(identity_tab_contents_),
338 gtk_hseparator_new(),
339 FALSE, FALSE, 0);
340 gtk_box_pack_start(
341 GTK_BOX(identity_tab_contents_),
342 CreateSection(
343 l10n_util::GetStringUTF8(
344 IDS_WEBSITE_SETTINGS_TITEL_CONNECTION),
345 connection_box),
346 TRUE,
347 FALSE,
348 0);
349
350 gtk_widget_show_all(identity_tab_contents_);
351 }
352
254 void WebsiteSettingsPopupGtk::SetPermissionInfo( 353 void WebsiteSettingsPopupGtk::SetPermissionInfo(
255 const PermissionInfoList& permission_info_list) { 354 const PermissionInfoList& permission_info_list) {
256 DCHECK(permissions_section_contents_); 355 DCHECK(permissions_section_contents_);
257 ClearContainer(permissions_section_contents_); 356 ClearContainer(permissions_section_contents_);
258 357
259 for (PermissionInfoList::const_iterator permission = 358 for (PermissionInfoList::const_iterator permission =
260 permission_info_list.begin(); 359 permission_info_list.begin();
261 permission != permission_info_list.end(); 360 permission != permission_info_list.end();
262 ++permission) { 361 ++permission) {
263 // Add a label for the permission type. 362 // Add a label for the permission type.
264 GtkWidget* label = theme_service_->BuildLabel( 363 GtkWidget* label =
265 PermissionTypeToString(permission->type), ui::kGdkBlack); 364 CreateTextLabel(PermissionTypeToString(permission->type), 250);
266 gtk_util::SetLabelWidth(label, 280);
267 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); 365 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
268 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 366 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
269 367
270 GtkListStore* store = 368 GtkListStore* store =
271 gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); 369 gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT);
272 GtkTreeIter iter; 370 GtkTreeIter iter;
273 // Add option for permission "Allow" to the combobox model. 371 // Add option for permission "Allow" to the combobox model.
274 std::string setting_str = PermissionValueToString(CONTENT_SETTING_ALLOW); 372 std::string setting_str = PermissionValueToString(CONTENT_SETTING_ALLOW);
275 gtk_list_store_append(store, &iter); 373 gtk_list_store_append(store, &iter);
276 gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1, 374 gtk_list_store_set(store, &iter, 0, setting_str.c_str(), 1,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_COMBO_BOX(widget))); 477 GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_COMBO_BOX(widget)));
380 478
381 int value = -1; 479 int value = -1;
382 int type = -1; 480 int type = -1;
383 gtk_tree_model_get(store, &it, 1, &value, 2, &type, -1); 481 gtk_tree_model_get(store, &it, 1, &value, 2, &type, -1);
384 482
385 if (presenter_) 483 if (presenter_)
386 presenter_->OnSitePermissionChanged(ContentSettingsType(type), 484 presenter_->OnSitePermissionChanged(ContentSettingsType(type),
387 ContentSetting(value)); 485 ContentSetting(value));
388 } 486 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698