Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File Handling: Add extension types to permission prompt.
Add file extensions sourced from the registrar, to the permission prompt. The permission prompt should now inform users which file extensions the web app would like to access file handlers for. Different translation strings exist for each possible amount of handlers, to allow for better translation between languages with different sentence structure. File Handler information is retrieved from the WebAppRegistrar (instead of from the blink manifest), to match what's registered in the operating system. Previous UI: https://storage.cloud.google.com/chromium-translation-screenshots/55ddb345d69ee2187e402f22579fc4459b9563d1 New UI: https://storage.cloud.google.com/chromium-translation-screenshots/aa286efbaee111ce1a8e37854ff384fa397f929e Bug: 1198339 Change-Id: Iad350f2f5c753af3a1315f3813d5fda505b93549 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2824363 Commit-Queue: Darwin Huang <huangdarwin@chromium.org> Reviewed-by: Andy Paicu <andypaicu@chromium.org> Reviewed-by: Evan Stade <estade@chromium.org> Reviewed-by: Chase Phillips <cmp@chromium.org> Reviewed-by: Daniel Murphy <dmurph@chromium.org> Cr-Commit-Position: refs/heads/master@{#877746}
- Loading branch information
Darwin Huang
authored and
Chromium LUCI CQ
committed
Apr 30, 2021
1 parent
b63f81c
commit 2aedfd5
Showing
19 changed files
with
244 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...e/app/generated_resources_grd/IDS_WEB_APP_FILE_HANDLING_EXTENSION_LIST_SEPARATOR.png.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
aa286efbaee111ce1a8e37854ff384fa397f929e |
1 change: 1 addition & 0 deletions
1
chrome/app/generated_resources_grd/IDS_WEB_APP_FILE_HANDLING_PERMISSION_TEXT.png.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
aa286efbaee111ce1a8e37854ff384fa397f929e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
chrome/browser/web_applications/components/file_handling_permission_context.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/web_applications/components/file_handling_permission_context.h" | ||
|
||
#include <string> | ||
|
||
#include "chrome/browser/web_applications/components/file_handling_permission_request_impl.h" | ||
#include "components/content_settings/core/common/content_settings_types.h" | ||
#include "components/permissions/permission_context_base.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom.h" | ||
|
||
FileHandlingPermissionContext::FileHandlingPermissionContext( | ||
content::BrowserContext* browser_context) | ||
: PermissionContextBase(browser_context, | ||
ContentSettingsType::FILE_HANDLING, | ||
blink::mojom::PermissionsPolicyFeature::kNotFound) { | ||
} | ||
|
||
FileHandlingPermissionContext::~FileHandlingPermissionContext() = default; | ||
|
||
bool FileHandlingPermissionContext::IsRestrictedToSecureOrigins() const { | ||
return true; | ||
} | ||
|
||
std::unique_ptr<permissions::PermissionRequest> | ||
FileHandlingPermissionContext::CreatePermissionRequest( | ||
const GURL& request_origin, | ||
ContentSettingsType content_settings_type, | ||
bool has_gesture, | ||
content::WebContents* web_contents, | ||
permissions::PermissionRequestImpl::PermissionDecidedCallback | ||
permission_decided_callback, | ||
base::OnceClosure delete_callback) const { | ||
return std::make_unique<permissions::FileHandlingPermissionRequestImpl>( | ||
request_origin, content_settings_type, has_gesture, web_contents, | ||
std::move(permission_decided_callback), std::move(delete_callback)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
chrome/browser/web_applications/components/file_handling_permission_request_impl.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/web_applications/components/file_handling_permission_request_impl.h" | ||
|
||
#include "base/strings/utf_string_conversions.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/web_applications/components/web_app_utils.h" | ||
#include "chrome/grit/generated_resources.h" | ||
#include "components/strings/grit/components_strings.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
|
||
namespace permissions { | ||
|
||
FileHandlingPermissionRequestImpl::FileHandlingPermissionRequestImpl( | ||
const GURL& request_origin, | ||
ContentSettingsType content_settings_type, | ||
bool has_gesture, | ||
content::WebContents* web_contents, | ||
PermissionDecidedCallback permission_decided_callback, | ||
base::OnceClosure delete_callback) | ||
: PermissionRequestImpl(request_origin, | ||
content_settings_type, | ||
has_gesture, | ||
std::move(permission_decided_callback), | ||
std::move(delete_callback)) { | ||
auto* browser = web_contents->GetBrowserContext(); | ||
if (!browser) { | ||
return; | ||
} | ||
Profile* profile = Profile::FromBrowserContext(browser); | ||
DCHECK(profile); | ||
|
||
std::u16string extensions_list = | ||
web_app::GetFileExtensionsHandledByWebAppDisplayedAsList( | ||
profile, web_contents->GetLastCommittedURL()); | ||
message_text_fragment_ = l10n_util::GetStringFUTF16( | ||
IDS_WEB_APP_FILE_HANDLING_PERMISSION_TEXT, extensions_list); | ||
} | ||
|
||
FileHandlingPermissionRequestImpl::~FileHandlingPermissionRequestImpl() = | ||
default; | ||
|
||
std::u16string FileHandlingPermissionRequestImpl::GetMessageTextFragment() | ||
const { | ||
return message_text_fragment_; | ||
} | ||
|
||
} // namespace permissions |
36 changes: 36 additions & 0 deletions
36
chrome/browser/web_applications/components/file_handling_permission_request_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_FILE_HANDLING_PERMISSION_REQUEST_IMPL_H_ | ||
#define CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_FILE_HANDLING_PERMISSION_REQUEST_IMPL_H_ | ||
|
||
#include <string> | ||
#include "components/permissions/permission_request_impl.h" | ||
|
||
namespace content { | ||
class WebContents; | ||
} | ||
|
||
namespace permissions { | ||
|
||
// Provides a custom message text fragment that differs based on file handlers | ||
// requested by a web app. | ||
class FileHandlingPermissionRequestImpl : public PermissionRequestImpl { | ||
public: | ||
FileHandlingPermissionRequestImpl( | ||
const GURL& request_origin, | ||
ContentSettingsType content_settings_type, | ||
bool has_gesture, | ||
content::WebContents* web_contents, | ||
PermissionDecidedCallback permission_decided_callback, | ||
base::OnceClosure delete_callback); | ||
~FileHandlingPermissionRequestImpl() override; | ||
|
||
private: | ||
std::u16string GetMessageTextFragment() const override; | ||
std::u16string message_text_fragment_; | ||
}; | ||
} // namespace permissions | ||
|
||
#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_FILE_HANDLING_PERMISSION_REQUEST_IMPL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
components/permissions/contexts/file_handling_permission_context.cc
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.