Skip to content

frame navigation API - #11607

Merged
zcbenz merged 3 commits into
electron:masterfrom
bughit:frame_navigation_api
Feb 26, 2018
Merged

zcbenz merged 3 commits into
electron:masterfrom
bughit:frame_navigation_api

Conversation

@bughit

@bughit bughit commented Jan 9, 2018

Copy link
Copy Markdown
Contributor

a couple of things I'm uncertain about

  1. can WebFrame* be cast to WebLocalFrame* (it's working empirically)
  2. if there is a better way to do string conversions (v8:String => blink::WebString)

@bughit
bughit requested a review from a team January 9, 2018 19:48
@welcome

welcome Bot commented Jan 9, 2018

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

Here is a list of things that will help get it across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.
    We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@bughit
bughit force-pushed the frame_navigation_api branch 2 times, most recently from 776406d to e3a8b80 Compare January 9, 2018 23:40
@MarshallOfSound

Copy link
Copy Markdown
Member

Hey @bughit, struggling to review this because all the line-endings changed. Can you fix those line-endings please 👍

@bughit
bughit force-pushed the frame_navigation_api branch from e3a8b80 to 8bfa9c4 Compare January 9, 2018 23:55
@bughit

bughit commented Jan 10, 2018

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound fixed

I initally create a .git\info\attributes with * text=auto which I thought would convert to lf on commit, but it didn't somehow

@bughit

bughit commented Jan 10, 2018

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound could you please comment on the following:

  1. can WebFrame* be cast to WebLocalFrame* (i.e. they are always WelLocalFrames) as I am doing in all methods but GetFrameForSelector.
    1. GetFrameForSelector is able to obtain a WebLocalFrame* via blink::WebLocalFrame::FromFrameOwnerElement which kind of implies that they are indeed always WebLocal
    2. What are the WebRemoteFrames for?
  2. if there is a better way to do string conversions (v8:String => blink::WebString) than what I'm doing in GetFrameForSelector and FindFrameByName

Comment thread atom/renderer/api/atom_api_web_frame.h Outdated

private:
explicit WebFrame(v8::Isolate* isolate);
explicit WebFrame(v8::Isolate* isolate,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to have two versions of WebFrame constructors rather than having an implicit definition for clarity.

WebFrame(v8::Isolate* isolate);
WebFrame(v8::Isolate* isolate, blink::WebFrame* web_frame);

Comment thread atom/renderer/api/atom_api_web_frame.cc Outdated
return v8::Null(isolate());
}

v8::Local<v8::Value> WebFrame::FindFrameByName(v8::Local<v8::Value> name_value,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extract the name or selector values directly from mate::Arguments which performs the right string conversion.

v8::Local<v8::Value> WebFrame::FindFrameByName(mate::Arguments* args) {
  std::string name;
  if (args && args->Length() == 1 && args->GetNext(&name) {}
}

Comment thread atom/renderer/api/atom_api_web_frame.cc Outdated

v8::Local<v8::Value> WebFrame::Opener() const {
blink::WebLocalFrame* local_frame =
(blink::WebLocalFrame*) WebFrame::web_frame_->Opener();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its possible for a blink::WebFrame to be either blink::WebLocalFrame or blink::WebRemoteFrame when traversing frames across process, this model isn't currently enabled in Electron but will soon be. So its better to prepare for it by using the helpers blink::WebFrame::IsWebLocalFrame and blink::WebFrame::ToWebLocalFrame

@bughit
bughit force-pushed the frame_navigation_api branch 2 times, most recently from 77bf4f8 to 41961a6 Compare January 11, 2018 18:15
@bughit

bughit commented Jan 11, 2018

Copy link
Copy Markdown
Contributor Author

@deepak1556 updated

@bughit
bughit force-pushed the frame_navigation_api branch from 41961a6 to 34ee695 Compare January 11, 2018 18:28
@bughit

bughit commented Jan 12, 2018

Copy link
Copy Markdown
Contributor Author

Is there anything else I need to do here?

@bughit

bughit commented Jan 17, 2018

Copy link
Copy Markdown
Contributor Author

@deepak1556, I made the changes you requested almost a week ago, could you please review them.

@bughit

bughit commented Jan 29, 2018

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound @deepak1556

Could one of you please explain what I can expect to happen with this pull request? It's been sitting in the "Changes requested" state for 18 days after requested changes were made. Is that not enough time to let me know if the changes are acceptable or if you need anything else?

@deepak1556

Copy link
Copy Markdown
Member

@bughit sorry for the delay on this. I am not convinced on exposing the traversal methods on WebFrame which creates unnecessary instances. We can just add one method to retrieve all WebElement of a frame and another method to return a WebFrame instance for given WebElement.

@bughit

bughit commented Feb 1, 2018

Copy link
Copy Markdown
Contributor Author

@deepak1556

Please look at #5115 (comment) and following. I initially tried that approach and could not figure out how to get a blink::WebElement from a v8::Value (#5115 (comment)), got as far as blink::Element.

The current approach resulted as workaround. I am not opposed to the original way (webelement -> webframe), but I would need to know how.

@bughit

bughit commented Feb 5, 2018 •

Copy link
Copy Markdown
Contributor Author

@deepak1556

If we are going to communicate with a periodicity of 3 weeks, this will never get done.

Besides not being clear on what exactly you want, I don't understand your objection. The api I exposed is:

  • v8::Localv8::Value Opener() const;
  • v8::Localv8::Value Parent() const;
  • v8::Localv8::Value Top() const;
  • v8::Localv8::Value FirstChild() const;
  • v8::Localv8::Value NextSibling() const;
  • v8::Localv8::Value TraverseNext() const;
  • v8::Localv8::Value GetFrameForSelector(mate::Arguments* args) const;
  • v8::Localv8::Value FindFrameByName(mate::Arguments* args) const;

Opener, Parent, Top, GetFrameForSelector, FindFrameByName are definitely useful and don't create any unnecessary instances. Do you have anything against these?

FirstChild, NextSibling, TraverseNext only create unnecessary instances if you are using them to achieve array like indexing (e.g. 5th child). In other cases (collecting the frames, or searching through them) they are not unnecessary. Even in the indexing scenario the the extra instances are hardly significant (pages which have so many frames where this might become an issue are theoretical)

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And can you add some documents for the new APIs in docs/api/web-frame.md?

Comment thread atom/renderer/api/atom_api_web_frame.cc Outdated

v8::Local<v8::Value> WebFrame::Opener() const {
blink::WebLocalFrame* local_frame =
WebFrame::web_frame_->Opener()->ToWebLocalFrame();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToWebLocalFrame would cause assertion under Debug mode when called for remote web frame, we should call IsWebLocalFrame() before doing conversion.

All the ToWebLocalFrame calls bellow should also be checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to understand when a WebFrame is local vs remote.
Does it depend on the chosen process model?
What's the current model? Process per window (which would mean all frames are local)?
Is the process model going to change (so that not all frames are local)?
Will it be possible to configure the process model?

And now to the details, what should these methods return if the frame is not local?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of process model, it is always possible to have a remote WebFrame inside any page , especially after Chromium started to enable out-of-process iframes.

I think for now it is fine to return null for remote WebFrame.

Comment thread atom/renderer/api/atom_api_web_frame.cc Outdated

v8::Local<v8::Value> WebFrame::TraverseNext() const {
blink::WebLocalFrame* local_frame =
WebFrame::web_frame_->TraverseNext()->ToWebLocalFrame();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The travel would stop when encountered a remote frame. Also TraverseNext returns nullptr at the end so it would then crash here.

If we do not really need this API, I prefer to simply remove this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included it just because it was there, so I am ok with removing it, firstChild and nextSibling should enough to walk the whole tree.

Comment thread atom/renderer/api/atom_api_web_frame.cc Outdated
return v8::Null(isolate());
}

v8::Local<v8::Value> WebFrame::GetFrameForSelector(mate::Arguments* args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can define the function as GetFrameForSelector(const std::string& selector) and the argument would be converted automatically.

This also applies to FindFrameByName.

@bughit
bughit force-pushed the frame_navigation_api branch from 34ee695 to a36710b Compare February 21, 2018 21:00
@bughit
bughit requested a review from a team February 21, 2018 21:00
@bughit
bughit force-pushed the frame_navigation_api branch from a36710b to c1df960 Compare February 21, 2018 21:25
@bughit

bughit commented Feb 21, 2018

Copy link
Copy Markdown
Contributor Author

@zcbenz I made the requested changes. The docs linting is failing, I am not clear on how to fix it, please advise.

Comment thread docs/api/web-frame.md
webFrame.setZoomFactor(2)
```

## Methods

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why linting has failing, if you revert this back to Methods everything should work. webFrame is not a class, it's a module (that happens to be an the instance of a native WebFrame class) but it's a module 😄

@bughit bughit Feb 21, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert it to fix the problem, but webFrame is not a module, unless Electron has its own concept of modules.

  • it is an exported object of the electron module require('electron').webFrame
  • it is an instance of the WebFrame class (which is not exported because you can't create new frames)
  • it represents the top frame of the current window
  • its methods are instance methods of the WebFrame class
  • till now it was a singleton (the only WebFrame instance you could obtain) but with this pull request you can get others

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went back to Methods, still failing: Failed to lint electron.d.ts

@bughit
bughit force-pushed the frame_navigation_api branch from c1df960 to 88b887f Compare February 21, 2018 23:50
@bughit

bughit commented Feb 22, 2018

Copy link
Copy Markdown
Contributor Author

@zcbenz @deepak1556

I added the documentation per your request, but I don't know what it takes to satisfy your linter (Failed to lint electron.d.ts). Please advise.

@bughit

bughit commented Feb 23, 2018

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound @deepak1556 @zcbenz

Do none of you know what's wrong with the documentation I added? I can take it out, but you asked for it, so why not help me get it right?

@qazbnm456

qazbnm456 commented Feb 26, 2018 •

Copy link
Copy Markdown
Contributor

@bughit The linting has failed because you don't follow the style guide mentioned here I think. 🤔

Hopefully, amending the docs of properties of the webFrame may make the linting happy.

@bughit

bughit commented Feb 26, 2018

Copy link
Copy Markdown
Contributor Author

@qazbnm456 Is it just the backquotes? Or are properties not allowed at all for "modules"?

Speaking of which, where does the electron concept of a module come from? From the node perspective webFrame is not a module.

  • it is an exported object of the electron module require('electron').webFrame
  • it is an instance of the WebFrame class require('electron').webFrame.constructor.name, which is not exported directly because you can't create new frames
  • it represents the top frame of the current window
  • its methods are instance methods of the WebFrame class

@zcbenz

zcbenz commented Feb 26, 2018

Copy link
Copy Markdown
Contributor

@bughit The docs parser is treating Returns as a keyword in method description to get the return type, so it is using its own conceptions when parsing the docs, instead of following common conceptions which only humans can do. I'll fix the docs parser.

@zcbenz

zcbenz commented Feb 26, 2018

Copy link
Copy Markdown
Contributor

The CI is a bit flaky and the failing tests are not related to this PR, I'm merging with the failing tests ignored.

@zcbenz
zcbenz merged commit fdd66bd into electron:master Feb 26, 2018
@welcome

welcome Bot commented Feb 26, 2018

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@bughit

bughit commented Feb 28, 2018

Copy link
Copy Markdown
Contributor Author

@zcbenz Can this be added to 2-0-x?

Would like to be able to start using this sooner. Also master can't even be built on windows currently (#12061)

@bughit

bughit commented Mar 1, 2018

Copy link
Copy Markdown
Contributor Author

@zcbenz Is backporting to a beta branch a possibility?

@zcbenz

zcbenz commented Mar 1, 2018

Copy link
Copy Markdown
Contributor

According our versioning policy, you have to wait for major/minor release for a new feature.

@bughit
bughit deleted the frame_navigation_api branch May 1, 2018 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants