summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc')
-rw-r--r--chromium/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc75
1 files changed, 72 insertions, 3 deletions
diff --git a/chromium/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc b/chromium/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
index 3a33fe8e797..6d06524c940 100644
--- a/chromium/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
+++ b/chromium/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
@@ -8,6 +8,7 @@
#include <utility>
#include <vector>
+#include "base/base64.h"
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/macros.h"
@@ -17,11 +18,14 @@
#include "base/values.h"
#include "base/version.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/install_tracker.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.h"
+#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/app_list/app_list_util.h"
#include "chrome/common/extensions/extension_constants.h"
@@ -32,6 +36,7 @@
#include "content/public/browser/gpu_feature_checker.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
+#include "extensions/browser/extension_function_constants.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
@@ -44,6 +49,8 @@
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#endif
+using safe_browsing::SafeBrowsingNavigationObserverManager;
+
namespace extensions {
namespace BeginInstallWithManifest3 =
@@ -60,6 +67,7 @@ namespace IsPendingCustodianApproval =
namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode;
namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp;
namespace SetStoreLogin = api::webstore_private::SetStoreLogin;
+namespace GetReferrerChain = api::webstore_private::GetReferrerChain;
namespace {
@@ -140,6 +148,9 @@ const char kIncognitoError[] =
const char kEphemeralAppLaunchingNotSupported[] =
"Ephemeral launching of apps is no longer supported.";
+// The number of user gestures to trace back for the referrer chain.
+const int kExtensionReferrerUserGestureLimit = 2;
+
WebstoreInstaller::Delegate* test_webstore_installer_delegate = nullptr;
// We allow the web store to set a string containing login information when a
@@ -299,7 +310,7 @@ void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess(
return;
}
- content::WebContents* web_contents = GetAssociatedWebContents();
+ content::WebContents* web_contents = GetSenderWebContents();
if (!web_contents) {
// The browser window has gone away.
Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED,
@@ -435,6 +446,12 @@ WebstorePrivateCompleteInstallFunction::Run() {
params->expected_id));
}
+ content::WebContents* web_contents = GetSenderWebContents();
+ if (!web_contents) {
+ return RespondNow(
+ Error(function_constants::kCouldNotFindSenderWebContents));
+ }
+
scoped_active_install_.reset(new ScopedActiveInstall(
InstallTracker::Get(browser_context()), params->expected_id));
@@ -444,8 +461,7 @@ WebstorePrivateCompleteInstallFunction::Run() {
// The extension will install through the normal extension install flow, but
// the whitelist entry will bypass the normal permissions install dialog.
scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller(
- chrome_details_.GetProfile(), this,
- chrome_details_.GetAssociatedWebContents(), params->expected_id,
+ chrome_details_.GetProfile(), this, web_contents, params->expected_id,
std::move(approval_), WebstoreInstaller::INSTALL_SOURCE_OTHER);
installer->Start();
@@ -657,4 +673,57 @@ WebstorePrivateIsPendingCustodianApprovalFunction::BuildResponse(bool result) {
return OneArgument(std::make_unique<base::Value>(result));
}
+WebstorePrivateGetReferrerChainFunction::
+ WebstorePrivateGetReferrerChainFunction()
+ : chrome_details_(this) {}
+
+WebstorePrivateGetReferrerChainFunction::
+ ~WebstorePrivateGetReferrerChainFunction() {}
+
+ExtensionFunction::ResponseAction
+WebstorePrivateGetReferrerChainFunction::Run() {
+ Profile* profile = chrome_details_.GetProfile();
+ if (!SafeBrowsingNavigationObserverManager::IsEnabledAndReady(profile))
+ return RespondNow(ArgumentList(GetReferrerChain::Results::Create("")));
+
+ content::WebContents* web_contents = GetSenderWebContents();
+ if (!web_contents) {
+ return RespondNow(ErrorWithArguments(GetReferrerChain::Results::Create(""),
+ kUserCancelledError));
+ }
+
+ scoped_refptr<SafeBrowsingNavigationObserverManager>
+ navigation_observer_manager = g_browser_process->safe_browsing_service()
+ ->navigation_observer_manager();
+
+ safe_browsing::ReferrerChain referrer_chain;
+ SafeBrowsingNavigationObserverManager::AttributionResult result =
+ navigation_observer_manager->IdentifyReferrerChainByWebContents(
+ web_contents, kExtensionReferrerUserGestureLimit, &referrer_chain);
+
+ // If the referrer chain is incomplete we'll append the most recent
+ // navigations to referrer chain for diagnostic purposes. This only happens if
+ // the user is not in incognito mode and has opted into extended reporting or
+ // Scout reporting. Otherwise, |CountOfRecentNavigationsToAppend| returns 0.
+ int recent_navigations_to_collect =
+ SafeBrowsingNavigationObserverManager::CountOfRecentNavigationsToAppend(
+ *profile, result);
+ if (recent_navigations_to_collect > 0) {
+ navigation_observer_manager->AppendRecentNavigations(
+ recent_navigations_to_collect, &referrer_chain);
+ }
+
+ safe_browsing::ExtensionWebStoreInstallRequest request;
+ request.mutable_referrer_chain()->Swap(&referrer_chain);
+ request.mutable_referrer_chain_options()->set_recent_navigations_to_collect(
+ recent_navigations_to_collect);
+
+ std::string serialized_referrer_proto = request.SerializeAsString();
+ // Base64 encode the proto to avoid issues with base::Value rejecting strings
+ // which are not valid UTF8.
+ base::Base64Encode(serialized_referrer_proto, &serialized_referrer_proto);
+ return RespondNow(ArgumentList(
+ GetReferrerChain::Results::Create(serialized_referrer_proto)));
+}
+
} // namespace extensions