-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Leo AI becomes an installable PWA #27025
Merged
+246
−2
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
if (!is_android) { | ||
source_set("browser_tests") { | ||
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ] | ||
|
||
testonly = true | ||
|
||
sources = [ "app_banner_manager_desktop_browsertest.cc" ] | ||
|
||
deps = [ | ||
"//brave/components/constants", | ||
"//chrome/browser", | ||
"//chrome/test:test_support", | ||
"//chrome/test:test_support_ui", | ||
"//content/public/common", | ||
] | ||
} | ||
} |
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,57 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "chrome/browser/banners/app_banner_manager_desktop.h" | ||
|
||
#include "brave/components/constants/webui_url_constants.h" | ||
#include "chrome/browser/banners/test_app_banner_manager_desktop.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "content/public/common/url_constants.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace webapps { | ||
|
||
class AppBannerManagerDesktopBrowserTest_Brave : public InProcessBrowserTest { | ||
public: | ||
AppBannerManagerDesktopBrowserTest_Brave() = default; | ||
~AppBannerManagerDesktopBrowserTest_Brave() override = default; | ||
|
||
AppBannerManagerDesktopBrowserTest_Brave( | ||
const AppBannerManagerDesktopBrowserTest_Brave&) = delete; | ||
AppBannerManagerDesktopBrowserTest_Brave& operator=( | ||
const AppBannerManagerDesktopBrowserTest_Brave&) = delete; | ||
|
||
void SetUp() override { | ||
TestAppBannerManagerDesktop::SetUp(); | ||
InProcessBrowserTest::SetUp(); | ||
} | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(AppBannerManagerDesktopBrowserTest_Brave, | ||
InstallableWebUI) { | ||
TestAppBannerManagerDesktop* manager = | ||
TestAppBannerManagerDesktop::FromWebContents( | ||
browser()->tab_strip_model()->GetActiveWebContents()); | ||
|
||
// Iterate through kInstallablePWAWebUIHosts and navigate to each one, | ||
// checking that it's installable and promotable. If they have a bad | ||
// webmanifest or aren't on the ChromeUI scheme, the test should fail. | ||
for (const auto& host : kInstallablePWAWebUIHosts) { | ||
SCOPED_TRACE(testing::Message() << "Host: " << host); | ||
|
||
ASSERT_TRUE(ui_test_utils::NavigateToURL( | ||
browser(), GURL(base::StrCat({"chrome://", host})))); | ||
|
||
ASSERT_TRUE(manager->WaitForInstallableCheck()); | ||
|
||
EXPECT_EQ(InstallableWebAppCheckResult::kYes_Promotable, | ||
manager->GetInstallableWebAppCheckResult()); | ||
} | ||
} | ||
|
||
} // namespace webapps |
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
23 changes: 23 additions & 0 deletions
23
chromium_src/chrome/browser/web_applications/web_app_helpers.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,23 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "base/containers/contains.h" | ||
#include "brave/components/constants/webui_url_constants.h" | ||
|
||
// Make sure IsValidWebAppUrl also checks for allowed Brave WebUI hosts | ||
#define IsValidWebAppUrl IsValidWebAppUrl_ChromiumImpl | ||
|
||
#include "src/chrome/browser/web_applications/web_app_helpers.cc" | ||
#undef IsValidWebAppUrl | ||
|
||
namespace web_app { | ||
|
||
bool IsValidWebAppUrl(const GURL& app_url) { | ||
return IsValidWebAppUrl_ChromiumImpl(app_url) || | ||
(app_url.SchemeIs(content::kChromeUIScheme) && | ||
base::Contains(kInstallablePWAWebUIHosts, app_url.host_piece())); | ||
} | ||
|
||
} // namespace web_app |
14 changes: 14 additions & 0 deletions
14
chromium_src/chrome/browser/web_applications/web_app_helpers_unittest.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,14 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "src/chrome/browser/web_applications/web_app_helpers_unittest.cc" | ||
|
||
namespace web_app { | ||
|
||
TEST(WebAppHelpers, Brave_IsValidWebAppUrl) { | ||
EXPECT_TRUE(IsValidWebAppUrl(GURL("chrome://leo-ai"))); | ||
} | ||
|
||
} // namespace web_app |
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,3 @@ | ||
include_rules = [ | ||
"+brave/components/constants", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this dependency should also appear in |
||
] |
19 changes: 19 additions & 0 deletions
19
chromium_src/components/webapps/browser/banners/app_banner_manager.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,19 @@ | ||
// Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "base/containers/contains.h" | ||
#include "brave/components/constants/webui_url_constants.h" | ||
|
||
// Include password_manager constants before override so we don't override the | ||
// definition. | ||
#include "components/password_manager/content/common/web_ui_constants.h" | ||
|
||
// Add some extra items to WebUI hosts considered valid for PWAs | ||
#define kChromeUIPasswordManagerHost \ | ||
kChromeUIPasswordManagerHost && \ | ||
!base::Contains(kInstallablePWAWebUIHosts, url.host_piece()) | ||
|
||
#include "src/components/webapps/browser/banners/app_banner_manager.cc" | ||
#undef kChromeUIPasswordManagerHost |
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
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,15 @@ | ||
{ | ||
"short_name": "$i18n{siteTitle}", | ||
"name": "$i18n{pwaTitle}", | ||
"icons": [ | ||
{ | ||
"src": "/pwa_icon.svg", | ||
"type": "image/svg+xml", | ||
"sizes": "any" | ||
} | ||
], | ||
"start_url": "/?source=pwa", | ||
"id": "chrome://leo-ai/", | ||
"display": "standalone", | ||
"scope": "chrome://leo-ai/" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,6 @@ | ||
# Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
brave_components_webapps_browser_deps = [ "//brave/components/constants" ] |
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,12 @@ | ||
diff --git a/components/webapps/browser/BUILD.gn b/components/webapps/browser/BUILD.gn | ||
index 01e91deb89f88c9672374a1143a44d36d4fae465..f03c84afd64841599268a91ebd9d7d8c9e7900db 100644 | ||
--- a/components/webapps/browser/BUILD.gn | ||
+++ b/components/webapps/browser/BUILD.gn | ||
@@ -179,6 +179,7 @@ source_set("browser") { | ||
"//ui/gfx", | ||
] | ||
} | ||
+ import("//brave/components/webapps/browser/sources.gni") deps += brave_components_webapps_browser_deps | ||
} | ||
|
||
source_set("test_support") { |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we don't need this check as this
browser_tests
target is already filtered intest/BUILD.gn
?