feat: implement chrome.tabs.reload (#33560)
This commit is contained in:
		
					parent
					
						
							
								a7a5e7fcfd
							
						
					
				
			
			
				commit
				
					
						caddc83cfe
					
				
			
		
					 4 changed files with 59 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -99,6 +99,7 @@ Only `chrome.storage.local` is supported; `chrome.storage.sync` and
 | 
			
		|||
The following methods of `chrome.tabs` are supported:
 | 
			
		||||
 | 
			
		||||
- `chrome.tabs.sendMessage`
 | 
			
		||||
- `chrome.tabs.reload`
 | 
			
		||||
- `chrome.tabs.executeScript`
 | 
			
		||||
- `chrome.tabs.update` (partial support)
 | 
			
		||||
  - supported properties: `url`, `muted`.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -182,6 +182,30 @@ bool TabsExecuteScriptFunction::ShouldRemoveCSS() const {
 | 
			
		|||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ExtensionFunction::ResponseAction TabsReloadFunction::Run() {
 | 
			
		||||
  std::unique_ptr<tabs::Reload::Params> params(
 | 
			
		||||
      tabs::Reload::Params::Create(args()));
 | 
			
		||||
  EXTENSION_FUNCTION_VALIDATE(params.get());
 | 
			
		||||
 | 
			
		||||
  bool bypass_cache = false;
 | 
			
		||||
  if (params->reload_properties.get() &&
 | 
			
		||||
      params->reload_properties->bypass_cache.get()) {
 | 
			
		||||
    bypass_cache = *params->reload_properties->bypass_cache;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int tab_id = params->tab_id ? *params->tab_id : -1;
 | 
			
		||||
  auto* contents = electron::api::WebContents::FromID(tab_id);
 | 
			
		||||
  if (!contents)
 | 
			
		||||
    return RespondNow(Error("No such tab"));
 | 
			
		||||
 | 
			
		||||
  contents->web_contents()->GetController().Reload(
 | 
			
		||||
      bypass_cache ? content::ReloadType::BYPASSING_CACHE
 | 
			
		||||
                   : content::ReloadType::NORMAL,
 | 
			
		||||
      true);
 | 
			
		||||
 | 
			
		||||
  return RespondNow(NoArguments());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ExtensionFunction::ResponseAction TabsGetFunction::Run() {
 | 
			
		||||
  std::unique_ptr<tabs::Get::Params> params(tabs::Get::Params::Create(args()));
 | 
			
		||||
  EXTENSION_FUNCTION_VALIDATE(params.get());
 | 
			
		||||
| 
						 | 
				
			
			@ -262,17 +286,17 @@ ExtensionFunction::ResponseAction TabsGetZoomSettingsFunction::Run() {
 | 
			
		|||
  auto* zoom_controller = contents->GetZoomController();
 | 
			
		||||
  WebContentsZoomController::ZoomMode zoom_mode =
 | 
			
		||||
      contents->GetZoomController()->zoom_mode();
 | 
			
		||||
  api::tabs::ZoomSettings zoom_settings;
 | 
			
		||||
  tabs::ZoomSettings zoom_settings;
 | 
			
		||||
  ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
 | 
			
		||||
  zoom_settings.default_zoom_factor = std::make_unique<double>(
 | 
			
		||||
      blink::PageZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()));
 | 
			
		||||
 | 
			
		||||
  return RespondNow(
 | 
			
		||||
      ArgumentList(api::tabs::GetZoomSettings::Results::Create(zoom_settings)));
 | 
			
		||||
      ArgumentList(tabs::GetZoomSettings::Results::Create(zoom_settings)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ExtensionFunction::ResponseAction TabsSetZoomSettingsFunction::Run() {
 | 
			
		||||
  using api::tabs::ZoomSettings;
 | 
			
		||||
  using tabs::ZoomSettings;
 | 
			
		||||
 | 
			
		||||
  std::unique_ptr<tabs::SetZoomSettings::Params> params(
 | 
			
		||||
      tabs::SetZoomSettings::Params::Create(args()));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,9 +46,19 @@ class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction {
 | 
			
		|||
  DECLARE_EXTENSION_FUNCTION("tabs.executeScript", TABS_EXECUTESCRIPT)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TabsReloadFunction : public ExtensionFunction {
 | 
			
		||||
  ~TabsReloadFunction() override {}
 | 
			
		||||
 | 
			
		||||
  ResponseAction Run() override;
 | 
			
		||||
 | 
			
		||||
  DECLARE_EXTENSION_FUNCTION("tabs.reload", TABS_RELOAD)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TabsGetFunction : public ExtensionFunction {
 | 
			
		||||
  ~TabsGetFunction() override {}
 | 
			
		||||
 | 
			
		||||
  ResponseAction Run() override;
 | 
			
		||||
 | 
			
		||||
  DECLARE_EXTENSION_FUNCTION("tabs.get", TABS_GET)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -120,6 +120,27 @@
 | 
			
		|||
      }
 | 
			
		||||
    ],
 | 
			
		||||
    "functions": [
 | 
			
		||||
      {
 | 
			
		||||
        "name": "reload",
 | 
			
		||||
        "type": "function",
 | 
			
		||||
        "description": "Reload a tab.",
 | 
			
		||||
        "parameters": [
 | 
			
		||||
          {"type": "integer", "name": "tabId", "minimum": 0, "optional": true, "description": "The ID of the tab to reload; defaults to the selected tab of the current window."},
 | 
			
		||||
          {
 | 
			
		||||
            "type": "object",
 | 
			
		||||
            "name": "reloadProperties",
 | 
			
		||||
            "optional": true,
 | 
			
		||||
            "properties": {
 | 
			
		||||
              "bypassCache": {
 | 
			
		||||
                "type": "boolean",
 | 
			
		||||
                "optional": true,
 | 
			
		||||
                "description": "Whether using any local cache. Default is false."
 | 
			
		||||
              }
 | 
			
		||||
            }
 | 
			
		||||
          },
 | 
			
		||||
          {"type": "function", "name": "callback", "optional": true, "parameters": []}
 | 
			
		||||
        ]
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        "name": "get",
 | 
			
		||||
        "type": "function",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue