| 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/content_settings/content_setting_image_model.h" | 5 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 6 | 6 |
| 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 9 #include "chrome/browser/prerender/prerender_manager.h" | 9 #include "chrome/browser/prerender/prerender_manager.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/content_settings/core/browser/host_content_settings_map.h" | 12 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/material_design/material_design_controller.h" | 16 #include "ui/base/resource/material_design/material_design_controller.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/vector_icons_public.h" | |
| 19 | |
| 20 #if !defined(OS_MACOSX) | |
| 21 #include "ui/gfx/color_palette.h" | 18 #include "ui/gfx/color_palette.h" |
| 22 #include "ui/gfx/color_utils.h" | 19 #include "ui/gfx/color_utils.h" |
| 23 #include "ui/gfx/paint_vector_icon.h" | 20 #include "ui/gfx/paint_vector_icon.h" |
| 24 #endif | 21 #include "ui/gfx/vector_icons_public.h" |
| 25 | 22 |
| 26 using content::WebContents; | 23 using content::WebContents; |
| 27 | 24 |
| 28 namespace { | 25 namespace { |
| 29 | 26 |
| 30 bool UseVectorGraphics() { | 27 bool UseVectorGraphics() { |
| 31 #if defined(OS_MACOSX) | 28 #if defined(OS_MACOSX) |
| 32 return false; | 29 return false; |
| 33 #else | 30 #else |
| 34 return ui::MaterialDesignController::IsModeMaterial(); | 31 return ui::MaterialDesignController::IsModeMaterial(); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 return; | 301 return; |
| 305 | 302 |
| 306 icon_id = image_details->accessed_icon_id; | 303 icon_id = image_details->accessed_icon_id; |
| 307 tooltip_id = image_details->accessed_tooltip_id; | 304 tooltip_id = image_details->accessed_tooltip_id; |
| 308 explanation_id = 0; | 305 explanation_id = 0; |
| 309 } | 306 } |
| 310 set_visible(true); | 307 set_visible(true); |
| 311 if (!UseVectorGraphics()) { | 308 if (!UseVectorGraphics()) { |
| 312 DCHECK(icon_id); | 309 DCHECK(icon_id); |
| 313 SetIconByResourceId(icon_id); | 310 SetIconByResourceId(icon_id); |
| 314 #if !defined(OS_MACOSX) | |
| 315 } else { | 311 } else { |
| 316 gfx::VectorIconId badge_id = gfx::VectorIconId::VECTOR_ICON_NONE; | 312 gfx::VectorIconId badge_id = gfx::VectorIconId::VECTOR_ICON_NONE; |
| 317 if (type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER) | 313 if (type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER) |
| 318 badge_id = gfx::VectorIconId::WARNING_BADGE; | 314 badge_id = gfx::VectorIconId::WARNING_BADGE; |
| 319 else if (content_settings->IsContentBlocked(type)) | 315 else if (content_settings->IsContentBlocked(type)) |
| 320 badge_id = gfx::VectorIconId::BLOCKED_BADGE; | 316 badge_id = gfx::VectorIconId::BLOCKED_BADGE; |
| 321 | 317 |
| 322 set_icon_by_vector_id(image_details->vector_icon_id, badge_id); | 318 set_icon_by_vector_id(image_details->vector_icon_id, badge_id); |
| 323 #endif | |
| 324 } | 319 } |
| 325 set_explanatory_string_id(explanation_id); | 320 set_explanatory_string_id(explanation_id); |
| 326 DCHECK(tooltip_id); | 321 DCHECK(tooltip_id); |
| 327 set_tooltip(l10n_util::GetStringUTF16(tooltip_id)); | 322 set_tooltip(l10n_util::GetStringUTF16(tooltip_id)); |
| 328 } | 323 } |
| 329 | 324 |
| 330 // Geolocation ----------------------------------------------------------------- | 325 // Geolocation ----------------------------------------------------------------- |
| 331 | 326 |
| 332 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() | 327 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() |
| 333 : ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 328 : ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 349 set_visible(true); | 344 set_visible(true); |
| 350 | 345 |
| 351 // If any embedded site has access the allowed icon takes priority over the | 346 // If any embedded site has access the allowed icon takes priority over the |
| 352 // blocked icon. | 347 // blocked icon. |
| 353 unsigned int state_flags = 0; | 348 unsigned int state_flags = 0; |
| 354 usages_state.GetDetailedInfo(NULL, &state_flags); | 349 usages_state.GetDetailedInfo(NULL, &state_flags); |
| 355 bool allowed = | 350 bool allowed = |
| 356 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); | 351 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
| 357 if (!UseVectorGraphics()) { | 352 if (!UseVectorGraphics()) { |
| 358 SetIconByResourceId(allowed ? IDR_ALLOWED_LOCATION : IDR_BLOCKED_LOCATION); | 353 SetIconByResourceId(allowed ? IDR_ALLOWED_LOCATION : IDR_BLOCKED_LOCATION); |
| 359 #if !defined(OS_MACOSX) | |
| 360 } else { | 354 } else { |
| 361 set_icon_by_vector_id(gfx::VectorIconId::MY_LOCATION, | 355 set_icon_by_vector_id(gfx::VectorIconId::MY_LOCATION, |
| 362 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE | 356 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE |
| 363 : gfx::VectorIconId::BLOCKED_BADGE); | 357 : gfx::VectorIconId::BLOCKED_BADGE); |
| 364 #endif | |
| 365 } | 358 } |
| 366 set_tooltip(l10n_util::GetStringUTF16(allowed | 359 set_tooltip(l10n_util::GetStringUTF16(allowed |
| 367 ? IDS_GEOLOCATION_ALLOWED_TOOLTIP | 360 ? IDS_GEOLOCATION_ALLOWED_TOOLTIP |
| 368 : IDS_GEOLOCATION_BLOCKED_TOOLTIP)); | 361 : IDS_GEOLOCATION_BLOCKED_TOOLTIP)); |
| 369 } | 362 } |
| 370 | 363 |
| 371 // Media ----------------------------------------------------------------------- | 364 // Media ----------------------------------------------------------------------- |
| 372 | 365 |
| 373 ContentSettingMediaImageModel::ContentSettingMediaImageModel() | 366 ContentSettingMediaImageModel::ContentSettingMediaImageModel() |
| 374 : ContentSettingImageModel() { | 367 : ContentSettingImageModel() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 395 | 388 |
| 396 bool is_mic = (state & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; | 389 bool is_mic = (state & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; |
| 397 bool is_cam = (state & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; | 390 bool is_cam = (state & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; |
| 398 DCHECK(is_mic || is_cam); | 391 DCHECK(is_mic || is_cam); |
| 399 | 392 |
| 400 int id = IDS_CAMERA_BLOCKED; | 393 int id = IDS_CAMERA_BLOCKED; |
| 401 if (state & (TabSpecificContentSettings::MICROPHONE_BLOCKED | | 394 if (state & (TabSpecificContentSettings::MICROPHONE_BLOCKED | |
| 402 TabSpecificContentSettings::CAMERA_BLOCKED)) { | 395 TabSpecificContentSettings::CAMERA_BLOCKED)) { |
| 403 if (!UseVectorGraphics()) { | 396 if (!UseVectorGraphics()) { |
| 404 SetIconByResourceId(IDR_BLOCKED_CAMERA); | 397 SetIconByResourceId(IDR_BLOCKED_CAMERA); |
| 405 #if !defined(OS_MACOSX) | |
| 406 } else { | 398 } else { |
| 407 set_icon_by_vector_id(gfx::VectorIconId::VIDEOCAM, | 399 set_icon_by_vector_id(gfx::VectorIconId::VIDEOCAM, |
| 408 gfx::VectorIconId::BLOCKED_BADGE); | 400 gfx::VectorIconId::BLOCKED_BADGE); |
| 409 #endif | |
| 410 } | 401 } |
| 411 if (is_mic) | 402 if (is_mic) |
| 412 id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; | 403 id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; |
| 413 } else { | 404 } else { |
| 414 if (!UseVectorGraphics()) { | 405 if (!UseVectorGraphics()) { |
| 415 SetIconByResourceId(IDR_ALLOWED_CAMERA); | 406 SetIconByResourceId(IDR_ALLOWED_CAMERA); |
| 416 #if !defined(OS_MACOSX) | |
| 417 } else { | 407 } else { |
| 418 set_icon_by_vector_id(gfx::VectorIconId::VIDEOCAM, | 408 set_icon_by_vector_id(gfx::VectorIconId::VIDEOCAM, |
| 419 gfx::VectorIconId::VECTOR_ICON_NONE); | 409 gfx::VectorIconId::VECTOR_ICON_NONE); |
| 420 #endif | |
| 421 } | 410 } |
| 422 id = IDS_CAMERA_ACCESSED; | 411 id = IDS_CAMERA_ACCESSED; |
| 423 if (is_mic) | 412 if (is_mic) |
| 424 id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; | 413 id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; |
| 425 } | 414 } |
| 426 set_tooltip(l10n_util::GetStringUTF16(id)); | 415 set_tooltip(l10n_util::GetStringUTF16(id)); |
| 427 set_visible(true); | 416 set_visible(true); |
| 428 } | 417 } |
| 429 | 418 |
| 430 ContentSettingBubbleModel* ContentSettingMediaImageModel::CreateBubbleModel( | 419 ContentSettingBubbleModel* ContentSettingMediaImageModel::CreateBubbleModel( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 456 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 468 } | 457 } |
| 469 } | 458 } |
| 470 | 459 |
| 471 // Protocol handlers ----------------------------------------------------------- | 460 // Protocol handlers ----------------------------------------------------------- |
| 472 | 461 |
| 473 ContentSettingRPHImageModel::ContentSettingRPHImageModel() | 462 ContentSettingRPHImageModel::ContentSettingRPHImageModel() |
| 474 : ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | 463 : ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
| 475 if (!UseVectorGraphics()) { | 464 if (!UseVectorGraphics()) { |
| 476 SetIconByResourceId(IDR_REGISTER_PROTOCOL_HANDLER); | 465 SetIconByResourceId(IDR_REGISTER_PROTOCOL_HANDLER); |
| 477 #if !defined(OS_MACOSX) | |
| 478 } else { | 466 } else { |
| 479 set_icon_by_vector_id(gfx::VectorIconId::PROTOCOL_HANDLER, | 467 set_icon_by_vector_id(gfx::VectorIconId::PROTOCOL_HANDLER, |
| 480 gfx::VectorIconId::VECTOR_ICON_NONE); | 468 gfx::VectorIconId::VECTOR_ICON_NONE); |
| 481 #endif | |
| 482 } | 469 } |
| 483 set_tooltip(l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP)); | 470 set_tooltip(l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP)); |
| 484 } | 471 } |
| 485 | 472 |
| 486 void ContentSettingRPHImageModel::UpdateFromWebContents( | 473 void ContentSettingRPHImageModel::UpdateFromWebContents( |
| 487 WebContents* web_contents) { | 474 WebContents* web_contents) { |
| 488 set_visible(false); | 475 set_visible(false); |
| 489 if (!web_contents) | 476 if (!web_contents) |
| 490 return; | 477 return; |
| 491 | 478 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 522 | 509 |
| 523 // If any embedded site has access the allowed icon takes priority over the | 510 // If any embedded site has access the allowed icon takes priority over the |
| 524 // blocked icon. | 511 // blocked icon. |
| 525 unsigned int state_flags = 0; | 512 unsigned int state_flags = 0; |
| 526 usages_state.GetDetailedInfo(NULL, &state_flags); | 513 usages_state.GetDetailedInfo(NULL, &state_flags); |
| 527 bool allowed = | 514 bool allowed = |
| 528 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); | 515 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
| 529 if (!UseVectorGraphics()) { | 516 if (!UseVectorGraphics()) { |
| 530 SetIconByResourceId(allowed ? IDR_ALLOWED_MIDI_SYSEX | 517 SetIconByResourceId(allowed ? IDR_ALLOWED_MIDI_SYSEX |
| 531 : IDR_BLOCKED_MIDI_SYSEX); | 518 : IDR_BLOCKED_MIDI_SYSEX); |
| 532 #if !defined(OS_MACOSX) | |
| 533 } else { | 519 } else { |
| 534 set_icon_by_vector_id(gfx::VectorIconId::MIDI, | 520 set_icon_by_vector_id(gfx::VectorIconId::MIDI, |
| 535 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE | 521 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE |
| 536 : gfx::VectorIconId::BLOCKED_BADGE); | 522 : gfx::VectorIconId::BLOCKED_BADGE); |
| 537 #endif | |
| 538 } | 523 } |
| 539 set_tooltip(l10n_util::GetStringUTF16(allowed | 524 set_tooltip(l10n_util::GetStringUTF16(allowed |
| 540 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP | 525 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP |
| 541 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); | 526 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); |
| 542 } | 527 } |
| 543 | 528 |
| 544 // Base class ------------------------------------------------------------------ | 529 // Base class ------------------------------------------------------------------ |
| 545 | 530 |
| 546 #if !defined(OS_MACOSX) | |
| 547 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { | 531 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { |
| 548 return UseVectorGraphics() | 532 return UseVectorGraphics() |
| 549 ? gfx::Image(gfx::CreateVectorIconWithBadge( | 533 ? gfx::Image(gfx::CreateVectorIconWithBadge( |
| 550 vector_icon_id_, 16, | 534 vector_icon_id_, 16, |
| 551 color_utils::DeriveDefaultIconColor(nearby_text_color), | 535 color_utils::DeriveDefaultIconColor(nearby_text_color), |
| 552 vector_icon_badge_id_)) | 536 vector_icon_badge_id_)) |
| 553 : icon_; | 537 : raster_icon_; |
| 554 } | 538 } |
| 555 #endif | |
| 556 | 539 |
| 557 ContentSettingImageModel::ContentSettingImageModel() | 540 ContentSettingImageModel::ContentSettingImageModel() |
| 558 : is_visible_(false), | 541 : is_visible_(false), |
| 559 icon_id_(0), | 542 raster_icon_id_(0), |
| 560 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 543 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 561 vector_icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 544 vector_icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 562 explanatory_string_id_(0) {} | 545 explanatory_string_id_(0) {} |
| 563 | 546 |
| 564 // static | 547 // static |
| 565 ScopedVector<ContentSettingImageModel> | 548 ScopedVector<ContentSettingImageModel> |
| 566 ContentSettingImageModel::GenerateContentSettingImageModels() { | 549 ContentSettingImageModel::GenerateContentSettingImageModels() { |
| 567 ScopedVector<ContentSettingImageModel> result; | 550 ScopedVector<ContentSettingImageModel> result; |
| 568 | 551 |
| 569 // The ordering of the models here influences the order in which icons are | 552 // The ordering of the models here influences the order in which icons are |
| (...skipping 17 matching lines...) Expand all Loading... |
| 587 result.push_back(new ContentSettingMediaImageModel()); | 570 result.push_back(new ContentSettingMediaImageModel()); |
| 588 result.push_back( | 571 result.push_back( |
| 589 new ContentSettingBlockedImageModel( | 572 new ContentSettingBlockedImageModel( |
| 590 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)); | 573 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)); |
| 591 result.push_back(new ContentSettingMIDISysExImageModel()); | 574 result.push_back(new ContentSettingMIDISysExImageModel()); |
| 592 | 575 |
| 593 return result.Pass(); | 576 return result.Pass(); |
| 594 } | 577 } |
| 595 | 578 |
| 596 void ContentSettingImageModel::SetIconByResourceId(int id) { | 579 void ContentSettingImageModel::SetIconByResourceId(int id) { |
| 597 icon_id_ = id; | 580 raster_icon_id_ = id; |
| 598 icon_ = ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(id); | 581 raster_icon_ = |
| 582 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(id); |
| 599 } | 583 } |
| OLD | NEW |