Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: webFrameMain.origin #35438

Merged
merged 3 commits into from Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/api/web-frame-main.md
Expand Up @@ -169,6 +169,13 @@ convenient when `nodeIntegrationInSubFrames` is not enabled.

A `string` representing the current URL of the frame.

#### `frame.origin` _Readonly_

A `string` representing the current origin of the frame. This may be different
from the URL. For instance, if the frame is a child window opened to
`about:blank`, then `frame.origin` will return the parent frame's origin, while
`frame.url` will return the empty string.

#### `frame.top` _Readonly_

A `WebFrameMain | null` representing top frame in the frame hierarchy to which `frame`
Expand Down
7 changes: 7 additions & 0 deletions shell/browser/api/electron_api_web_frame_main.cc
Expand Up @@ -296,6 +296,12 @@ GURL WebFrameMain::URL() const {
return render_frame_->GetLastCommittedURL();
}

std::string WebFrameMain::Origin() const {
if (!CheckRenderFrame())
return std::string();
ckerr marked this conversation as resolved.
Show resolved Hide resolved
return render_frame_->GetLastCommittedOrigin().Serialize();
}
nornagon marked this conversation as resolved.
Show resolved Hide resolved

blink::mojom::PageVisibilityState WebFrameMain::VisibilityState() const {
if (!CheckRenderFrame())
return blink::mojom::PageVisibilityState::kHidden;
Expand Down Expand Up @@ -397,6 +403,7 @@ v8::Local<v8::ObjectTemplate> WebFrameMain::FillObjectTemplate(
.SetProperty("processId", &WebFrameMain::ProcessID)
.SetProperty("routingId", &WebFrameMain::RoutingID)
.SetProperty("url", &WebFrameMain::URL)
.SetProperty("origin", &WebFrameMain::Origin)
.SetProperty("visibilityState", &WebFrameMain::VisibilityState)
.SetProperty("top", &WebFrameMain::Top)
.SetProperty("parent", &WebFrameMain::Parent)
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/electron_api_web_frame_main.h
Expand Up @@ -109,6 +109,7 @@ class WebFrameMain : public gin::Wrappable<WebFrameMain>,
int ProcessID() const;
int RoutingID() const;
GURL URL() const;
std::string Origin() const;
nornagon marked this conversation as resolved.
Show resolved Hide resolved
blink::mojom::PageVisibilityState VisibilityState() const;

content::RenderFrameHost* Top() const;
Expand Down