Open Bug 1529554 Opened 5 years ago Updated 2 years ago

Have nsIChannel return raw nsILoadinfo pointer within ::Loadinfo()

Categories

(Core :: DOM: Security, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: ckerschb, Unassigned)

Details

(Whiteboard: [domsecurity-active])

Attachments

(1 file, 3 obsolete files)

Currently we do the following within nsIChannel:

inline already_AddRefed<nsILoadInfo> LoadInfo()

which results in having callsites doing the following:

nsCOMPtr<nsILoadInfo> loadInfo = chan->LoadInfo();
loadInfo->Foo();

it would be nice if we could return a raw pointer so callsites can look like:
| chan->LoadInfo()->Foo();

which would also safe all the addref and deref quirks.

Problem is the following. If we update nsIChannel to do something like:

/**

  • A C++-friendly version of loadInfo.
    */
    [noscript, notxpcom, nostdcall, binaryname(LoadInfo)]
    nsILoadInfo binaryLoadInfo();

then all the nsIChannel implementations have to implement that like:
| nsILoadInfo* FooChannel::LoadInfo() { return mLoadInfo; }

which is also not that great. I wonder if there are better solutions to that problem.

Baku, can you think of a better solution, or should we just have all nsIChannel implementations provide a ::LoadInfo() method?

Flags: needinfo?(amarchesini)

Well, in theory you could add this in nsIChannel.idl:

%{C++
inline nsILoadInfo* LoadInfo() {
nsCOMPtr<nsILoadInfo> result;
mozilla::DebugOnly<nsresult> rv = GetLoadInfo(getter_AddRefs(result));
MOZ_ASSERT(NS_SUCCEEDED(rv) || !result);
return result;
}
%}

But nothing guarantees the lifetime of the loadInfo in this way. If you add something like what you suggest, we can audit all the channel implementation and see if the loadInfo is set correctly.

Flags: needinfo?(amarchesini)

(In reply to Andrea Marchesini [:baku] from comment #2)

Well, in theory you could add this in nsIChannel.idl:

%{C++
inline nsILoadInfo* LoadInfo() {
nsCOMPtr<nsILoadInfo> result;
mozilla::DebugOnly<nsresult> rv = GetLoadInfo(getter_AddRefs(result));
MOZ_ASSERT(NS_SUCCEEDED(rv) || !result);
return result;
}
%}

But nothing guarantees the lifetime of the loadInfo in this way. If you add something like what you suggest, we can audit all the channel implementation and see if the loadInfo is set correctly.

Right, I thought about the solution you suggested above, but that still creates an intermediate nsCOMPtr - which I guess we want to avoid, right?

Would we accept a patch with my proposed solution from comment 0? Put differently, is this the way to go - or worth doing?

Flags: needinfo?(amarchesini)

Would we accept a patch with my proposed solution from comment 0? Put differently, is this the way to go - or worth doing?

Yes. It's fine to me.

Flags: needinfo?(amarchesini)
Assignee: nobody → ckerschb
Status: NEW → ASSIGNED
Priority: -- → P2
Whiteboard: [domsecurity-active]
Assignee: ckerschb → streich.mobile

Basti, there is a WIP patch (I think it doesn't even compile) but it will give you an idea of what we are trying to accomplish.

Currently, the Proposed Patch failes on tests that are using mock-Channels that are implemented on the JS side.

This is a side effect; as to be able to call chan->LoadInfo()->Foo(); like proposed in Comment 0, we must set the notxpcom flag (which implies noscript) on Loadinfo.

So this Patch would effectively remove support for js implementations of NsIChannels

My question is, do we have to support NsIchannels in js ?

Flags: needinfo?(valentin.gosu)
Flags: needinfo?(honzab.moz)

(In reply to Sebastian Streich [:sstreich] from comment #7)

My question is, do we have to support NsIchannels in js ?

Yes: https://searchfox.org/mozilla-central/search?q=nsI(Http)%3FChannel&case=true&regexp=true&path=*.js

Flags: needinfo?(honzab.moz)

Sorry i was unclear.
Its about whether we have to support JS to be able to implement and register new nsIChannels.
Which is afaik only used in a few unit-tests, if i'm correct.

This is not about accessing nsIChannels in js.
Sorry about my miscommunication.

(In reply to Sebastian Streich [:sstreich] from comment #9)

Sorry i was unclear.
Its about whether we have to support JS to be able to implement and register new nsIChannels.
Which is afaik only used in a few unit-tests, if i'm correct.

This is not about accessing nsIChannels in js.
Sorry about my miscommunication.

I was wondering :) I think we only impl nsIChannel in tests, yes. I'd have to double check that, tho. I can't recall a particular test that would do this. This won't be that simple to find.

Are you sure we want to undergo all of this just to be able to type chan->LoadInfo()->Foo(); on few places in cpp?

What about a virtual method defined by default as baku suggest in comment 2 that would be overridden by some heavily used classes like nsHttpChannel to return mLoadInfo directly? (With a single thread access assertions, preferably).

Flags: needinfo?(valentin.gosu)

(valentin is on pto)

Honza, being able to write chan->LoadInfo()->Foo() would be a nice to have, but maybe not for every price. Maybe we should simply update nsIChannel.idl [1] and replace

inline already_AddRefed<nsILoadInfo> LoadInfo()
with
inline nsILoadInfo* LoadInfo()

That way, we would still have the add/deref overhead but we could write chan->LoadInfo()->Foo().

Alternatively, we should just let it go and mark this one as a wontfix. Updating and investing that much time to eliminate JS implemented nsIChannels sounds like overkill after all.

Any preferences?

[1] https://searchfox.org/mozilla-central/source/netwerk/base/nsIChannel.idl#358

Flags: needinfo?(honzab.moz)

(In reply to Christoph Kerschbaumer [:ckerschb] from comment #13)

Honza, being able to write chan->LoadInfo()->Foo() would be a nice to have, but maybe not for every price. Maybe we should simply update nsIChannel.idl [1] and replace

inline already_AddRefed<nsILoadInfo> LoadInfo()
with
inline nsILoadInfo* LoadInfo()

yes. and if the method is also made virtual, some channels may override it and get rid of the addref/release when mLoadInfo can be returned directly. single thread access assertions should be added too.

Flags: needinfo?(honzab.moz)
Attachment #9057245 - Attachment is obsolete: true
Attachment #9058585 - Attachment is obsolete: true

The other Attempt using the Virt-Method had a few side effects, where the effort to make that one work is bigger than the win in being able to do chan->LoadInfo()->Foo().

As far as i can tell those are the Tests that are still using JS-Channel implementations and thus blocking my intial attempt implementing Comment 0 :

netwerk/test/unit/test_bug365133.js
netwerk/test/unit/test_bug484684.js
netwerk/test/unit/test_bug515583.js
netwerk/test/unit/test_bug543805.js
netwerk/test/unit/test_bug894586.js
dom/base/test/chrome/test_bug682305.html

Most of those are actually related to the FTP-Channel,
so i would propose we might reassess this again later.

Assignee: streich.mobile → nobody
Status: ASSIGNED → NEW
Priority: P2 → P3

Comment on attachment 9058506 [details]
Bug 1529554 - Remove GetLoadInfo callsites r=ckerschb

Revision D27647 was moved to bug 1546913. Setting attachment 9058506 [details] to obsolete.

Attachment #9058506 - Attachment is obsolete: true
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: