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

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

Powered by Google App Engine
This is Rietveld 408576698