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

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

Issue 560030: Refactored out JS specific part of modal dialog stack into its own class, exp... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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
« no previous file with comments | « chrome/browser/views/cookie_prompt_view.h ('k') | chrome/browser/views/jsmessage_box_dialog.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/cookie_prompt_view.h" 5 #include "chrome/browser/views/cookie_prompt_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/gfx/canvas.h" 9 #include "app/gfx/canvas.h"
10 #include "app/gfx/color_utils.h" 10 #include "app/gfx/color_utils.h"
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "base/i18n/time_formatting.h" 12 #include "base/i18n/time_formatting.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "chrome/browser/cookie_modal_dialog.h"
15 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
16 #include "chrome/browser/views/cookie_info_view.h" 17 #include "chrome/browser/views/cookie_info_view.h"
17 #include "chrome/browser/views/local_storage_info_view.h" 18 #include "chrome/browser/views/local_storage_info_view.h"
18 #include "chrome/browser/views/options/content_settings_window_view.h" 19 #include "chrome/browser/views/options/content_settings_window_view.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "grit/locale_settings.h" 21 #include "grit/locale_settings.h"
21 #include "net/base/cookie_monster.h" 22 #include "net/base/cookie_monster.h"
22 #include "views/controls/label.h" 23 #include "views/controls/label.h"
23 #include "views/controls/button/native_button.h" 24 #include "views/controls/button/native_button.h"
24 #include "views/controls/button/radio_button.h" 25 #include "views/controls/button/radio_button.h"
25 #include "views/controls/textfield/textfield.h" 26 #include "views/controls/textfield/textfield.h"
26 #include "views/grid_layout.h" 27 #include "views/grid_layout.h"
27 #include "views/standard_layout.h" 28 #include "views/standard_layout.h"
28 #include "views/window/non_client_view.h" 29 #include "views/window/non_client_view.h"
29 30
30 static const int kCookiePromptViewInsetSize = 5; 31 static const int kCookiePromptViewInsetSize = 5;
31 32
32 /////////////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////////////
33 // CookiesPromptView, public: 34 // CookiePromptView, public:
34 35
35 // static 36 CookiePromptView::CookiePromptView(
36 void CookiesPromptView::ShowCookiePromptWindow( 37 CookiePromptModalDialog* parent,
37 gfx::NativeWindow parent, 38 gfx::NativeWindow root_window,
38 Profile* profile, 39 Profile* profile,
39 const std::string& domain, 40 const GURL& url,
40 const net::CookieMonster::CanonicalCookie& cookie, 41 const std::string& cookie_line,
41 CookiesPromptViewDelegate* delegate) { 42 CookiePromptModalDialogDelegate* delegate)
42 CookiesPromptView* cookies_view = new CookiesPromptView(profile, delegate); 43 : parent_(parent),
43 cookies_view->SetCookie(domain, cookie); 44 root_window_(root_window),
44 views::Window::CreateChromeWindow(parent, 45 profile_(profile),
45 gfx::Rect(), 46 delegate_(delegate) {
46 cookies_view)->Show(); 47 cookie_ui_ = true;
48 net::CookieMonster::ParsedCookie cookie(cookie_line);
49 InitializeViewResources(cookie.HasDomain() ? cookie.Domain() : url.host());
47 } 50 }
48 51
49 // static 52 CookiePromptView::CookiePromptView(
50 void CookiesPromptView::ShowLocalStoragePromptWindow( 53 CookiePromptModalDialog* parent,
51 gfx::NativeWindow parent, 54 gfx::NativeWindow root_window,
52 Profile* profile, 55 Profile* profile,
53 const std::string& domain, 56 const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info,
54 const BrowsingDataLocalStorageHelper::LocalStorageInfo& local_storage_info, 57 CookiePromptModalDialogDelegate* delegate)
55 CookiesPromptViewDelegate* delegate) { 58 : parent_(parent),
56 CookiesPromptView* cookies_view = new CookiesPromptView(profile, delegate); 59 root_window_(root_window),
57 cookies_view->SetLocalStorage(domain, local_storage_info); 60 profile_(profile),
58 views::Window::CreateChromeWindow(parent, 61 local_storage_info_(storage_info),
59 gfx::Rect(), 62 delegate_(delegate) {
60 cookies_view)->Show(); 63 cookie_ui_ = false;
64 InitializeViewResources(storage_info.host);
61 } 65 }
62 66
63 67 CookiePromptView::~CookiePromptView() {
64 CookiesPromptView::~CookiesPromptView() {
65 }
66
67 void CookiesPromptView::SetCookie(
68 const std::string& domain,
69 const net::CookieMonster::CanonicalCookie& cookie) {
70 cookie_ui_ = true;
71 InitializeViewResources(domain);
72 cookie_ = cookie;
73 }
74
75 void CookiesPromptView::SetLocalStorage(
76 const std::string& domain,
77 const BrowsingDataLocalStorageHelper::LocalStorageInfo storage_info) {
78 cookie_ui_ = false;
79 InitializeViewResources(domain);
80 local_storage_info_ = storage_info;
81 } 68 }
82 69
83 /////////////////////////////////////////////////////////////////////////////// 70 ///////////////////////////////////////////////////////////////////////////////
84 // CookiesPromptView, views::View overrides: 71 // CookiePromptView, views::View overrides:
85 72
86 gfx::Size CookiesPromptView::GetPreferredSize() { 73 gfx::Size CookiePromptView::GetPreferredSize() {
87 gfx::Size client_size = views::View::GetPreferredSize(); 74 gfx::Size client_size = views::View::GetPreferredSize();
88 return gfx::Size(client_size.width(), 75 return gfx::Size(client_size.width(),
89 client_size.height() + GetExtendedViewHeight()); 76 client_size.height() + GetExtendedViewHeight());
90 } 77 }
91 78
92 79
93 void CookiesPromptView::ViewHierarchyChanged(bool is_add, 80 void CookiePromptView::ViewHierarchyChanged(bool is_add,
94 views::View* parent, 81 views::View* parent,
95 views::View* child) { 82 views::View* child) {
96 if (is_add && child == this) 83 if (is_add && child == this)
97 Init(); 84 Init();
98 } 85 }
99 86
100 /////////////////////////////////////////////////////////////////////////////// 87 ///////////////////////////////////////////////////////////////////////////////
101 // CookiesPromptView, views::DialogDelegate implementation: 88 // CookiePromptView, ModalDialogDelegate implementation:
102 89
103 std::wstring CookiesPromptView::GetWindowTitle() const { 90 gfx::NativeWindow CookiePromptView::GetDialogRootWindow() {
91 return root_window_;
92 }
93
94 ///////////////////////////////////////////////////////////////////////////////
95 // CookiePromptView, views::DialogDelegate implementation:
96
97 std::wstring CookiePromptView::GetWindowTitle() const {
104 return title_; 98 return title_;
105 } 99 }
106 100
107 void CookiesPromptView::WindowClosing() { 101 void CookiePromptView::WindowClosing() {
108 if (!signaled_ && delegate_) 102 if (!signaled_ && delegate_)
109 delegate_->BlockSiteData(false); 103 delegate_->BlockSiteData(false);
104 parent_->CompleteDialog();
110 } 105 }
111 106
112 views::View* CookiesPromptView::GetContentsView() { 107 views::View* CookiePromptView::GetContentsView() {
113 return this; 108 return this;
114 } 109 }
115 110
116 // CookieInfoViewDelegate overrides: 111 // CookieInfoViewDelegate overrides:
117 void CookiesPromptView::ModifyExpireDate(bool session_expire) { 112 void CookiePromptView::ModifyExpireDate(bool session_expire) {
118 session_expire_ = session_expire; 113 session_expire_ = session_expire;
119 } 114 }
120 115
121 116
122 /////////////////////////////////////////////////////////////////////////////// 117 ///////////////////////////////////////////////////////////////////////////////
123 // CookiesPromptView, views::ButtonListener implementation: 118 // CookiePromptView, views::ButtonListener implementation:
124 119
125 void CookiesPromptView::ButtonPressed(views::Button* sender, 120 void CookiePromptView::ButtonPressed(views::Button* sender,
126 const views::Event& event) { 121 const views::Event& event) {
127 if (sender == allow_button_) { 122 if (sender == allow_button_) {
128 if (delegate_) { 123 if (delegate_) {
129 delegate_->AllowSiteData(remember_radio_->checked(), session_expire_); 124 delegate_->AllowSiteData(remember_radio_->checked(), session_expire_);
130 signaled_ = true; 125 signaled_ = true;
131 } 126 }
132 GetWindow()->Close(); 127 GetWindow()->Close();
133 } else if (sender == block_button_) { 128 } else if (sender == block_button_) {
134 if (delegate_) { 129 if (delegate_) {
135 delegate_->BlockSiteData(remember_radio_->checked()); 130 delegate_->BlockSiteData(remember_radio_->checked());
136 signaled_ = true; 131 signaled_ = true;
137 } 132 }
138 GetWindow()->Close(); 133 GetWindow()->Close();
139 } 134 }
140 } 135 }
141 136
142 /////////////////////////////////////////////////////////////////////////////// 137 ///////////////////////////////////////////////////////////////////////////////
143 // CookiesPromptView, views::LinkController implementation: 138 // CookiePromptView, views::LinkController implementation:
144 void CookiesPromptView::LinkActivated(views::Link* source, int event_flags) { 139 void CookiePromptView::LinkActivated(views::Link* source, int event_flags) {
145 if (source == show_cookie_link_) 140 if (source == show_cookie_link_)
146 ToggleDetailsViewExpand(); 141 ToggleDetailsViewExpand();
147 else if (source == manage_cookies_link_) 142 else if (source == manage_cookies_link_)
148 ContentSettingsWindowView::Show(CONTENT_SETTINGS_TYPE_COOKIES, profile_); 143 ContentSettingsWindowView::Show(CONTENT_SETTINGS_TYPE_COOKIES, profile_);
149 else 144 else
150 NOTREACHED(); 145 NOTREACHED();
151 } 146 }
152 147
153 /////////////////////////////////////////////////////////////////////////////// 148 ///////////////////////////////////////////////////////////////////////////////
154 // CookiesPromptView, private: 149 // CookiePromptView, private:
155 150
156 CookiesPromptView::CookiesPromptView(Profile* profile, 151 CookiePromptView::CookiePromptView(Profile* profile,
157 CookiesPromptViewDelegate* delegate) 152 CookiePromptModalDialogDelegate* delegate)
158 : remember_radio_(NULL), 153 : remember_radio_(NULL),
159 ask_radio_(NULL), 154 ask_radio_(NULL),
160 allow_button_(NULL), 155 allow_button_(NULL),
161 block_button_(NULL), 156 block_button_(NULL),
162 show_cookie_link_(NULL), 157 show_cookie_link_(NULL),
163 manage_cookies_link_(NULL), 158 manage_cookies_link_(NULL),
164 info_view_(NULL), 159 info_view_(NULL),
165 session_expire_(false), 160 session_expire_(false),
166 expanded_view_(false), 161 expanded_view_(false),
167 signaled_(false), 162 signaled_(false),
168 delegate_(delegate), 163 delegate_(delegate),
169 profile_(profile) { 164 profile_(profile) {
170 } 165 }
171 166
172 void CookiesPromptView::Init() { 167 void CookiePromptView::Init() {
173 views::Label* description_label = new views::Label(l10n_util::GetStringF( 168 views::Label* description_label = new views::Label(l10n_util::GetStringF(
174 cookie_ui_ ? IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL, 169 cookie_ui_ ? IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL,
175 display_domain_)); 170 display_domain_));
176 int radio_group_id = 0; 171 int radio_group_id = 0;
177 remember_radio_ = new views::RadioButton( 172 remember_radio_ = new views::RadioButton(
178 l10n_util::GetStringF(IDS_COOKIE_ALERT_REMEMBER_RADIO, display_domain_), 173 l10n_util::GetStringF(IDS_COOKIE_ALERT_REMEMBER_RADIO, display_domain_),
179 radio_group_id); 174 radio_group_id);
180 remember_radio_->set_listener(this); 175 remember_radio_->set_listener(this);
181 ask_radio_ = new views::RadioButton( 176 ask_radio_ = new views::RadioButton(
182 l10n_util::GetString(IDS_COOKIE_ALERT_ASK_RADIO), radio_group_id); 177 l10n_util::GetString(IDS_COOKIE_ALERT_ASK_RADIO), radio_group_id);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 GridLayout::TRAILING, GridLayout::CENTER); 255 GridLayout::TRAILING, GridLayout::CENTER);
261 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 256 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
262 257
263 layout->StartRow(0, one_column_layout_id); 258 layout->StartRow(0, one_column_layout_id);
264 259
265 if (cookie_ui_) { 260 if (cookie_ui_) {
266 CookieInfoView* cookie_info_view = new CookieInfoView(true); 261 CookieInfoView* cookie_info_view = new CookieInfoView(true);
267 cookie_info_view->set_delegate(this); 262 cookie_info_view->set_delegate(this);
268 layout->AddView(cookie_info_view, 1, 1, GridLayout::FILL, 263 layout->AddView(cookie_info_view, 1, 1, GridLayout::FILL,
269 GridLayout::CENTER); 264 GridLayout::CENTER);
270 cookie_info_view->SetCookie(domain_, cookie_); 265
266 cookie_info_view->SetCookieString(domain_, cookie_line_);
271 info_view_ = cookie_info_view; 267 info_view_ = cookie_info_view;
272 } else { 268 } else {
273 LocalStorageInfoView* local_storage_info_view = new LocalStorageInfoView(); 269 LocalStorageInfoView* local_storage_info_view = new LocalStorageInfoView();
274 layout->AddView(local_storage_info_view, 1, 1, GridLayout::FILL, 270 layout->AddView(local_storage_info_view, 1, 1, GridLayout::FILL,
275 GridLayout::CENTER); 271 GridLayout::CENTER);
276 local_storage_info_view->SetLocalStorageInfo(local_storage_info_); 272 local_storage_info_view->SetLocalStorageInfo(local_storage_info_);
277 info_view_ = local_storage_info_view; 273 info_view_ = local_storage_info_view;
278 } 274 }
279 info_view_->SetVisible(false); 275 info_view_->SetVisible(false);
280 276
281 // Set default values. 277 // Set default values.
282 ask_radio_->SetChecked(true); 278 ask_radio_->SetChecked(true);
283 } 279 }
284 280
285 int CookiesPromptView::GetExtendedViewHeight() { 281 int CookiePromptView::GetExtendedViewHeight() {
286 DCHECK(info_view_); 282 DCHECK(info_view_);
287 return expanded_view_ ? 283 return expanded_view_ ?
288 kRelatedControlVerticalSpacing : -info_view_->GetPreferredSize().height(); 284 kRelatedControlVerticalSpacing : -info_view_->GetPreferredSize().height();
289 } 285 }
290 286
291 void CookiesPromptView::ToggleDetailsViewExpand() { 287 void CookiePromptView::ToggleDetailsViewExpand() {
292 expanded_view_ = !expanded_view_; 288 expanded_view_ = !expanded_view_;
293 views::Window* parent = GetWindow(); 289 views::Window* parent = GetWindow();
294 gfx::Size non_client_size = parent->GetNonClientView()->GetPreferredSize(); 290 gfx::Size non_client_size = parent->GetNonClientView()->GetPreferredSize();
295 gfx::Rect bounds = parent->GetBounds(); 291 gfx::Rect bounds = parent->GetBounds();
296 bounds.set_height(non_client_size.height() + GetExtendedViewHeight()); 292 bounds.set_height(non_client_size.height() + GetExtendedViewHeight());
297 parent->SetBounds(bounds, NULL); 293 parent->SetBounds(bounds, NULL);
298 294
299 info_view_->SetVisible(expanded_view_); 295 info_view_->SetVisible(expanded_view_);
300 Layout(); 296 Layout();
301 } 297 }
302 298
303 void CookiesPromptView::InitializeViewResources(const std::string& domain) { 299 void CookiePromptView::InitializeViewResources(const std::string& domain) {
304 domain_ = domain; 300 domain_ = domain;
305 std::string display_domain = domain; 301 std::string display_domain = domain;
306 if (!domain.empty() && domain[0] == '.') 302 if (!domain.empty() && domain[0] == '.')
307 display_domain = display_domain.substr(1); 303 display_domain = display_domain.substr(1);
308 display_domain_ = UTF8ToWide(display_domain); 304 display_domain_ = UTF8ToWide(display_domain);
309 title_ = l10n_util::GetStringF( 305 title_ = l10n_util::GetStringF(
310 cookie_ui_ ? IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE, 306 cookie_ui_ ? IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE,
311 display_domain_); 307 display_domain_);
312 } 308 }
313 309
OLDNEW
« no previous file with comments | « chrome/browser/views/cookie_prompt_view.h ('k') | chrome/browser/views/jsmessage_box_dialog.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698