refactor: cleanup WebFrameMain + improve tests (#27455)
This commit is contained in:
parent
ddf3ef0a5f
commit
bde714c1c6
3 changed files with 28 additions and 30 deletions
|
@ -156,7 +156,7 @@ v8::Local<v8::Promise> WebFrameMain::ExecuteJavaScriptInIsolatedWorld(
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebFrameMain::Reload(v8::Isolate* isolate) {
|
bool WebFrameMain::Reload() {
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return false;
|
return false;
|
||||||
return render_frame_->Reload();
|
return render_frame_->Reload();
|
||||||
|
@ -219,19 +219,19 @@ void WebFrameMain::PostMessage(v8::Isolate* isolate,
|
||||||
std::move(transferable_message));
|
std::move(transferable_message));
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebFrameMain::FrameTreeNodeID(v8::Isolate* isolate) const {
|
int WebFrameMain::FrameTreeNodeID() const {
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return -1;
|
return -1;
|
||||||
return render_frame_->GetFrameTreeNodeId();
|
return render_frame_->GetFrameTreeNodeId();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WebFrameMain::Name(v8::Isolate* isolate) const {
|
std::string WebFrameMain::Name() const {
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return std::string();
|
return std::string();
|
||||||
return render_frame_->GetFrameName();
|
return render_frame_->GetFrameName();
|
||||||
}
|
}
|
||||||
|
|
||||||
base::ProcessId WebFrameMain::OSProcessID(v8::Isolate* isolate) const {
|
base::ProcessId WebFrameMain::OSProcessID() const {
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return -1;
|
return -1;
|
||||||
base::ProcessHandle process_handle =
|
base::ProcessHandle process_handle =
|
||||||
|
@ -239,38 +239,37 @@ base::ProcessId WebFrameMain::OSProcessID(v8::Isolate* isolate) const {
|
||||||
return base::GetProcId(process_handle);
|
return base::GetProcId(process_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebFrameMain::ProcessID(v8::Isolate* isolate) const {
|
int WebFrameMain::ProcessID() const {
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return -1;
|
return -1;
|
||||||
return render_frame_->GetProcess()->GetID();
|
return render_frame_->GetProcess()->GetID();
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebFrameMain::RoutingID(v8::Isolate* isolate) const {
|
int WebFrameMain::RoutingID() const {
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return -1;
|
return -1;
|
||||||
return render_frame_->GetRoutingID();
|
return render_frame_->GetRoutingID();
|
||||||
}
|
}
|
||||||
|
|
||||||
GURL WebFrameMain::URL(v8::Isolate* isolate) const {
|
GURL WebFrameMain::URL() const {
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return GURL::EmptyGURL();
|
return GURL::EmptyGURL();
|
||||||
return render_frame_->GetLastCommittedURL();
|
return render_frame_->GetLastCommittedURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
content::RenderFrameHost* WebFrameMain::Top(v8::Isolate* isolate) const {
|
content::RenderFrameHost* WebFrameMain::Top() const {
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return render_frame_->GetMainFrame();
|
return render_frame_->GetMainFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
content::RenderFrameHost* WebFrameMain::Parent(v8::Isolate* isolate) const {
|
content::RenderFrameHost* WebFrameMain::Parent() const {
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return render_frame_->GetParent();
|
return render_frame_->GetParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<content::RenderFrameHost*> WebFrameMain::Frames(
|
std::vector<content::RenderFrameHost*> WebFrameMain::Frames() const {
|
||||||
v8::Isolate* isolate) const {
|
|
||||||
std::vector<content::RenderFrameHost*> frame_hosts;
|
std::vector<content::RenderFrameHost*> frame_hosts;
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return frame_hosts;
|
return frame_hosts;
|
||||||
|
@ -283,8 +282,7 @@ std::vector<content::RenderFrameHost*> WebFrameMain::Frames(
|
||||||
return frame_hosts;
|
return frame_hosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<content::RenderFrameHost*> WebFrameMain::FramesInSubtree(
|
std::vector<content::RenderFrameHost*> WebFrameMain::FramesInSubtree() const {
|
||||||
v8::Isolate* isolate) const {
|
|
||||||
std::vector<content::RenderFrameHost*> frame_hosts;
|
std::vector<content::RenderFrameHost*> frame_hosts;
|
||||||
if (!CheckRenderFrame())
|
if (!CheckRenderFrame())
|
||||||
return frame_hosts;
|
return frame_hosts;
|
||||||
|
|
|
@ -76,7 +76,7 @@ class WebFrameMain : public gin::Wrappable<WebFrameMain>,
|
||||||
gin::Arguments* args,
|
gin::Arguments* args,
|
||||||
int world_id,
|
int world_id,
|
||||||
const base::string16& code);
|
const base::string16& code);
|
||||||
bool Reload(v8::Isolate* isolate);
|
bool Reload();
|
||||||
void Send(v8::Isolate* isolate,
|
void Send(v8::Isolate* isolate,
|
||||||
bool internal,
|
bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
|
@ -86,18 +86,17 @@ class WebFrameMain : public gin::Wrappable<WebFrameMain>,
|
||||||
v8::Local<v8::Value> message_value,
|
v8::Local<v8::Value> message_value,
|
||||||
base::Optional<v8::Local<v8::Value>> transfer);
|
base::Optional<v8::Local<v8::Value>> transfer);
|
||||||
|
|
||||||
int FrameTreeNodeID(v8::Isolate* isolate) const;
|
int FrameTreeNodeID() const;
|
||||||
std::string Name(v8::Isolate* isolate) const;
|
std::string Name() const;
|
||||||
base::ProcessId OSProcessID(v8::Isolate* isolate) const;
|
base::ProcessId OSProcessID() const;
|
||||||
int ProcessID(v8::Isolate* isolate) const;
|
int ProcessID() const;
|
||||||
int RoutingID(v8::Isolate* isolate) const;
|
int RoutingID() const;
|
||||||
GURL URL(v8::Isolate* isolate) const;
|
GURL URL() const;
|
||||||
|
|
||||||
content::RenderFrameHost* Top(v8::Isolate* isolate) const;
|
content::RenderFrameHost* Top() const;
|
||||||
content::RenderFrameHost* Parent(v8::Isolate* isolate) const;
|
content::RenderFrameHost* Parent() const;
|
||||||
std::vector<content::RenderFrameHost*> Frames(v8::Isolate* isolate) const;
|
std::vector<content::RenderFrameHost*> Frames() const;
|
||||||
std::vector<content::RenderFrameHost*> FramesInSubtree(
|
std::vector<content::RenderFrameHost*> FramesInSubtree() const;
|
||||||
v8::Isolate* isolate) const;
|
|
||||||
|
|
||||||
content::RenderFrameHost* render_frame_ = nullptr;
|
content::RenderFrameHost* render_frame_ = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -126,11 +126,12 @@ describe('webFrameMain module', () => {
|
||||||
const w = new BrowserWindow({ show: false, webPreferences: { contextIsolation: true } });
|
const w = new BrowserWindow({ show: false, webPreferences: { contextIsolation: true } });
|
||||||
await w.loadFile(path.join(subframesPath, 'frame.html'));
|
await w.loadFile(path.join(subframesPath, 'frame.html'));
|
||||||
const webFrame = w.webContents.mainFrame;
|
const webFrame = w.webContents.mainFrame;
|
||||||
expect(webFrame).to.haveOwnProperty('frameTreeNodeId');
|
expect(webFrame).to.have.ownProperty('url').that.is.a('string');
|
||||||
expect(webFrame).to.haveOwnProperty('name');
|
expect(webFrame).to.have.ownProperty('frameTreeNodeId').that.is.a('number');
|
||||||
expect(webFrame).to.haveOwnProperty('osProcessId');
|
expect(webFrame).to.have.ownProperty('name').that.is.a('string');
|
||||||
expect(webFrame).to.haveOwnProperty('processId');
|
expect(webFrame).to.have.ownProperty('osProcessId').that.is.a('number');
|
||||||
expect(webFrame).to.haveOwnProperty('routingId');
|
expect(webFrame).to.have.ownProperty('processId').that.is.a('number');
|
||||||
|
expect(webFrame).to.have.ownProperty('routingId').that.is.a('number');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue