Add "Inspect Element" to text selection dropdown menu
This CL adds the "Inspect Element" option to the text selection dropdown
menu on Android (triggered via mouse right-click on selected text). It
modifies ChromeSelectionDropdownMenuDelegate to evaluate if DevTools is
enabled and injects the inspect item into the ui::MenuModel, intercepting
the click to launch DevToolsWindow.
To make the label string available in C++ on Android, this CL also moves
IDS_CONTENT_CONTEXT_INSPECTELEMENT outside the `not is_android`
conditional block in generated_resources.grd.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Jenna could you also take a look since I'm not actually that familiar with this code?
class ChromeSelectionDropdownMenuModel : public ui::SimpleMenuModel,Should we override the other methods for this too?
Can we have just one implementation and share common logic and just wrap the extension related things in the buildflag?
std::unique_ptr<ChromeSelectionDropdownMenuModel> model =
std::make_unique<ChromeSelectionDropdownMenuModel>(render_frame_host,
params);
model->PopulateModel();
if (is_devtools_allowed) {
if (model->GetItemCount() > 0) {
model->AddSeparator(ui::NORMAL_SEPARATOR);
}
model->AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTELEMENT,
IDS_CONTENT_CONTEXT_INSPECTELEMENT);
}
return std::move(model);
#else
if (!is_devtools_allowed) {
return nullptr;
}
std::unique_ptr<ChromeSelectionDropdownMenuModel> model =
std::make_unique<ChromeSelectionDropdownMenuModel>(render_frame_host,
params);
model->AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTELEMENT,
IDS_CONTENT_CONTEXT_INSPECTELEMENT);
return std::move(model);
#endifAgain this is mostly duplicated. Combining it might be nicer?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
<message name="IDS_CONTENT_CONTEXT_INSPECTELEMENT" desc="The name of the Inspect Element command in the content area context menu">I think we don't support & for accelerators in Android, and generally Clank has its own strings files instead of using strings in chrome/app.
Consider adding a dedicated Android string in chrome/browser/ui/android/strings/android_chrome_strings.grd. C++ can still access it by including the generated header.
raw_ptr<content::RenderFrameHost> rfh_ptr_;ExtensionMenuModel already stores the RenderFrameHost and ContextMenuParams. While they are private in the base class, re-defining them here leads to redundant storage and potential confusion. If you unify the classes as suggested above, you might still need them for the non-extension case, but consider naming them consistently.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
<message name="IDS_CONTENT_CONTEXT_INSPECTELEMENT" desc="The name of the Inspect Element command in the content area context menu">I think we don't support & for accelerators in Android, and generally Clank has its own strings files instead of using strings in chrome/app.
Consider adding a dedicated Android string in chrome/browser/ui/android/strings/android_chrome_strings.grd. C++ can still access it by including the generated header.
I see, thanks!
ExtensionMenuModel already stores the RenderFrameHost and ContextMenuParams. While they are private in the base class, re-defining them here leads to redundant storage and potential confusion. If you unify the classes as suggested above, you might still need them for the non-extension case, but consider naming them consistently.
sure, unified both implementations into a single `ChromeSelectionDropdownMenuModel` class and rename the parameters
class ChromeSelectionDropdownMenuModel : public ui::SimpleMenuModel,Should we override the other methods for this too?
Can we have just one implementation and share common logic and just wrap the extension related things in the buildflag?
sure, combined both model into a single `ChromeSelectionDropdownMenuModel` class and used a preprocessor guards to eliminate the duplicate structures.
std::unique_ptr<ChromeSelectionDropdownMenuModel> model =
std::make_unique<ChromeSelectionDropdownMenuModel>(render_frame_host,
params);
model->PopulateModel();
if (is_devtools_allowed) {
if (model->GetItemCount() > 0) {
model->AddSeparator(ui::NORMAL_SEPARATOR);
}
model->AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTELEMENT,
IDS_CONTENT_CONTEXT_INSPECTELEMENT);
}
return std::move(model);
#else
if (!is_devtools_allowed) {
return nullptr;
}
std::unique_ptr<ChromeSelectionDropdownMenuModel> model =
std::make_unique<ChromeSelectionDropdownMenuModel>(render_frame_host,
params);
model->AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTELEMENT,
IDS_CONTENT_CONTEXT_INSPECTELEMENT);
return std::move(model);
#endifAgain this is mostly duplicated. Combining it might be nicer?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
To make the label string available in C++ on Android, this CL also moves
IDS_CONTENT_CONTEXT_INSPECTELEMENT outside the `not is_android`
conditional block in generated_resources.grd.I think this is stale?
if (!is_devtools_allowed
#if !BUILDFLAG(ENABLE_DESKTOP_ANDROID_EXTENSIONS)
) {
return nullptr;
}
#else
) {
}
#endifI think this is more readable?
```suggestion
#if !BUILDFLAG(ENABLE_DESKTOP_ANDROID_EXTENSIONS)
if (!is_devtools_allowed) {
return nullptr;
}
#endif
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
<message name="IDS_INSPECT_ELEMENT_ANDROID" desc="The name of the Inspect Element command in the context menu for Android.">The commit message says this CL moves `IDS_CONTENT_CONTEXT_INSPECTELEMENT`, but it actually adds a new `IDS_INSPECT_ELEMENT_ANDROID`. Please update the commit message to be accurate.
return true;Would it be safer to return false here? I'm not sure when we expect to hit this code block and what happens based on true / false returns.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
To make the label string available in C++ on Android, this CL also moves
IDS_CONTENT_CONTEXT_INSPECTELEMENT outside the `not is_android`
conditional block in generated_resources.grd.I think this is stale?
thanks! updated msg
<message name="IDS_INSPECT_ELEMENT_ANDROID" desc="The name of the Inspect Element command in the context menu for Android.">The commit message says this CL moves `IDS_CONTENT_CONTEXT_INSPECTELEMENT`, but it actually adds a new `IDS_INSPECT_ELEMENT_ANDROID`. Please update the commit message to be accurate.
thanks! updated commit msg
Would it be safer to return false here? I'm not sure when we expect to hit this code block and what happens based on true / false returns.
changed both fallbacks to return false for safety
if (!is_devtools_allowed
#if !BUILDFLAG(ENABLE_DESKTOP_ANDROID_EXTENSIONS)
) {
return nullptr;
}
#else
) {
}
#endifI think this is more readable?
```suggestion
#if !BUILDFLAG(ENABLE_DESKTOP_ANDROID_EXTENSIONS)
if (!is_devtools_allowed) {
return nullptr;
}
#endif
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
3 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: chrome/browser/android/selection/chrome_selection_dropdown_menu_delegate.cc
Insertions: 9, Deletions: 14.
The diff is too large to show. Please review the diff.
```
Add "Inspect Element" to text selection dropdown menu
This CL adds the "Inspect Element" option to the text selection dropdown
menu on Android (triggered via mouse right-click on selected text). It
modifies ChromeSelectionDropdownMenuDelegate to evaluate if DevTools is
enabled and injects the inspect item into the ui::MenuModel, intercepting
the click to launch DevToolsWindow.
To make the label string available in C++ on Android, this CL also defines
a new IDS_INSPECT_ELEMENT_ANDROID string outside the is_android block in
generated_resources.grd.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |