Commit 55f43dec authored by Bret Sepulveda's avatar Bret Sepulveda Committed by Commit Bot

Fall back to existing permission prompt when there's no chip string.

When the Permission Chip is enabled, you get a broken-looking UI when
there's no short string written. This patch works around this by falling
back to the old UI.

Bug: 1019129
Change-Id: If214734f780a0423c4ef9bdb0198c433cffc3cae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431429
Commit-Queue: Balazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811075}
parent d61e7903
...@@ -259,7 +259,7 @@ base::string16 PermissionChip::GetPermissionMessage() { ...@@ -259,7 +259,7 @@ base::string16 PermissionChip::GetPermissionMessage() {
auto requests = delegate_->Requests(); auto requests = delegate_->Requests();
return requests.size() == 1 return requests.size() == 1
? requests[0]->GetChipText() ? requests[0]->GetChipText().value()
: l10n_util::GetStringUTF16( : l10n_util::GetStringUTF16(
IDS_MEDIA_CAPTURE_VIDEO_AND_AUDIO_PERMISSION_CHIP); IDS_MEDIA_CAPTURE_VIDEO_AND_AUDIO_PERMISSION_CHIP);
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/browser/ui/ui_features.h" #include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/permission_bubble/permission_prompt_bubble_view.h" #include "chrome/browser/ui/views/permission_bubble/permission_prompt_bubble_view.h"
#include "components/permissions/permission_request.h"
#include "components/permissions/permission_request_manager.h" #include "components/permissions/permission_request_manager.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/views/bubble/bubble_frame_view.h" #include "ui/views/bubble/bubble_frame_view.h"
...@@ -51,7 +52,12 @@ PermissionPromptImpl::PermissionPromptImpl(Browser* browser, ...@@ -51,7 +52,12 @@ PermissionPromptImpl::PermissionPromptImpl(Browser* browser,
content_settings::UpdateLocationBarUiForWebContents(web_contents_); content_settings::UpdateLocationBarUiForWebContents(web_contents_);
} else { } else {
LocationBarView* lbv = GetLocationBarView(); LocationBarView* lbv = GetLocationBarView();
if (base::FeatureList::IsEnabled(features::kPermissionChip) && lbv) { std::vector<permissions::PermissionRequest*> requests =
delegate->Requests();
if (base::FeatureList::IsEnabled(features::kPermissionChip) && lbv &&
std::all_of(requests.begin(), requests.end(), [](auto* request) {
return request->GetChipText().has_value();
})) {
permission_chip_ = lbv->permission_chip(); permission_chip_ = lbv->permission_chip();
permission_chip_->Show(delegate); permission_chip_->Show(delegate);
prompt_style_ = PromptStyle::kChip; prompt_style_ = PromptStyle::kChip;
......
...@@ -19,8 +19,8 @@ ContentSettingsType PermissionRequest::GetContentSettingsType() const { ...@@ -19,8 +19,8 @@ ContentSettingsType PermissionRequest::GetContentSettingsType() const {
} }
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
base::string16 PermissionRequest::GetChipText() const { base::Optional<base::string16> PermissionRequest::GetChipText() const {
return base::string16(); return base::nullopt;
} }
#endif #endif
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_H_ #define COMPONENTS_PERMISSIONS_PERMISSION_REQUEST_H_
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/content_settings/core/common/content_settings_types.h" #include "components/content_settings/core/common/content_settings_types.h"
...@@ -115,7 +116,7 @@ class PermissionRequest { ...@@ -115,7 +116,7 @@ class PermissionRequest {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
// Returns the short text for the chip button related to this permission. // Returns the short text for the chip button related to this permission.
virtual base::string16 GetChipText() const; virtual base::Optional<base::string16> GetChipText() const;
#endif #endif
// Returns the shortened prompt text for this permission. The permission // Returns the shortened prompt text for this permission. The permission
......
...@@ -253,7 +253,7 @@ base::string16 PermissionRequestImpl::GetMessageTextFragment() const { ...@@ -253,7 +253,7 @@ base::string16 PermissionRequestImpl::GetMessageTextFragment() const {
} }
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
base::string16 PermissionRequestImpl::GetChipText() const { base::Optional<base::string16> PermissionRequestImpl::GetChipText() const {
int message_id; int message_id;
switch (content_settings_type_) { switch (content_settings_type_) {
case ContentSettingsType::GEOLOCATION: case ContentSettingsType::GEOLOCATION:
...@@ -284,8 +284,10 @@ base::string16 PermissionRequestImpl::GetChipText() const { ...@@ -284,8 +284,10 @@ base::string16 PermissionRequestImpl::GetChipText() const {
message_id = IDS_IDLE_DETECTION_PERMISSION_CHIP; message_id = IDS_IDLE_DETECTION_PERMISSION_CHIP;
break; break;
default: default:
NOTREACHED(); // TODO(bsep): We don't actually want to support having no string in the
return base::string16(); // long term, but writing them takes time. In the meantime, we fall back
// to the existing UI when the string is missing.
return base::nullopt;
} }
return l10n_util::GetStringUTF16(message_id); return l10n_util::GetStringUTF16(message_id);
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h" #include "components/content_settings/core/common/content_settings_types.h"
...@@ -41,7 +42,7 @@ class PermissionRequestImpl : public PermissionRequest { ...@@ -41,7 +42,7 @@ class PermissionRequestImpl : public PermissionRequest {
base::string16 GetQuietMessageText() const override; base::string16 GetQuietMessageText() const override;
#endif #endif
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
base::string16 GetChipText() const override; base::Optional<base::string16> GetChipText() const override;
#endif #endif
base::string16 GetMessageTextFragment() const override; base::string16 GetMessageTextFragment() const override;
GURL GetOrigin() const override; GURL GetOrigin() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment