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

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

Powered by Google App Engine
This is Rietveld 408576698