Chromium Code Reviews| Index: chrome/browser/usb/usb_tab_helper.cc |
| diff --git a/chrome/browser/usb/usb_tab_helper.cc b/chrome/browser/usb/usb_tab_helper.cc |
| index 539e8787286bf26323895048f0251cc35e68c3e7..055183e282a3837963c0598b3d4d0cbc5af107c3 100644 |
| --- a/chrome/browser/usb/usb_tab_helper.cc |
| +++ b/chrome/browser/usb/usb_tab_helper.cc |
| @@ -10,7 +10,11 @@ |
| #include "chrome/browser/ui/browser_finder.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/browser/usb/web_usb_permission_provider.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/common/content_features.h" |
| #include "device/usb/mojo/device_manager_impl.h" |
| +#include "mojo/public/cpp/bindings/message.h" |
| +#include "third_party/WebKit/public/platform/WebFeaturePolicy.h" |
| #if defined(OS_ANDROID) |
| #include "chrome/browser/android/usb/web_usb_chooser_service_android.h" |
| @@ -21,6 +25,15 @@ |
| using content::RenderFrameHost; |
| using content::WebContents; |
| +namespace { |
| + |
| +// The renderer performs its own feature policy checks so a request that gets |
| +// to the browser process indicates malicous code. |
| +const char kFeaturePolicyViolation[] = |
| + "Feature policy blocks access to WebUSB."; |
| + |
| +} // namespace |
| + |
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(UsbTabHelper); |
| struct FrameUsbServices { |
| @@ -50,6 +63,16 @@ void UsbTabHelper::CreateDeviceManager( |
| RenderFrameHost* render_frame_host, |
| mojo::InterfaceRequest<device::mojom::UsbDeviceManager> request) { |
| DCHECK(WebContents::FromRenderFrameHost(render_frame_host) == web_contents()); |
| + if (base::FeatureList::IsEnabled(features::kFeaturePolicy)) { |
|
iclelland.google
2017/05/02 14:42:52
Could this block, and the identical one below, be
Reilly Grant (use Gerrit)
2017/05/02 19:29:05
Done.
|
| + if (!render_frame_host->IsFeatureEnabled( |
| + blink::WebFeaturePolicyFeature::kUsb)) { |
| + mojo::ReportBadMessage(kFeaturePolicyViolation); |
| + return; |
| + } |
| + } else if (web_contents()->GetMainFrame() != render_frame_host) { |
| + mojo::ReportBadMessage(kFeaturePolicyViolation); |
| + return; |
| + } |
| device::usb::DeviceManagerImpl::Create( |
| GetPermissionProvider(render_frame_host), std::move(request)); |
| } |
| @@ -57,6 +80,17 @@ void UsbTabHelper::CreateDeviceManager( |
| void UsbTabHelper::CreateChooserService( |
| content::RenderFrameHost* render_frame_host, |
| mojo::InterfaceRequest<device::mojom::UsbChooserService> request) { |
| + DCHECK(WebContents::FromRenderFrameHost(render_frame_host) == web_contents()); |
| + if (base::FeatureList::IsEnabled(features::kFeaturePolicy)) { |
| + if (!render_frame_host->IsFeatureEnabled( |
| + blink::WebFeaturePolicyFeature::kUsb)) { |
| + mojo::ReportBadMessage(kFeaturePolicyViolation); |
| + return; |
| + } |
| + } else if (web_contents()->GetMainFrame() != render_frame_host) { |
| + mojo::ReportBadMessage(kFeaturePolicyViolation); |
| + return; |
| + } |
| GetChooserService(render_frame_host, std::move(request)); |
| } |