| 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 "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // The image models hierarchy: | 36 // The image models hierarchy: |
| 37 // | 37 // |
| 38 // ContentSettingImageModel - base class | 38 // ContentSettingImageModel - base class |
| 39 // ContentSettingSimpleImageModel - single content setting | 39 // ContentSettingSimpleImageModel - single content setting |
| 40 // ContentSettingBlockedImageModel - generic blocked setting | 40 // ContentSettingBlockedImageModel - generic blocked setting |
| 41 // ContentSettingGeolocationImageModel - geolocation | 41 // ContentSettingGeolocationImageModel - geolocation |
| 42 // ContentSettingRPHImageModel - protocol handlers | 42 // ContentSettingRPHImageModel - protocol handlers |
| 43 // ContentSettingMIDISysExImageModel - midi sysex | 43 // ContentSettingMIDISysExImageModel - midi sysex |
| 44 // ContentSettingMediaImageModel - media | 44 // ContentSettingMediaImageModel - media |
| 45 // ContentSettingSubresourceFilterImageModel - deceptive content |
| 45 | 46 |
| 46 class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel { | 47 class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel { |
| 47 public: | 48 public: |
| 48 explicit ContentSettingBlockedImageModel(ContentSettingsType content_type); | 49 explicit ContentSettingBlockedImageModel(ContentSettingsType content_type); |
| 49 | 50 |
| 50 void UpdateFromWebContents(WebContents* web_contents) override; | 51 void UpdateFromWebContents(WebContents* web_contents) override; |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 DISALLOW_COPY_AND_ASSIGN(ContentSettingBlockedImageModel); | 54 DISALLOW_COPY_AND_ASSIGN(ContentSettingBlockedImageModel); |
| 54 }; | 55 }; |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 ContentSettingBubbleModel::Delegate* delegate, | 413 ContentSettingBubbleModel::Delegate* delegate, |
| 413 WebContents* web_contents, | 414 WebContents* web_contents, |
| 414 Profile* profile) { | 415 Profile* profile) { |
| 415 return new ContentSettingMediaStreamBubbleModel(delegate, | 416 return new ContentSettingMediaStreamBubbleModel(delegate, |
| 416 web_contents, | 417 web_contents, |
| 417 profile); | 418 profile); |
| 418 } | 419 } |
| 419 | 420 |
| 420 bool ContentSettingMediaImageModel::ShouldRunAnimation( | 421 bool ContentSettingMediaImageModel::ShouldRunAnimation( |
| 421 WebContents* web_contents) { | 422 WebContents* web_contents) { |
| 422 // TODO(msramek): For bubbles that are not tied to a single content setting, | |
| 423 // TabSpecificContentSettings is not a good place to store this bit. | |
| 424 // Perhaps we should instead use a map<WebContents*, bool> here in | |
| 425 // ContentSettingMediaImageModel. | |
| 426 if (!web_contents) | 423 if (!web_contents) |
| 427 return false; | 424 return false; |
| 428 TabSpecificContentSettings* content_settings = | 425 TabSpecificContentSettings* content_settings = |
| 429 TabSpecificContentSettings::FromWebContents(web_contents); | 426 TabSpecificContentSettings::FromWebContents(web_contents); |
| 430 if (!content_settings) | 427 if (!content_settings) |
| 431 return false; | 428 return false; |
| 432 return (!content_settings->IsBlockageIndicated( | 429 return (!content_settings->IsBlockageIndicated( |
| 433 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && | 430 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) && |
| 434 !content_settings->IsBlockageIndicated( | 431 !content_settings->IsBlockageIndicated( |
| 435 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 432 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 436 } | 433 } |
| 437 | 434 |
| 438 void ContentSettingMediaImageModel::SetAnimationHasRun( | 435 void ContentSettingMediaImageModel::SetAnimationHasRun( |
| 439 WebContents* web_contents) { | 436 WebContents* web_contents) { |
| 440 if (!web_contents) | 437 if (!web_contents) |
| 441 return; | 438 return; |
| 442 TabSpecificContentSettings* content_settings = | 439 TabSpecificContentSettings* content_settings = |
| 443 TabSpecificContentSettings::FromWebContents(web_contents); | 440 TabSpecificContentSettings::FromWebContents(web_contents); |
| 444 if (content_settings) { | 441 if (content_settings) { |
| 445 content_settings->SetBlockageHasBeenIndicated( | 442 content_settings->SetBlockageHasBeenIndicated( |
| 446 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 443 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 447 content_settings->SetBlockageHasBeenIndicated( | 444 content_settings->SetBlockageHasBeenIndicated( |
| 448 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 445 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 449 } | 446 } |
| 450 } | 447 } |
| 451 | 448 |
| 449 // Subresource Filter ---------------------------------------------------------- |
| 450 |
| 451 ContentSettingSubresourceFilterImageModel:: |
| 452 ContentSettingSubresourceFilterImageModel() |
| 453 : ContentSettingImageModel() {} |
| 454 |
| 455 void ContentSettingSubresourceFilterImageModel::UpdateFromWebContents( |
| 456 WebContents* web_contents) { |
| 457 set_visible(false); |
| 458 |
| 459 if (!web_contents) |
| 460 return; |
| 461 |
| 462 TabSpecificContentSettings* content_settings = |
| 463 TabSpecificContentSettings::FromWebContents(web_contents); |
| 464 |
| 465 if (!content_settings || !content_settings->IsSubresourceBlocked()) |
| 466 return; |
| 467 |
| 468 if (!UseVectorGraphics()) { |
| 469 SetIconByResourceId(IDR_SUBRESOURCE_FILTER_ACTIVE); |
| 470 } else { |
| 471 set_icon_by_vector_id(gfx::VectorIconId::SUBRESOURCE_FILTER_ACTIVE, |
| 472 gfx::VectorIconId::BLOCKED_BADGE); |
| 473 } |
| 474 set_explanatory_string_id(IDS_FILTERED_DECEPTIVE_CONTENT_PROMPT_TITLE); |
| 475 // TODO(melandory): Set tooltip text. |
| 476 set_visible(true); |
| 477 } |
| 478 |
| 479 ContentSettingBubbleModel* |
| 480 ContentSettingSubresourceFilterImageModel::CreateBubbleModel( |
| 481 ContentSettingBubbleModel::Delegate* delegate, |
| 482 WebContents* web_contents, |
| 483 Profile* profile) { |
| 484 return new ContentSettingSubresourceFilterBubbleModel(delegate, web_contents, |
| 485 profile); |
| 486 } |
| 487 |
| 488 bool ContentSettingSubresourceFilterImageModel::ShouldRunAnimation( |
| 489 WebContents* web_contents) { |
| 490 if (!web_contents) |
| 491 return false; |
| 492 TabSpecificContentSettings* content_settings = |
| 493 TabSpecificContentSettings::FromWebContents(web_contents); |
| 494 return content_settings && |
| 495 content_settings->IsSubresourceFilteringActivationIndicated(); |
| 496 } |
| 497 |
| 498 void ContentSettingSubresourceFilterImageModel::SetAnimationHasRun( |
| 499 WebContents* web_contents) { |
| 500 if (!web_contents) |
| 501 return; |
| 502 TabSpecificContentSettings* content_settings = |
| 503 TabSpecificContentSettings::FromWebContents(web_contents); |
| 504 if (content_settings) |
| 505 content_settings->SetSubresourceFilteringActivationIndicated(); |
| 506 } |
| 507 |
| 452 // Protocol handlers ----------------------------------------------------------- | 508 // Protocol handlers ----------------------------------------------------------- |
| 453 | 509 |
| 454 ContentSettingRPHImageModel::ContentSettingRPHImageModel() | 510 ContentSettingRPHImageModel::ContentSettingRPHImageModel() |
| 455 : ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | 511 : ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
| 456 if (!UseVectorGraphics()) { | 512 if (!UseVectorGraphics()) { |
| 457 SetIconByResourceId(IDR_REGISTER_PROTOCOL_HANDLER); | 513 SetIconByResourceId(IDR_REGISTER_PROTOCOL_HANDLER); |
| 458 } else { | 514 } else { |
| 459 set_icon_by_vector_id(gfx::VectorIconId::PROTOCOL_HANDLER, | 515 set_icon_by_vector_id(gfx::VectorIconId::PROTOCOL_HANDLER, |
| 460 gfx::VectorIconId::VECTOR_ICON_NONE); | 516 gfx::VectorIconId::VECTOR_ICON_NONE); |
| 461 } | 517 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 new ContentSettingBlockedImageModel(CONTENT_SETTINGS_TYPE_PPAPI_BROKER)); | 612 new ContentSettingBlockedImageModel(CONTENT_SETTINGS_TYPE_PPAPI_BROKER)); |
| 557 result.push_back( | 613 result.push_back( |
| 558 new ContentSettingBlockedImageModel(CONTENT_SETTINGS_TYPE_PLUGINS)); | 614 new ContentSettingBlockedImageModel(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 559 result.push_back( | 615 result.push_back( |
| 560 new ContentSettingBlockedImageModel(CONTENT_SETTINGS_TYPE_POPUPS)); | 616 new ContentSettingBlockedImageModel(CONTENT_SETTINGS_TYPE_POPUPS)); |
| 561 result.push_back(new ContentSettingGeolocationImageModel()); | 617 result.push_back(new ContentSettingGeolocationImageModel()); |
| 562 result.push_back( | 618 result.push_back( |
| 563 new ContentSettingBlockedImageModel(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 619 new ContentSettingBlockedImageModel(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); |
| 564 result.push_back(new ContentSettingRPHImageModel()); | 620 result.push_back(new ContentSettingRPHImageModel()); |
| 565 result.push_back(new ContentSettingMediaImageModel()); | 621 result.push_back(new ContentSettingMediaImageModel()); |
| 622 result.push_back(new ContentSettingSubresourceFilterImageModel()); |
| 566 result.push_back( | 623 result.push_back( |
| 567 new ContentSettingBlockedImageModel( | 624 new ContentSettingBlockedImageModel( |
| 568 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)); | 625 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)); |
| 569 result.push_back(new ContentSettingMIDISysExImageModel()); | 626 result.push_back(new ContentSettingMIDISysExImageModel()); |
| 570 | 627 |
| 571 return result; | 628 return result; |
| 572 } | 629 } |
| 573 | 630 |
| 574 void ContentSettingImageModel::SetIconByResourceId(int id) { | 631 void ContentSettingImageModel::SetIconByResourceId(int id) { |
| 575 raster_icon_id_ = id; | 632 raster_icon_id_ = id; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 586 UpdateFromWebContents(web_contents); | 643 UpdateFromWebContents(web_contents); |
| 587 return old_vector_icon != vector_icon_id_ && | 644 return old_vector_icon != vector_icon_id_ && |
| 588 old_badge_icon != vector_icon_badge_id_; | 645 old_badge_icon != vector_icon_badge_id_; |
| 589 } else { | 646 } else { |
| 590 int old_icon = raster_icon_id_; | 647 int old_icon = raster_icon_id_; |
| 591 UpdateFromWebContents(web_contents); | 648 UpdateFromWebContents(web_contents); |
| 592 return old_icon != raster_icon_id_; | 649 return old_icon != raster_icon_id_; |
| 593 } | 650 } |
| 594 } | 651 } |
| 595 #endif | 652 #endif |
| OLD | NEW |