Commit 66bf5121 authored by Adrian Elder's avatar Adrian Elder Committed by Commit Bot

Show extension name in permission bubble.

This applies to browser permissions checks, not app permissions. For
example: getUserMedia. If the permission is not requested by an
extension, or the extension name cannot be looked up, the origin from
the URL is shown as before.

Tested by launching an extension that attempts to access the mic with
getUserMedia and verifying the existing behavior for a web site.

Bug: 717625
Change-Id: I4e17c97f932ee163afa2fe972687259d794e4cfc
Reviewed-on: https://chromium-review.googlesource.com/677983
Commit-Queue: Adrian Elder <aelder@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Reviewed-by: default avatarMustafa Emre Acer <meacer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519520}
parent e811a3e5
......@@ -4,10 +4,13 @@
#include "chrome/browser/extensions/extension_ui_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_util.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
......@@ -51,5 +54,19 @@ bool ShouldDisplayInExtensionSettings(const Extension* extension,
return extension->ShouldDisplayInExtensionSettings();
}
base::string16 GetEnabledExtensionNameForUrl(const GURL& url,
content::BrowserContext* context) {
if (!url.SchemeIs(extensions::kExtensionScheme))
return base::string16();
extensions::ExtensionRegistry* extension_registry =
extensions::ExtensionRegistry::Get(context);
const extensions::Extension* extension =
extension_registry->enabled_extensions().GetByID(url.host());
return extension ? base::CollapseWhitespace(
base::UTF8ToUTF16(extension->name()), false)
: base::string16();
}
} // namespace ui_util
} // namespace extensions
......@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UI_UTIL_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_UI_UTIL_H_
#include "url/gurl.h"
namespace content {
class BrowserContext;
}
......@@ -39,6 +41,12 @@ bool ShouldDisplayInNewTabPage(const Extension* extension,
bool ShouldDisplayInExtensionSettings(const Extension* extension,
content::BrowserContext* context);
// If |url| is an extension URL, returns the name of the associated extension,
// with whitespace collapsed. Otherwise, returns empty string. |context| is used
// to get at the extension registry.
base::string16 GetEnabledExtensionNameForUrl(const GURL& url,
content::BrowserContext* context);
} // namespace ui_util
} // namespace extensions
......
......@@ -18,10 +18,16 @@
#include "chrome/browser/ui/permission_bubble/permission_prompt.h"
#include "chrome/browser/vr/vr_tab_helper.h"
#include "chrome/common/chrome_switches.h"
#include "components/url_formatter/elide_url.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
#include "url/origin.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/extensions/extension_ui_util.h"
#include "extensions/common/constants.h"
#endif // !defined(OS_ANDROID)
namespace {
class CancelledRequest : public PermissionRequest {
......@@ -339,6 +345,26 @@ const std::vector<PermissionRequest*>& PermissionRequestManager::Requests() {
return requests_;
}
base::string16 PermissionRequestManager::GetDisplayOrigin() {
DCHECK(!requests_.empty());
GURL origin_url = requests_[0]->GetOrigin();
#if !defined(OS_ANDROID)
if (origin_url.SchemeIs(extensions::kExtensionScheme)) {
base::string16 extension_name =
extensions::ui_util::GetEnabledExtensionNameForUrl(
origin_url, web_contents()->GetBrowserContext());
if (!extension_name.empty()) {
return extension_name;
}
}
#endif // !defined(OS_ANDROID)
// Web URLs should be displayed as the origin in the URL.
return url_formatter::FormatUrlForSecurityDisplay(
origin_url, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
}
void PermissionRequestManager::Accept() {
DCHECK(view_);
std::vector<PermissionRequest*>::iterator requests_iter;
......
......@@ -126,6 +126,7 @@ class PermissionRequestManager
// PermissionPrompt::Delegate:
const std::vector<PermissionRequest*>& Requests() override;
base::string16 GetDisplayOrigin() override;
void Accept() override;
void Deny() override;
void Closing() override;
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/command_updater.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
#include "chrome/browser/extensions/extension_ui_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/translate/chrome_translate_client.h"
......@@ -591,8 +592,9 @@ void LocationBarViewMac::UpdatePageInfoText() {
PageInfoVerboseType type = GetPageInfoVerboseType();
if (type == PageInfoVerboseType::kEVCert) {
label = GetToolbarModel()->GetEVCertName();
} else if (type == PageInfoVerboseType::kExtension) {
label = GetExtensionName(GetToolbarModel()->GetURL(), GetWebContents());
} else if (type == PageInfoVerboseType::kExtension && GetWebContents()) {
label = extensions::ui_util::GetEnabledExtensionNameForUrl(
GetToolbarModel()->GetURL(), GetWebContents()->GetBrowserContext());
} else if (type == PageInfoVerboseType::kChrome) {
label = l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
} else if (type == PageInfoVerboseType::kSecurity &&
......
......@@ -96,6 +96,8 @@ class PermissionBubbleControllerTest : public CocoaProfileTest,
return requests_;
}
base::string16 GetDisplayOrigin() override { return base::string16(); }
void AddRequest(const std::string& title) {
std::unique_ptr<MockPermissionRequest> request =
base::MakeUnique<MockPermissionRequest>(
......
......@@ -5,14 +5,11 @@
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "base/scoped_observer.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/feature_switch.h"
#include "extensions/common/permissions/permissions_data.h"
......@@ -78,24 +75,3 @@ bool LocationBar::IsBookmarkStarHiddenByExtension() const {
return false;
}
// static
base::string16 LocationBar::GetExtensionName(
const GURL& url,
content::WebContents* web_contents) {
// On ChromeOS, this function can be called using web_contents from
// SimpleWebViewDialog::GetWebContents() which always returns null.
// TODO(crbug.com/680329) Remove the null check and make
// SimpleWebViewDialog::GetWebContents return the proper web contents instead.
if (!web_contents || !url.SchemeIs(extensions::kExtensionScheme))
return base::string16();
content::BrowserContext* browser_context = web_contents->GetBrowserContext();
extensions::ExtensionRegistry* extension_registry =
extensions::ExtensionRegistry::Get(browser_context);
const extensions::Extension* extension =
extension_registry->enabled_extensions().GetByID(url.host());
return extension ? base::CollapseWhitespace(
base::UTF8ToUTF16(extension->name()), false)
: base::string16();
}
......@@ -86,12 +86,6 @@ class LocationBar {
// Checks if any extension has requested that the bookmark star be hidden.
bool IsBookmarkStarHiddenByExtension() const;
// If |url| is an extension URL, returns the name of the associated extension,
// with whitespace collapsed. Otherwise, returns empty string. |web_contents|
// is used to get at the extension registry.
static base::string16 GetExtensionName(const GURL& url,
content::WebContents* web_contents);
private:
class ExtensionLoadObserver;
......
......@@ -29,6 +29,10 @@ TestPermissionBubbleViewDelegate::Requests() {
return requests_;
}
base::string16 TestPermissionBubbleViewDelegate::GetDisplayOrigin() {
return base::string16();
}
PermissionBubbleBrowserTest::PermissionBubbleBrowserTest() {
}
......
......@@ -24,6 +24,7 @@ class TestPermissionBubbleViewDelegate : public PermissionPrompt::Delegate {
~TestPermissionBubbleViewDelegate() override;
const std::vector<PermissionRequest*>& Requests() override;
base::string16 GetDisplayOrigin() override;
void Accept() override {}
void Deny() override {}
......
......@@ -32,6 +32,7 @@ class PermissionPrompt {
// These pointers should not be stored as the actual request objects may be
// deleted upon navigation and so on.
virtual const std::vector<PermissionRequest*>& Requests() = 0;
virtual base::string16 GetDisplayOrigin() = 0;
virtual void Accept() = 0;
virtual void Deny() = 0;
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/command_updater.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
#include "chrome/browser/extensions/extension_ui_util.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
......@@ -814,10 +815,19 @@ base::string16 LocationBarView::GetLocationIconText() const {
if (GetToolbarModel()->GetURL().SchemeIs(content::kChromeUIScheme))
return l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
const base::string16 extension_name = GetExtensionName(
GetToolbarModel()->GetURL(), delegate_->GetWebContents());
if (!extension_name.empty())
return extension_name;
if (delegate_->GetWebContents()) {
// On ChromeOS, this can be called using web_contents from
// SimpleWebViewDialog::GetWebContents() which always returns null.
// TODO(crbug.com/680329) Remove the null check and make
// SimpleWebViewDialog::GetWebContents return the proper web contents
// instead.
const base::string16 extension_name =
extensions::ui_util::GetEnabledExtensionNameForUrl(
GetToolbarModel()->GetURL(),
delegate_->GetWebContents()->GetBrowserContext());
if (!extension_name.empty())
return extension_name;
}
bool has_ev_cert =
(GetToolbarModel()->GetSecurityLevel(false) == security_state::EV_SECURE);
......
......@@ -68,7 +68,8 @@ class PermissionsBubbleDialogDelegateView
public:
PermissionsBubbleDialogDelegateView(
PermissionPromptImpl* owner,
const std::vector<PermissionRequest*>& requests);
const std::vector<PermissionRequest*>& requests,
const base::string16& display_origin);
~PermissionsBubbleDialogDelegateView() override;
void CloseBubble();
......@@ -101,8 +102,9 @@ class PermissionsBubbleDialogDelegateView
PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView(
PermissionPromptImpl* owner,
const std::vector<PermissionRequest*>& requests)
: owner_(owner) {
const std::vector<PermissionRequest*>& requests,
const base::string16& display_origin)
: owner_(owner), display_origin_(display_origin) {
DCHECK(!requests.empty());
set_close_on_deactivate(false);
......@@ -121,10 +123,6 @@ PermissionsBubbleDialogDelegateView::PermissionsBubbleDialogDelegateView(
views::BoxLayout::kVertical, gfx::Insets(),
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
display_origin_ = url_formatter::FormatUrlForSecurityDisplay(
requests[0]->GetOrigin(),
url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
for (size_t index = 0; index < requests.size(); index++) {
views::View* label_container = new views::View();
int indent =
......@@ -311,8 +309,8 @@ void PermissionPromptImpl::Show() {
DCHECK(browser_);
DCHECK(browser_->window());
bubble_delegate_ =
new PermissionsBubbleDialogDelegateView(this, delegate_->Requests());
bubble_delegate_ = new PermissionsBubbleDialogDelegateView(
this, delegate_->Requests(), delegate_->GetDisplayOrigin());
// Set |parent_window| because some valid anchors can become hidden.
bubble_delegate_->set_parent_window(
......
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