Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Unified Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc

Issue 2898383002: [Extensions] Make Event::restrict_to_browser_context const. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc
index e80814a4ae6fdb9d0f007f712bc6b0176ed5d010..d79229f5cbcc5331a870d83a0cc02db088de53b4 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc
@@ -55,7 +55,6 @@ void DispatchEvent(content::BrowserContext* browser_context,
Profile* profile = Profile::FromBrowserContext(browser_context);
EventRouter* event_router = EventRouter::Get(profile);
if (profile && event_router) {
- event->restrict_to_browser_context = profile;
Devlin 2017/05/24 16:08:18 maybe substitute this with DCHECK_EQ(profile, even
lazyboy 2017/05/24 19:19:33 Done.
event->filter_info = info;
event_router->BroadcastEvent(std::move(event));
}
@@ -78,16 +77,14 @@ std::unique_ptr<Event> CreateOnBeforeNavigateEvent(
ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle);
details.time_stamp = MilliSecondsFromTime(base::Time::Now());
- std::unique_ptr<Event> event(
- new Event(events::WEB_NAVIGATION_ON_BEFORE_NAVIGATE,
- web_navigation::OnBeforeNavigate::kEventName,
- web_navigation::OnBeforeNavigate::Create(details)));
+ auto event = base::MakeUnique<Event>(
+ events::WEB_NAVIGATION_ON_BEFORE_NAVIGATE,
+ web_navigation::OnBeforeNavigate::kEventName,
+ web_navigation::OnBeforeNavigate::Create(details),
+ navigation_handle->GetWebContents()->GetBrowserContext());
EventFilteringInfo info;
info.SetURL(navigation_handle->GetURL());
-
- event->restrict_to_browser_context =
- navigation_handle->GetWebContents()->GetBrowserContext();
event->filter_info = info;
return event;
@@ -138,10 +135,11 @@ void DispatchOnCommitted(events::HistogramValue histogram_value,
dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args->Append(std::move(dict));
- std::unique_ptr<Event> event(
- new Event(histogram_value, event_name, std::move(args)));
- DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(),
- std::move(event), url);
+ content::BrowserContext* context =
+ navigation_handle->GetWebContents()->GetBrowserContext();
+ auto event = base::MakeUnique<Event>(histogram_value, event_name,
+ std::move(args), context);
+ DispatchEvent(context, std::move(event), url);
}
// Constructs and dispatches an onDOMContentLoaded event.
@@ -203,10 +201,11 @@ void DispatchOnCreatedNavigationTarget(
details.tab_id = ExtensionTabUtil::GetTabId(target_web_contents);
details.time_stamp = MilliSecondsFromTime(base::Time::Now());
- std::unique_ptr<Event> event(
- new Event(events::WEB_NAVIGATION_ON_CREATED_NAVIGATION_TARGET,
- web_navigation::OnCreatedNavigationTarget::kEventName,
- web_navigation::OnCreatedNavigationTarget::Create(details)));
+ auto event = base::MakeUnique<Event>(
+ events::WEB_NAVIGATION_ON_CREATED_NAVIGATION_TARGET,
+ web_navigation::OnCreatedNavigationTarget::kEventName,
+ web_navigation::OnCreatedNavigationTarget::Create(details),
+ browser_context);
DispatchEvent(browser_context, std::move(event), target_url);
// If the target WebContents already received the onBeforeNavigate event,
@@ -229,10 +228,11 @@ void DispatchOnErrorOccurred(content::WebContents* web_contents,
details.error = net::ErrorToString(error_code);
details.time_stamp = MilliSecondsFromTime(base::Time::Now());
- std::unique_ptr<Event> event(
- new Event(events::WEB_NAVIGATION_ON_ERROR_OCCURRED,
- web_navigation::OnErrorOccurred::kEventName,
- web_navigation::OnErrorOccurred::Create(details)));
+ auto event =
+ base::MakeUnique<Event>(events::WEB_NAVIGATION_ON_ERROR_OCCURRED,
+ web_navigation::OnErrorOccurred::kEventName,
+ web_navigation::OnErrorOccurred::Create(details),
+ web_contents->GetBrowserContext());
DispatchEvent(web_contents->GetBrowserContext(), std::move(event), url);
Devlin 2017/05/24 16:08:19 nit: cache context
lazyboy 2017/05/24 19:19:32 Done.
}
@@ -248,12 +248,13 @@ void DispatchOnErrorOccurred(content::NavigationHandle* navigation_handle) {
: net::ErrorToString(net::ERR_ABORTED);
details.time_stamp = MilliSecondsFromTime(base::Time::Now());
- std::unique_ptr<Event> event(
- new Event(events::WEB_NAVIGATION_ON_ERROR_OCCURRED,
- web_navigation::OnErrorOccurred::kEventName,
- web_navigation::OnErrorOccurred::Create(details)));
- DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(),
- std::move(event), navigation_handle->GetURL());
+ content::BrowserContext* context =
+ navigation_handle->GetWebContents()->GetBrowserContext();
+ auto event = base::MakeUnique<Event>(
+ events::WEB_NAVIGATION_ON_ERROR_OCCURRED,
+ web_navigation::OnErrorOccurred::kEventName,
+ web_navigation::OnErrorOccurred::Create(details), context);
+ DispatchEvent(context, std::move(event), navigation_handle->GetURL());
}
// Constructs and dispatches an onTabReplaced event.
@@ -266,10 +267,10 @@ void DispatchOnTabReplaced(
details.tab_id = ExtensionTabUtil::GetTabId(new_web_contents);
details.time_stamp = MilliSecondsFromTime(base::Time::Now());
- std::unique_ptr<Event> event(
- new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED,
- web_navigation::OnTabReplaced::kEventName,
- web_navigation::OnTabReplaced::Create(details)));
+ auto event = base::MakeUnique<Event>(
+ events::WEB_NAVIGATION_ON_TAB_REPLACED,
+ web_navigation::OnTabReplaced::kEventName,
+ web_navigation::OnTabReplaced::Create(details), browser_context);
DispatchEvent(browser_context, std::move(event), GURL());
}

Powered by Google App Engine
This is Rietveld 408576698