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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_install_dialog_view.cc

Issue 501273002: Update extension install prompt to reflect withheld permissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor extension install dialog view constructor Created 6 years, 3 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) 2012 The Chromium Authors. All rights reserved. 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 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/ui/views/extensions/extension_install_dialog_view.h" 5 #include "chrome/browser/ui/views/extensions/extension_install_dialog_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt) 189 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt)
190 : navigator_(navigator), 190 : navigator_(navigator),
191 delegate_(delegate), 191 delegate_(delegate),
192 prompt_(prompt), 192 prompt_(prompt),
193 scroll_view_(NULL), 193 scroll_view_(NULL),
194 scrollable_(NULL), 194 scrollable_(NULL),
195 scrollable_header_only_(NULL), 195 scrollable_header_only_(NULL),
196 show_details_link_(NULL), 196 show_details_link_(NULL),
197 checkbox_info_label_(NULL), 197 checkbox_info_label_(NULL),
198 unchecked_boxes_(0) { 198 unchecked_boxes_(0) {
199 InitView();
200 }
201
202 ExtensionInstallDialogView::~ExtensionInstallDialogView() {
203 }
204
205 void ExtensionInstallDialogView::InitView() {
199 // Possible grid layouts without ExtensionPermissionDialog experiment: 206 // Possible grid layouts without ExtensionPermissionDialog experiment:
200 // Inline install 207 // Inline install
201 // w/ permissions no permissions 208 // w/ permissions no permissions
202 // +--------------------+------+ +--------------+------+ 209 // +--------------------+------+ +--------------+------+
203 // | heading | icon | | heading | icon | 210 // | heading | icon | | heading | icon |
204 // +--------------------| | +--------------| | 211 // +--------------------| | +--------------| |
205 // | rating | | | rating | | 212 // | rating | | | rating | |
206 // +--------------------| | +--------------+ | 213 // +--------------------| | +--------------+ |
207 // | user_count | | | user_count | | 214 // | user_count | | | user_count | |
208 // +--------------------| | +--------------| | 215 // +--------------------| | +--------------| |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // +--------------------| | 277 // +--------------------| |
271 // |checkbox|permission1| | 278 // |checkbox|permission1| |
272 // +--------------------| | 279 // +--------------------| |
273 // |checkbox|permission2| | 280 // |checkbox|permission2| |
274 // +--------------------+------+ 281 // +--------------------+------+
275 // 282 //
276 // Additionally, links or informational text is added to non-client areas of 283 // Additionally, links or informational text is added to non-client areas of
277 // the dialog depending on the experiment group. 284 // the dialog depending on the experiment group.
278 285
279 int left_column_width = 286 int left_column_width =
280 (prompt->ShouldShowPermissions() + prompt->GetRetainedFileCount()) > 0 287 (prompt_->ShouldShowPermissions() + prompt_->GetRetainedFileCount()) > 0
281 ? kPermissionsLeftColumnWidth 288 ? kPermissionsLeftColumnWidth
282 : kNoPermissionsLeftColumnWidth; 289 : kNoPermissionsLeftColumnWidth;
283 if (is_bundle_install()) 290 if (is_bundle_install())
284 left_column_width = kBundleLeftColumnWidth; 291 left_column_width = kBundleLeftColumnWidth;
285 if (is_external_install()) 292 if (is_external_install())
286 left_column_width = kExternalInstallLeftColumnWidth; 293 left_column_width = kExternalInstallLeftColumnWidth;
287 294
288 scroll_view_ = new views::ScrollView(); 295 scroll_view_ = new views::ScrollView();
289 scroll_view_->set_hide_horizontal_scrollbar(true); 296 scroll_view_->set_hide_horizontal_scrollbar(true);
290 AddChildView(scroll_view_); 297 AddChildView(scroll_view_);
291 298
292 int column_set_id = 0; 299 int column_set_id = 0;
293 // Create the full scrollable view which will contain all the information 300 // Create the full scrollable view which will contain all the information
294 // including the permissions. 301 // including the permissions.
295 scrollable_ = new CustomScrollableView(); 302 scrollable_ = new CustomScrollableView();
296 views::GridLayout* layout = CreateLayout( 303 views::GridLayout* layout = CreateLayout(
297 scrollable_, left_column_width, column_set_id, false); 304 scrollable_, left_column_width, column_set_id, false);
298 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 305 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
299 306
300 if (prompt->ShouldShowPermissions() && 307 if (prompt_->ShouldShowPermissions() &&
301 prompt->experiment()->should_show_expandable_permission_list()) { 308 prompt_->experiment()->should_show_expandable_permission_list()) {
302 // If the experiment should hide the permission list initially, create a 309 // If the experiment should hide the permission list initially, create a
303 // simple layout that contains only the header, extension name and icon. 310 // simple layout that contains only the header, extension name and icon.
304 scrollable_header_only_ = new CustomScrollableView(); 311 scrollable_header_only_ = new CustomScrollableView();
305 CreateLayout(scrollable_header_only_, left_column_width, 312 CreateLayout(scrollable_header_only_, left_column_width,
306 column_set_id, true); 313 column_set_id, true);
307 scroll_view_->SetContents(scrollable_header_only_); 314 scroll_view_->SetContents(scrollable_header_only_);
308 } else { 315 } else {
309 scroll_view_->SetContents(scrollable_); 316 scroll_view_->SetContents(scrollable_);
310 } 317 }
311 318
312 int dialog_width = left_column_width + 2 * views::kPanelHorizMargin; 319 int dialog_width = left_column_width + 2 * views::kPanelHorizMargin;
313 if (!is_bundle_install()) 320 if (!is_bundle_install())
314 dialog_width += views::kPanelHorizMargin + kIconSize + kIconOffset; 321 dialog_width += views::kPanelHorizMargin + kIconSize + kIconOffset;
315 322
316 // Widen the dialog for experiment with checkboxes so that the information 323 // Widen the dialog for experiment with checkboxes so that the information
317 // label fits the area to the left of the buttons. 324 // label fits the area to the left of the buttons.
318 if (prompt->experiment()->show_checkboxes()) 325 if (prompt_->experiment()->show_checkboxes())
319 dialog_width += 4 * views::kPanelHorizMargin; 326 dialog_width += 4 * views::kPanelHorizMargin;
320 327
321 if (prompt->has_webstore_data()) { 328 if (prompt_->has_webstore_data()) {
322 layout->StartRow(0, column_set_id); 329 layout->StartRow(0, column_set_id);
323 views::View* rating = new views::View(); 330 views::View* rating = new views::View();
324 rating->SetLayoutManager(new views::BoxLayout( 331 rating->SetLayoutManager(new views::BoxLayout(
325 views::BoxLayout::kHorizontal, 0, 0, 0)); 332 views::BoxLayout::kHorizontal, 0, 0, 0));
326 layout->AddView(rating); 333 layout->AddView(rating);
327 prompt->AppendRatingStars(AddResourceIcon, rating); 334 prompt_->AppendRatingStars(AddResourceIcon, rating);
328 335
329 const gfx::FontList& small_font_list = 336 const gfx::FontList& small_font_list =
330 rb.GetFontList(ui::ResourceBundle::SmallFont); 337 rb.GetFontList(ui::ResourceBundle::SmallFont);
331 views::Label* rating_count = 338 views::Label* rating_count =
332 new views::Label(prompt->GetRatingCount(), small_font_list); 339 new views::Label(prompt_->GetRatingCount(), small_font_list);
333 // Add some space between the stars and the rating count. 340 // Add some space between the stars and the rating count.
334 rating_count->SetBorder(views::Border::CreateEmptyBorder(0, 2, 0, 0)); 341 rating_count->SetBorder(views::Border::CreateEmptyBorder(0, 2, 0, 0));
335 rating->AddChildView(rating_count); 342 rating->AddChildView(rating_count);
336 343
337 layout->StartRow(0, column_set_id); 344 layout->StartRow(0, column_set_id);
338 views::Label* user_count = 345 views::Label* user_count =
339 new views::Label(prompt->GetUserCount(), small_font_list); 346 new views::Label(prompt_->GetUserCount(), small_font_list);
340 user_count->SetAutoColorReadabilityEnabled(false); 347 user_count->SetAutoColorReadabilityEnabled(false);
341 user_count->SetEnabledColor(SK_ColorGRAY); 348 user_count->SetEnabledColor(SK_ColorGRAY);
342 layout->AddView(user_count); 349 layout->AddView(user_count);
343 350
344 layout->StartRow(0, column_set_id); 351 layout->StartRow(0, column_set_id);
345 views::Link* store_link = new views::Link( 352 views::Link* store_link = new views::Link(
346 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_STORE_LINK)); 353 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_STORE_LINK));
347 store_link->SetFontList(small_font_list); 354 store_link->SetFontList(small_font_list);
348 store_link->set_listener(this); 355 store_link->set_listener(this);
349 layout->AddView(store_link); 356 layout->AddView(store_link);
350 } 357 }
351 358
352 if (is_bundle_install()) { 359 if (is_bundle_install()) {
353 BundleInstaller::ItemList items = prompt->bundle()->GetItemsWithState( 360 BundleInstaller::ItemList items = prompt_->bundle()->GetItemsWithState(
354 BundleInstaller::Item::STATE_PENDING); 361 BundleInstaller::Item::STATE_PENDING);
355 for (size_t i = 0; i < items.size(); ++i) { 362 for (size_t i = 0; i < items.size(); ++i) {
356 base::string16 extension_name = 363 base::string16 extension_name =
357 base::UTF8ToUTF16(items[i].localized_name); 364 base::UTF8ToUTF16(items[i].localized_name);
358 base::i18n::AdjustStringForLocaleDirection(&extension_name); 365 base::i18n::AdjustStringForLocaleDirection(&extension_name);
359 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 366 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
360 layout->StartRow(0, column_set_id); 367 layout->StartRow(0, column_set_id);
361 views::Label* extension_label = new views::Label( 368 views::Label* extension_label = new views::Label(
362 PrepareForDisplay(extension_name, true)); 369 PrepareForDisplay(extension_name, true));
363 extension_label->SetMultiLine(true); 370 extension_label->SetMultiLine(true);
364 extension_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 371 extension_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
365 extension_label->SizeToFit(left_column_width); 372 extension_label->SizeToFit(left_column_width);
366 layout->AddView(extension_label); 373 layout->AddView(extension_label);
367 } 374 }
368 } 375 }
369 376
370 if (prompt->ShouldShowPermissions()) { 377 if (prompt_->ShouldShowPermissions()) {
371 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 378 MaybeAddPermissions(
372 379 layout,
373 if (prompt->GetPermissionCount() > 0) { 380 rb,
374 if (is_inline_install()) { 381 column_set_id,
375 layout->StartRow(0, column_set_id); 382 left_column_width,
376 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 383 ExtensionInstallPrompt::PermissionsType::REGULAR_PERMISSIONS);
377 3, 1, views::GridLayout::FILL, views::GridLayout::FILL); 384 MaybeAddPermissions(
378 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 385 layout,
379 } 386 rb,
380 387 column_set_id,
381 layout->StartRow(0, column_set_id); 388 left_column_width,
382 views::Label* permissions_header = NULL; 389 ExtensionInstallPrompt::PermissionsType::WITHHELD_PERMISSIONS);
383 if (is_bundle_install()) { 390 if (prompt_->GetPermissionCount(
384 // We need to pass the FontList in the constructor, rather than calling 391 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS) == 0) {
385 // SetFontList later, because otherwise SizeToFit mis-judges the width
386 // of the line.
387 permissions_header =
388 new views::Label(prompt->GetPermissionsHeading(),
389 rb.GetFontList(ui::ResourceBundle::MediumFont));
390 } else {
391 permissions_header = new views::Label(prompt->GetPermissionsHeading());
392 }
393 permissions_header->SetMultiLine(true);
394 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
395 permissions_header->SizeToFit(left_column_width);
396 layout->AddView(permissions_header);
397
398 for (size_t i = 0; i < prompt->GetPermissionCount(); ++i) {
399 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
400 layout->StartRow(0, column_set_id);
401 views::Label* permission_label =
402 new views::Label(prompt->GetPermission(i));
403
404 const SkColor kTextHighlight = SK_ColorRED;
405 const SkColor kBackgroundHighlight = SkColorSetRGB(0xFB, 0xF7, 0xA3);
406 if (prompt->experiment()->ShouldHighlightText(
407 prompt->GetPermission(i))) {
408 permission_label->SetAutoColorReadabilityEnabled(false);
409 permission_label->SetEnabledColor(kTextHighlight);
410 } else if (prompt->experiment()->ShouldHighlightBackground(
411 prompt->GetPermission(i))) {
412 permission_label->SetLineHeight(18);
413 permission_label->set_background(
414 views::Background::CreateSolidBackground(kBackgroundHighlight));
415 }
416
417 permission_label->SetMultiLine(true);
418 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
419
420 if (prompt->experiment()->show_checkboxes()) {
421 permission_label->SizeToFit(left_column_width);
422 layout->AddView(new CheckboxedView(permission_label, this));
423 ++unchecked_boxes_;
424 } else {
425 permission_label->SizeToFit(left_column_width - kBulletWidth);
426 layout->AddView(new BulletedView(permission_label));
427 }
428
429 // If we have more details to provide, show them in collapsed form.
430 if (!prompt->GetPermissionsDetails(i).empty()) {
431 layout->StartRow(0, column_set_id);
432 PermissionDetails details;
433 details.push_back(
434 PrepareForDisplay(prompt->GetPermissionsDetails(i), false));
435 ExpandableContainerView* details_container =
436 new ExpandableContainerView(
437 this, base::string16(), details, left_column_width,
438 true, true, false);
439 layout->AddView(details_container);
440 }
441
442 if (prompt->experiment()->should_show_inline_explanations()) {
443 base::string16 explanation =
444 prompt->experiment()->GetInlineExplanation(
445 prompt->GetPermission(i));
446 if (!explanation.empty()) {
447 PermissionDetails details;
448 details.push_back(explanation);
449 ExpandableContainerView* container =
450 new ExpandableContainerView(this, base::string16(), details,
451 left_column_width,
452 false, false, true);
453 // Inline explanations are expanded by default if there is
454 // no "Show details" link.
455 if (!prompt->experiment()->show_details_link())
456 container->ExpandWithoutAnimation();
457 layout->StartRow(0, column_set_id);
458 layout->AddView(container);
459 inline_explanations_.push_back(container);
460 }
461 }
462 }
463 } else {
464 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 392 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
465 layout->StartRow(0, column_set_id); 393 layout->StartRow(0, column_set_id);
466 views::Label* permission_label = new views::Label( 394 views::Label* permission_label = new views::Label(
467 l10n_util::GetStringUTF16(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS)); 395 l10n_util::GetStringUTF16(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS));
468 permission_label->SetMultiLine(true); 396 permission_label->SetMultiLine(true);
469 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 397 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
470 permission_label->SizeToFit(left_column_width); 398 permission_label->SizeToFit(left_column_width);
471 layout->AddView(permission_label); 399 layout->AddView(permission_label);
472 } 400 }
473 } 401 }
474 402
475 if (prompt->GetRetainedFileCount()) { 403 if (prompt_->GetRetainedFileCount()) {
476 // Slide in under the permissions, if there are any. If there are 404 // Slide in under the permissions, if there are any. If there are
477 // either, the retained files prompt stretches all the way to the 405 // either, the retained files prompt stretches all the way to the
478 // right of the dialog. If there are no permissions, the retained 406 // right of the dialog. If there are no permissions, the retained
479 // files prompt just takes up the left column. 407 // files prompt just takes up the left column.
480 int space_for_files = left_column_width; 408 int space_for_files = left_column_width;
481 if (prompt->GetPermissionCount()) { 409 if (prompt_->GetPermissionCount(
410 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS)) {
482 space_for_files += kIconSize; 411 space_for_files += kIconSize;
483 views::ColumnSet* column_set = layout->AddColumnSet(++column_set_id); 412 views::ColumnSet* column_set = layout->AddColumnSet(++column_set_id);
484 column_set->AddColumn(views::GridLayout::FILL, 413 column_set->AddColumn(views::GridLayout::FILL,
485 views::GridLayout::FILL, 414 views::GridLayout::FILL,
486 1, 415 1,
487 views::GridLayout::USE_PREF, 416 views::GridLayout::USE_PREF,
488 0, // no fixed width 417 0, // no fixed width
489 space_for_files); 418 space_for_files);
490 } 419 }
491 420
492 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 421 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
493 422
494 layout->StartRow(0, column_set_id); 423 layout->StartRow(0, column_set_id);
495 views::Label* retained_files_header = NULL; 424 views::Label* retained_files_header = NULL;
496 retained_files_header = new views::Label(prompt->GetRetainedFilesHeading()); 425 retained_files_header =
426 new views::Label(prompt_->GetRetainedFilesHeading());
497 retained_files_header->SetMultiLine(true); 427 retained_files_header->SetMultiLine(true);
498 retained_files_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); 428 retained_files_header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
499 retained_files_header->SizeToFit(space_for_files); 429 retained_files_header->SizeToFit(space_for_files);
500 layout->AddView(retained_files_header); 430 layout->AddView(retained_files_header);
501 431
502 layout->StartRow(0, column_set_id); 432 layout->StartRow(0, column_set_id);
503 PermissionDetails details; 433 PermissionDetails details;
504 for (size_t i = 0; i < prompt->GetRetainedFileCount(); ++i) 434 for (size_t i = 0; i < prompt_->GetRetainedFileCount(); ++i)
505 details.push_back(prompt->GetRetainedFile(i)); 435 details.push_back(prompt_->GetRetainedFile(i));
506 ExpandableContainerView* issue_advice_view = 436 ExpandableContainerView* issue_advice_view =
507 new ExpandableContainerView( 437 new ExpandableContainerView(
508 this, base::string16(), details, space_for_files, 438 this, base::string16(), details, space_for_files,
509 false, true, false); 439 false, true, false);
510 layout->AddView(issue_advice_view); 440 layout->AddView(issue_advice_view);
511 } 441 }
512 442
513 DCHECK(prompt->type() >= 0); 443 DCHECK(prompt_->type() >= 0);
514 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallPrompt.Type", 444 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallPrompt.Type",
515 prompt->type(), 445 prompt_->type(),
516 ExtensionInstallPrompt::NUM_PROMPT_TYPES); 446 ExtensionInstallPrompt::NUM_PROMPT_TYPES);
517 447
518 if (prompt->ShouldShowPermissions()) { 448 if (prompt_->ShouldShowPermissions()) {
519 if (prompt->ShouldShowExplanationText()) { 449 if (prompt_->ShouldShowExplanationText()) {
520 views::ColumnSet* column_set = layout->AddColumnSet(++column_set_id); 450 views::ColumnSet* column_set = layout->AddColumnSet(++column_set_id);
521 column_set->AddColumn(views::GridLayout::LEADING, 451 column_set->AddColumn(views::GridLayout::LEADING,
522 views::GridLayout::FILL, 452 views::GridLayout::FILL,
523 1, 453 1,
524 views::GridLayout::USE_PREF, 454 views::GridLayout::USE_PREF,
525 0, 455 0,
526 0); 456 0);
527 // Add two rows of space so that the text stands out. 457 // Add two rows of space so that the text stands out.
528 layout->AddPaddingRow(0, 2 * views::kRelatedControlVerticalSpacing); 458 layout->AddPaddingRow(0, 2 * views::kRelatedControlVerticalSpacing);
529 459
530 layout->StartRow(0, column_set_id); 460 layout->StartRow(0, column_set_id);
531 views::Label* explanation = 461 views::Label* explanation =
532 new views::Label(prompt->experiment()->GetExplanationText()); 462 new views::Label(prompt_->experiment()->GetExplanationText());
533 explanation->SetMultiLine(true); 463 explanation->SetMultiLine(true);
534 explanation->SetHorizontalAlignment(gfx::ALIGN_LEFT); 464 explanation->SetHorizontalAlignment(gfx::ALIGN_LEFT);
535 explanation->SizeToFit(left_column_width + kIconSize); 465 explanation->SizeToFit(left_column_width + kIconSize);
536 layout->AddView(explanation); 466 layout->AddView(explanation);
537 } 467 }
538 468
539 if (prompt->experiment()->should_show_expandable_permission_list() || 469 if (prompt_->experiment()->should_show_expandable_permission_list() ||
540 (prompt->experiment()->show_details_link() && 470 (prompt_->experiment()->show_details_link() &&
541 prompt->experiment()->should_show_inline_explanations() && 471 prompt_->experiment()->should_show_inline_explanations() &&
542 !inline_explanations_.empty())) { 472 !inline_explanations_.empty())) {
543 // Don't show the "Show details" link if there are retained 473 // Don't show the "Show details" link if there are retained
544 // files. These have their own "Show details" links and having 474 // files. These have their own "Show details" links and having
545 // multiple levels of links is confusing. 475 // multiple levels of links is confusing.
546 if (prompt->GetRetainedFileCount() == 0) { 476 if (prompt_->GetRetainedFileCount() == 0) {
547 int text_id = 477 int text_id =
548 prompt->experiment()->should_show_expandable_permission_list() 478 prompt_->experiment()->should_show_expandable_permission_list()
549 ? IDS_EXTENSION_PROMPT_EXPERIMENT_SHOW_PERMISSIONS 479 ? IDS_EXTENSION_PROMPT_EXPERIMENT_SHOW_PERMISSIONS
550 : IDS_EXTENSION_PROMPT_EXPERIMENT_SHOW_DETAILS; 480 : IDS_EXTENSION_PROMPT_EXPERIMENT_SHOW_DETAILS;
551 show_details_link_ = new views::Link( 481 show_details_link_ = new views::Link(
552 l10n_util::GetStringUTF16(text_id)); 482 l10n_util::GetStringUTF16(text_id));
553 show_details_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 483 show_details_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
554 show_details_link_->set_listener(this); 484 show_details_link_->set_listener(this);
555 UpdateLinkActionHistogram(LINK_SHOWN); 485 UpdateLinkActionHistogram(LINK_SHOWN);
556 } else { 486 } else {
557 UpdateLinkActionHistogram(LINK_NOT_SHOWN); 487 UpdateLinkActionHistogram(LINK_NOT_SHOWN);
558 } 488 }
559 } 489 }
560 490
561 if (prompt->experiment()->show_checkboxes()) { 491 if (prompt_->experiment()->show_checkboxes()) {
562 checkbox_info_label_ = new views::Label( 492 checkbox_info_label_ = new views::Label(
563 l10n_util::GetStringUTF16( 493 l10n_util::GetStringUTF16(
564 IDS_EXTENSION_PROMPT_EXPERIMENT_CHECKBOX_INFO)); 494 IDS_EXTENSION_PROMPT_EXPERIMENT_CHECKBOX_INFO));
565 checkbox_info_label_->SetMultiLine(true); 495 checkbox_info_label_->SetMultiLine(true);
566 checkbox_info_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 496 checkbox_info_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
567 checkbox_info_label_->SetAutoColorReadabilityEnabled(false); 497 checkbox_info_label_->SetAutoColorReadabilityEnabled(false);
568 checkbox_info_label_->SetEnabledColor(kLighterLabelColor); 498 checkbox_info_label_->SetEnabledColor(kLighterLabelColor);
569 } 499 }
570 } 500 }
571 501
572 gfx::Size scrollable_size = scrollable_->GetPreferredSize(); 502 gfx::Size scrollable_size = scrollable_->GetPreferredSize();
573 scrollable_->SetBoundsRect(gfx::Rect(scrollable_size)); 503 scrollable_->SetBoundsRect(gfx::Rect(scrollable_size));
574 dialog_size_ = gfx::Size( 504 dialog_size_ = gfx::Size(
575 dialog_width, 505 dialog_width,
576 std::min(scrollable_size.height(), kDialogMaxHeight)); 506 std::min(scrollable_size.height(), kDialogMaxHeight));
577 507
578 if (scrollable_header_only_) { 508 if (scrollable_header_only_) {
579 gfx::Size header_only_size = scrollable_header_only_->GetPreferredSize(); 509 gfx::Size header_only_size = scrollable_header_only_->GetPreferredSize();
580 scrollable_header_only_->SetBoundsRect(gfx::Rect(header_only_size)); 510 scrollable_header_only_->SetBoundsRect(gfx::Rect(header_only_size));
581 dialog_size_ = gfx::Size( 511 dialog_size_ = gfx::Size(
582 dialog_width, std::min(header_only_size.height(), kDialogMaxHeight)); 512 dialog_width, std::min(header_only_size.height(), kDialogMaxHeight));
583 } 513 }
584 514
585 std::string event_name = ExperienceSamplingEvent::kExtensionInstallDialog; 515 std::string event_name = ExperienceSamplingEvent::kExtensionInstallDialog;
586 event_name.append( 516 event_name.append(
587 ExtensionInstallPrompt::PromptTypeToString(prompt_->type())); 517 ExtensionInstallPrompt::PromptTypeToString(prompt_->type()));
588 sampling_event_ = ExperienceSamplingEvent::Create(event_name); 518 sampling_event_ = ExperienceSamplingEvent::Create(event_name);
589 } 519 }
590 520
591 ExtensionInstallDialogView::~ExtensionInstallDialogView() {} 521 bool ExtensionInstallDialogView::MaybeAddPermissions(
522 views::GridLayout* layout,
523 ui::ResourceBundle& rb,
524 int column_set_id,
525 int left_column_width,
526 ExtensionInstallPrompt::PermissionsType perm_type) {
527 if (prompt_->GetPermissionCount(perm_type) == 0)
528 return false;
529
530 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
531 if (is_inline_install()) {
532 layout->StartRow(0, column_set_id);
533 layout->AddView(new views::Separator(views::Separator::HORIZONTAL),
534 3,
535 1,
536 views::GridLayout::FILL,
537 views::GridLayout::FILL);
538 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
539 }
540
541 layout->StartRow(0, column_set_id);
542 views::Label* permissions_header = NULL;
543 if (is_bundle_install()) {
544 // We need to pass the FontList in the constructor, rather than calling
545 // SetFontList later, because otherwise SizeToFit mis-judges the width
546 // of the line.
547 permissions_header =
548 new views::Label(prompt_->GetPermissionsHeading(perm_type),
549 rb.GetFontList(ui::ResourceBundle::MediumFont));
550 } else {
551 permissions_header =
552 new views::Label(prompt_->GetPermissionsHeading(perm_type));
553 }
554 permissions_header->SetMultiLine(true);
555 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
556 permissions_header->SizeToFit(left_column_width);
557 layout->AddView(permissions_header);
558
559 for (size_t i = 0; i < prompt_->GetPermissionCount(perm_type); ++i) {
560 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
561 layout->StartRow(0, column_set_id);
562 views::Label* permission_label =
563 new views::Label(prompt_->GetPermission(i, perm_type));
564
565 const SkColor kTextHighlight = SK_ColorRED;
566 const SkColor kBackgroundHighlight = SkColorSetRGB(0xFB, 0xF7, 0xA3);
567 if (prompt_->experiment()->ShouldHighlightText(
568 prompt_->GetPermission(i, perm_type))) {
569 permission_label->SetAutoColorReadabilityEnabled(false);
570 permission_label->SetEnabledColor(kTextHighlight);
571 } else if (prompt_->experiment()->ShouldHighlightBackground(
572 prompt_->GetPermission(i, perm_type))) {
573 permission_label->SetLineHeight(18);
574 permission_label->set_background(
575 views::Background::CreateSolidBackground(kBackgroundHighlight));
576 }
577
578 permission_label->SetMultiLine(true);
579 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
580
581 if (prompt_->experiment()->show_checkboxes()) {
582 permission_label->SizeToFit(left_column_width);
583 layout->AddView(new CheckboxedView(permission_label, this));
584 ++unchecked_boxes_;
585 } else {
586 permission_label->SizeToFit(left_column_width - kBulletWidth);
587 layout->AddView(new BulletedView(permission_label));
588 }
589
590 // If we have more details to provide, show them in collapsed form.
591 if (!prompt_->GetPermissionsDetails(i, perm_type).empty()) {
592 layout->StartRow(0, column_set_id);
593 PermissionDetails details;
594 details.push_back(PrepareForDisplay(
595 prompt_->GetPermissionsDetails(i, perm_type), false));
596 ExpandableContainerView* details_container =
597 new ExpandableContainerView(this,
598 base::string16(),
599 details,
600 left_column_width,
601 true,
602 true,
603 false);
604 layout->AddView(details_container);
605 }
606
607 if (prompt_->experiment()->should_show_inline_explanations()) {
608 base::string16 explanation = prompt_->experiment()->GetInlineExplanation(
609 prompt_->GetPermission(i, perm_type));
610 if (!explanation.empty()) {
611 PermissionDetails details;
612 details.push_back(explanation);
613 ExpandableContainerView* container =
614 new ExpandableContainerView(this,
615 base::string16(),
616 details,
617 left_column_width,
618 false,
619 false,
620 true);
621 // Inline explanations are expanded by default if there is
622 // no "Show details" link.
623 if (!prompt_->experiment()->show_details_link())
624 container->ExpandWithoutAnimation();
625 layout->StartRow(0, column_set_id);
626 layout->AddView(container);
627 inline_explanations_.push_back(container);
628 }
629 }
630 }
631 return true;
632 }
592 633
593 views::GridLayout* ExtensionInstallDialogView::CreateLayout( 634 views::GridLayout* ExtensionInstallDialogView::CreateLayout(
594 views::View* parent, 635 views::View* parent,
595 int left_column_width, 636 int left_column_width,
596 int column_set_id, 637 int column_set_id,
597 bool single_detail_row) const { 638 bool single_detail_row) const {
598 views::GridLayout* layout = views::GridLayout::CreatePanel(parent); 639 views::GridLayout* layout = views::GridLayout::CreatePanel(parent);
599 parent->SetLayoutManager(layout); 640 parent->SetLayoutManager(layout);
600 641
601 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 642 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 icon->SetHorizontalAlignment(views::ImageView::CENTER); 679 icon->SetHorizontalAlignment(views::ImageView::CENTER);
639 icon->SetVerticalAlignment(views::ImageView::CENTER); 680 icon->SetVerticalAlignment(views::ImageView::CENTER);
640 if (single_detail_row) { 681 if (single_detail_row) {
641 layout->AddView(icon); 682 layout->AddView(icon);
642 } else { 683 } else {
643 int icon_row_span = 1; 684 int icon_row_span = 1;
644 if (is_inline_install()) { 685 if (is_inline_install()) {
645 // Also span the rating, user_count and store_link rows. 686 // Also span the rating, user_count and store_link rows.
646 icon_row_span = 4; 687 icon_row_span = 4;
647 } else if (prompt_->ShouldShowPermissions()) { 688 } else if (prompt_->ShouldShowPermissions()) {
648 size_t permission_count = prompt_->GetPermissionCount(); 689 size_t permission_count = prompt_->GetPermissionCount(
690 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS);
649 // Also span the permission header and each of the permission rows (all 691 // Also span the permission header and each of the permission rows (all
650 // have a padding row above it). This also works for the 'no special 692 // have a padding row above it). This also works for the 'no special
651 // permissions' case. 693 // permissions' case.
652 icon_row_span = 3 + permission_count * 2; 694 icon_row_span = 3 + permission_count * 2;
653 } else if (prompt_->GetRetainedFileCount()) { 695 } else if (prompt_->GetRetainedFileCount()) {
654 // Also span the permission header and the retained files container. 696 // Also span the permission header and the retained files container.
655 icon_row_span = 4; 697 icon_row_span = 4;
656 } 698 }
657 layout->AddView(icon, 1, icon_row_span); 699 layout->AddView(icon, 1, icon_row_span);
658 } 700 }
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 void ExpandableContainerView::ExpandWithoutAnimation() { 1109 void ExpandableContainerView::ExpandWithoutAnimation() {
1068 expanded_ = true; 1110 expanded_ = true;
1069 details_view_->AnimateToState(1.0); 1111 details_view_->AnimateToState(1.0);
1070 } 1112 }
1071 1113
1072 // static 1114 // static
1073 ExtensionInstallPrompt::ShowDialogCallback 1115 ExtensionInstallPrompt::ShowDialogCallback
1074 ExtensionInstallPrompt::GetDefaultShowDialogCallback() { 1116 ExtensionInstallPrompt::GetDefaultShowDialogCallback() {
1075 return base::Bind(&ShowExtensionInstallDialogImpl); 1117 return base::Bind(&ShowExtensionInstallDialogImpl);
1076 } 1118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698