-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirect users to extension store for inline install requests
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 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
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,42 @@ | ||
/* 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/extensions/brave_webstore_inline_installer.h" | ||
|
||
#include "base/strings/stringprintf.h" | ||
#include "base/values.h" | ||
#include "content/public/browser/web_contents.h" | ||
|
||
namespace extensions { | ||
|
||
// The URL to the webstore page for a specific app. | ||
const char kWebstoreUrlFormat[] = | ||
"https://chrome.google.com/webstore/detail/%s"; | ||
|
||
BraveWebstoreInlineInstaller::BraveWebstoreInlineInstaller( | ||
content::WebContents* web_contents, | ||
content::RenderFrameHost* host, | ||
const std::string& webstore_item_id, | ||
const GURL& requestor_url, | ||
const Callback& callback) | ||
: WebstoreInlineInstaller(web_contents, host, | ||
webstore_item_id, requestor_url, callback) { | ||
} | ||
|
||
BraveWebstoreInlineInstaller::~BraveWebstoreInlineInstaller() {} | ||
|
||
bool BraveWebstoreInlineInstaller::CheckInlineInstallPermitted( | ||
const base::DictionaryValue& webstore_data, | ||
std::string* error) const { | ||
// Open a URL corresponding to the extension ID. | ||
GURL url(base::StringPrintf(kWebstoreUrlFormat, id().c_str())); | ||
web_contents()->OpenURL(content::OpenURLParams( | ||
url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | ||
ui::PAGE_TRANSITION_LINK, false)); | ||
// Return an error so nothing else is processed | ||
*error = kInlineInstallNotSupportedKey; | ||
return false; | ||
} | ||
|
||
} // namespace extensions |
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,34 @@ | ||
/* 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_EXTENSIONS_BRAVE_WEBSTORE_INLINE_INSTALLER_H_ | ||
#define BRAVE_BROWSER_EXTENSIONS_BRAVE_WEBSTORE_INLINE_INSTALLER_H_ | ||
|
||
class BraveWebstoreBrowserTest; | ||
|
||
#include "chrome/browser/extensions/webstore_inline_installer.h" | ||
|
||
namespace extensions { | ||
|
||
extern const char kWebstoreUrlFormat[]; | ||
|
||
class BraveWebstoreInlineInstaller : public WebstoreInlineInstaller { | ||
public: | ||
BraveWebstoreInlineInstaller(content::WebContents* web_contents, | ||
content::RenderFrameHost* host, | ||
const std::string& webstore_item_id, | ||
const GURL& requestor_url, | ||
const Callback& callback); | ||
|
||
protected: | ||
~BraveWebstoreInlineInstaller() override; | ||
friend class ::BraveWebstoreBrowserTest; | ||
bool CheckInlineInstallPermitted(const base::DictionaryValue& webstore_data, | ||
std::string* error) const override; | ||
DISALLOW_IMPLICIT_CONSTRUCTORS(BraveWebstoreInlineInstaller); | ||
}; | ||
|
||
} // namespace extensions | ||
|
||
#endif // BRAVE_BROWSER_EXTENSIONS_BRAVE_WEBSTORE_INLINE_INSTALLER_H_ |
61 changes: 61 additions & 0 deletions
61
browser/extensions/brave_webstore_inline_installer_browsertest.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,61 @@ | ||
/* 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/extensions/brave_webstore_inline_installer.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/test/browser_test_utils.h" | ||
|
||
void OnInstalled(bool success, const std::string& error, | ||
extensions::webstore_install::Result result) { | ||
} | ||
|
||
class BraveWebstoreBrowserTest : public InProcessBrowserTest { | ||
public: | ||
void SetUpOnMainThread() override { | ||
InProcessBrowserTest::SetUpOnMainThread(); | ||
extension_id_ = "apdfllckaahabafndbhieahigkjlhalf"; | ||
} | ||
|
||
content::WebContents* contents() { | ||
return browser()->tab_strip_model()->GetActiveWebContents(); | ||
} | ||
|
||
bool NavigateToURLUntilLoadStop(const GURL& url) { | ||
ui_test_utils::NavigateToURL(browser(), url); | ||
return WaitForLoadStop(contents()); | ||
} | ||
|
||
int GetTabCount() const { | ||
return browser()->tab_strip_model()->count(); | ||
} | ||
|
||
bool CheckInlineInstallPermitted() { | ||
base::DictionaryValue webstore_data; | ||
std::string err; | ||
auto* installer = new extensions::BraveWebstoreInlineInstaller(contents(), | ||
contents()->GetMainFrame(), extension_id(), GURL(), | ||
base::Bind(&OnInstalled)); | ||
return installer->CheckInlineInstallPermitted(webstore_data, &err); | ||
} | ||
|
||
std::string extension_id() const { | ||
return extension_id_; | ||
} | ||
|
||
protected: | ||
std::string extension_id_; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(BraveWebstoreBrowserTest, | ||
RedirectsUserToChromeWebStore) { | ||
// Inline install should not be permitted. | ||
ASSERT_FALSE(CheckInlineInstallPermitted()); | ||
// Inline install should create a second tab for the web-contents. | ||
GURL url(base::StringPrintf(extensions::kWebstoreUrlFormat, | ||
extension_id().c_str())); | ||
ASSERT_EQ(GetTabCount(), 2); | ||
ASSERT_STREQ(browser()->tab_strip_model()->GetWebContentsAt(1)->GetVisibleURL().spec().c_str(), url.spec().c_str()); | ||
} |
23 changes: 23 additions & 0 deletions
23
patches/chrome-browser-extensions-webstore_inline_installer_factory.cc.patch
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 @@ | ||
diff --git a/chrome/browser/extensions/webstore_inline_installer_factory.cc b/chrome/browser/extensions/webstore_inline_installer_factory.cc | ||
index 39e0b83a7aa1b2b75fa412a762134a163e3ae0d7..b61d998422a012fb7bdbe623108cc16b211eac1e 100644 | ||
--- a/chrome/browser/extensions/webstore_inline_installer_factory.cc | ||
+++ b/chrome/browser/extensions/webstore_inline_installer_factory.cc | ||
@@ -6,6 +6,7 @@ | ||
|
||
#include <memory> | ||
|
||
+#include "brave/browser/extensions/brave_webstore_inline_installer.h" | ||
#include "chrome/browser/extensions/webstore_inline_installer.h" | ||
#include "content/public/browser/web_contents.h" | ||
|
||
@@ -17,8 +18,8 @@ WebstoreInlineInstaller* WebstoreInlineInstallerFactory::CreateInstaller( | ||
const std::string& webstore_item_id, | ||
const GURL& requestor_url, | ||
const WebstoreStandaloneInstaller::Callback& callback) { | ||
- return new WebstoreInlineInstaller(contents, host, webstore_item_id, | ||
- requestor_url, callback); | ||
+ return new BraveWebstoreInlineInstaller(contents, host, webstore_item_id, | ||
+ requestor_url, callback); | ||
} | ||
|
||
} // namespace extensions |
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