OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/messaging/message_property_provider.h" | 5 #include "chrome/browser/extensions/api/messaging/message_property_provider.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| 11 #include "base/thread_task_runner_handle.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "extensions/common/api/runtime.h" | 15 #include "extensions/common/api/runtime.h" |
15 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
16 #include "net/cert/asn1_util.h" | 17 #include "net/cert/asn1_util.h" |
17 #include "net/cert/jwk_serializer.h" | 18 #include "net/cert/jwk_serializer.h" |
18 #include "net/ssl/channel_id_service.h" | 19 #include "net/ssl/channel_id_service.h" |
19 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
23 namespace extensions { | 24 namespace extensions { |
24 | 25 |
25 MessagePropertyProvider::MessagePropertyProvider() {} | 26 MessagePropertyProvider::MessagePropertyProvider() {} |
26 | 27 |
27 void MessagePropertyProvider::GetChannelID(Profile* profile, | 28 void MessagePropertyProvider::GetChannelID(Profile* profile, |
28 const GURL& source_url, const ChannelIDCallback& reply) { | 29 const GURL& source_url, const ChannelIDCallback& reply) { |
29 if (!source_url.is_valid()) { | 30 if (!source_url.is_valid()) { |
30 // This isn't a real URL, so there's no sense in looking for a channel ID | 31 // This isn't a real URL, so there's no sense in looking for a channel ID |
31 // for it. Dispatch with an empty tls channel ID. | 32 // for it. Dispatch with an empty tls channel ID. |
32 reply.Run(std::string()); | 33 reply.Run(std::string()); |
33 return; | 34 return; |
34 } | 35 } |
35 scoped_refptr<net::URLRequestContextGetter> request_context_getter( | 36 scoped_refptr<net::URLRequestContextGetter> request_context_getter( |
36 profile->GetRequestContext()); | 37 profile->GetRequestContext()); |
37 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 38 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
38 base::Bind(&MessagePropertyProvider::GetChannelIDOnIOThread, | 39 base::Bind(&MessagePropertyProvider::GetChannelIDOnIOThread, |
39 base::MessageLoopProxy::current(), | 40 base::ThreadTaskRunnerHandle::Get(), |
40 request_context_getter, | 41 request_context_getter, |
41 source_url.host(), | 42 source_url.host(), |
42 reply)); | 43 reply)); |
43 } | 44 } |
44 | 45 |
45 // Helper struct to bind the memory addresses that will be written to by | 46 // Helper struct to bind the memory addresses that will be written to by |
46 // ChannelIDService::GetChannelID to the callback provided to | 47 // ChannelIDService::GetChannelID to the callback provided to |
47 // MessagePropertyProvider::GetChannelID. | 48 // MessagePropertyProvider::GetChannelID. |
48 struct MessagePropertyProvider::GetChannelIDOutput { | 49 struct MessagePropertyProvider::GetChannelIDOutput { |
49 std::string domain_bound_private_key; | 50 std::string domain_bound_private_key; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if (!net::JwkSerializer::ConvertSpkiFromDerToJwk(spki, &jwk_value)) { | 99 if (!net::JwkSerializer::ConvertSpkiFromDerToJwk(spki, &jwk_value)) { |
99 original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure); | 100 original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure); |
100 return; | 101 return; |
101 } | 102 } |
102 std::string jwk_str; | 103 std::string jwk_str; |
103 base::JSONWriter::Write(&jwk_value, &jwk_str); | 104 base::JSONWriter::Write(&jwk_value, &jwk_str); |
104 original_task_runner->PostTask(FROM_HERE, base::Bind(reply, jwk_str)); | 105 original_task_runner->PostTask(FROM_HERE, base::Bind(reply, jwk_str)); |
105 } | 106 } |
106 | 107 |
107 } // namespace extensions | 108 } // namespace extensions |
OLD | NEW |