| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 bool has_permissions = |
| 371 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 378 prompt_->GetPermissionCount( |
| 372 | 379 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS) > 0; |
| 373 if (prompt->GetPermissionCount() > 0) { | 380 if (prompt_->ShouldShowPermissions()) { |
| 374 if (is_inline_install()) { | 381 AddPermissions( |
| 375 layout->StartRow(0, column_set_id); | 382 layout, |
| 376 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), | 383 rb, |
| 377 3, 1, views::GridLayout::FILL, views::GridLayout::FILL); | 384 column_set_id, |
| 378 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 385 left_column_width, |
| 379 } | 386 ExtensionInstallPrompt::PermissionsType::REGULAR_PERMISSIONS); |
| 380 | 387 AddPermissions( |
| 381 layout->StartRow(0, column_set_id); | 388 layout, |
| 382 views::Label* permissions_header = NULL; | 389 rb, |
| 383 if (is_bundle_install()) { | 390 column_set_id, |
| 384 // We need to pass the FontList in the constructor, rather than calling | 391 left_column_width, |
| 385 // SetFontList later, because otherwise SizeToFit mis-judges the width | 392 ExtensionInstallPrompt::PermissionsType::WITHHELD_PERMISSIONS); |
| 386 // of the line. | 393 if (!has_permissions) { |
| 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); | 394 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 465 layout->StartRow(0, column_set_id); | 395 layout->StartRow(0, column_set_id); |
| 466 views::Label* permission_label = new views::Label( | 396 views::Label* permission_label = new views::Label( |
| 467 l10n_util::GetStringUTF16(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS)); | 397 l10n_util::GetStringUTF16(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS)); |
| 468 permission_label->SetMultiLine(true); | 398 permission_label->SetMultiLine(true); |
| 469 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 399 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 470 permission_label->SizeToFit(left_column_width); | 400 permission_label->SizeToFit(left_column_width); |
| 471 layout->AddView(permission_label); | 401 layout->AddView(permission_label); |
| 472 } | 402 } |
| 473 } | 403 } |
| 474 | 404 |
| 475 if (prompt->GetRetainedFileCount()) { | 405 if (prompt_->GetRetainedFileCount()) { |
| 476 // Slide in under the permissions, if there are any. If there are | 406 // Slide in under the permissions, if there are any. If there are |
| 477 // either, the retained files prompt stretches all the way to the | 407 // either, the retained files prompt stretches all the way to the |
| 478 // right of the dialog. If there are no permissions, the retained | 408 // right of the dialog. If there are no permissions, the retained |
| 479 // files prompt just takes up the left column. | 409 // files prompt just takes up the left column. |
| 480 int space_for_files = left_column_width; | 410 int space_for_files = left_column_width; |
| 481 if (prompt->GetPermissionCount()) { | 411 if (has_permissions) { |
| 482 space_for_files += kIconSize; | 412 space_for_files += kIconSize; |
| 483 views::ColumnSet* column_set = layout->AddColumnSet(++column_set_id); | 413 views::ColumnSet* column_set = layout->AddColumnSet(++column_set_id); |
| 484 column_set->AddColumn(views::GridLayout::FILL, | 414 column_set->AddColumn(views::GridLayout::FILL, |
| 485 views::GridLayout::FILL, | 415 views::GridLayout::FILL, |
| 486 1, | 416 1, |
| 487 views::GridLayout::USE_PREF, | 417 views::GridLayout::USE_PREF, |
| 488 0, // no fixed width | 418 0, // no fixed width |
| 489 space_for_files); | 419 space_for_files); |
| 490 } | 420 } |
| 491 | 421 |
| 492 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 422 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 493 | 423 |
| 494 layout->StartRow(0, column_set_id); | 424 layout->StartRow(0, column_set_id); |
| 495 views::Label* retained_files_header = NULL; | 425 views::Label* retained_files_header = NULL; |
| 496 retained_files_header = new views::Label(prompt->GetRetainedFilesHeading()); | 426 retained_files_header = |
| 427 new views::Label(prompt_->GetRetainedFilesHeading()); |
| 497 retained_files_header->SetMultiLine(true); | 428 retained_files_header->SetMultiLine(true); |
| 498 retained_files_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 429 retained_files_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 499 retained_files_header->SizeToFit(space_for_files); | 430 retained_files_header->SizeToFit(space_for_files); |
| 500 layout->AddView(retained_files_header); | 431 layout->AddView(retained_files_header); |
| 501 | 432 |
| 502 layout->StartRow(0, column_set_id); | 433 layout->StartRow(0, column_set_id); |
| 503 PermissionDetails details; | 434 PermissionDetails details; |
| 504 for (size_t i = 0; i < prompt->GetRetainedFileCount(); ++i) | 435 for (size_t i = 0; i < prompt_->GetRetainedFileCount(); ++i) |
| 505 details.push_back(prompt->GetRetainedFile(i)); | 436 details.push_back(prompt_->GetRetainedFile(i)); |
| 506 ExpandableContainerView* issue_advice_view = | 437 ExpandableContainerView* issue_advice_view = |
| 507 new ExpandableContainerView( | 438 new ExpandableContainerView( |
| 508 this, base::string16(), details, space_for_files, | 439 this, base::string16(), details, space_for_files, |
| 509 false, true, false); | 440 false, true, false); |
| 510 layout->AddView(issue_advice_view); | 441 layout->AddView(issue_advice_view); |
| 511 } | 442 } |
| 512 | 443 |
| 513 DCHECK(prompt->type() >= 0); | 444 DCHECK(prompt_->type() >= 0); |
| 514 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallPrompt.Type", | 445 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallPrompt.Type", |
| 515 prompt->type(), | 446 prompt_->type(), |
| 516 ExtensionInstallPrompt::NUM_PROMPT_TYPES); | 447 ExtensionInstallPrompt::NUM_PROMPT_TYPES); |
| 517 | 448 |
| 518 if (prompt->ShouldShowPermissions()) { | 449 if (prompt_->ShouldShowPermissions()) { |
| 519 if (prompt->ShouldShowExplanationText()) { | 450 if (prompt_->ShouldShowExplanationText()) { |
| 520 views::ColumnSet* column_set = layout->AddColumnSet(++column_set_id); | 451 views::ColumnSet* column_set = layout->AddColumnSet(++column_set_id); |
| 521 column_set->AddColumn(views::GridLayout::LEADING, | 452 column_set->AddColumn(views::GridLayout::LEADING, |
| 522 views::GridLayout::FILL, | 453 views::GridLayout::FILL, |
| 523 1, | 454 1, |
| 524 views::GridLayout::USE_PREF, | 455 views::GridLayout::USE_PREF, |
| 525 0, | 456 0, |
| 526 0); | 457 0); |
| 527 // Add two rows of space so that the text stands out. | 458 // Add two rows of space so that the text stands out. |
| 528 layout->AddPaddingRow(0, 2 * views::kRelatedControlVerticalSpacing); | 459 layout->AddPaddingRow(0, 2 * views::kRelatedControlVerticalSpacing); |
| 529 | 460 |
| 530 layout->StartRow(0, column_set_id); | 461 layout->StartRow(0, column_set_id); |
| 531 views::Label* explanation = | 462 views::Label* explanation = |
| 532 new views::Label(prompt->experiment()->GetExplanationText()); | 463 new views::Label(prompt_->experiment()->GetExplanationText()); |
| 533 explanation->SetMultiLine(true); | 464 explanation->SetMultiLine(true); |
| 534 explanation->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 465 explanation->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 535 explanation->SizeToFit(left_column_width + kIconSize); | 466 explanation->SizeToFit(left_column_width + kIconSize); |
| 536 layout->AddView(explanation); | 467 layout->AddView(explanation); |
| 537 } | 468 } |
| 538 | 469 |
| 539 if (prompt->experiment()->should_show_expandable_permission_list() || | 470 if (prompt_->experiment()->should_show_expandable_permission_list() || |
| 540 (prompt->experiment()->show_details_link() && | 471 (prompt_->experiment()->show_details_link() && |
| 541 prompt->experiment()->should_show_inline_explanations() && | 472 prompt_->experiment()->should_show_inline_explanations() && |
| 542 !inline_explanations_.empty())) { | 473 !inline_explanations_.empty())) { |
| 543 // Don't show the "Show details" link if there are retained | 474 // Don't show the "Show details" link if there are retained |
| 544 // files. These have their own "Show details" links and having | 475 // files. These have their own "Show details" links and having |
| 545 // multiple levels of links is confusing. | 476 // multiple levels of links is confusing. |
| 546 if (prompt->GetRetainedFileCount() == 0) { | 477 if (prompt_->GetRetainedFileCount() == 0) { |
| 547 int text_id = | 478 int text_id = |
| 548 prompt->experiment()->should_show_expandable_permission_list() | 479 prompt_->experiment()->should_show_expandable_permission_list() |
| 549 ? IDS_EXTENSION_PROMPT_EXPERIMENT_SHOW_PERMISSIONS | 480 ? IDS_EXTENSION_PROMPT_EXPERIMENT_SHOW_PERMISSIONS |
| 550 : IDS_EXTENSION_PROMPT_EXPERIMENT_SHOW_DETAILS; | 481 : IDS_EXTENSION_PROMPT_EXPERIMENT_SHOW_DETAILS; |
| 551 show_details_link_ = new views::Link( | 482 show_details_link_ = new views::Link( |
| 552 l10n_util::GetStringUTF16(text_id)); | 483 l10n_util::GetStringUTF16(text_id)); |
| 553 show_details_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 484 show_details_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 554 show_details_link_->set_listener(this); | 485 show_details_link_->set_listener(this); |
| 555 UpdateLinkActionHistogram(LINK_SHOWN); | 486 UpdateLinkActionHistogram(LINK_SHOWN); |
| 556 } else { | 487 } else { |
| 557 UpdateLinkActionHistogram(LINK_NOT_SHOWN); | 488 UpdateLinkActionHistogram(LINK_NOT_SHOWN); |
| 558 } | 489 } |
| 559 } | 490 } |
| 560 | 491 |
| 561 if (prompt->experiment()->show_checkboxes()) { | 492 if (prompt_->experiment()->show_checkboxes()) { |
| 562 checkbox_info_label_ = new views::Label( | 493 checkbox_info_label_ = new views::Label( |
| 563 l10n_util::GetStringUTF16( | 494 l10n_util::GetStringUTF16( |
| 564 IDS_EXTENSION_PROMPT_EXPERIMENT_CHECKBOX_INFO)); | 495 IDS_EXTENSION_PROMPT_EXPERIMENT_CHECKBOX_INFO)); |
| 565 checkbox_info_label_->SetMultiLine(true); | 496 checkbox_info_label_->SetMultiLine(true); |
| 566 checkbox_info_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 497 checkbox_info_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 567 checkbox_info_label_->SetAutoColorReadabilityEnabled(false); | 498 checkbox_info_label_->SetAutoColorReadabilityEnabled(false); |
| 568 checkbox_info_label_->SetEnabledColor(kLighterLabelColor); | 499 checkbox_info_label_->SetEnabledColor(kLighterLabelColor); |
| 569 } | 500 } |
| 570 } | 501 } |
| 571 | 502 |
| 572 gfx::Size scrollable_size = scrollable_->GetPreferredSize(); | 503 gfx::Size scrollable_size = scrollable_->GetPreferredSize(); |
| 573 scrollable_->SetBoundsRect(gfx::Rect(scrollable_size)); | 504 scrollable_->SetBoundsRect(gfx::Rect(scrollable_size)); |
| 574 dialog_size_ = gfx::Size( | 505 dialog_size_ = gfx::Size( |
| 575 dialog_width, | 506 dialog_width, |
| 576 std::min(scrollable_size.height(), kDialogMaxHeight)); | 507 std::min(scrollable_size.height(), kDialogMaxHeight)); |
| 577 | 508 |
| 578 if (scrollable_header_only_) { | 509 if (scrollable_header_only_) { |
| 579 gfx::Size header_only_size = scrollable_header_only_->GetPreferredSize(); | 510 gfx::Size header_only_size = scrollable_header_only_->GetPreferredSize(); |
| 580 scrollable_header_only_->SetBoundsRect(gfx::Rect(header_only_size)); | 511 scrollable_header_only_->SetBoundsRect(gfx::Rect(header_only_size)); |
| 581 dialog_size_ = gfx::Size( | 512 dialog_size_ = gfx::Size( |
| 582 dialog_width, std::min(header_only_size.height(), kDialogMaxHeight)); | 513 dialog_width, std::min(header_only_size.height(), kDialogMaxHeight)); |
| 583 } | 514 } |
| 584 | 515 |
| 585 std::string event_name = ExperienceSamplingEvent::kExtensionInstallDialog; | 516 std::string event_name = ExperienceSamplingEvent::kExtensionInstallDialog; |
| 586 event_name.append( | 517 event_name.append( |
| 587 ExtensionInstallPrompt::PromptTypeToString(prompt_->type())); | 518 ExtensionInstallPrompt::PromptTypeToString(prompt_->type())); |
| 588 sampling_event_ = ExperienceSamplingEvent::Create(event_name); | 519 sampling_event_ = ExperienceSamplingEvent::Create(event_name); |
| 589 } | 520 } |
| 590 | 521 |
| 591 ExtensionInstallDialogView::~ExtensionInstallDialogView() {} | 522 bool ExtensionInstallDialogView::AddPermissions( |
| 523 views::GridLayout* layout, |
| 524 ui::ResourceBundle& rb, |
| 525 int column_set_id, |
| 526 int left_column_width, |
| 527 ExtensionInstallPrompt::PermissionsType perm_type) { |
| 528 if (prompt_->GetPermissionCount(perm_type) == 0) |
| 529 return false; |
| 530 |
| 531 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 532 if (is_inline_install()) { |
| 533 layout->StartRow(0, column_set_id); |
| 534 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), |
| 535 3, |
| 536 1, |
| 537 views::GridLayout::FILL, |
| 538 views::GridLayout::FILL); |
| 539 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 540 } |
| 541 |
| 542 layout->StartRow(0, column_set_id); |
| 543 views::Label* permissions_header = NULL; |
| 544 if (is_bundle_install()) { |
| 545 // We need to pass the FontList in the constructor, rather than calling |
| 546 // SetFontList later, because otherwise SizeToFit mis-judges the width |
| 547 // of the line. |
| 548 permissions_header = |
| 549 new views::Label(prompt_->GetPermissionsHeading(perm_type), |
| 550 rb.GetFontList(ui::ResourceBundle::MediumFont)); |
| 551 } else { |
| 552 permissions_header = |
| 553 new views::Label(prompt_->GetPermissionsHeading(perm_type)); |
| 554 } |
| 555 permissions_header->SetMultiLine(true); |
| 556 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 557 permissions_header->SizeToFit(left_column_width); |
| 558 layout->AddView(permissions_header); |
| 559 |
| 560 for (size_t i = 0; i < prompt_->GetPermissionCount(perm_type); ++i) { |
| 561 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 562 layout->StartRow(0, column_set_id); |
| 563 views::Label* permission_label = |
| 564 new views::Label(prompt_->GetPermission(i, perm_type)); |
| 565 |
| 566 const SkColor kTextHighlight = SK_ColorRED; |
| 567 const SkColor kBackgroundHighlight = SkColorSetRGB(0xFB, 0xF7, 0xA3); |
| 568 if (prompt_->experiment()->ShouldHighlightText( |
| 569 prompt_->GetPermission(i, perm_type))) { |
| 570 permission_label->SetAutoColorReadabilityEnabled(false); |
| 571 permission_label->SetEnabledColor(kTextHighlight); |
| 572 } else if (prompt_->experiment()->ShouldHighlightBackground( |
| 573 prompt_->GetPermission(i, perm_type))) { |
| 574 permission_label->SetLineHeight(18); |
| 575 permission_label->set_background( |
| 576 views::Background::CreateSolidBackground(kBackgroundHighlight)); |
| 577 } |
| 578 |
| 579 permission_label->SetMultiLine(true); |
| 580 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 581 |
| 582 if (prompt_->experiment()->show_checkboxes()) { |
| 583 permission_label->SizeToFit(left_column_width); |
| 584 layout->AddView(new CheckboxedView(permission_label, this)); |
| 585 ++unchecked_boxes_; |
| 586 } else { |
| 587 permission_label->SizeToFit(left_column_width - kBulletWidth); |
| 588 layout->AddView(new BulletedView(permission_label)); |
| 589 } |
| 590 |
| 591 // If we have more details to provide, show them in collapsed form. |
| 592 if (!prompt_->GetPermissionsDetails(i, perm_type).empty()) { |
| 593 layout->StartRow(0, column_set_id); |
| 594 PermissionDetails details; |
| 595 details.push_back(PrepareForDisplay( |
| 596 prompt_->GetPermissionsDetails(i, perm_type), false)); |
| 597 ExpandableContainerView* details_container = |
| 598 new ExpandableContainerView(this, |
| 599 base::string16(), |
| 600 details, |
| 601 left_column_width, |
| 602 true, |
| 603 true, |
| 604 false); |
| 605 layout->AddView(details_container); |
| 606 } |
| 607 |
| 608 if (prompt_->experiment()->should_show_inline_explanations()) { |
| 609 base::string16 explanation = prompt_->experiment()->GetInlineExplanation( |
| 610 prompt_->GetPermission(i, perm_type)); |
| 611 if (!explanation.empty()) { |
| 612 PermissionDetails details; |
| 613 details.push_back(explanation); |
| 614 ExpandableContainerView* container = |
| 615 new ExpandableContainerView(this, |
| 616 base::string16(), |
| 617 details, |
| 618 left_column_width, |
| 619 false, |
| 620 false, |
| 621 true); |
| 622 // Inline explanations are expanded by default if there is |
| 623 // no "Show details" link. |
| 624 if (!prompt_->experiment()->show_details_link()) |
| 625 container->ExpandWithoutAnimation(); |
| 626 layout->StartRow(0, column_set_id); |
| 627 layout->AddView(container); |
| 628 inline_explanations_.push_back(container); |
| 629 } |
| 630 } |
| 631 } |
| 632 return true; |
| 633 } |
| 592 | 634 |
| 593 views::GridLayout* ExtensionInstallDialogView::CreateLayout( | 635 views::GridLayout* ExtensionInstallDialogView::CreateLayout( |
| 594 views::View* parent, | 636 views::View* parent, |
| 595 int left_column_width, | 637 int left_column_width, |
| 596 int column_set_id, | 638 int column_set_id, |
| 597 bool single_detail_row) const { | 639 bool single_detail_row) const { |
| 598 views::GridLayout* layout = views::GridLayout::CreatePanel(parent); | 640 views::GridLayout* layout = views::GridLayout::CreatePanel(parent); |
| 599 parent->SetLayoutManager(layout); | 641 parent->SetLayoutManager(layout); |
| 600 | 642 |
| 601 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 643 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 icon->SetHorizontalAlignment(views::ImageView::CENTER); | 680 icon->SetHorizontalAlignment(views::ImageView::CENTER); |
| 639 icon->SetVerticalAlignment(views::ImageView::CENTER); | 681 icon->SetVerticalAlignment(views::ImageView::CENTER); |
| 640 if (single_detail_row) { | 682 if (single_detail_row) { |
| 641 layout->AddView(icon); | 683 layout->AddView(icon); |
| 642 } else { | 684 } else { |
| 643 int icon_row_span = 1; | 685 int icon_row_span = 1; |
| 644 if (is_inline_install()) { | 686 if (is_inline_install()) { |
| 645 // Also span the rating, user_count and store_link rows. | 687 // Also span the rating, user_count and store_link rows. |
| 646 icon_row_span = 4; | 688 icon_row_span = 4; |
| 647 } else if (prompt_->ShouldShowPermissions()) { | 689 } else if (prompt_->ShouldShowPermissions()) { |
| 648 size_t permission_count = prompt_->GetPermissionCount(); | 690 size_t permission_count = prompt_->GetPermissionCount( |
| 691 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS); |
| 649 // Also span the permission header and each of the permission rows (all | 692 // 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 | 693 // have a padding row above it). This also works for the 'no special |
| 651 // permissions' case. | 694 // permissions' case. |
| 652 icon_row_span = 3 + permission_count * 2; | 695 icon_row_span = 3 + permission_count * 2; |
| 653 } else if (prompt_->GetRetainedFileCount()) { | 696 } else if (prompt_->GetRetainedFileCount()) { |
| 654 // Also span the permission header and the retained files container. | 697 // Also span the permission header and the retained files container. |
| 655 icon_row_span = 4; | 698 icon_row_span = 4; |
| 656 } | 699 } |
| 657 layout->AddView(icon, 1, icon_row_span); | 700 layout->AddView(icon, 1, icon_row_span); |
| 658 } | 701 } |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 void ExpandableContainerView::ExpandWithoutAnimation() { | 1110 void ExpandableContainerView::ExpandWithoutAnimation() { |
| 1068 expanded_ = true; | 1111 expanded_ = true; |
| 1069 details_view_->AnimateToState(1.0); | 1112 details_view_->AnimateToState(1.0); |
| 1070 } | 1113 } |
| 1071 | 1114 |
| 1072 // static | 1115 // static |
| 1073 ExtensionInstallPrompt::ShowDialogCallback | 1116 ExtensionInstallPrompt::ShowDialogCallback |
| 1074 ExtensionInstallPrompt::GetDefaultShowDialogCallback() { | 1117 ExtensionInstallPrompt::GetDefaultShowDialogCallback() { |
| 1075 return base::Bind(&ShowExtensionInstallDialogImpl); | 1118 return base::Bind(&ShowExtensionInstallDialogImpl); |
| 1076 } | 1119 } |
| OLD | NEW |