Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/extension_message_bubble_bridge.h" | 5 #include "chrome/browser/ui/extensions/extension_message_bubble_bridge.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | |
| 9 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 10 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/grit/generated_resources.h" | |
| 13 #include "components/grit/components_scaled_resources.h" | |
| 14 #include "extensions/browser/extension_registry.h" | |
| 15 #include "ui/base/l10n/l10n_util.h" | |
| 16 #include "ui/base/resource/resource_bundle.h" | |
|
Devlin
2016/10/20 17:04:07
needed?
catmullings
2016/10/21 03:49:29
Done.
| |
| 17 #include "ui/gfx/vector_icons_public.h" | |
| 10 | 18 |
| 11 ExtensionMessageBubbleBridge::ExtensionMessageBubbleBridge( | 19 ExtensionMessageBubbleBridge::ExtensionMessageBubbleBridge( |
| 12 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller) | 20 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller) |
| 13 : controller_(std::move(controller)) {} | 21 : controller_(std::move(controller)) {} |
| 14 | 22 |
| 15 ExtensionMessageBubbleBridge::~ExtensionMessageBubbleBridge() {} | 23 ExtensionMessageBubbleBridge::~ExtensionMessageBubbleBridge() {} |
| 16 | 24 |
| 17 bool ExtensionMessageBubbleBridge::ShouldShow() { | 25 bool ExtensionMessageBubbleBridge::ShouldShow() { |
| 18 return controller_->ShouldShow(); | 26 return controller_->ShouldShow(); |
| 19 } | 27 } |
| 20 | 28 |
| 21 bool ExtensionMessageBubbleBridge::ShouldCloseOnDeactivate() { | 29 bool ExtensionMessageBubbleBridge::ShouldCloseOnDeactivate() { |
| 22 return controller_->CloseOnDeactivate(); | 30 return controller_->CloseOnDeactivate(); |
| 23 } | 31 } |
| 24 | 32 |
| 33 bool ExtensionMessageBubbleBridge::IsPolicyIndicationNeeded( | |
| 34 const extensions::Extension* extension) { | |
| 35 return controller_->delegate()->SupportsPolicyIndicator() && | |
| 36 extensions::Manifest::IsPolicyLocation(extension->location()); | |
| 37 } | |
| 38 | |
| 25 base::string16 ExtensionMessageBubbleBridge::GetHeadingText() { | 39 base::string16 ExtensionMessageBubbleBridge::GetHeadingText() { |
| 26 return controller_->delegate()->GetTitle(); | 40 return controller_->delegate()->GetTitle(); |
| 27 } | 41 } |
| 28 | 42 |
| 29 base::string16 ExtensionMessageBubbleBridge::GetBodyText( | 43 base::string16 ExtensionMessageBubbleBridge::GetBodyText( |
| 30 bool anchored_to_action) { | 44 bool anchored_to_action) { |
| 31 return controller_->delegate()->GetMessageBody( | 45 return controller_->delegate()->GetMessageBody( |
| 32 anchored_to_action, controller_->GetExtensionIdList().size()); | 46 anchored_to_action, controller_->GetExtensionIdList().size()); |
| 33 } | 47 } |
| 34 | 48 |
| 35 base::string16 ExtensionMessageBubbleBridge::GetItemListText() { | 49 base::string16 ExtensionMessageBubbleBridge::GetItemListText() { |
| 36 return controller_->GetExtensionListForDisplay(); | 50 return controller_->GetExtensionListForDisplay(); |
| 37 } | 51 } |
| 38 | 52 |
| 39 base::string16 ExtensionMessageBubbleBridge::GetActionButtonText() { | 53 base::string16 ExtensionMessageBubbleBridge::GetActionButtonText() { |
| 54 const extensions::ExtensionIdList& list = controller_->GetExtensionIdList(); | |
| 55 DCHECK(!list.empty()); | |
| 56 const extensions::Extension* extension = | |
| 57 extensions::ExtensionRegistry::Get(controller_->profile()) | |
| 58 ->enabled_extensions() | |
| 59 .GetByID(list[0]); | |
| 60 | |
| 61 DCHECK(extension); | |
| 62 // An empty string is returned so that we don't display the button prompting | |
| 63 // to remove policy-installed extensions. | |
| 64 if (IsPolicyIndicationNeeded(extension)) | |
| 65 return base::string16(); | |
| 40 return controller_->delegate()->GetActionButtonLabel(); | 66 return controller_->delegate()->GetActionButtonLabel(); |
| 41 } | 67 } |
| 42 | 68 |
| 43 base::string16 ExtensionMessageBubbleBridge::GetDismissButtonText() { | 69 base::string16 ExtensionMessageBubbleBridge::GetDismissButtonText() { |
| 44 return controller_->delegate()->GetDismissButtonLabel(); | 70 return controller_->delegate()->GetDismissButtonLabel(); |
| 45 } | 71 } |
| 46 | 72 |
| 47 base::string16 ExtensionMessageBubbleBridge::GetLearnMoreButtonText() { | 73 base::string16 ExtensionMessageBubbleBridge::GetLearnMoreButtonText() { |
| 48 return controller_->delegate()->GetLearnMoreLabel(); | 74 return controller_->delegate()->GetLearnMoreLabel(); |
| 49 } | 75 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 67 break; | 93 break; |
| 68 } | 94 } |
| 69 case CLOSE_EXECUTE: | 95 case CLOSE_EXECUTE: |
| 70 controller_->OnBubbleAction(); | 96 controller_->OnBubbleAction(); |
| 71 break; | 97 break; |
| 72 case CLOSE_LEARN_MORE: | 98 case CLOSE_LEARN_MORE: |
| 73 controller_->OnLinkClicked(); | 99 controller_->OnLinkClicked(); |
| 74 break; | 100 break; |
| 75 } | 101 } |
| 76 } | 102 } |
| 103 | |
| 104 std::unique_ptr<ToolbarActionsBarBubbleDelegate::ExtraViewInfo> | |
| 105 ExtensionMessageBubbleBridge::GetExtraViewInfo() { | |
| 106 const extensions::ExtensionIdList& list = controller_->GetExtensionIdList(); | |
| 107 const extensions::Extension* extension = | |
| 108 extensions::ExtensionRegistry::Get(controller_->profile()) | |
| 109 ->enabled_extensions() | |
| 110 .GetByID(list[0]); | |
| 111 | |
| 112 DCHECK(extension); | |
| 113 | |
| 114 std::unique_ptr<ExtraViewInfo> extra_view_info = | |
| 115 base::MakeUnique<ExtraViewInfo>(); | |
| 116 | |
| 117 if (IsPolicyIndicationNeeded(extension)) { | |
| 118 DCHECK_EQ(1u, list.size()); | |
| 119 extra_view_info->resource_id = gfx::VectorIconId::BUSINESS; | |
| 120 extra_view_info->text = | |
| 121 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALLED_BY_ADMIN); | |
| 122 extra_view_info->is_text_linked = false; | |
| 123 } else { | |
| 124 extra_view_info->text = controller_->delegate()->GetLearnMoreLabel(); | |
| 125 extra_view_info->is_text_linked = true; | |
| 126 } | |
| 127 | |
| 128 return extra_view_info; | |
| 129 } | |
| OLD | NEW |