Commit 8f5f1ff4 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] Remove GetAssociatedWebContents() calls from usb API

The ExtensionFunction::GetAssociatedWebContents() 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 USB API to use GetSenderWebContents() instead.

Bug: 461394

Change-Id: I284a4efc98d878fff0ad48714177467004510d6b
Reviewed-on: https://chromium-review.googlesource.com/1018532Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552250}
parent cf899af2
......@@ -127,6 +127,8 @@ jumbo_source_set("browser_sources") {
"extension_file_task_runner.h",
"extension_function.cc",
"extension_function.h",
"extension_function_constants.cc",
"extension_function_constants.h",
"extension_function_dispatcher.cc",
"extension_function_dispatcher.h",
"extension_function_registry.cc",
......
......@@ -26,6 +26,7 @@
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/api/usb/usb_device_resource.h"
#include "extensions/browser/api/usb/usb_guid_map.h"
#include "extensions/browser/extension_function_constants.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/api/usb.h"
#include "extensions/common/permissions/permissions_data.h"
......@@ -668,8 +669,14 @@ ExtensionFunction::ResponseAction UsbGetUserSelectedDevicesFunction::Run() {
filters.push_back(ConvertDeviceFilter(filter));
}
prompt_ = ExtensionsAPIClient::Get()->CreateDevicePermissionsPrompt(
GetAssociatedWebContentsDeprecated());
content::WebContents* web_contents = GetSenderWebContents();
if (!web_contents) {
return RespondNow(
Error(function_constants::kCouldNotFindSenderWebContents));
}
prompt_ =
ExtensionsAPIClient::Get()->CreateDevicePermissionsPrompt(web_contents);
if (!prompt_) {
return RespondNow(Error(kErrorNotSupported));
}
......
// Copyright 2018 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 "extensions/browser/extension_function_constants.h"
namespace extensions {
namespace function_constants {
// An error thrown when determining the WebContents that sent the request for
// the API call failed. Note: typically, this would only happen if the
// WebContents disappeared after the API call (i.e., the caller is no longer
// alive, such as a tab closing or background page suspending). For this reason,
// the error is not overly helpful. However, it is important that we have a
// specific error message in order to track down any peculiar cases.
const char kCouldNotFindSenderWebContents[] =
"Could not find sender WebContents.";
} // namespace function_constants
} // namespace extensions
// Copyright 2018 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 EXTENSIONS_BROWSER_EXTENSION_FUNCTION_CONSTANTS_H_
#define EXTENSIONS_BROWSER_EXTENSION_FUNCTION_CONSTANTS_H_
namespace extensions {
namespace function_constants {
// TODO(devlin): Move ExtensionFunction::kUnknownErrorDoNotUse here.
extern const char kCouldNotFindSenderWebContents[];
} // namespace function_constants
} // namespace extensions
#endif // EXTENSIONS_BROWSER_EXTENSION_FUNCTION_CONSTANTS_H_
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