| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 int source_routing_id, | 188 int source_routing_id, |
| 189 int receiver_port_id, | 189 int receiver_port_id, |
| 190 const std::string& source_extension_id, | 190 const std::string& source_extension_id, |
| 191 const std::string& native_app_name) { | 191 const std::string& native_app_name) { |
| 192 content::RenderProcessHost* source = | 192 content::RenderProcessHost* source = |
| 193 content::RenderProcessHost::FromID(source_process_id); | 193 content::RenderProcessHost::FromID(source_process_id); |
| 194 if (!source) | 194 if (!source) |
| 195 return; | 195 return; |
| 196 | 196 |
| 197 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | 197 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
| 198 Profile* profile = Profile::FromBrowserContext(source->GetBrowserContext()); |
| 199 ExtensionService* extension_service = |
| 200 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 201 bool has_permission = false; |
| 202 if (extension_service) { |
| 203 const Extension* extension = |
| 204 extension_service->GetExtensionById(source_extension_id, false); |
| 205 has_permission = extension && extension->HasAPIPermission( |
| 206 APIPermission::kNativeMessaging); |
| 207 } |
| 208 |
| 209 if (!has_permission) { |
| 210 ExtensionMessagePort port(source, MSG_ROUTING_CONTROL, ""); |
| 211 port.DispatchOnDisconnect(GET_OPPOSITE_PORT_ID(receiver_port_id), true); |
| 212 return; |
| 213 } |
| 214 |
| 198 WebContents* source_contents = tab_util::GetWebContentsByID( | 215 WebContents* source_contents = tab_util::GetWebContentsByID( |
| 199 source_process_id, source_routing_id); | 216 source_process_id, source_routing_id); |
| 200 | 217 |
| 201 // Include info about the opener's tab (if it was a tab). | 218 // Include info about the opener's tab (if it was a tab). |
| 202 std::string tab_json = "null"; | 219 std::string tab_json = "null"; |
| 203 if (source_contents) { | 220 if (source_contents) { |
| 204 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( | 221 scoped_ptr<DictionaryValue> tab_value(ExtensionTabUtil::CreateTabValue( |
| 205 source_contents)); | 222 source_contents)); |
| 206 base::JSONWriter::Write(tab_value.get(), &tab_json); | 223 base::JSONWriter::Write(tab_value.get(), &tab_json); |
| 207 } | 224 } |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 return; | 501 return; |
| 485 | 502 |
| 486 params->source = source; | 503 params->source = source; |
| 487 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), | 504 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), |
| 488 MSG_ROUTING_CONTROL, | 505 MSG_ROUTING_CONTROL, |
| 489 params->target_extension_id)); | 506 params->target_extension_id)); |
| 490 OpenChannelImpl(params.Pass()); | 507 OpenChannelImpl(params.Pass()); |
| 491 } | 508 } |
| 492 | 509 |
| 493 } // namespace extensions | 510 } // namespace extensions |
| OLD | NEW |