Skip to content

Commit

Permalink
Extensions: Delete WebRequestEventRouterDelegate.
Browse files Browse the repository at this point in the history
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: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595979}
  • Loading branch information
Karan Bhatia authored and Commit Bot committed Oct 2, 2018
1 parent 20b13df commit 967bd53
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 152 deletions.
2 changes: 0 additions & 2 deletions chrome/browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
59 changes: 53 additions & 6 deletions chrome/browser/extensions/api/chrome_extensions_api_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/extensions/api/chrome_extensions_api_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

This file was deleted.

This file was deleted.

11 changes: 5 additions & 6 deletions extensions/browser/api/extensions_api_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions extensions/browser/api/extensions_api_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -54,7 +55,6 @@ class SettingsObserver;
class ValueStoreCache;
class ValueStoreFactory;
class VirtualKeyboardDelegate;
class WebRequestEventRouterDelegate;
struct WebRequestInfo;
class WebViewGuest;
class WebViewGuestDelegate;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion extensions/browser/api/web_request/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions extensions/browser/api/web_request/web_request_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions extensions/browser/api/web_request/web_request_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ enum class WebRequestResourceType : uint8_t;

class InfoMap;
class WebRequestEventDetails;
class WebRequestEventRouterDelegate;
struct WebRequestInfo;
class WebRequestRulesRegistry;

Expand Down Expand Up @@ -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);
};

Expand Down

This file was deleted.

0 comments on commit 967bd53

Please sign in to comment.