Chromium Code Reviews| 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/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 void UpdateFromWebContents(WebContents* web_contents) override; | 68 void UpdateFromWebContents(WebContents* web_contents) override; |
| 69 | 69 |
| 70 ContentSettingBubbleModel* CreateBubbleModel( | 70 ContentSettingBubbleModel* CreateBubbleModel( |
| 71 ContentSettingBubbleModel::Delegate* delegate, | 71 ContentSettingBubbleModel::Delegate* delegate, |
| 72 WebContents* web_contents, | 72 WebContents* web_contents, |
| 73 Profile* profile) override; | 73 Profile* profile) override; |
| 74 | 74 |
| 75 bool ShouldRunAnimation(WebContents* web_contents) override; | 75 bool ShouldRunAnimation(WebContents* web_contents) override; |
| 76 void SetAnimationHasRun(WebContents* web_contents) override; | 76 void SetAnimationHasRun(WebContents* web_contents) override; |
| 77 | 77 |
| 78 ContentSettingsType GetContentType() override; | |
| 78 private: | 79 private: |
| 80 // This is cached here for testing purposes. | |
| 81 ContentSettingsType last_content_type_; | |
| 79 DISALLOW_COPY_AND_ASSIGN(ContentSettingMediaImageModel); | 82 DISALLOW_COPY_AND_ASSIGN(ContentSettingMediaImageModel); |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 class ContentSettingRPHImageModel : public ContentSettingSimpleImageModel { | 85 class ContentSettingRPHImageModel : public ContentSettingSimpleImageModel { |
| 83 public: | 86 public: |
| 84 ContentSettingRPHImageModel(); | 87 ContentSettingRPHImageModel(); |
| 85 | 88 |
| 86 void UpdateFromWebContents(WebContents* web_contents) override; | 89 void UpdateFromWebContents(WebContents* web_contents) override; |
| 87 }; | 90 }; |
| 88 | 91 |
| 89 class ContentSettingMIDISysExImageModel | 92 class ContentSettingMIDISysExImageModel |
| 90 : public ContentSettingSimpleImageModel { | 93 : public ContentSettingSimpleImageModel { |
| 91 public: | 94 public: |
| 92 ContentSettingMIDISysExImageModel(); | 95 ContentSettingMIDISysExImageModel(); |
| 93 | 96 |
| 94 void UpdateFromWebContents(WebContents* web_contents) override; | 97 void UpdateFromWebContents(WebContents* web_contents) override; |
| 95 | |
| 96 private: | 98 private: |
| 97 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); | 99 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 namespace { | 102 namespace { |
| 101 | 103 |
| 102 struct ContentSettingsImageDetails { | 104 struct ContentSettingsImageDetails { |
| 103 ContentSettingsType type; | 105 ContentSettingsType type; |
| 104 gfx::VectorIconId icon_id; | 106 gfx::VectorIconId icon_id; |
| 105 int blocked_tooltip_id; | 107 int blocked_tooltip_id; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 } | 148 } |
| 147 | 149 |
| 148 ContentSettingBubbleModel* ContentSettingSimpleImageModel::CreateBubbleModel( | 150 ContentSettingBubbleModel* ContentSettingSimpleImageModel::CreateBubbleModel( |
| 149 ContentSettingBubbleModel::Delegate* delegate, | 151 ContentSettingBubbleModel::Delegate* delegate, |
| 150 WebContents* web_contents, | 152 WebContents* web_contents, |
| 151 Profile* profile) { | 153 Profile* profile) { |
| 152 return ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 154 return ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 153 delegate, | 155 delegate, |
| 154 web_contents, | 156 web_contents, |
| 155 profile, | 157 profile, |
| 156 content_type()); | 158 GetContentType()); |
|
tapted
2017/02/03 00:35:39
since this was claimed "for testing only" we shoul
| |
| 157 } | 159 } |
| 158 | 160 |
| 159 bool ContentSettingSimpleImageModel::ShouldRunAnimation( | 161 bool ContentSettingSimpleImageModel::ShouldRunAnimation( |
| 160 WebContents* web_contents) { | 162 WebContents* web_contents) { |
| 161 if (!web_contents) | 163 if (!web_contents) |
| 162 return false; | 164 return false; |
| 163 | 165 |
| 164 TabSpecificContentSettings* content_settings = | 166 TabSpecificContentSettings* content_settings = |
| 165 TabSpecificContentSettings::FromWebContents(web_contents); | 167 TabSpecificContentSettings::FromWebContents(web_contents); |
| 166 if (!content_settings) | 168 if (!content_settings) |
| 167 return false; | 169 return false; |
| 168 | 170 |
| 169 return !content_settings->IsBlockageIndicated(content_type()); | 171 return !content_settings->IsBlockageIndicated(GetContentType()); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void ContentSettingSimpleImageModel::SetAnimationHasRun( | 174 void ContentSettingSimpleImageModel::SetAnimationHasRun( |
| 173 WebContents* web_contents) { | 175 WebContents* web_contents) { |
| 174 if (!web_contents) | 176 if (!web_contents) |
| 175 return; | 177 return; |
| 176 TabSpecificContentSettings* content_settings = | 178 TabSpecificContentSettings* content_settings = |
| 177 TabSpecificContentSettings::FromWebContents(web_contents); | 179 TabSpecificContentSettings::FromWebContents(web_contents); |
| 178 if (content_settings) | 180 if (content_settings) |
| 179 content_settings->SetBlockageHasBeenIndicated(content_type()); | 181 content_settings->SetBlockageHasBeenIndicated(GetContentType()); |
| 182 } | |
| 183 | |
| 184 ContentSettingsType ContentSettingSimpleImageModel::GetContentType() { | |
| 185 return content_type_; | |
| 180 } | 186 } |
| 181 | 187 |
| 182 // static | 188 // static |
| 183 std::unique_ptr<ContentSettingImageModel> | 189 std::unique_ptr<ContentSettingImageModel> |
| 184 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( | 190 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( |
| 185 ContentSettingsType content_settings_type) { | 191 ContentSettingsType content_settings_type) { |
| 186 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | 192 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 187 return base::MakeUnique<ContentSettingGeolocationImageModel>(); | 193 return base::MakeUnique<ContentSettingGeolocationImageModel>(); |
| 188 | 194 |
| 189 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) | 195 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 202 ContentSettingsType content_type) | 208 ContentSettingsType content_type) |
| 203 : ContentSettingSimpleImageModel(content_type) { | 209 : ContentSettingSimpleImageModel(content_type) { |
| 204 } | 210 } |
| 205 | 211 |
| 206 void ContentSettingBlockedImageModel::UpdateFromWebContents( | 212 void ContentSettingBlockedImageModel::UpdateFromWebContents( |
| 207 WebContents* web_contents) { | 213 WebContents* web_contents) { |
| 208 set_visible(false); | 214 set_visible(false); |
| 209 if (!web_contents) | 215 if (!web_contents) |
| 210 return; | 216 return; |
| 211 | 217 |
| 212 const ContentSettingsType type = content_type(); | 218 const ContentSettingsType type = GetContentType(); |
| 213 const ContentSettingsImageDetails* image_details = GetImageDetails(type); | 219 const ContentSettingsImageDetails* image_details = GetImageDetails(type); |
| 214 DCHECK(image_details) << "No entry for " << type << " in kImageDetails[]."; | 220 DCHECK(image_details) << "No entry for " << type << " in kImageDetails[]."; |
| 215 | 221 |
| 216 int tooltip_id = image_details->blocked_tooltip_id; | 222 int tooltip_id = image_details->blocked_tooltip_id; |
| 217 int explanation_id = image_details->blocked_explanatory_text_id; | 223 int explanation_id = image_details->blocked_explanatory_text_id; |
| 218 | 224 |
| 219 Profile* profile = | 225 Profile* profile = |
| 220 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 226 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 221 HostContentSettingsMap* map = | 227 HostContentSettingsMap* map = |
| 222 HostContentSettingsMapFactory::GetForProfile(profile); | 228 HostContentSettingsMapFactory::GetForProfile(profile); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 | 310 |
| 305 // Media ----------------------------------------------------------------------- | 311 // Media ----------------------------------------------------------------------- |
| 306 | 312 |
| 307 ContentSettingMediaImageModel::ContentSettingMediaImageModel() | 313 ContentSettingMediaImageModel::ContentSettingMediaImageModel() |
| 308 : ContentSettingImageModel() { | 314 : ContentSettingImageModel() { |
| 309 } | 315 } |
| 310 | 316 |
| 311 void ContentSettingMediaImageModel::UpdateFromWebContents( | 317 void ContentSettingMediaImageModel::UpdateFromWebContents( |
| 312 WebContents* web_contents) { | 318 WebContents* web_contents) { |
| 313 set_visible(false); | 319 set_visible(false); |
| 314 | 320 last_content_type_ = CONTENT_SETTINGS_TYPE_DEFAULT; |
| 315 if (!web_contents) | 321 if (!web_contents) |
| 316 return; | 322 return; |
| 317 | 323 |
| 318 TabSpecificContentSettings* content_settings = | 324 TabSpecificContentSettings* content_settings = |
| 319 TabSpecificContentSettings::FromWebContents(web_contents); | 325 TabSpecificContentSettings::FromWebContents(web_contents); |
| 320 if (!content_settings) | 326 if (!content_settings) |
| 321 return; | 327 return; |
| 322 TabSpecificContentSettings::MicrophoneCameraState state = | 328 TabSpecificContentSettings::MicrophoneCameraState state = |
| 323 content_settings->GetMicrophoneCameraState(); | 329 content_settings->GetMicrophoneCameraState(); |
| 324 | 330 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 338 gfx::VectorIconId::BLOCKED_BADGE); | 344 gfx::VectorIconId::BLOCKED_BADGE); |
| 339 if (is_mic) | 345 if (is_mic) |
| 340 id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; | 346 id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; |
| 341 } else { | 347 } else { |
| 342 set_icon_by_vector_id(gfx::VectorIconId::VIDEOCAM, | 348 set_icon_by_vector_id(gfx::VectorIconId::VIDEOCAM, |
| 343 gfx::VectorIconId::VECTOR_ICON_NONE); | 349 gfx::VectorIconId::VECTOR_ICON_NONE); |
| 344 id = IDS_CAMERA_ACCESSED; | 350 id = IDS_CAMERA_ACCESSED; |
| 345 if (is_mic) | 351 if (is_mic) |
| 346 id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; | 352 id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; |
| 347 } | 353 } |
| 354 // During bubble dialog testing, only one of the 'devices' will be blocked | |
| 355 last_content_type_ = is_mic ? CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC : | |
| 356 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; | |
|
tapted
2017/02/03 00:35:39
did `git cl format` do this? (looks different to h
kylix_rd
2017/02/03 18:55:03
Yes, 'git cl format' did this.
| |
| 348 set_tooltip(l10n_util::GetStringUTF16(id)); | 357 set_tooltip(l10n_util::GetStringUTF16(id)); |
| 349 set_visible(true); | 358 set_visible(true); |
| 350 } | 359 } |
| 351 | 360 |
| 352 ContentSettingBubbleModel* ContentSettingMediaImageModel::CreateBubbleModel( | 361 ContentSettingBubbleModel* ContentSettingMediaImageModel::CreateBubbleModel( |
| 353 ContentSettingBubbleModel::Delegate* delegate, | 362 ContentSettingBubbleModel::Delegate* delegate, |
| 354 WebContents* web_contents, | 363 WebContents* web_contents, |
| 355 Profile* profile) { | 364 Profile* profile) { |
| 356 return new ContentSettingMediaStreamBubbleModel(delegate, | 365 return new ContentSettingMediaStreamBubbleModel(delegate, |
| 357 web_contents, | 366 web_contents, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 379 TabSpecificContentSettings* content_settings = | 388 TabSpecificContentSettings* content_settings = |
| 380 TabSpecificContentSettings::FromWebContents(web_contents); | 389 TabSpecificContentSettings::FromWebContents(web_contents); |
| 381 if (content_settings) { | 390 if (content_settings) { |
| 382 content_settings->SetBlockageHasBeenIndicated( | 391 content_settings->SetBlockageHasBeenIndicated( |
| 383 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 392 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 384 content_settings->SetBlockageHasBeenIndicated( | 393 content_settings->SetBlockageHasBeenIndicated( |
| 385 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 394 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 386 } | 395 } |
| 387 } | 396 } |
| 388 | 397 |
| 398 ContentSettingsType ContentSettingMediaImageModel::GetContentType() { | |
| 399 return last_content_type_; | |
| 400 } | |
| 401 | |
|
tapted
2017/02/03 00:35:39
nit: remove blank line
| |
| 402 | |
| 389 // Subresource Filter ---------------------------------------------------------- | 403 // Subresource Filter ---------------------------------------------------------- |
| 390 | 404 |
| 391 ContentSettingSubresourceFilterImageModel:: | 405 ContentSettingSubresourceFilterImageModel:: |
| 392 ContentSettingSubresourceFilterImageModel() | 406 ContentSettingSubresourceFilterImageModel() |
| 393 : ContentSettingImageModel() {} | 407 : ContentSettingImageModel() {} |
| 394 | 408 |
| 395 void ContentSettingSubresourceFilterImageModel::UpdateFromWebContents( | 409 void ContentSettingSubresourceFilterImageModel::UpdateFromWebContents( |
| 396 WebContents* web_contents) { | 410 WebContents* web_contents) { |
| 397 set_visible(false); | 411 set_visible(false); |
| 398 | 412 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 return gfx::Image( | 528 return gfx::Image( |
| 515 gfx::CreateVectorIconWithBadge(icon_id_, 16, icon_color, icon_badge_id_)); | 529 gfx::CreateVectorIconWithBadge(icon_id_, 16, icon_color, icon_badge_id_)); |
| 516 } | 530 } |
| 517 | 531 |
| 518 ContentSettingImageModel::ContentSettingImageModel() | 532 ContentSettingImageModel::ContentSettingImageModel() |
| 519 : is_visible_(false), | 533 : is_visible_(false), |
| 520 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 534 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 521 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 535 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 522 explanatory_string_id_(0) {} | 536 explanatory_string_id_(0) {} |
| 523 | 537 |
| 538 ContentSettingsType ContentSettingImageModel::GetContentType() { | |
| 539 return CONTENT_SETTINGS_TYPE_DEFAULT; | |
| 540 } | |
| 541 | |
| 524 // static | 542 // static |
| 525 std::vector<std::unique_ptr<ContentSettingImageModel>> | 543 std::vector<std::unique_ptr<ContentSettingImageModel>> |
| 526 ContentSettingImageModel::GenerateContentSettingImageModels() { | 544 ContentSettingImageModel::GenerateContentSettingImageModels() { |
| 527 std::vector<std::unique_ptr<ContentSettingImageModel>> result; | 545 std::vector<std::unique_ptr<ContentSettingImageModel>> result; |
| 528 | 546 |
| 529 // The ordering of the models here influences the order in which icons are | 547 // The ordering of the models here influences the order in which icons are |
| 530 // shown in the omnibox. | 548 // shown in the omnibox. |
| 531 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 549 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( |
| 532 CONTENT_SETTINGS_TYPE_COOKIES)); | 550 CONTENT_SETTINGS_TYPE_COOKIES)); |
| 533 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 551 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 556 | 574 |
| 557 #if defined(OS_MACOSX) | 575 #if defined(OS_MACOSX) |
| 558 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( | 576 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( |
| 559 content::WebContents* web_contents) { | 577 content::WebContents* web_contents) { |
| 560 gfx::VectorIconId old_icon = icon_id_; | 578 gfx::VectorIconId old_icon = icon_id_; |
| 561 gfx::VectorIconId old_badge_icon = icon_badge_id_; | 579 gfx::VectorIconId old_badge_icon = icon_badge_id_; |
| 562 UpdateFromWebContents(web_contents); | 580 UpdateFromWebContents(web_contents); |
| 563 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; | 581 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; |
| 564 } | 582 } |
| 565 #endif | 583 #endif |
| OLD | NEW |