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

Side by Side Diff: chrome/browser/ui/views/website_settings_popup_view.cc

Issue 10456017: Add WebsiteSettingsUI for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments (Finnur) Created 8 years, 6 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/views/website_settings_popup_view.h"
6
7 #include "base/string_number_conversions.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/website_settings/website_settings.h"
11 #include "chrome/browser/ui/views/collected_cookies_views.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
13 #include "chrome/common/content_settings_types.h"
14 #include "content/public/browser/cert_store.h"
15 #include "googleurl/src/gurl.h"
16 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/gfx/font.h"
19 #include "ui/views/controls/combobox/combobox.h"
20 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/link.h"
22 #include "ui/views/controls/tabbed_pane/tabbed_pane.h"
23 #include "ui/views/layout/box_layout.h"
24 #include "ui/views/layout/grid_layout.h"
25 #include "ui/views/layout/layout_manager.h"
26
27 namespace {
28
29 // In order to make the arrow of the bubble point directly at the location icon
30 // in the Omnibox rather then the bottom border of the Omnibox, the position of
31 // the bubble must be adjusted. This is the number of pixel the bubble must be
32 // moved towards the top of the screen (starting from the bottom border of the
33 // Omnibox).
34 const int kLocationIconBottomMargin = 5;
35
36 string16 PermissionTypeToString(ContentSettingsType type) {
37 return l10n_util::GetStringUTF16(
38 WebsiteSettingsUI::PermissionTypeToUIStringID(type));
39 }
40
41 string16 PermissionValueToString(ContentSetting value) {
42 return l10n_util::GetStringUTF16(
43 WebsiteSettingsUI::PermissionValueToUIStringID(value));
44 }
45
46 } // namespace
47
48 // |PopupHeader| is the UI element (view) that represents the header of the
49 // |WebsiteSettingsPopupView|. The header shows the status of the site's
50 // identity check and the name of the site's identity.
51 class PopupHeader : public views::View {
52 public:
53 PopupHeader();
54 virtual ~PopupHeader();
55
56 // Sets the name of the site's identity.
57 void SetIdentityName(const string16& name);
58
59 // Sets the status text for the identity check of this site.
60 void SetIdentityStatus(const string16& status_text);
61
62 private:
63 // The label that displays the name of the site's identity.
64 views::Label* name_;
65 // The label that displays the status of the identity check for this site.
66 views::Label* status_;
67
68 DISALLOW_COPY_AND_ASSIGN(PopupHeader);
69 };
70
71 // A |ComboboxModel| implementation that is used for |Combobox|es that allow
72 // selecting a setting for a given site permission.
73 class PermissionComboboxModel : public ui::ComboboxModel {
74 public:
75 // Creates a combobox model that provides all possible settings for the given
76 // |site_permission|.
77 PermissionComboboxModel(ContentSettingsType site_permission,
78 ContentSetting default_setting);
79 virtual ~PermissionComboboxModel();
80
81 // Returns the setting for the given |index|.
82 ContentSetting GetSettingAt(int index) const;
83
84 // Returns the site permission for which the combobox model provides
85 // settings.
86 ContentSettingsType site_permission() const {
87 return site_permission_;
88 }
89
90 // ui::ComboboxModel implementations.
91 virtual int GetItemCount() const OVERRIDE;
92 virtual string16 GetItemAt(int index) OVERRIDE;
93
94 private:
95 // The site permission (the |ContentSettingsType|) for which the combobox
96 // model provides settings.
97 ContentSettingsType site_permission_;
98
99 // The global default setting for the |site_permission_|.
100 ContentSetting default_setting_;
101
102 // All possible valid setting for the |site_permission_|.
103 std::vector<ContentSetting> settings_;
104
105 DISALLOW_COPY_AND_ASSIGN(PermissionComboboxModel);
106 };
107
108 ////////////////////////////////////////////////////////////////////////////////
109 // Popup Header
110 ////////////////////////////////////////////////////////////////////////////////
111
112 PopupHeader::PopupHeader() : name_(NULL), status_(NULL) {
113 views::GridLayout* layout = new views::GridLayout(this);
114 SetLayoutManager(layout);
115 const int label_column = 0;
116 views::ColumnSet* column_set = layout->AddColumnSet(label_column);
117 column_set->AddColumn(views::GridLayout::FILL,
118 views::GridLayout::FILL,
119 1,
120 views::GridLayout::USE_PREF,
121 0,
122 0);
123
124 layout->AddPaddingRow(0, 8);
125
126 layout->StartRow(0, label_column);
127 name_ = new views::Label(string16());
128 name_->SetFont(name_->font().DeriveFont(0, gfx::Font::BOLD));
129 layout->AddView(name_, 1, 1, views::GridLayout::LEADING,
130 views::GridLayout::CENTER);
131
132 layout->AddPaddingRow(0, 4);
133
134 status_ = new views::Label(string16());
135 layout->StartRow(0, label_column);
136 layout->AddView(status_,
137 1,
138 1,
139 views::GridLayout::LEADING,
140 views::GridLayout::CENTER);
141 }
142
143 PopupHeader::~PopupHeader() {
144 }
145
146 void PopupHeader::SetIdentityName(const string16& name) {
147 name_->SetText(name);
148 }
149
150 void PopupHeader::SetIdentityStatus(const string16& status) {
151 status_->SetText(status);
152 }
153
154 ////////////////////////////////////////////////////////////////////////////////
155 // PermissionComboboxModel
156 ////////////////////////////////////////////////////////////////////////////////
157
158 PermissionComboboxModel::PermissionComboboxModel(
159 ContentSettingsType site_permission, ContentSetting default_setting)
tfarina 2012/06/06 16:58:29 nit: I'd wrap it argument in its own line.
markusheintz_ 2012/06/07 20:10:38 Done.
160 : site_permission_(site_permission),
161 default_setting_(default_setting){
162 settings_.push_back(CONTENT_SETTING_DEFAULT);
163 settings_.push_back(CONTENT_SETTING_ALLOW);
164 settings_.push_back(CONTENT_SETTING_BLOCK);
165 if (site_permission == CONTENT_SETTINGS_TYPE_GEOLOCATION ||
166 site_permission == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
167 settings_.push_back(CONTENT_SETTING_ASK);
168 }
tfarina 2012/06/06 16:58:29 nit: Peter (pkasting) insists that single-line sta
markusheintz_ 2012/06/07 20:10:38 Done.
169 }
170
171 PermissionComboboxModel::~PermissionComboboxModel() {
172 }
173
174 ContentSetting PermissionComboboxModel::GetSettingAt(int index) const {
175 if (index < static_cast<int>(settings_.size()))
176 return settings_[index];
177 NOTREACHED();
178 return CONTENT_SETTING_DEFAULT;
179 }
180
181 int PermissionComboboxModel::GetItemCount() const {
182 return settings_.size();
183 }
184
185 string16 PermissionComboboxModel::GetItemAt(int index) {
186 if (index == 0) {
187 return l10n_util::GetStringFUTF16(
188 IDS_WEBSITE_SETTINGS_DEFAULT_PERMISSION_LABEL,
189 PermissionValueToString(default_setting_));
190 }
191 if (index < static_cast<int>(settings_.size())) {
192 return l10n_util::GetStringFUTF16(
193 IDS_WEBSITE_SETTINGS_PERMISSION_LABEL,
194 PermissionValueToString(settings_[index]));
195 }
196 NOTREACHED();
197 return string16();
198 }
199
200 ///////////////////////////////////////////////////////////////////////////////
201 // WebsiteSettingsPopupView
202 ///////////////////////////////////////////////////////////////////////////////
203
204 // static
205 void WebsiteSettingsPopupView::ShowPopup(views::View* anchor_view,
206 Profile* profile,
207 TabContentsWrapper* wrapper,
208 const GURL& url,
209 const content::SSLStatus& ssl) {
210 new WebsiteSettingsPopupView(anchor_view, profile, wrapper, url, ssl);
211 }
212
213 WebsiteSettingsPopupView::WebsiteSettingsPopupView(
214 views::View* anchor_view,
215 Profile* profile,
216 TabContentsWrapper* wrapper,
217 const GURL& url,
218 const content::SSLStatus& ssl)
219 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
220 tab_contents_wrapper_(wrapper),
221 presenter_(NULL),
222 header_(NULL),
223 tabbed_pane_(NULL),
224 site_data_content_(NULL),
225 cookie_dialog_link_(NULL),
226 permissions_content_(NULL),
227 identity_info_text_(NULL),
228 connection_info_text_(NULL),
229 page_info_text_(NULL) {
230 views::GridLayout* layout = new views::GridLayout(this);
231 SetLayoutManager(layout);
232 const int content_column = 0;
233 views::ColumnSet* column_set = layout->AddColumnSet(content_column);
234 column_set->AddColumn(views::GridLayout::FILL,
235 views::GridLayout::FILL,
236 1,
237 views::GridLayout::USE_PREF,
238 0,
239 0);
240
241 header_ = new PopupHeader();
242 layout->StartRow(1, content_column);
243 layout->AddView(header_);
244
245 layout->AddPaddingRow(1, 10);
246
247 tabbed_pane_ = new views::TabbedPane();
248 layout->StartRow(1, content_column);
249 layout->AddView(tabbed_pane_);
250 // Tabs must be added after the tabbed_pane_ was added to the views hierachy.
251 // Adding the |tabbed_pane_| to the views hierachy triggers the
252 // initialization of the native tab UI element. If the native tab UI element
253 // is not initalized adding a tab will result in a NULL pointer excetion.
254 tabbed_pane_->AddTab(
255 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS),
256 CreatePermissionsTab());
257 tabbed_pane_->AddTab(
258 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_IDENTITY),
259 CreateIdentityTab());
260 tabbed_pane_->SelectTabAt(0);
261 tabbed_pane_->set_listener(this);
262
263 views::BubbleDelegateView::CreateBubble(this);
264 this->Show();
265 SizeToContents();
266
267 presenter_.reset(new WebsiteSettings(this, profile,
268 wrapper->content_settings(), url, ssl,
269 content::CertStore::GetInstance()));
270 }
271
272 WebsiteSettingsPopupView::~WebsiteSettingsPopupView() {
273 }
274
275 void WebsiteSettingsPopupView::SetCookieInfo(
276 const CookieInfoList& cookie_info_list) {
277 site_data_content_->RemoveAllChildViews(true);
278
279 views::GridLayout* layout = new views::GridLayout(site_data_content_);
280 site_data_content_->SetLayoutManager(layout);
281
282 const int site_data_content_column = 0;
283 views::ColumnSet* column_set =
284 layout->AddColumnSet(site_data_content_column);
285 column_set->AddColumn(views::GridLayout::FILL,
286 views::GridLayout::FILL,
287 1,
288 views::GridLayout::USE_PREF,
289 0,
290 0);
291
292 for (CookieInfoList::const_iterator it = cookie_info_list.begin();
293 it != cookie_info_list.end();
294 ++it) {
295 string16 label_text = l10n_util::GetStringFUTF16(
296 IDS_WEBSITE_SETTINGS_SITE_DATA_STATS_LINE,
297 UTF8ToUTF16(it->cookie_source),
298 base::IntToString16(it->allowed),
299 base::IntToString16(it->allowed));
300 layout->StartRow(1, site_data_content_column);
301 layout->AddView(new views::Label(label_text),
302 1,
303 1,
304 views::GridLayout::LEADING,
305 views::GridLayout::CENTER);
306
307 layout->AddPaddingRow(1, 4);
308 }
309
310 layout->Layout(site_data_content_);
311 SizeToContents();
312 }
313
314 void WebsiteSettingsPopupView::SetPermissionInfo(
315 const PermissionInfoList& permission_info_list) {
316 permissions_content_->RemoveAllChildViews(true);
317
318 views::GridLayout* layout =
319 new views::GridLayout(permissions_content_);
320 permissions_content_->SetLayoutManager(layout);
321 const int content_column = 0;
322 views::ColumnSet* column_set =
323 layout->AddColumnSet(content_column);
324 column_set->AddColumn(views::GridLayout::FILL,
325 views::GridLayout::FILL,
326 1,
327 views::GridLayout::USE_PREF,
328 0,
329 0);
330 for (PermissionInfoList::const_iterator permission =
331 permission_info_list.begin();
332 permission != permission_info_list.end();
333 ++permission) {
334 views::Label* label =
335 new views::Label(PermissionTypeToString(permission->type));
336 views::Combobox* combobox = new views::Combobox(
337 new PermissionComboboxModel(permission->type,
tfarina 2012/06/06 16:58:29 nit: Please, do not do this way. I have written ma
markusheintz_ 2012/06/07 20:10:38 Thanks a lot for pointing this out! I didn't know
338 permission->default_setting));
339 switch (permission->setting) {
340 case CONTENT_SETTING_DEFAULT: combobox->SetSelectedIndex(0);
341 break;
342 case CONTENT_SETTING_ALLOW: combobox->SetSelectedIndex(1);
343 break;
344 case CONTENT_SETTING_BLOCK: combobox->SetSelectedIndex(2);
345 break;
346 default: combobox->SetSelectedIndex(4);
347 break;
348 }
349 combobox->set_listener(this);
350
351 layout->StartRow(1, content_column);
352 layout->AddView(CreatePermissionRow(label, combobox),
353 1,
354 1,
355 views::GridLayout::LEADING,
356 views::GridLayout::CENTER);
357
358 }
359
360 SizeToContents();
361 }
362
363 void WebsiteSettingsPopupView::SetIdentityInfo(
364 const IdentityInfo& identity_info) {
365 string16 identity_status_text;
366 switch (identity_info.identity_status) {
367 case WebsiteSettings::SITE_IDENTITY_STATUS_CERT:
368 case WebsiteSettings::SITE_IDENTITY_STATUS_DNSSEC_CERT:
369 case WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT:
370 identity_status_text =
371 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_IDENTITY_VERIFIED);
372 break;
373 default:
374 identity_status_text =
375 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_IDENTITY_NOT_VERIFIED);
376 break;
377 }
378 header_->SetIdentityName(UTF8ToUTF16(identity_info.site_identity));
379 header_->SetIdentityStatus(identity_status_text);
380
381 identity_info_text_->SetText(
382 UTF8ToUTF16(identity_info.identity_status_description));
383
384 connection_info_text_->SetText(
385 UTF8ToUTF16(identity_info.connection_status_description));
386
387 GetLayoutManager()->Layout(this);
388 SizeToContents();
389 }
390
391 gfx::Size WebsiteSettingsPopupView::GetPreferredSize() {
392 int height = 0;
393 int width = 300;
394 if (header_)
395 height += header_->GetPreferredSize().height();
396 if (tabbed_pane_)
397 height += tabbed_pane_->GetPreferredSize().height();
398
399 gfx::Size size(width, height);
400 return size;
401 }
402
403 void WebsiteSettingsPopupView::SetFirstVisit(const string16& first_visit) {
404 page_info_text_->SetText(first_visit);
405 }
406
407 gfx::Rect WebsiteSettingsPopupView::GetAnchorRect() {
408 // Compensate for some built-in padding in the icon. This will make the arrow
409 // point to the middle of the icon.
410 gfx::Rect anchor(BubbleDelegateView::GetAnchorRect());
411 anchor.Inset(0, anchor_view() ? kLocationIconBottomMargin : 0);
412 return anchor;
413 }
414
415 void WebsiteSettingsPopupView::OnSelectedIndexChanged(
416 views::Combobox* combobox) {
417 PermissionComboboxModel* model =
418 static_cast<PermissionComboboxModel*>(combobox->model());
tfarina 2012/06/06 16:58:29 nice: although I like this trick, see my comment a
markusheintz_ 2012/06/07 20:10:38 :) I'll keep it this way since this allows me to u
419 DCHECK(model);
420 presenter_->OnSitePermissionChanged(
421 model->site_permission(),
422 model->GetSettingAt(combobox->selected_index()));
423 }
424
425 void WebsiteSettingsPopupView::LinkClicked(views::Link* source,
426 int event_flags) {
427 if (source != cookie_dialog_link_)
428 NOTREACHED();
429 new CollectedCookiesViews(tab_contents_wrapper_);
430 GetWidget()->CloseNow();
431 }
432
433 void WebsiteSettingsPopupView::TabSelectedAt(int index) {
434 tabbed_pane_->GetSelectedTab()->Layout();
435 SizeToContents();
436 }
437
438 views::View* WebsiteSettingsPopupView::CreatePermissionsTab() {
439 views::View* pane = new views::View();
440 pane->SetLayoutManager(
441 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
442
443 cookie_dialog_link_ = new views::Link(
444 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_SHOW_SITE_DATA));
445 cookie_dialog_link_->set_listener(this);
446 site_data_content_ = new views::View();
447 views::View* site_data_section =
448 CreateSection(l10n_util::GetStringUTF16(
449 IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA),
450 site_data_content_,
451 cookie_dialog_link_);
452 pane->AddChildView(site_data_section);
453
454 permissions_content_ = new views::View();
455 views::View* permissions_section =
456 CreateSection(l10n_util::GetStringUTF16(
457 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS),
458 permissions_content_,
459 NULL);
460 pane->AddChildView(permissions_section);
461 return pane;
462 }
463
464 views::View* WebsiteSettingsPopupView::CreateIdentityTab() {
465 views::View* pane = new views::View();
466 pane->SetLayoutManager(
467 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
468
469 // Add Identity section.
470 views::View* section_content = new views::View();
471 views::GridLayout* layout =
472 new views::GridLayout(section_content);
473 section_content->SetLayoutManager(layout);
474 const int content_column = 0;
475 views::ColumnSet* column_set =
476 layout->AddColumnSet(content_column);
477 column_set->AddColumn(views::GridLayout::FILL,
478 views::GridLayout::FILL,
479 1,
480 views::GridLayout::USE_PREF,
481 0,
482 0);
483 identity_info_text_ = CreateTextLabel(string16());
484 layout->StartRow(1, content_column);
485 layout->AddView(identity_info_text_, 1, 1, views::GridLayout::LEADING,
486 views::GridLayout::CENTER);
487 views::View* section =
488 CreateSection(l10n_util::GetStringUTF16(
489 IDS_WEBSITE_SETTINGS_TITEL_IDENTITY),
490 section_content,
491 NULL);
492 pane->AddChildView(section);
493
494 // Add connection section.
495 section_content = new views::View();
496 layout = new views::GridLayout(section_content);
497 section_content->SetLayoutManager(layout);
498 column_set = layout->AddColumnSet(content_column);
499 column_set->AddColumn(views::GridLayout::FILL,
500 views::GridLayout::FILL,
501 1,
502 views::GridLayout::USE_PREF,
503 0,
504 0);
505 connection_info_text_ = CreateTextLabel(string16());
506 layout->StartRow(1, content_column);
507 layout->AddView(connection_info_text_, 1, 1, views::GridLayout::LEADING,
508 views::GridLayout::CENTER);
509 section = CreateSection(l10n_util::GetStringUTF16(
510 IDS_WEBSITE_SETTINGS_TITEL_CONNECTION),
511 section_content,
512 NULL);
513 pane->AddChildView(section);
514
515 // Add page info section.
516 section_content = new views::View();
517 layout = new views::GridLayout(section_content);
518 section_content->SetLayoutManager(layout);
519 column_set = layout->AddColumnSet(content_column);
520 column_set->AddColumn(views::GridLayout::FILL,
521 views::GridLayout::FILL,
522 1,
523 views::GridLayout::USE_PREF,
524 0,
525 0);
526 page_info_text_ = CreateTextLabel(string16());
527 layout->StartRow(1, content_column);
528 layout->AddView(page_info_text_, 1, 1, views::GridLayout::LEADING,
529 views::GridLayout::CENTER);
530 section = CreateSection(l10n_util::GetStringUTF16(
531 IDS_PAGE_INFO_SITE_INFO_TITLE),
532 section_content,
533 NULL);
534 pane->AddChildView(section);
535
536 return pane;
537 }
538
539 views::View* WebsiteSettingsPopupView::CreateSection(
540 const string16& headline_text,
541 views::View* content,
542 views::Link* link) {
543 views::View* container = new views::View();
544 views::GridLayout* layout = new views::GridLayout(container);
545 container->SetLayoutManager(layout);
546 const int content_column = 0;
547 views::ColumnSet* column_set = layout->AddColumnSet(content_column);
548 column_set->AddColumn(views::GridLayout::FILL,
549 views::GridLayout::FILL,
550 1,
551 views::GridLayout::USE_PREF,
552 0,
553 0);
554
555 layout->AddPaddingRow(1, 4);
556 layout->StartRow(1, content_column);
557 views::Label* headline = new views::Label(headline_text);
558 headline->SetFont(headline->font().DeriveFont(0, gfx::Font::BOLD));
559 layout->AddView(headline, 1, 1, views::GridLayout::LEADING,
560 views::GridLayout::CENTER);
561
562 layout->AddPaddingRow(1, 4);
563 layout->StartRow(1, content_column);
564 layout->AddView(content, 1, 1, views::GridLayout::LEADING,
565 views::GridLayout::CENTER);
566
567 if (link) {
568 layout->AddPaddingRow(1, 4);
569 layout->StartRow(1, content_column);
570 layout->AddView(link, 1, 1, views::GridLayout::LEADING,
571 views::GridLayout::CENTER);
572 }
573
574 return container;
575 }
576
577 views::View* WebsiteSettingsPopupView::CreatePermissionRow(
578 views::Label* label,
579 views::Combobox* combobox) {
580 views::View* container = new views::View();
581 views::GridLayout* layout = new views::GridLayout(container);
582 container->SetLayoutManager(layout);
583 const int two_column_layout = 0;
584 views::ColumnSet* column_set = layout->AddColumnSet(two_column_layout);
585 column_set->AddColumn(views::GridLayout::FILL,
586 views::GridLayout::FILL,
587 1,
588 views::GridLayout::USE_PREF,
589 0,
590 0);
591 column_set->AddPaddingColumn(0, 8);
592 column_set->AddColumn(views::GridLayout::FILL,
593 views::GridLayout::FILL,
594 1,
595 views::GridLayout::USE_PREF,
596 0,
597 0);
598
599 layout->StartRow(1, two_column_layout);
600 layout->AddView(label);
601 layout->AddView(combobox);
602 return container;
603 }
604
605 views::Label* WebsiteSettingsPopupView::CreateTextLabel(const string16& text) {
606 views::Label* label = new views::Label(text);
607 label->SetMultiLine(true);
608 label->SetAllowCharacterBreak(true);
609 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
610 return label;
611 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698