Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Issue 6369003: New extension API: "tab.socketAddress" (Closed)

Created:
9 years, 11 months ago by pmarks
Modified:
9 years, 7 months ago
Reviewers:
eroman, agl, Brian Ryner
CC:
chromium-reviews, cbentzel+watch_chromium.org, Erik does not do reviews, brettw-cc_chromium.org, Aaron Boodman, pam+watch_chromium.org, Paweł Hajdan Jr., darin-cc_chromium.org, jochen (gone - plz use gerrit), lzheng, eroman
Visibility:
Public.

Description

This change captures the low-level socket address whenever a page is loaded, and pushes it all the way up to the 'tabs' API, where extensions can read it and do nifty things, such as displaying an IPv4/IPv6 indicator. Here's a description of what's happening: 1. Extract the address in http_stream_parser.cc (for HTTP) or spdy_http_stream (for SPDY). Note that if the connection is via a proxy, then we get the address of the proxy server... not terribly useful, but not wrong either. 2. Put it into an HttpResponseInfo instance. 3. HttpResponseInfo (de)serializes the address. 4. Add a socket_address accessor in url_request.h, which pulls the address from its HttpResponseInfo instance. 5. In resource_dispatcher_host.cc, move the address from URLRequest to ResourceResponseHead (which is a subclass of ResourceResponseInfo). 6. In render_messages.cc (de)serialize the ResourceResponseInfo. 7. In weburlloader_impl.cc, copy from ResourceResponseInfo to WebURLResponse. At this point, a patch to third_party/WebKit/Source is required: http://www.pmarks.net/posted_links/socket_address_webkit.patch 8. In render_view.cc, copy from WebURLResponse to ViewHostMsg_FrameNavigate_Params. 9. In render_messages_params.cc, *_FrameNavigate_Params is (de)serialized. 10. In navigation_controller.cc, copy from *_FrameNavigate_Params to a NavigationEntry. Note: there's a warning about SessionService in navigation_entry.h, but I don't think it's relevant here. In the worst case, we just don't report the address after restoring a tab, but I haven't seen this occur. 11. In extension_tabs_module.cc, check if the current NavigationEntry has a socket address. If so, add a "socketAddress" string to the JSON object. 12. Finally, when someone registers a callback using chrome.tabs.onUpdated, the 'tab' parameter includes the new socketAddress parameter. Extensions can use the new paramter to display an IPv4/IPv6 icon, or do whatever else with the IP and port. I've written a simple demo: http://www.pmarks.net/posted_links/seetheips-newapi.crx BUG=51663 TEST=unit tests, demo extension.

Patch Set 1 : '' #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+268 lines, -75 lines) Patch
M chrome/browser/extensions/extension_tabs_apitest.cc View 2 chunks +2 lines, -0 lines 0 comments Download
M chrome/browser/extensions/extension_tabs_module.cc View 1 chunk +2 lines, -0 lines 0 comments Download
M chrome/browser/extensions/extension_tabs_module_constants.h View 1 chunk +1 line, -0 lines 0 comments Download
M chrome/browser/extensions/extension_tabs_module_constants.cc View 1 chunk +1 line, -0 lines 0 comments Download
M chrome/browser/renderer_host/resource_dispatcher_host.cc View 1 chunk +1 line, -0 lines 0 comments Download
M chrome/browser/renderer_host/test/test_render_view_host.cc View 1 chunk +1 line, -0 lines 0 comments Download
M chrome/browser/tab_contents/navigation_controller.cc View 1 chunk +3 lines, -0 lines 0 comments Download
M chrome/browser/tab_contents/navigation_controller_unittest.cc View 1 chunk +2 lines, -0 lines 0 comments Download
M chrome/browser/tab_contents/navigation_entry.h View 2 chunks +10 lines, -0 lines 0 comments Download
M chrome/browser/tab_contents/navigation_entry_unittest.cc View 1 chunk +6 lines, -0 lines 0 comments Download
M chrome/common/extensions/api/extension_api.json View 1 chunk +1 line, -0 lines 0 comments Download
M chrome/common/extensions/docs/tabs.html View 1 chunk +58 lines, -0 lines 0 comments Download
M chrome/common/render_messages.cc View 3 chunks +5 lines, -1 line 0 comments Download
M chrome/common/render_messages_params.h View 1 chunk +4 lines, -0 lines 0 comments Download
M chrome/common/render_messages_params.cc View 3 chunks +5 lines, -1 line 0 comments Download
M chrome/renderer/render_view.cc View 1 chunk +1 line, -0 lines 0 comments Download
M chrome/test/data/extensions/api_test/tabs/on_updated/test.html View 1 chunk +94 lines, -72 lines 0 comments Download
M net/http/http_cache_unittest.cc View 1 chunk +24 lines, -0 lines 0 comments Download
M net/http/http_network_transaction_unittest.cc View 1 chunk +2 lines, -0 lines 0 comments Download
M net/http/http_response_info.h View 1 chunk +4 lines, -0 lines 0 comments Download
M net/http/http_response_info.cc View 6 chunks +16 lines, -0 lines 2 comments Download
M net/http/http_stream_parser.cc View 2 chunks +8 lines, -0 lines 0 comments Download
M net/socket/socket_test_util.cc View 1 chunk +1 line, -1 line 0 comments Download
M net/spdy/spdy_http_stream.cc View 1 chunk +6 lines, -0 lines 0 comments Download
M net/spdy/spdy_network_transaction_unittest.cc View 1 chunk +1 line, -0 lines 0 comments Download
M net/url_request/url_request.h View 1 chunk +4 lines, -0 lines 0 comments Download
M webkit/glue/resource_loader_bridge.h View 1 chunk +4 lines, -0 lines 0 comments Download
M webkit/glue/weburlloader_impl.cc View 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 13 (0 generated)
pmarks
Hi Eric, let me know if you can do this code review, or if you ...
9 years, 11 months ago (2011-01-19 10:08:35 UTC) #1
agl
Have you confirmed this change with the extensions folks? They are very careful about their ...
9 years, 11 months ago (2011-01-19 13:59:25 UTC) #2
Erik does not do reviews
As Adam says, there are some rules and restrictions about adding new extension APIs. Please ...
9 years, 11 months ago (2011-01-19 18:38:13 UTC) #3
eroman
Some high level comments: - Need similar plumbing for FTP responses - What is the ...
9 years, 11 months ago (2011-01-19 19:21:30 UTC) #4
eroman
Seems like this use-case might fit into the webNavigation/webRequest API. Be sure to include Jochen ...
9 years, 11 months ago (2011-01-19 19:28:15 UTC) #5
pmarks
Awesome, so I'm looking at the documentation for chrome.webRequest.onRequestSent, and it says: "ip (string) - ...
9 years, 11 months ago (2011-01-20 08:05:53 UTC) #6
jochen (gone - plz use gerrit)
It's on our okr for this quarter, however, nothing is implemented yet Jochen On Jan ...
9 years, 11 months ago (2011-01-20 09:16:23 UTC) #7
pmarks
I think I'm just going to drop this CL and leave it here as a ...
9 years, 11 months ago (2011-01-21 08:19:54 UTC) #8
pmarks
http://codereview.chromium.org/6369003/diff/45001/net/http/http_response_info.cc File net/http/http_response_info.cc (right): http://codereview.chromium.org/6369003/diff/45001/net/http/http_response_info.cc#newcode210 net/http/http_response_info.cc:210: flags |= RESPONSE_INFO_HAS_SOCKET_ADDRESS; On 2011/01/19 19:21:30, eroman wrote: > ...
9 years, 11 months ago (2011-01-21 08:21:56 UTC) #9
Brian Ryner
FYI, we'd like to use this functionality for client-side phishing detection as well. After some ...
9 years, 10 months ago (2011-02-03 19:21:01 UTC) #10
Brian Ryner
On 2011/01/21 08:21:56, pmarks wrote: > http://codereview.chromium.org/6369003/diff/45001/net/http/http_response_info.cc > File net/http/http_response_info.cc (right): > > http://codereview.chromium.org/6369003/diff/45001/net/http/http_response_info.cc#newcode210 > ...
9 years, 10 months ago (2011-02-05 19:50:21 UTC) #11
Brian Ryner
On 2011/01/19 19:21:30, eroman wrote: > - What happens on redirects? Specifically, it seems like ...
9 years, 10 months ago (2011-02-05 21:27:05 UTC) #12
pmarks
9 years, 10 months ago (2011-02-06 03:26:59 UTC) #13
On 2011/02/05 19:50:21, Brian Ryner wrote:
> > I added this flag so that it'd be possible to unpickle an older version of
the
> > object.  I think that allowing ReadString() to return false would also work.
> 
> It seems like if we don't have a flag, and instead just ignore the return
value
> from ReadString(), we won't be able to distinguish between the case where the
> socket address is missing (which is ok) and the case where it's malformed (for
> example, if the data was truncated somehow).  In the latter case, I'd think we
> would want to give up on deserializing the ResponseInfo.  So the flag seems
> preferable to me -- am I missing something?

Well, look at BaseSessionService::RestoreUpdateTabNavigationCommand(), for
example.  The type_mask and referrer fields were added later, so they're
permitted to fail.  As soon as one fails, it stops reading and assumes it's got
an older version.

In order to make the versioning work without a flag, you'd have to *always*
write the socket address, even if it's empty.

On 2011/02/05 21:27:05, Brian Ryner wrote:
> re: making the socket address work for FTP, I'm not sure what the best way is
to
> proceed.  URLRequest only has an HTTPResponseInfo field (i.e. there's no
> FTPResponseInfo).  I think it would be possible to copy the value across to
the
> HTTPResponseInfo in URLRequestFTPJob; would that make sense or is there a
better
> way to do this (without making major changes to URLRequest).

For FTP, the socket address should be extracted from
FtpNetworkTransaction::ctrl_socket_ at some point.

To export the address from URLRequest, I see two approaches:
1. Implement URLRequestFtpJob::GetResponseInfo(), and make it set only the
socket_address field.
2. Add a URLRequest::GetSocketAddress() method, which works analogously to
GetLoadState().  This requires adding a virtual GetSocketAddress() to
URLRequestJob as well.

Option 1 is less code, but it involves putting non-HTTP state into
"HttpResponseInfo", which could be considered dishonest.

Powered by Google App Engine
This is Rietveld 408576698