OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_service.h" | 5 #include "chrome/browser/extensions/api/messaging/message_service.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 int source_routing_id, | 187 int source_routing_id, |
188 int receiver_port_id, | 188 int receiver_port_id, |
189 const std::string& source_extension_id, | 189 const std::string& source_extension_id, |
190 const std::string& native_app_name) { | 190 const std::string& native_app_name) { |
191 content::RenderProcessHost* source = | 191 content::RenderProcessHost* source = |
192 content::RenderProcessHost::FromID(source_process_id); | 192 content::RenderProcessHost::FromID(source_process_id); |
193 if (!source) | 193 if (!source) |
194 return; | 194 return; |
195 | 195 |
196 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | 196 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
197 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext()); | |
198 ExtensionService* extension_service = | |
199 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
200 bool has_permission = false; | |
201 if (extension_service && extension_service->is_ready()) { | |
Matt Perry
2013/02/28 20:28:45
You don't need to check for is_ready.
Sergey Ulanov
2013/03/01 03:15:30
Done.
| |
202 const Extension* extension = | |
203 extension_service->GetExtensionById(source_extension_id, false); | |
204 has_permission = extension && extension->HasAPIPermission( | |
205 APIPermission::kNativeMessaging); | |
206 } | |
207 | |
208 if (!has_permission) { | |
209 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); | |
210 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), true); | |
211 return; | |
212 } | |
213 | |
197 WebContents* source_contents = tab_util::GetWebContentsByID( | 214 WebContents* source_contents = tab_util::GetWebContentsByID( |
198 source_process_id, source_routing_id); | 215 source_process_id, source_routing_id); |
199 | 216 |
200 // Include info about the opener's tab (if it was a tab). | 217 // Include info about the opener's tab (if it was a tab). |
201 std::string tab_json = "null"; | 218 std::string tab_json = "null"; |
202 if (source_contents) { | 219 if (source_contents) { |
203 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( | 220 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( |
204 source_contents)); | 221 source_contents)); |
205 base::JSONWriter::Write(tab_value.get(), &tab_json); | 222 base::JSONWriter::Write(tab_value.get(), &tab_json); |
206 } | 223 } |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 return; | 500 return; |
484 | 501 |
485 params->source = source; | 502 params->source = source; |
486 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), | 503 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), |
487 MSG_ROUTING_CONTROL, | 504 MSG_ROUTING_CONTROL, |
488 params->target_extension_id)); | 505 params->target_extension_id)); |
489 OpenChannelImpl(params.Pass()); | 506 OpenChannelImpl(params.Pass()); |
490 } | 507 } |
491 | 508 |
492 } // namespace extensions | 509 } // namespace extensions |
OLD | NEW |