Commit 037e1f80 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] Remove GetAssociatedWebContents() calls from webstore APIs

The ExtensionFunction::GetAssociatedWebContentsDeprecated() method is
unpredictable and can return surprising values in certain circumstances.
It is deprecated and should be removed to ensure that callers are using
the WebContents they expect.

Update the webstore APIs (dashboardPrivate, inlineInstallPrivate,
webstorePrivate, and webstoreWidgetPrivate) to use
GetSenderWebContents() instead.

Bug: 461394

Change-Id: I0c42797004c62218ab8de139ce58a175f796a50a
Reviewed-on: https://chromium-review.googlesource.com/1019567Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555834}
parent f4db7c47
......@@ -124,7 +124,7 @@ void DashboardPrivateShowPermissionPromptForDelegatedInstallFunction::
return;
}
content::WebContents* web_contents = GetAssociatedWebContentsDeprecated();
content::WebContents* web_contents = GetSenderWebContents();
if (!web_contents) {
// The browser window has gone away.
Respond(BuildResponse(api::dashboard_private::RESULT_USER_CANCELLED,
......
......@@ -14,6 +14,7 @@
#include "components/crx_file/id_util.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/view_type_utils.h"
namespace extensions {
......@@ -106,10 +107,11 @@ InlineInstallPrivateInstallFunction::Run() {
return RespondNow(CreateResponse("Must be called with a user gesture",
webstore_install::NOT_PERMITTED));
content::WebContents* web_contents = GetAssociatedWebContentsDeprecated();
if (!web_contents)
content::WebContents* web_contents = GetSenderWebContents();
if (!web_contents || GetViewType(web_contents) != VIEW_TYPE_APP_WINDOW) {
return RespondNow(CreateResponse("Must be called from a foreground page",
webstore_install::NOT_PERMITTED));
}
ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context());
if (registry->GetExtensionById(params->id, ExtensionRegistry::EVERYTHING))
......
......@@ -36,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"
......@@ -309,7 +310,7 @@ void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess(
return;
}
content::WebContents* web_contents = GetAssociatedWebContentsDeprecated();
content::WebContents* web_contents = GetSenderWebContents();
if (!web_contents) {
// The browser window has gone away.
Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED,
......@@ -445,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));
......@@ -454,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_.GetAssociatedWebContentsDeprecated(), params->expected_id,
chrome_details_.GetProfile(), this, web_contents, params->expected_id,
std::move(approval_), WebstoreInstaller::INSTALL_SOURCE_OTHER);
installer->Start();
......
......@@ -42,6 +42,7 @@ AppInstaller::AppInstaller(content::WebContents* web_contents,
callback_(callback),
web_contents_(web_contents),
web_contents_observer_(new WebContentsObserver(web_contents, this)) {
DCHECK(web_contents_);
}
AppInstaller::~AppInstaller() {
......
......@@ -14,6 +14,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/webstore_widget_private.h"
#include "chrome/grit/generated_resources.h"
#include "extensions/browser/extension_function_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h"
......@@ -90,9 +91,14 @@ WebstoreWidgetPrivateInstallWebstoreItemFunction::Run() {
&WebstoreWidgetPrivateInstallWebstoreItemFunction::OnInstallComplete,
this);
content::WebContents* web_contents = GetSenderWebContents();
if (!web_contents) {
return RespondNow(
Error(function_constants::kCouldNotFindSenderWebContents));
}
scoped_refptr<webstore_widget::AppInstaller> installer(
new webstore_widget::AppInstaller(
GetAssociatedWebContentsDeprecated(), params->item_id,
web_contents, params->item_id,
Profile::FromBrowserContext(browser_context()),
params->silent_installation, callback));
// installer will be AddRef()'d in BeginInstall().
......
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