Commit 967bd538 authored by Karan Bhatia's avatar Karan Bhatia Committed by Commit Bot

Extensions: Delete WebRequestEventRouterDelegate.

This CL deletes WebRequestEventRouterDelegate and its implementation
ChromeExtensionWebRequestEventRouterDelegate. It's only method,
NotifyWebRequestWithheld is replaced with a method on the ExtensionsAPIClient.
This will make it easier to share the implementation with the Declarative Net
Request API.

This CL should have no behavior change.

BUG=809680

Change-Id: I696dbf8d3a34ae546342eb7ba98a1dd9e26fe3aa
Reviewed-on: https://chromium-review.googlesource.com/c/1256218
Commit-Queue: Karan Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595979}
parent 20b13dfd
......@@ -403,8 +403,6 @@ jumbo_static_library("extensions") {
"api/web_navigation/web_navigation_api_constants.h",
"api/web_navigation/web_navigation_api_helpers.cc",
"api/web_navigation/web_navigation_api_helpers.h",
"api/web_request/chrome_extension_web_request_event_router_delegate.cc",
"api/web_request/chrome_extension_web_request_event_router_delegate.h",
"api/web_view/chrome_web_view_internal_api.cc",
"api/web_view/chrome_web_view_internal_api.h",
"api/webrtc_audio_private/webrtc_audio_private_api.cc",
......
......@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/strings/string_util.h"
#include "base/task/post_task.h"
#include "build/build_config.h"
#include "chrome/browser/data_use_measurement/data_use_web_contents_observer.h"
#include "chrome/browser/extensions/api/chrome_device_permissions_prompt.h"
......@@ -23,8 +24,8 @@
#include "chrome/browser/extensions/api/networking_cast_private/chrome_networking_cast_private_delegate.h"
#include "chrome/browser/extensions/api/storage/managed_value_store_cache.h"
#include "chrome/browser/extensions/api/storage/sync_value_store_cache.h"
#include "chrome/browser/extensions/api/web_request/chrome_extension_web_request_event_router_delegate.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/guest_view/app_view/chrome_app_view_guest_delegate.h"
#include "chrome/browser/guest_view/chrome_guest_view_manager_delegate.h"
......@@ -39,9 +40,13 @@
#include "components/pdf/browser/pdf_web_contents_helper.h"
#include "components/signin/core/browser/signin_header_helper.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/api/virtual_keyboard_private/virtual_keyboard_delegate.h"
#include "extensions/browser/api/web_request/web_request_info.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
#include "google_apis/gaia/gaia_urls.h"
......@@ -139,6 +144,53 @@ bool ChromeExtensionsAPIClient::ShouldHideBrowserNetworkRequest(
return is_sensitive_request;
}
void ChromeExtensionsAPIClient::NotifyWebRequestWithheld(
int render_process_id,
int render_frame_id,
const ExtensionId& extension_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
auto notify_web_request_withheld_on_ui = [](int render_process_id,
int render_frame_id,
const ExtensionId& extension_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Track down the ExtensionActionRunner and the extension. Since this is
// asynchronous, we could hit a null anywhere along the path.
content::RenderFrameHost* rfh =
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
if (!rfh)
return;
// We don't count subframe blocked actions as yet, since there's no way to
// surface this to the user. Ignore these (which is also what we do for
// content scripts).
if (rfh->GetParent())
return;
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(rfh);
if (!web_contents)
return;
extensions::ExtensionActionRunner* runner =
extensions::ExtensionActionRunner::GetForWebContents(web_contents);
if (!runner)
return;
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext())
->enabled_extensions()
.GetByID(extension_id);
if (!extension)
return;
runner->OnWebRequestBlocked(extension);
};
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(std::move(notify_web_request_withheld_on_ui),
render_process_id, render_frame_id, extension_id));
}
AppViewGuestDelegate* ChromeExtensionsAPIClient::CreateAppViewGuestDelegate()
const {
return new ChromeAppViewGuestDelegate();
......@@ -173,11 +225,6 @@ WebViewPermissionHelperDelegate* ChromeExtensionsAPIClient::
return new ChromeWebViewPermissionHelperDelegate(web_view_permission_helper);
}
std::unique_ptr<WebRequestEventRouterDelegate>
ChromeExtensionsAPIClient::CreateWebRequestEventRouterDelegate() const {
return std::make_unique<ChromeExtensionWebRequestEventRouterDelegate>();
}
scoped_refptr<ContentRulesRegistry>
ChromeExtensionsAPIClient::CreateContentRulesRegistry(
content::BrowserContext* browser_context,
......
......@@ -34,6 +34,9 @@ class ChromeExtensionsAPIClient : public ExtensionsAPIClient {
const std::string& header_name) const override;
bool ShouldHideBrowserNetworkRequest(
const WebRequestInfo& request) const override;
void NotifyWebRequestWithheld(int render_process_id,
int render_frame_id,
const ExtensionId& extension_id) override;
AppViewGuestDelegate* CreateAppViewGuestDelegate() const override;
ExtensionOptionsGuestDelegate* CreateExtensionOptionsGuestDelegate(
ExtensionOptionsGuest* guest) const override;
......@@ -47,8 +50,6 @@ class ChromeExtensionsAPIClient : public ExtensionsAPIClient {
WebViewGuest* web_view_guest) const override;
WebViewPermissionHelperDelegate* CreateWebViewPermissionHelperDelegate(
WebViewPermissionHelper* web_view_permission_helper) const override;
std::unique_ptr<WebRequestEventRouterDelegate>
CreateWebRequestEventRouterDelegate() const override;
scoped_refptr<ContentRulesRegistry> CreateContentRulesRegistry(
content::BrowserContext* browser_context,
RulesCacheDelegate* cache_delegate) const override;
......
// Copyright (c) 2014 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 "chrome/browser/extensions/api/web_request/chrome_extension_web_request_event_router_delegate.h"
#include "base/task/post_task.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
namespace {
void NotifyWebRequestWithheldOnUI(int render_process_id,
int render_frame_id,
const std::string& extension_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Track down the ExtensionActionRunner and the extension. Since this is
// asynchronous, we could hit a null anywhere along the path.
content::RenderFrameHost* rfh =
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
if (!rfh)
return;
// We don't count subframe blocked actions as yet, since there's no way to
// surface this to the user. Ignore these (which is also what we do for
// content scripts).
if (rfh->GetParent())
return;
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(rfh);
if (!web_contents)
return;
extensions::ExtensionActionRunner* runner =
extensions::ExtensionActionRunner::GetForWebContents(web_contents);
if (!runner)
return;
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext())
->enabled_extensions()
.GetByID(extension_id);
if (!extension)
return;
runner->OnWebRequestBlocked(extension);
}
} // namespace
ChromeExtensionWebRequestEventRouterDelegate::
ChromeExtensionWebRequestEventRouterDelegate() {
}
ChromeExtensionWebRequestEventRouterDelegate::
~ChromeExtensionWebRequestEventRouterDelegate() {
}
void ChromeExtensionWebRequestEventRouterDelegate::NotifyWebRequestWithheld(
int render_process_id,
int render_frame_id,
const std::string& extension_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&NotifyWebRequestWithheldOnUI, render_process_id,
render_frame_id, extension_id));
}
// Copyright 2014 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 CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_CHROME_EXTENSION_WEB_REQUEST_EVENT_ROUTER_DELEGATE_H_
#define CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_CHROME_EXTENSION_WEB_REQUEST_EVENT_ROUTER_DELEGATE_H_
#include <memory>
#include "extensions/browser/api/web_request/web_request_event_router_delegate.h"
class ChromeExtensionWebRequestEventRouterDelegate
: public extensions::WebRequestEventRouterDelegate {
public:
ChromeExtensionWebRequestEventRouterDelegate();
~ChromeExtensionWebRequestEventRouterDelegate() override;
void NotifyWebRequestWithheld(int render_process_id,
int render_frame_id,
const std::string& extension_id) override;
};
#endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_CHROME_EXTENSION_WEB_REQUEST_EVENT_ROUTER_DELEGATE_H_
......@@ -7,7 +7,6 @@
#include "base/logging.h"
#include "extensions/browser/api/device_permissions_prompt.h"
#include "extensions/browser/api/virtual_keyboard_private/virtual_keyboard_delegate.h"
#include "extensions/browser/api/web_request/web_request_event_router_delegate.h"
#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h"
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h"
#include "extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.h"
......@@ -48,6 +47,11 @@ bool ExtensionsAPIClient::ShouldHideBrowserNetworkRequest(
return false;
}
void ExtensionsAPIClient::NotifyWebRequestWithheld(
int render_process_id,
int render_frame_id,
const ExtensionId& extension_id) {}
AppViewGuestDelegate* ExtensionsAPIClient::CreateAppViewGuestDelegate() const {
return NULL;
}
......@@ -81,11 +85,6 @@ WebViewPermissionHelperDelegate* ExtensionsAPIClient::
return new WebViewPermissionHelperDelegate(web_view_permission_helper);
}
std::unique_ptr<WebRequestEventRouterDelegate>
ExtensionsAPIClient::CreateWebRequestEventRouterDelegate() const {
return nullptr;
}
scoped_refptr<ContentRulesRegistry>
ExtensionsAPIClient::CreateContentRulesRegistry(
content::BrowserContext* browser_context,
......
......@@ -15,6 +15,7 @@
#include "extensions/browser/api/declarative_content/content_rules_registry.h"
#include "extensions/browser/api/storage/settings_namespace.h"
#include "extensions/common/api/clipboard.h"
#include "extensions/common/extension_id.h"
class GURL;
......@@ -54,7 +55,6 @@ class SettingsObserver;
class ValueStoreCache;
class ValueStoreFactory;
class VirtualKeyboardDelegate;
class WebRequestEventRouterDelegate;
struct WebRequestInfo;
class WebViewGuest;
class WebViewGuestDelegate;
......@@ -100,6 +100,12 @@ class ExtensionsAPIClient {
virtual bool ShouldHideBrowserNetworkRequest(
const WebRequestInfo& request) const;
// Notifies that an extension failed to act on a network request because the
// access to request was withheld.
virtual void NotifyWebRequestWithheld(int render_process_id,
int render_frame_id,
const ExtensionId& extension_id);
// Creates the AppViewGuestDelegate.
virtual AppViewGuestDelegate* CreateAppViewGuestDelegate() const;
......@@ -127,10 +133,6 @@ class ExtensionsAPIClient {
CreateWebViewPermissionHelperDelegate(
WebViewPermissionHelper* web_view_permission_helper) const;
// Creates a delegate for WebRequestEventRouter.
virtual std::unique_ptr<WebRequestEventRouterDelegate>
CreateWebRequestEventRouterDelegate() const;
// TODO(wjmaclean): Remove this when (if) ContentRulesRegistry code moves
// to extensions/browser/api.
virtual scoped_refptr<ContentRulesRegistry> CreateContentRulesRegistry(
......
......@@ -21,7 +21,6 @@ source_set("web_request") {
"web_request_api_helpers.h",
"web_request_event_details.cc",
"web_request_event_details.h",
"web_request_event_router_delegate.h",
"web_request_info.cc",
"web_request_info.h",
"web_request_permissions.cc",
......
......@@ -50,7 +50,6 @@
#include "extensions/browser/api/web_request/web_request_api_constants.h"
#include "extensions/browser/api/web_request/web_request_api_helpers.h"
#include "extensions/browser/api/web_request/web_request_event_details.h"
#include "extensions/browser/api/web_request/web_request_event_router_delegate.h"
#include "extensions/browser/api/web_request/web_request_info.h"
#include "extensions/browser/api/web_request/web_request_proxying_url_loader_factory.h"
#include "extensions/browser/api/web_request/web_request_proxying_websocket.h"
......@@ -897,9 +896,6 @@ ExtensionWebRequestEventRouter* ExtensionWebRequestEventRouter::GetInstance() {
ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter()
: request_time_tracker_(new ExtensionWebRequestTimeTracker) {
DCHECK(ExtensionsAPIClient::Get());
web_request_event_router_delegate_ =
ExtensionsAPIClient::Get()->CreateWebRequestEventRouterDelegate();
}
void ExtensionWebRequestEventRouter::RegisterRulesRegistry(
......@@ -1743,9 +1739,9 @@ void ExtensionWebRequestEventRouter::GetMatchingListenersImpl(
request->initiator);
if (access != PermissionsData::PageAccess::kAllowed) {
if (access == PermissionsData::PageAccess::kWithheld &&
web_request_event_router_delegate_) {
web_request_event_router_delegate_->NotifyWebRequestWithheld(
if (access == PermissionsData::PageAccess::kWithheld) {
DCHECK(ExtensionsAPIClient::Get());
ExtensionsAPIClient::Get()->NotifyWebRequestWithheld(
request->render_process_id, request->frame_id,
listener->id.extension_id);
}
......
......@@ -64,7 +64,6 @@ enum class WebRequestResourceType : uint8_t;
class InfoMap;
class WebRequestEventDetails;
class WebRequestEventRouterDelegate;
struct WebRequestInfo;
class WebRequestRulesRegistry;
......@@ -705,9 +704,6 @@ class ExtensionWebRequestEventRouter {
std::map<RulesRegistryKey,
scoped_refptr<extensions::WebRequestRulesRegistry> > rules_registries_;
std::unique_ptr<extensions::WebRequestEventRouterDelegate>
web_request_event_router_delegate_;
DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter);
};
......
// Copyright 2014 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_API_WEB_REQUEST_WEB_REQUEST_EVENT_ROUTER_DELEGATE_H_
#define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_EVENT_ROUTER_DELEGATE_H_
#include <string>
namespace extensions {
// A delegate class of WebRequestApi that are not a part of chrome.
class WebRequestEventRouterDelegate {
public:
virtual ~WebRequestEventRouterDelegate() {}
// Notifies that a webRequest event that normally would be forwarded to a
// listener was instead blocked because of withheld permissions.
virtual void NotifyWebRequestWithheld(int render_process_id,
int render_frame_id,
const std::string& extension_id) = 0;
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_EVENT_ROUTER_DELEGATE_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