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

Side by Side Diff: chrome/browser/views/database_open_info_view.cc

Issue 1338001: Block database access on allowDatabase instead of databaseOpenFile. (Closed)
Patch Set: without worker support Created 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/database_open_info_view.h" 5 #include "chrome/browser/views/database_open_info_view.h"
6 6
7 #include <algorithm> 7 #include "app/l10n_util.h"
8 #include "base/utf_string_conversions.h"
9 #include "grit/generated_resources.h"
8 10
9 #include "app/l10n_util.h" 11 namespace {
10 #include "base/i18n/time_formatting.h" 12 const int kInfoLabelIds[] = {
11 #include "base/utf_string_conversions.h" 13 IDS_COOKIES_COOKIE_DOMAIN_LABEL,
12 #include "gfx/color_utils.h" 14 IDS_COOKIES_WEB_DATABASE_NAME,
13 #include "grit/generated_resources.h" 15 IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL,
14 #include "views/grid_layout.h" 16 IDS_COOKIES_SIZE_LABEL
15 #include "views/controls/label.h" 17 };
16 #include "views/controls/textfield/textfield.h" 18 } // namespace
17 #include "views/standard_layout.h"
18
19 static const int kDatabaseOpenInfoViewBorderSize = 1;
20 static const int kDatabaseOpenInfoViewInsetSize = 3;
21 19
22 /////////////////////////////////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////////////////////////////////
23 // DatabaseOpenInfoView, public: 21 // DatabaseOpenInfoView, public:
24 22
25 DatabaseOpenInfoView::DatabaseOpenInfoView() 23 DatabaseOpenInfoView::DatabaseOpenInfoView()
26 : host_value_field_(NULL), 24 : GenericInfoView(ARRAYSIZE(kInfoLabelIds), kInfoLabelIds) {
27 database_name_value_field_(NULL) {
28 }
29
30 DatabaseOpenInfoView::~DatabaseOpenInfoView() {
31 } 25 }
32 26
33 void DatabaseOpenInfoView::SetFields(const std::string& host, 27 void DatabaseOpenInfoView::SetFields(const std::string& host,
34 const string16& database_name) { 28 const string16& database_name,
35 host_value_field_->SetText(UTF8ToWide(host)); 29 const string16& display_name,
36 database_name_value_field_->SetText(database_name); 30 unsigned long estimated_size) {
37 EnableDisplay(true); 31 string16 url = UTF8ToUTF16(host);
32 string16 size = FormatBytes(estimated_size,
33 GetByteDisplayUnits(estimated_size),
34 true);
35 int row = 0;
36 SetValue(row++, url);
37 SetValue(row++, database_name);
38 SetValue(row++, display_name);
39 SetValue(row++, size);
38 } 40 }
39
40 void DatabaseOpenInfoView::EnableDisplay(bool enabled) {
41 host_value_field_->SetEnabled(enabled);
42 database_name_value_field_->SetEnabled(enabled);
43 }
44
45 ///////////////////////////////////////////////////////////////////////////////
46 // DatabaseOpenInfoView, views::View overrides:
47
48 void DatabaseOpenInfoView::ViewHierarchyChanged(bool is_add,
49 views::View* parent,
50 views::View* child) {
51 if (is_add && child == this)
52 Init();
53 }
54
55 ///////////////////////////////////////////////////////////////////////////////
56 // DatabaseOpenInfoView, private:
57
58 void DatabaseOpenInfoView::Init() {
59 SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW);
60 views::Border* border = views::Border::CreateSolidBorder(
61 kDatabaseOpenInfoViewBorderSize, border_color);
62 set_border(border);
63
64 views::Label* host_label = new views::Label(
65 l10n_util::GetString(IDS_COOKIES_COOKIE_DOMAIN_LABEL));
66 host_value_field_ = new views::Textfield;
67 views::Label* database_name_label = new views::Label(
68 l10n_util::GetString(IDS_COOKIES_WEB_DATABASE_NAME));
69 database_name_value_field_ = new views::Textfield;
70
71 using views::GridLayout;
72
73 GridLayout* layout = new GridLayout(this);
74 layout->SetInsets(kDatabaseOpenInfoViewInsetSize,
75 kDatabaseOpenInfoViewInsetSize,
76 kDatabaseOpenInfoViewInsetSize,
77 kDatabaseOpenInfoViewInsetSize);
78 SetLayoutManager(layout);
79
80 int three_column_layout_id = 0;
81 views::ColumnSet* column_set = layout->AddColumnSet(three_column_layout_id);
82 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0,
83 GridLayout::USE_PREF, 0, 0);
84 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
85 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
86 GridLayout::USE_PREF, 0, 0);
87
88 layout->StartRow(0, three_column_layout_id);
89 layout->AddView(host_label);
90 layout->AddView(host_value_field_);
91 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing);
92 layout->StartRow(0, three_column_layout_id);
93 layout->AddView(database_name_label);
94 layout->AddView(database_name_value_field_);
95
96 // Color these borderless text areas the same as the containing dialog.
97 SkColor text_area_background = color_utils::GetSysSkColor(COLOR_3DFACE);
98 // Now that the Textfields are in the view hierarchy, we can initialize them.
99 host_value_field_->SetReadOnly(true);
100 host_value_field_->RemoveBorder();
101 host_value_field_->SetBackgroundColor(text_area_background);
102 database_name_value_field_->SetReadOnly(true);
103 database_name_value_field_->RemoveBorder();
104 database_name_value_field_->SetBackgroundColor(text_area_background);
105 }
106
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698