Skip to content

Commit

Permalink
Expose window.internals when enabled by flag (#4840)
Browse files Browse the repository at this point in the history
b/393406740
  • Loading branch information
hlwarriner authored Feb 7, 2025
1 parent 6b97831 commit 34e4019
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cobalt/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ source_set("renderer") {
sources = [
"cobalt_content_renderer_client.cc",
"cobalt_content_renderer_client.h",
"cobalt_render_frame_observer.cc",
"cobalt_render_frame_observer.h",
]

deps = [
Expand Down
2 changes: 2 additions & 0 deletions cobalt/renderer/cobalt_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <string>

#include "cobalt/renderer/cobalt_render_frame_observer.h"
#include "components/cdm/renderer/widevine_key_system_info.h"
#include "starboard/media.h"

Expand Down Expand Up @@ -72,6 +73,7 @@ CobaltContentRendererClient::~CobaltContentRendererClient() {}
void CobaltContentRendererClient::RenderFrameCreated(
content::RenderFrame* render_frame) {
new js_injection::JsCommunication(render_frame);
new CobaltRenderFrameObserver(render_frame);
}

#if BUILDFLAG(IS_ANDROID)
Expand Down
42 changes: 42 additions & 0 deletions cobalt/renderer/cobalt_render_frame_observer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2025 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "cobalt/renderer/cobalt_render_frame_observer.h"

#include "base/command_line.h"
#include "cobalt/common/shell_switches.h"
#include "content/public/renderer/render_frame.h"
#include "third_party/blink/public/web/web_testing_support.h"

namespace cobalt {

CobaltRenderFrameObserver::CobaltRenderFrameObserver(
content::RenderFrame* render_frame)
: content::RenderFrameObserver(render_frame) {}

CobaltRenderFrameObserver::~CobaltRenderFrameObserver() = default;

void CobaltRenderFrameObserver::OnDestruct() {
delete this;
}

void CobaltRenderFrameObserver::DidClearWindowObject() {
auto& cmd = *base::CommandLine::ForCurrentProcess();
if (cmd.HasSwitch(switches::kExposeInternalsForTesting)) {
blink::WebTestingSupport::InjectInternalsObject(
render_frame()->GetWebFrame());
}
}

} // namespace cobalt
39 changes: 39 additions & 0 deletions cobalt/renderer/cobalt_render_frame_observer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2025 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef COBALT_RENDERER_COBALT_RENDERER_FRAME_OBSERVER_H_
#define COBALT_RENDERER_COBALT_RENDERER_FRAME_OBSERVER_H_

#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"

namespace cobalt {

class CobaltRenderFrameObserver : public content::RenderFrameObserver {
public:
explicit CobaltRenderFrameObserver(content::RenderFrame* render_frame);
~CobaltRenderFrameObserver() override;

CobaltRenderFrameObserver(const CobaltRenderFrameObserver&) = delete;
CobaltRenderFrameObserver& operator=(const CobaltRenderFrameObserver&) =
delete;

private:
void OnDestruct() override;
void DidClearWindowObject() override;
};

} // namespace cobalt

#endif // COBALT_RENDERER_COBALT_RENDERER_FRAME_OBSERVER_H_

0 comments on commit 34e4019

Please sign in to comment.