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