2015-07-16 23:40:01 +02: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.
|
|
|
|
|
|
|
|
#include "libcef/browser/extensions/extension_web_contents_observer.h"
|
|
|
|
|
2019-05-01 21:09:59 +02:00
|
|
|
#include "chrome/common/webui_url_constants.h"
|
2015-10-09 17:23:12 +02:00
|
|
|
#include "content/public/browser/child_process_security_policy.h"
|
2017-09-06 23:40:58 +02:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2015-10-09 17:23:12 +02:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "content/public/common/url_constants.h"
|
2021-06-04 03:34:56 +02:00
|
|
|
#include "third_party/blink/public/common/chrome_debug_urls.h"
|
2015-10-09 17:23:12 +02:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
CefExtensionWebContentsObserver::CefExtensionWebContentsObserver(
|
|
|
|
content::WebContents* web_contents)
|
2017-08-04 00:55:19 +02:00
|
|
|
: ExtensionWebContentsObserver(web_contents),
|
2022-01-25 21:26:51 +01:00
|
|
|
content::WebContentsUserData<CefExtensionWebContentsObserver>(
|
|
|
|
*web_contents),
|
2018-10-24 22:37:39 +02:00
|
|
|
script_executor_(new ScriptExecutor(web_contents)) {}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefExtensionWebContentsObserver::~CefExtensionWebContentsObserver() {}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
// static
|
|
|
|
void CefExtensionWebContentsObserver::CreateForWebContents(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
content::WebContentsUserData<
|
|
|
|
CefExtensionWebContentsObserver>::CreateForWebContents(web_contents);
|
|
|
|
|
|
|
|
// Initialize this instance if necessary.
|
|
|
|
FromWebContents(web_contents)->Initialize();
|
|
|
|
}
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
void CefExtensionWebContentsObserver::RenderFrameCreated(
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
|
|
|
ExtensionWebContentsObserver::RenderFrameCreated(render_frame_host);
|
2015-10-09 17:23:12 +02:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
const Extension* extension = GetExtensionFromFrame(render_frame_host, false);
|
2015-10-09 17:23:12 +02:00
|
|
|
if (!extension)
|
|
|
|
return;
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
int process_id = render_frame_host->GetProcess()->GetID();
|
2015-10-09 17:23:12 +02:00
|
|
|
auto policy = content::ChildProcessSecurityPolicy::GetInstance();
|
|
|
|
|
|
|
|
// Components of chrome that are implemented as extensions or platform apps
|
2019-05-01 21:09:59 +02:00
|
|
|
// are allowed to use chrome://resources/ and chrome://theme/ URLs.
|
2015-10-09 17:23:12 +02:00
|
|
|
if ((extension->is_extension() || extension->is_platform_app()) &&
|
|
|
|
Manifest::IsComponentLocation(extension->location())) {
|
2018-07-13 21:29:20 +02:00
|
|
|
policy->GrantRequestOrigin(
|
2021-06-04 03:34:56 +02:00
|
|
|
process_id, url::Origin::Create(GURL(blink::kChromeUIResourcesURL)));
|
2019-05-01 21:09:59 +02:00
|
|
|
policy->GrantRequestOrigin(
|
|
|
|
process_id, url::Origin::Create(GURL(chrome::kChromeUIThemeURL)));
|
2015-10-09 17:23:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 00:17:16 +02:00
|
|
|
WEB_CONTENTS_USER_DATA_KEY_IMPL(CefExtensionWebContentsObserver);
|
2019-01-17 10:56:52 +01:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
} // namespace extensions
|