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

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

Issue 5564007: Update Content Settings Bubbles (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address additional CR feedback Created 10 years 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/ui/views/content_setting_bubble_contents.h ('k') | no next file » | 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/content_setting_bubble_contents.h" 5 #include "chrome/browser/views/content_setting_bubble_contents.h"
6 6
7 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include <gdk/gdk.h> 8 #include <gdk/gdk.h>
9 #endif 9 #endif
10 10
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 108 }
109 109
110 ContentSettingBubbleContents::ContentSettingBubbleContents( 110 ContentSettingBubbleContents::ContentSettingBubbleContents(
111 ContentSettingBubbleModel* content_setting_bubble_model, 111 ContentSettingBubbleModel* content_setting_bubble_model,
112 Profile* profile, 112 Profile* profile,
113 TabContents* tab_contents) 113 TabContents* tab_contents)
114 : content_setting_bubble_model_(content_setting_bubble_model), 114 : content_setting_bubble_model_(content_setting_bubble_model),
115 profile_(profile), 115 profile_(profile),
116 tab_contents_(tab_contents), 116 tab_contents_(tab_contents),
117 info_bubble_(NULL), 117 info_bubble_(NULL),
118 close_button_(NULL), 118 custom_link_(NULL),
119 manage_link_(NULL), 119 manage_link_(NULL),
120 clear_link_(NULL), 120 close_button_(NULL) {
121 info_link_(NULL),
122 load_plugins_link_(NULL) {
123 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, 121 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
124 Source<TabContents>(tab_contents)); 122 Source<TabContents>(tab_contents));
125 } 123 }
126 124
127 ContentSettingBubbleContents::~ContentSettingBubbleContents() { 125 ContentSettingBubbleContents::~ContentSettingBubbleContents() {
128 } 126 }
129 127
130 gfx::Size ContentSettingBubbleContents::GetPreferredSize() { 128 gfx::Size ContentSettingBubbleContents::GetPreferredSize() {
131 gfx::Size preferred_size(views::View::GetPreferredSize()); 129 gfx::Size preferred_size(views::View::GetPreferredSize());
132 int preferred_width = 130 int preferred_width =
(...skipping 24 matching lines...) Expand all
157 if (sender == *i) { 155 if (sender == *i) {
158 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); 156 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin());
159 return; 157 return;
160 } 158 }
161 } 159 }
162 NOTREACHED() << "unknown radio"; 160 NOTREACHED() << "unknown radio";
163 } 161 }
164 162
165 void ContentSettingBubbleContents::LinkActivated(views::Link* source, 163 void ContentSettingBubbleContents::LinkActivated(views::Link* source,
166 int event_flags) { 164 int event_flags) {
165 if (source == custom_link_) {
166 content_setting_bubble_model_->OnCustomLinkClicked();
167 info_bubble_->set_fade_away_on_close(true);
168 info_bubble_->Close(); // CAREFUL: This deletes us.
169 return;
170 }
167 if (source == manage_link_) { 171 if (source == manage_link_) {
168 info_bubble_->set_fade_away_on_close(true); 172 info_bubble_->set_fade_away_on_close(true);
169 content_setting_bubble_model_->OnManageLinkClicked(); 173 content_setting_bubble_model_->OnManageLinkClicked();
170 // CAREFUL: Showing the settings window activates it, which deactivates the 174 // CAREFUL: Showing the settings window activates it, which deactivates the
171 // info bubble, which causes it to close, which deletes us. 175 // info bubble, which causes it to close, which deletes us.
172 return; 176 return;
173 } 177 }
174 if (source == clear_link_) {
175 content_setting_bubble_model_->OnClearLinkClicked();
176 info_bubble_->set_fade_away_on_close(true);
177 info_bubble_->Close(); // CAREFUL: This deletes us.
178 return;
179 }
180 if (source == info_link_) {
181 content_setting_bubble_model_->OnInfoLinkClicked();
182 info_bubble_->set_fade_away_on_close(true);
183 info_bubble_->Close(); // CAREFUL: This deletes us.
184 return;
185 }
186 if (source == load_plugins_link_) {
187 content_setting_bubble_model_->OnLoadPluginsLinkClicked();
188 info_bubble_->set_fade_away_on_close(true);
189 info_bubble_->Close(); // CAREFUL: This deletes us.
190 return;
191 }
192 178
193 PopupLinks::const_iterator i(popup_links_.find(source)); 179 PopupLinks::const_iterator i(popup_links_.find(source));
194 DCHECK(i != popup_links_.end()); 180 DCHECK(i != popup_links_.end());
195 content_setting_bubble_model_->OnPopupClicked(i->second); 181 content_setting_bubble_model_->OnPopupClicked(i->second);
196 } 182 }
197 183
198 void ContentSettingBubbleContents::Observe(NotificationType type, 184 void ContentSettingBubbleContents::Observe(NotificationType type,
199 const NotificationSource& source, 185 const NotificationSource& source,
200 const NotificationDetails& details) { 186 const NotificationDetails& details) {
201 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); 187 DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED);
202 DCHECK(source == Source<TabContents>(tab_contents_)); 188 DCHECK(source == Source<TabContents>(tab_contents_));
203 tab_contents_ = NULL; 189 tab_contents_ = NULL;
204 } 190 }
205 191
206 void ContentSettingBubbleContents::InitControlLayout() { 192 void ContentSettingBubbleContents::InitControlLayout() {
207 using views::GridLayout; 193 using views::GridLayout;
208 194
209 GridLayout* layout = new views::GridLayout(this); 195 GridLayout* layout = new views::GridLayout(this);
210 SetLayoutManager(layout); 196 SetLayoutManager(layout);
211 197
212 const int single_column_set_id = 0; 198 const int single_column_set_id = 0;
213 views::ColumnSet* column_set = layout->AddColumnSet(single_column_set_id); 199 views::ColumnSet* column_set = layout->AddColumnSet(single_column_set_id);
214 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 200 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
215 GridLayout::USE_PREF, 0, 0); 201 GridLayout::USE_PREF, 0, 0);
216 202
217 const ContentSettingBubbleModel::BubbleContent& bubble_content = 203 const ContentSettingBubbleModel::BubbleContent& bubble_content =
218 content_setting_bubble_model_->bubble_content(); 204 content_setting_bubble_model_->bubble_content();
205 bool bubble_content_empty = true;
219 206
220 if (!bubble_content.title.empty()) { 207 if (!bubble_content.title.empty()) {
221 views::Label* title_label = new views::Label(UTF8ToWide( 208 views::Label* title_label = new views::Label(UTF8ToWide(
222 bubble_content.title)); 209 bubble_content.title));
223 layout->StartRow(0, single_column_set_id); 210 layout->StartRow(0, single_column_set_id);
224 layout->AddView(title_label); 211 layout->AddView(title_label);
225 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 212 bubble_content_empty = false;
226 } 213 }
227 214
228 const std::set<std::string>& plugins = bubble_content.resource_identifiers; 215 const std::set<std::string>& plugins = bubble_content.resource_identifiers;
229 if (!plugins.empty()) { 216 if (!plugins.empty()) {
217 if (!bubble_content_empty)
218 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
230 for (std::set<std::string>::const_iterator it = plugins.begin(); 219 for (std::set<std::string>::const_iterator it = plugins.begin();
231 it != plugins.end(); ++it) { 220 it != plugins.end(); ++it) {
232 std::wstring name = UTF16ToWide( 221 std::wstring name = UTF16ToWide(
233 NPAPI::PluginList::Singleton()->GetPluginGroupName(*it)); 222 NPAPI::PluginList::Singleton()->GetPluginGroupName(*it));
234 if (name.empty()) 223 if (name.empty())
235 name = UTF8ToWide(*it); 224 name = UTF8ToWide(*it);
236 layout->StartRow(0, single_column_set_id); 225 layout->StartRow(0, single_column_set_id);
237 layout->AddView(new views::Label(name)); 226 layout->AddView(new views::Label(name));
227 bubble_content_empty = false;
238 } 228 }
239 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
240 } 229 }
241 230
242 if (content_setting_bubble_model_->content_type() == 231 if (content_setting_bubble_model_->content_type() ==
243 CONTENT_SETTINGS_TYPE_POPUPS) { 232 CONTENT_SETTINGS_TYPE_POPUPS) {
244 const int popup_column_set_id = 2; 233 const int popup_column_set_id = 2;
245 views::ColumnSet* popup_column_set = 234 views::ColumnSet* popup_column_set =
246 layout->AddColumnSet(popup_column_set_id); 235 layout->AddColumnSet(popup_column_set_id);
247 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, 236 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
248 GridLayout::USE_PREF, 0, 0); 237 GridLayout::USE_PREF, 0, 0);
249 popup_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); 238 popup_column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
250 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 239 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
251 GridLayout::USE_PREF, 0, 0); 240 GridLayout::USE_PREF, 0, 0);
252 241
253 for (std::vector<ContentSettingBubbleModel::PopupItem>::const_iterator 242 for (std::vector<ContentSettingBubbleModel::PopupItem>::const_iterator
254 i(bubble_content.popup_items.begin()); 243 i(bubble_content.popup_items.begin());
255 i != bubble_content.popup_items.end(); ++i) { 244 i != bubble_content.popup_items.end(); ++i) {
256 if (i != bubble_content.popup_items.begin()) 245 if (!bubble_content_empty)
257 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 246 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
258 layout->StartRow(0, popup_column_set_id); 247 layout->StartRow(0, popup_column_set_id);
259 248
260 views::Link* link = new views::Link(UTF8ToWide(i->title)); 249 views::Link* link = new views::Link(UTF8ToWide(i->title));
261 link->SetController(this); 250 link->SetController(this);
262 link->SetElideInMiddle(true); 251 link->SetElideInMiddle(true);
263 popup_links_[link] = i - bubble_content.popup_items.begin(); 252 popup_links_[link] = i - bubble_content.popup_items.begin();
264 layout->AddView(new Favicon((*i).bitmap, this, link)); 253 layout->AddView(new Favicon((*i).bitmap, this, link));
265 layout->AddView(link); 254 layout->AddView(link);
255 bubble_content_empty = false;
266 } 256 }
267 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
268
269 views::Separator* separator = new views::Separator;
270 layout->StartRow(0, single_column_set_id);
271 layout->AddView(separator);
272 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
273 } 257 }
274 258
275 const ContentSettingBubbleModel::RadioGroup& radio_group = 259 const ContentSettingBubbleModel::RadioGroup& radio_group =
276 bubble_content.radio_group; 260 bubble_content.radio_group;
277 for (ContentSettingBubbleModel::RadioItems::const_iterator i = 261 if (!radio_group.radio_items.empty()) {
278 radio_group.radio_items.begin(); 262 for (ContentSettingBubbleModel::RadioItems::const_iterator i =
279 i != radio_group.radio_items.end(); ++i) { 263 radio_group.radio_items.begin();
280 views::RadioButton* radio = new views::RadioButton(UTF8ToWide(*i), 0); 264 i != radio_group.radio_items.end(); ++i) {
281 radio->set_listener(this); 265 views::RadioButton* radio = new views::RadioButton(UTF8ToWide(*i), 0);
282 radio_group_.push_back(radio); 266 radio->set_listener(this);
283 layout->StartRow(0, single_column_set_id); 267 radio_group_.push_back(radio);
284 layout->AddView(radio); 268 if (!bubble_content_empty)
285 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 269 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
286 } 270 layout->StartRow(0, single_column_set_id);
287 if (!radio_group_.empty()) { 271 layout->AddView(radio);
288 views::Separator* separator = new views::Separator; 272 bubble_content_empty = false;
289 layout->StartRow(0, single_column_set_id); 273 }
290 layout->AddView(separator, 1, 1, GridLayout::FILL, GridLayout::FILL); 274 DCHECK(!radio_group_.empty());
291 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
292 // Now that the buttons have been added to the view hierarchy, it's safe 275 // Now that the buttons have been added to the view hierarchy, it's safe
293 // to call SetChecked() on them. 276 // to call SetChecked() on them.
294 radio_group_[radio_group.default_item]->SetChecked(true); 277 radio_group_[radio_group.default_item]->SetChecked(true);
295 } 278 }
296 279
297 gfx::Font domain_font = 280 gfx::Font domain_font =
298 views::Label().font().DeriveFont(0, gfx::Font::BOLD); 281 views::Label().font().DeriveFont(0, gfx::Font::BOLD);
299 const int indented_single_column_set_id = 3; 282 const int indented_single_column_set_id = 3;
300 // Insert a column set to indent the domain list. 283 // Insert a column set to indent the domain list.
301 views::ColumnSet* indented_single_column_set = 284 views::ColumnSet* indented_single_column_set =
302 layout->AddColumnSet(indented_single_column_set_id); 285 layout->AddColumnSet(indented_single_column_set_id);
303 indented_single_column_set->AddPaddingColumn(0, kPanelHorizIndentation); 286 indented_single_column_set->AddPaddingColumn(0, kPanelHorizIndentation);
304 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 287 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL,
305 1, GridLayout::USE_PREF, 0, 0); 288 1, GridLayout::USE_PREF, 0, 0);
306 for (std::vector<ContentSettingBubbleModel::DomainList>::const_iterator i = 289 for (std::vector<ContentSettingBubbleModel::DomainList>::const_iterator i =
307 bubble_content.domain_lists.begin(); 290 bubble_content.domain_lists.begin();
308 i != bubble_content.domain_lists.end(); ++i) { 291 i != bubble_content.domain_lists.end(); ++i) {
309 layout->StartRow(0, single_column_set_id); 292 layout->StartRow(0, single_column_set_id);
310 views::Label* section_title = new views::Label(UTF8ToWide(i->title)); 293 views::Label* section_title = new views::Label(UTF8ToWide(i->title));
311 section_title->SetMultiLine(true); 294 section_title->SetMultiLine(true);
312 section_title->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 295 section_title->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
313 layout->AddView(section_title, 1, 1, GridLayout::FILL, GridLayout::LEADING); 296 layout->AddView(section_title, 1, 1, GridLayout::FILL, GridLayout::LEADING);
314 for (std::set<std::string>::const_iterator j = i->hosts.begin(); 297 for (std::set<std::string>::const_iterator j = i->hosts.begin();
315 j != i->hosts.end(); ++j) { 298 j != i->hosts.end(); ++j) {
316 layout->StartRow(0, indented_single_column_set_id); 299 layout->StartRow(0, indented_single_column_set_id);
317 layout->AddView(new views::Label(UTF8ToWide(*j), domain_font)); 300 layout->AddView(new views::Label(UTF8ToWide(*j), domain_font));
318 } 301 }
319 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 302 bubble_content_empty = false;
320 } 303 }
321 304
322 if (!bubble_content.clear_link.empty()) { 305 if (!bubble_content.custom_link.empty()) {
323 clear_link_ = new views::Link(UTF8ToWide(bubble_content.clear_link)); 306 custom_link_ = new views::Link(UTF8ToWide(bubble_content.custom_link));
324 clear_link_->SetController(this); 307 custom_link_->SetEnabled(bubble_content.custom_link_enabled);
308 custom_link_->SetController(this);
309 if (!bubble_content_empty)
310 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
325 layout->StartRow(0, single_column_set_id); 311 layout->StartRow(0, single_column_set_id);
326 layout->AddView(clear_link_); 312 layout->AddView(custom_link_);
313 bubble_content_empty = false;
314 }
327 315
316 if (!bubble_content_empty) {
328 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 317 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
329 layout->StartRow(0, single_column_set_id); 318 layout->StartRow(0, single_column_set_id);
330 layout->AddView(new views::Separator, 1, 1, 319 layout->AddView(new views::Separator, 1, 1,
331 GridLayout::FILL, GridLayout::FILL);
332 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
333 }
334
335 if (!bubble_content.info_link.empty()) {
336 info_link_ = new views::Link(UTF8ToWide(bubble_content.info_link));
337 info_link_->SetController(this);
338 layout->StartRow(0, single_column_set_id);
339 layout->AddView(info_link_);
340
341 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
342 layout->StartRow(0, single_column_set_id);
343 layout->AddView(new views::Separator, 1, 1,
344 GridLayout::FILL, GridLayout::FILL);
345 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
346 }
347
348 if (!bubble_content.load_plugins_link_title.empty()) {
349 load_plugins_link_ = new views::Link(
350 UTF8ToWide(bubble_content.load_plugins_link_title));
351 load_plugins_link_->SetEnabled(bubble_content.load_plugins_link_enabled);
352 load_plugins_link_->SetController(this);
353 layout->StartRow(0, single_column_set_id);
354 layout->AddView(load_plugins_link_);
355
356 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
357 layout->StartRow(0, single_column_set_id);
358 layout->AddView(new views::Separator, 1, 1,
359 GridLayout::FILL, GridLayout::FILL); 320 GridLayout::FILL, GridLayout::FILL);
360 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 321 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
361 } 322 }
362 323
363 const int double_column_set_id = 1; 324 const int double_column_set_id = 1;
364 views::ColumnSet* double_column_set = 325 views::ColumnSet* double_column_set =
365 layout->AddColumnSet(double_column_set_id); 326 layout->AddColumnSet(double_column_set_id);
366 double_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, 327 double_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1,
367 GridLayout::USE_PREF, 0, 0); 328 GridLayout::USE_PREF, 0, 0);
368 double_column_set->AddPaddingColumn(0, kUnrelatedControlHorizontalSpacing); 329 double_column_set->AddPaddingColumn(0, kUnrelatedControlHorizontalSpacing);
369 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, 330 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0,
370 GridLayout::USE_PREF, 0, 0); 331 GridLayout::USE_PREF, 0, 0);
371 332
372 layout->StartRow(0, double_column_set_id); 333 layout->StartRow(0, double_column_set_id);
373 manage_link_ = new views::Link(UTF8ToWide(bubble_content.manage_link)); 334 manage_link_ = new views::Link(UTF8ToWide(bubble_content.manage_link));
374 manage_link_->SetController(this); 335 manage_link_->SetController(this);
375 layout->AddView(manage_link_); 336 layout->AddView(manage_link_);
376 337
377 close_button_ = 338 close_button_ =
378 new views::NativeButton(this, l10n_util::GetString(IDS_DONE)); 339 new views::NativeButton(this, l10n_util::GetString(IDS_DONE));
379 layout->AddView(close_button_); 340 layout->AddView(close_button_);
380 } 341 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/content_setting_bubble_contents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698