| 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" |
| 10 | 17 |
| 11 ExtensionMessageBubbleBridge::ExtensionMessageBubbleBridge( | 18 ExtensionMessageBubbleBridge::ExtensionMessageBubbleBridge( |
| 12 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller) | 19 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller) |
| 13 : controller_(std::move(controller)) {} | 20 : controller_(std::move(controller)) {} |
| 14 | 21 |
| 15 ExtensionMessageBubbleBridge::~ExtensionMessageBubbleBridge() {} | 22 ExtensionMessageBubbleBridge::~ExtensionMessageBubbleBridge() {} |
| 16 | 23 |
| 17 bool ExtensionMessageBubbleBridge::ShouldShow() { | 24 bool ExtensionMessageBubbleBridge::ShouldShow() { |
| 18 return controller_->ShouldShow(); | 25 return controller_->ShouldShow(); |
| 19 } | 26 } |
| 20 | 27 |
| 21 bool ExtensionMessageBubbleBridge::ShouldCloseOnDeactivate() { | 28 bool ExtensionMessageBubbleBridge::ShouldCloseOnDeactivate() { |
| 22 return controller_->CloseOnDeactivate(); | 29 return controller_->CloseOnDeactivate(); |
| 23 } | 30 } |
| 24 | 31 |
| 32 bool ExtensionMessageBubbleBridge::IsPolicyIndicationNeeded( |
| 33 const extensions::Extension* extension) { |
| 34 return controller_->delegate()->SupportsPolicyIndicator() && |
| 35 extensions::Manifest::IsPolicyLocation(extension->location()); |
| 36 } |
| 37 |
| 25 base::string16 ExtensionMessageBubbleBridge::GetHeadingText() { | 38 base::string16 ExtensionMessageBubbleBridge::GetHeadingText() { |
| 26 return controller_->delegate()->GetTitle(); | 39 return controller_->delegate()->GetTitle(); |
| 27 } | 40 } |
| 28 | 41 |
| 29 base::string16 ExtensionMessageBubbleBridge::GetBodyText( | 42 base::string16 ExtensionMessageBubbleBridge::GetBodyText( |
| 30 bool anchored_to_action) { | 43 bool anchored_to_action) { |
| 31 return controller_->delegate()->GetMessageBody( | 44 return controller_->delegate()->GetMessageBody( |
| 32 anchored_to_action, controller_->GetExtensionIdList().size()); | 45 anchored_to_action, controller_->GetExtensionIdList().size()); |
| 33 } | 46 } |
| 34 | 47 |
| 35 base::string16 ExtensionMessageBubbleBridge::GetItemListText() { | 48 base::string16 ExtensionMessageBubbleBridge::GetItemListText() { |
| 36 return controller_->GetExtensionListForDisplay(); | 49 return controller_->GetExtensionListForDisplay(); |
| 37 } | 50 } |
| 38 | 51 |
| 39 base::string16 ExtensionMessageBubbleBridge::GetActionButtonText() { | 52 base::string16 ExtensionMessageBubbleBridge::GetActionButtonText() { |
| 53 const extensions::ExtensionIdList& list = controller_->GetExtensionIdList(); |
| 54 const extensions::Extension* extension = |
| 55 extensions::ExtensionRegistry::Get(controller_->profile()) |
| 56 ->enabled_extensions() |
| 57 .GetByID(list[0]); |
| 58 |
| 59 DCHECK(extension); |
| 60 if (IsPolicyIndicationNeeded(extension)) |
| 61 return base::string16(); |
| 40 return controller_->delegate()->GetActionButtonLabel(); | 62 return controller_->delegate()->GetActionButtonLabel(); |
| 41 } | 63 } |
| 42 | 64 |
| 43 base::string16 ExtensionMessageBubbleBridge::GetDismissButtonText() { | 65 base::string16 ExtensionMessageBubbleBridge::GetDismissButtonText() { |
| 44 return controller_->delegate()->GetDismissButtonLabel(); | 66 return controller_->delegate()->GetDismissButtonLabel(); |
| 45 } | 67 } |
| 46 | 68 |
| 47 base::string16 ExtensionMessageBubbleBridge::GetLearnMoreButtonText() { | 69 base::string16 ExtensionMessageBubbleBridge::GetLearnMoreButtonText() { |
| 48 return controller_->delegate()->GetLearnMoreLabel(); | 70 return controller_->delegate()->GetLearnMoreLabel(); |
| 49 } | 71 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 67 break; | 89 break; |
| 68 } | 90 } |
| 69 case CLOSE_EXECUTE: | 91 case CLOSE_EXECUTE: |
| 70 controller_->OnBubbleAction(); | 92 controller_->OnBubbleAction(); |
| 71 break; | 93 break; |
| 72 case CLOSE_LEARN_MORE: | 94 case CLOSE_LEARN_MORE: |
| 73 controller_->OnLinkClicked(); | 95 controller_->OnLinkClicked(); |
| 74 break; | 96 break; |
| 75 } | 97 } |
| 76 } | 98 } |
| 99 |
| 100 std::unique_ptr<ToolbarActionsBarBubbleDelegate::ExtraViewInfo> |
| 101 ExtensionMessageBubbleBridge::GetExtraViewInfo() { |
| 102 const extensions::ExtensionIdList& list = controller_->GetExtensionIdList(); |
| 103 const extensions::Extension* extension = |
| 104 extensions::ExtensionRegistry::Get(controller_->profile()) |
| 105 ->enabled_extensions() |
| 106 .GetByID(list[0]); |
| 107 |
| 108 DCHECK(extension); |
| 109 |
| 110 std::unique_ptr<ExtraViewInfo> extra_view_info = |
| 111 base::MakeUnique<ExtraViewInfo>(); |
| 112 |
| 113 if (IsPolicyIndicationNeeded(extension)) { |
| 114 DCHECK_EQ(1u, list.size()); |
| 115 extra_view_info->resource_id = IDR_OMNIBOX_HTTPS_POLICY_WARNING; |
| 116 extra_view_info->text = |
| 117 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALLED_BY_ADMIN); |
| 118 extra_view_info->is_text_linked = false; |
| 119 } else { |
| 120 extra_view_info->text = controller_->delegate()->GetLearnMoreLabel(); |
| 121 extra_view_info->is_text_linked = true; |
| 122 } |
| 123 |
| 124 return extra_view_info; |
| 125 } |
| OLD | NEW |