Skip to content

Support custom protocols - #65

Merged
zcbenz merged 40 commits into
masterfrom
custom-protocol
Sep 4, 2013
Merged

zcbenz merged 40 commits into
masterfrom
custom-protocol

Conversation

@zcbenz

@zcbenz zcbenz commented Aug 24, 2013

Copy link
Copy Markdown
Contributor
  • API to register custom protocol.
  • Allow sending file in custom protocols.
  • Allow sending string in custom protocols.
  • API to control the cache of each request.
  • API to intercept existing protocol.
  • Provide information of from where the request is made (not sure if it's possible).

@zcbenz zcbenz mentioned this pull request Aug 24, 2013
@zcbenz

zcbenz commented Aug 26, 2013

Copy link
Copy Markdown
Contributor Author

The WebKit only allows setting referrer for urls with http or https protocols, so the handler registered with protocol.registerProtocol will not be able to receive the referrer, which is critical for implementing custom browser resource loader. The only solution I can thought of is to patch WebKit.

@nathansobo

Copy link
Copy Markdown

Forgive my ignorance here, but I don't understand why the referrer header is required. Is it required to resolve relative URLs or something?

@zcbenz

zcbenz commented Aug 26, 2013

Copy link
Copy Markdown
Contributor Author

it's required to resolve file paths in URLs with custom protocols, when writing something like src="atom://image.png" in HTML, browser would not translate it to src="atom:///path/to/current/page/image.png", because the browser thought it's an absolute URL. To correctly provide the requested file, we have to know from which page the request was sent, and then resolve the paths.

@nathansobo

Copy link
Copy Markdown

Yeah, that makes sense. We could use the custom protocol only to resolve absolute references on the load path, but I think it would probably be better to traverse the ancestor directories looking for node_modules similar to how node resolves a path when require is used. What do you think about patching Chromium then? I know we wanted to minimize changes but this feature seems really important to me. Perhaps we could get the patch upstreamed? Maybe @aroben could offer an opinion or assistance?

@aroben

aroben commented Aug 27, 2013

Copy link
Copy Markdown
Contributor

I'm not sure I understand the requirements. Can you give some examples of URLs and the file paths they should map to?

@nathansobo

Copy link
Copy Markdown

We're looking for a coherent mechanism for referring to images and other static resources provided by third-party packages. I'm imagining that index.html sits in Atom's root directory, and we resolve any static asset references against the same load path we use for requiring scripts. That means I could refer to atom://core/images/logo.png and it would resolve to Atom.app/Contents/Resources/node_modules/core/images/logo.png. Or the a custom tree view package could write an image tag to the DOM referencing atom://tree-view/images/oak.png that would resolve to ~/.atom/packages/tree-view/images/oak.png. Right now everything is relative to index.html which is sitting in some directory inside the app bundle on disk, which is pretty useless. Maybe all relative paths should be resolved against the load path by default? Because a relative path is otherwise pretty useless.

@zcbenz

zcbenz commented Aug 27, 2013

Copy link
Copy Markdown
Contributor Author

This is how I think the API would be like:

var protocol = require('protocol');
protocol.registerProtocol('atom', function(url, referrer) {
  // The url is 'atom://avatar.png',
  // and the referrer is 'file:///Applications/Atom.app/.../index.html',
  // Then we calculate the actual path to requested resource by traversing ancestor directories:
  // '/Applications/Atom.app/.../avatar.png',
  return new protocol.RequestFileJob(calculatePathFromUrlAndReferrer(url, referrer));
});

As for referrer, I just found that adding <meta name="referrer" content="always"> in HTML would force WebKit to send referrer to all requests, so it's not a problem any more.

But another problem is, to resolve resource path like node's require, we have to know from which .js file the request is sent. In the case of ArchiveView, we could add an image when creating the view in /Applications/Atom.app/Contents/Resources/node_modules/archive-view/lib/archive-view.js, or in ~/.atom/packages/archive-view/lib/archive-view.js, in order to know whether atom://image/zip.png points to /Applications/Atom.app/Contents/Resources/node_modules/archive-view/images/zip.png or ~/.atom/packages/archive-view/images/zip.png, we have to know which .js file requests the image. The referrer just always points to the index.html.

@nathansobo

Copy link
Copy Markdown

It seems really difficult (if not impossible?) to tie URL references in the DOM back to the .js file that inserted them. Maybe everything can just always be relative to index.html, which will be a sibling of the built-in node_modules, but we can also add ~/.atom/packages to the load path. Then you will have to explicitly mention the package name in the path atom://archive-view/images/zip.png instead of atom://images/zip.png. I guess alternatively we should just use fsUtils.resolveOnLoadPath('../images/zip.png') to make paths absolute before inserting them into the DOM. We could potentially add a convenience function in our view layer to help make this easy:

class SomeView extends View
  @content: -> @img src: @resolve('../images/flower.png')

Could we add some kind of mechanism like require.resolve that would resolve relative paths to any kind of file, not just scripts? Then we could just handle it explicitly in scripts. Maybe that makes the custom protocol less necessary? Either way, it seems like once the URL is in the DOM it will be very hard to determine where it came from.

@nathansobo

Copy link
Copy Markdown

@zcbenz After talking with Kevin the API you propose for registering a custom protocol from the JavaScript layer looks really good. Is it possible to provide a similar API to allow us to intercept relative file:// URLs? We would like to make it possible to refer to a less stylesheet in markup for example and automatically compile it before handing it back to the browser.

@nathansobo

Copy link
Copy Markdown

Another thought: I wonder if it would improve performance to register callbacks that are associated with regular expressions? Then we can run the regular expression against the URL in the native layer and only call into JS if it matches a certain pattern.

@zcbenz

zcbenz commented Sep 3, 2013

Copy link
Copy Markdown
Contributor Author

I found that the Network panel of devtools has a column of initiators, which is the exact thing we want for implementing the require.resolve style of resource loading, but the magic hides in the private WebKit code, I'm seeing how to expose it.

@zcbenz

zcbenz commented Sep 4, 2013

Copy link
Copy Markdown
Contributor Author

So the devtools' initiators feature is implemented by dumping the current JavaScript stack trace just before the request is sent, it's a clever idea. If we want to do the same in atom-shell, we still need to patch Chromium, since devtools is making use of private WebKit API.

@zcbenz

zcbenz commented Sep 4, 2013

Copy link
Copy Markdown
Contributor Author

After some explores on implementing the initiator feature, I think there are 4 types of initiators we need to get:

  1. requests from static pages, can be got via referrers.
  2. ajax requests, can be got via devtools's initiator column of Network panel.
  3. requests from dynamic DOM inserted by JavaScript scripts.
  4. requests sent from CSS.

The 1 is simple, the 2 can be implemented but needs small patches on Chromium, the 3 seems impossible, and the 4 needs big patches on Chromium.

Now I give up on this feature and stick to current API.

zcbenz added a commit that referenced this pull request Sep 4, 2013
@zcbenz
zcbenz merged commit 3b7dd85 into master Sep 4, 2013
@zcbenz
zcbenz deleted the custom-protocol branch September 4, 2013 10:33
@zcbenz zcbenz mentioned this pull request Sep 5, 2013
kevinsawicki pushed a commit that referenced this pull request May 9, 2017
Focus on devtools when it is opened on Mac.
kevinsawicki pushed a commit that referenced this pull request May 9, 2017
Focus on devtools when it is opened on Mac.
@taoqf

taoqf commented Feb 14, 2019 •

Copy link
Copy Markdown

Hi, guys! Do we plan to support require.resolve('jsfile', {paths:'xxxx'});?

VerteDinde added a commit that referenced this pull request Apr 13, 2026
Merged: [maglev] Account for phi smi type widening in BuildCheckHeapObject

Bug: 495679730
(cherry picked from commit c1e78b455e3224e286914b5ac241fbea064cb51d)

Change-Id: I77d6f184af8d62a0dbb643c6f34d4a3530b32b63
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7715042
Auto-Submit: Darius Mercadier <[email protected]>
Reviewed-by: Leszek Swirski <[email protected]>
Commit-Queue: Leszek Swirski <[email protected]>
Cr-Commit-Position: refs/branch-heads/14.6@{#65}
@VerteDinde VerteDinde mentioned this pull request Apr 13, 2026
4 tasks done
VerteDinde added a commit that referenced this pull request Apr 13, 2026
Merged: [maglev] Account for phi smi type widening in BuildCheckHeapObject

Bug: 495679730
(cherry picked from commit c1e78b455e3224e286914b5ac241fbea064cb51d)

Change-Id: I77d6f184af8d62a0dbb643c6f34d4a3530b32b63
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7715042
Auto-Submit: Darius Mercadier <[email protected]>
Reviewed-by: Leszek Swirski <[email protected]>
Commit-Queue: Leszek Swirski <[email protected]>
Cr-Commit-Position: refs/branch-heads/14.6@{#65}
Cr-Branched-From: e04c3a1a2543bdbee7beac8846c9cbe8f657636f-refs/heads/14.6.202@{#1}
Cr-Branched-From: 3b0b01e6594ec362369dc16f069012a81748c8ba-refs/heads/main@{#105132}
@VerteDinde VerteDinde mentioned this pull request Apr 13, 2026
4 tasks done
VerteDinde added a commit that referenced this pull request Apr 13, 2026
Merged: [maglev] Account for phi smi type widening in BuildCheckHeapObject

Bug: 495679730
(cherry picked from commit c1e78b455e3224e286914b5ac241fbea064cb51d)

Change-Id: I77d6f184af8d62a0dbb643c6f34d4a3530b32b63
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7715042
Auto-Submit: Darius Mercadier <[email protected]>
Reviewed-by: Leszek Swirski <[email protected]>
Commit-Queue: Leszek Swirski <[email protected]>
Cr-Commit-Position: refs/branch-heads/14.6@{#65}
Cr-Branched-From: e04c3a1a2543bdbee7beac8846c9cbe8f657636f-refs/heads/14.6.202@{#1}
Cr-Branched-From: 3b0b01e6594ec362369dc16f069012a81748c8ba-refs/heads/main@{#105132}
codebytere pushed a commit that referenced this pull request Apr 13, 2026
* chore: cherry-pick a0570afad500 from v8

[maglev] Fix deopt use counting for deopt scope data

We shouldn't count the deopt use when creating the scope data,
but only when creating the deopt frame.

If the scope was unused, then we were over counting,
not really a correctness issue though.

If the scope was used twice, we were under counting and
we can underflow the counting when removing the use of
a node.

Fixed: 470566252
Change-Id: I7b6f5647d1ed1f9a7c915d3682f10cfc71a5924c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7415271
Commit-Queue: Toon Verwaest <[email protected]>
Reviewed-by: Toon Verwaest <[email protected]>
Commit-Queue: Victor Gomes <[email protected]>
Auto-Submit: Victor Gomes <[email protected]>
Cr-Commit-Position: refs/heads/main@{#104601}

* chore: cherry-pick b54c7841e2cd from v8

[*lev] Correctly update use counts for nested builtin continuations

Fixed: 484527367
Change-Id: I4cda8c1bbb2788fca06b564eae509511aec0957e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7593054
Reviewed-by: Victor Gomes <[email protected]>
Auto-Submit: Darius Mercadier <[email protected]>
Commit-Queue: Darius Mercadier <[email protected]>
Cr-Commit-Position: refs/heads/main@{#105381}

* chore: cherry-pick ba0258ba9609 from v8

[inspector] Use std::shared_ptr for InspectedContext

Unfortunately at this point we are not able to move `InspectedContext`
to the managed C++ heap due to missing Heap* collections and the lack
of labeling retainer links.

The next best thing we can do for now is use std::shared_ptr for
InspectedContext and keep an instance on the stack every time we can
potentially transition into user JS.

[email protected]

Fixed: 486927780
Change-Id: I5e4921521a24cc3cd53ffb6cb5b6b6f9d98490e2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7613210
Auto-Submit: Simon Zünd <[email protected]>
Reviewed-by: Benedikt Meurer <[email protected]>
Commit-Queue: Simon Zünd <[email protected]>
Commit-Queue: Benedikt Meurer <[email protected]>
Cr-Commit-Position: refs/heads/main@{#105489}

* chore: cherry-pick 2d9ff4098967 from v8

Merged: [maglev] Avoid eliding Smi checks too aggressively

(cherry picked from commit 433b2912c5cb94ed0979c8284e96e4d08416b620)

Bug: 491884710
Change-Id: Id73c522c6f55cb05167f436c2ee7f60e0db71840
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7673820
Reviewed-by: Leszek Swirski <[email protected]>
Commit-Queue: Leszek Swirski <[email protected]>
Auto-Submit: Darius Mercadier <[email protected]>
Cr-Commit-Position: refs/branch-heads/14.6@{#45}
Cr-Branched-From: e04c3a1a2543bdbee7beac8846c9cbe8f657636f-refs/heads/14.6.202@{#1}
Cr-Branched-From: 3b0b01e6594ec362369dc16f069012a81748c8ba-refs/heads/main@{#105132}

* chore: cherry-pick f297f82fea96 from v8

Merged: [compiler][arm64] Force explicit zero-extension of load index

This is the merge-commit for:

1) [arm64][compiler] Always emit truncation to word32
     cherry picked from commit 522e74a35cf4e53c3708ea396c299bfbb29d8489
2) [compiler][arm64] Reenable implicit truncation and force
   explicit zero-extension of load/store index
     cherry picked from commit 4ef5cc27aa50b4a7e3096bbbffaf5058a811a2a9

Bug: 496301615
Change-Id: I3e5e13a90ad0a43768c9cd46a7ebd99d0f6a4e11
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7715044
Commit-Queue: Matthias Liedtke <[email protected]>
Commit-Queue: Darius Mercadier <[email protected]>
Reviewed-by: Darius Mercadier <[email protected]>
Auto-Submit: Matthias Liedtke <[email protected]>
Cr-Commit-Position: refs/branch-heads/14.6@{#63}
Cr-Branched-From: e04c3a1a2543bdbee7beac8846c9cbe8f657636f-refs/heads/14.6.202@{#1}
Cr-Branched-From: 3b0b01e6594ec362369dc16f069012a81748c8ba-refs/heads/main@{#105132}

* chore: cherry-pick 021c5b193bd4 from v8

Merged: [maglev] Account for phi smi type widening in BuildCheckHeapObject

Bug: 495679730
(cherry picked from commit c1e78b455e3224e286914b5ac241fbea064cb51d)

Change-Id: I77d6f184af8d62a0dbb643c6f34d4a3530b32b63
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7715042
Auto-Submit: Darius Mercadier <[email protected]>
Reviewed-by: Leszek Swirski <[email protected]>
Commit-Queue: Leszek Swirski <[email protected]>
Cr-Commit-Position: refs/branch-heads/14.6@{#65}
Cr-Branched-From: e04c3a1a2543bdbee7beac8846c9cbe8f657636f-refs/heads/14.6.202@{#1}
Cr-Branched-From: 3b0b01e6594ec362369dc16f069012a81748c8ba-refs/heads/main@{#105132}
codebytere pushed a commit that referenced this pull request Apr 13, 2026
* chore: cherry-pick a0570afad500 from v8

[maglev] Fix deopt use counting for deopt scope data

We shouldn't count the deopt use when creating the scope data,
but only when creating the deopt frame.

If the scope was unused, then we were over counting,
not really a correctness issue though.

If the scope was used twice, we were under counting and
we can underflow the counting when removing the use of
a node.

Fixed: 470566252
Change-Id: I7b6f5647d1ed1f9a7c915d3682f10cfc71a5924c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7415271
Commit-Queue: Toon Verwaest <[email protected]>
Reviewed-by: Toon Verwaest <[email protected]>
Commit-Queue: Victor Gomes <[email protected]>
Auto-Submit: Victor Gomes <[email protected]>
Cr-Commit-Position: refs/heads/main@{#104601}

* chore: cherry-pick b54c7841e2cd from v8

[*lev] Correctly update use counts for nested builtin continuations

Fixed: 484527367
Change-Id: I4cda8c1bbb2788fca06b564eae509511aec0957e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7593054
Reviewed-by: Victor Gomes <[email protected]>
Auto-Submit: Darius Mercadier <[email protected]>
Commit-Queue: Darius Mercadier <[email protected]>
Cr-Commit-Position: refs/heads/main@{#105381}

* chore: cherry-pick ba0258ba9609 from v8

[inspector] Use std::shared_ptr for InspectedContext

Unfortunately at this point we are not able to move `InspectedContext`
to the managed C++ heap due to missing Heap* collections and the lack
of labeling retainer links.

The next best thing we can do for now is use std::shared_ptr for
InspectedContext and keep an instance on the stack every time we can
potentially transition into user JS.

[email protected]

Fixed: 486927780
Change-Id: I5e4921521a24cc3cd53ffb6cb5b6b6f9d98490e2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7613210
Auto-Submit: Simon Zünd <[email protected]>
Reviewed-by: Benedikt Meurer <[email protected]>
Commit-Queue: Simon Zünd <[email protected]>
Commit-Queue: Benedikt Meurer <[email protected]>
Cr-Commit-Position: refs/heads/main@{#105489}

* chore: cherry-pick 2d9ff4098967 from v8

Merged: [maglev] Avoid eliding Smi checks too aggressively

(cherry picked from commit 433b2912c5cb94ed0979c8284e96e4d08416b620)

Bug: 491884710
Change-Id: Id73c522c6f55cb05167f436c2ee7f60e0db71840
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7673820
Reviewed-by: Leszek Swirski <[email protected]>
Commit-Queue: Leszek Swirski <[email protected]>
Auto-Submit: Darius Mercadier <[email protected]>
Cr-Commit-Position: refs/branch-heads/14.6@{#45}
Cr-Branched-From: e04c3a1a2543bdbee7beac8846c9cbe8f657636f-refs/heads/14.6.202@{#1}
Cr-Branched-From: 3b0b01e6594ec362369dc16f069012a81748c8ba-refs/heads/main@{#105132}

* chore: cherry-pick f297f82fea96 from v8

Merged: [compiler][arm64] Force explicit zero-extension of load index

This is the merge-commit for:

1) [arm64][compiler] Always emit truncation to word32
     cherry picked from commit 522e74a35cf4e53c3708ea396c299bfbb29d8489
2) [compiler][arm64] Reenable implicit truncation and force
   explicit zero-extension of load/store index
     cherry picked from commit 4ef5cc27aa50b4a7e3096bbbffaf5058a811a2a9

Bug: 496301615
Change-Id: I3e5e13a90ad0a43768c9cd46a7ebd99d0f6a4e11
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7715044
Commit-Queue: Matthias Liedtke <[email protected]>
Commit-Queue: Darius Mercadier <[email protected]>
Reviewed-by: Darius Mercadier <[email protected]>
Auto-Submit: Matthias Liedtke <[email protected]>
Cr-Commit-Position: refs/branch-heads/14.6@{#63}
Cr-Branched-From: e04c3a1a2543bdbee7beac8846c9cbe8f657636f-refs/heads/14.6.202@{#1}
Cr-Branched-From: 3b0b01e6594ec362369dc16f069012a81748c8ba-refs/heads/main@{#105132}

* chore: cherry-pick 021c5b193bd4 from v8

Merged: [maglev] Account for phi smi type widening in BuildCheckHeapObject

Bug: 495679730
(cherry picked from commit c1e78b455e3224e286914b5ac241fbea064cb51d)

Change-Id: I77d6f184af8d62a0dbb643c6f34d4a3530b32b63
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7715042
Auto-Submit: Darius Mercadier <[email protected]>
Reviewed-by: Leszek Swirski <[email protected]>
Commit-Queue: Leszek Swirski <[email protected]>
Cr-Commit-Position: refs/branch-heads/14.6@{#65}
Cr-Branched-From: e04c3a1a2543bdbee7beac8846c9cbe8f657636f-refs/heads/14.6.202@{#1}
Cr-Branched-From: 3b0b01e6594ec362369dc16f069012a81748c8ba-refs/heads/main@{#105132}
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.

4 participants