Skip to content

Commit

Permalink
[M118-Extensions] Don't update access if site permissions aren't allowed
Browse files Browse the repository at this point in the history
Page access options in the extension's context menu should only be
enabled when the extension site permissions can be changed. However, sometimes the command still gets invoked (crbug.com/1468151). Thus, we
exit early to prevent any crashes.

(cherry picked from commit bdf5332)

Bug: 1468151
Change-Id: I6549e9e95008873a2175a46d583c118ba92913f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4874994
Commit-Queue: Emilia Paz <emiliapaz@chromium.org>
Reviewed-by: David Bertoni <dbertoni@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1198540}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4943086
Auto-Submit: Emilia Paz <emiliapaz@chromium.org>
Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/branch-heads/5993@{#1309}
Cr-Branched-From: 5113507-refs/heads/main@{#1192594}
  • Loading branch information
emilia-paz authored and Chromium LUCI CQ committed Oct 16, 2023
1 parent eb9ece8 commit 2b8b577
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion chrome/browser/extensions/extension_context_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,24 @@ void ExtensionContextMenuModel::ExecuteCommand(int command_id,
case PAGE_ACCESS_RUN_ON_CLICK:
case PAGE_ACCESS_RUN_ON_SITE:
case PAGE_ACCESS_RUN_ON_ALL_SITES: {
// If the web contents have navigated to a different origin, do nothing.
// Do nothing if the web contents have navigated to a different origin.
auto* web_contents = GetActiveWebContents();
if (!web_contents ||
!origin_.IsSameOriginWith(web_contents->GetLastCommittedURL())) {
return;
}

LogPageAccessAction(command_id);

// Do nothing if the extension cannot have its site permissions updated.
// Page access option should only be enabled when the extension site
// permissions can be changed. However, sometimes the command still gets
// invoked (crbug.com/1468151). Thus, we exit early to prevent any
// crashes.
if (!PermissionsManager::Get(profile_)->CanAffectExtension(*extension)) {
return;
}

SitePermissionsHelper permissions(profile_);
permissions.UpdateSiteAccess(*extension, web_contents,
CommandIdToSiteAccess(command_id));
Expand Down

0 comments on commit 2b8b577

Please sign in to comment.