2019-07-24 23:01:08 +00:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/renderer/extensions/electron_extensions_renderer_client.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2021-02-11 15:58:03 +00:00
|
|
|
#include <string>
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "content/public/renderer/render_thread.h"
|
2021-02-11 15:58:03 +00:00
|
|
|
#include "extensions/common/constants.h"
|
|
|
|
#include "extensions/common/manifest_handlers/background_info.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "extensions/renderer/dispatcher.h"
|
2020-02-24 04:33:58 +00:00
|
|
|
#include "shell/common/world_ids.h"
|
2020-01-15 23:11:51 +00:00
|
|
|
#include "shell/renderer/extensions/electron_extensions_dispatcher_delegate.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
ElectronExtensionsRendererClient::ElectronExtensionsRendererClient()
|
2019-07-24 23:01:08 +00:00
|
|
|
: dispatcher_(std::make_unique<extensions::Dispatcher>(
|
2020-01-15 23:11:51 +00:00
|
|
|
std::make_unique<ElectronExtensionsDispatcherDelegate>())) {
|
2019-07-24 23:01:08 +00:00
|
|
|
dispatcher_->OnRenderThreadStarted(content::RenderThread::Get());
|
|
|
|
}
|
|
|
|
|
2021-06-04 04:16:13 +00:00
|
|
|
ElectronExtensionsRendererClient::~ElectronExtensionsRendererClient() = default;
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
bool ElectronExtensionsRendererClient::IsIncognitoProcess() const {
|
2019-07-24 23:01:08 +00:00
|
|
|
// app_shell doesn't support off-the-record contexts.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
int ElectronExtensionsRendererClient::GetLowestIsolatedWorldId() const {
|
2020-02-24 04:33:58 +00:00
|
|
|
return WorldIDs::ISOLATED_WORLD_ID_EXTENSIONS;
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
extensions::Dispatcher* ElectronExtensionsRendererClient::GetDispatcher() {
|
2019-07-24 23:01:08 +00:00
|
|
|
return dispatcher_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
bool ElectronExtensionsRendererClient::
|
|
|
|
ExtensionAPIEnabledForServiceWorkerScript(const GURL& scope,
|
|
|
|
const GURL& script_url) const {
|
2021-02-11 15:58:03 +00:00
|
|
|
if (!script_url.SchemeIs(extensions::kExtensionScheme))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const extensions::Extension* extension =
|
|
|
|
extensions::RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(
|
|
|
|
script_url);
|
|
|
|
|
|
|
|
if (!extension ||
|
|
|
|
!extensions::BackgroundInfo::IsServiceWorkerBased(extension))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (scope != extension->url())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const std::string& sw_script =
|
|
|
|
extensions::BackgroundInfo::GetBackgroundServiceWorkerScript(extension);
|
|
|
|
|
|
|
|
return extension->GetResourceURL(sw_script) == script_url;
|
2019-07-24 23:01:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
bool ElectronExtensionsRendererClient::AllowPopup() {
|
2019-07-24 23:01:08 +00:00
|
|
|
// TODO(samuelmaddock):
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsRendererClient::RunScriptsAtDocumentStart(
|
2019-07-24 23:01:08 +00:00
|
|
|
content::RenderFrame* render_frame) {
|
|
|
|
dispatcher_->RunScriptsAtDocumentStart(render_frame);
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsRendererClient::RunScriptsAtDocumentEnd(
|
2019-07-24 23:01:08 +00:00
|
|
|
content::RenderFrame* render_frame) {
|
|
|
|
dispatcher_->RunScriptsAtDocumentEnd(render_frame);
|
|
|
|
}
|
|
|
|
|
2020-02-03 22:01:10 +00:00
|
|
|
void ElectronExtensionsRendererClient::RunScriptsAtDocumentIdle(
|
2019-07-24 23:01:08 +00:00
|
|
|
content::RenderFrame* render_frame) {
|
|
|
|
dispatcher_->RunScriptsAtDocumentIdle(render_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace electron
|