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

Side by Side Diff: chrome/browser/extensions/api/messaging/message_service.cc

Issue 2006013002: [Extensions] Determine NativeMessaging ID solely on the browser process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 25 matching lines...) Expand all
36 #include "content/public/browser/render_widget_host_view.h" 36 #include "content/public/browser/render_widget_host_view.h"
37 #include "content/public/browser/site_instance.h" 37 #include "content/public/browser/site_instance.h"
38 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
39 #include "content/public/common/child_process_host.h" 39 #include "content/public/common/child_process_host.h"
40 #include "extensions/browser/event_router.h" 40 #include "extensions/browser/event_router.h"
41 #include "extensions/browser/extension_api_frame_id_map.h" 41 #include "extensions/browser/extension_api_frame_id_map.h"
42 #include "extensions/browser/extension_host.h" 42 #include "extensions/browser/extension_host.h"
43 #include "extensions/browser/extension_registry.h" 43 #include "extensions/browser/extension_registry.h"
44 #include "extensions/browser/extension_system.h" 44 #include "extensions/browser/extension_system.h"
45 #include "extensions/browser/extension_util.h" 45 #include "extensions/browser/extension_util.h"
46 #include "extensions/browser/extension_web_contents_observer.h"
46 #include "extensions/browser/extensions_browser_client.h" 47 #include "extensions/browser/extensions_browser_client.h"
47 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 48 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
48 #include "extensions/browser/lazy_background_task_queue.h" 49 #include "extensions/browser/lazy_background_task_queue.h"
49 #include "extensions/browser/pref_names.h" 50 #include "extensions/browser/pref_names.h"
50 #include "extensions/browser/process_manager.h" 51 #include "extensions/browser/process_manager.h"
51 #include "extensions/common/extension.h" 52 #include "extensions/common/extension.h"
52 #include "extensions/common/manifest_constants.h" 53 #include "extensions/common/manifest_constants.h"
53 #include "extensions/common/manifest_handlers/background_info.h" 54 #include "extensions/common/manifest_handlers/background_info.h"
54 #include "extensions/common/manifest_handlers/externally_connectable.h" 55 #include "extensions/common/manifest_handlers/externally_connectable.h"
55 #include "extensions/common/manifest_handlers/incognito_info.h" 56 #include "extensions/common/manifest_handlers/incognito_info.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 return; 400 return;
400 } 401 }
401 402
402 OnOpenChannelAllowed(std::move(params), true); 403 OnOpenChannelAllowed(std::move(params), true);
403 } 404 }
404 405
405 void MessageService::OpenChannelToNativeApp( 406 void MessageService::OpenChannelToNativeApp(
406 int source_process_id, 407 int source_process_id,
407 int source_routing_id, 408 int source_routing_id,
408 int receiver_port_id, 409 int receiver_port_id,
409 const std::string& source_extension_id,
410 const std::string& native_app_name) { 410 const std::string& native_app_name) {
411 DCHECK_CURRENTLY_ON(BrowserThread::UI); 411 DCHECK_CURRENTLY_ON(BrowserThread::UI);
412 412
413 content::RenderFrameHost* source = 413 content::RenderFrameHost* source =
414 content::RenderFrameHost::FromID(source_process_id, source_routing_id); 414 content::RenderFrameHost::FromID(source_process_id, source_routing_id);
415 if (!source) 415 if (!source)
416 return; 416 return;
417 417
418 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) 418 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
419 Profile* profile = 419 content::WebContents* web_contents =
420 Profile::FromBrowserContext(source->GetProcess()->GetBrowserContext()); 420 content::WebContents::FromRenderFrameHost(source);;
dcheng 2016/05/24 04:41:46 Nit: double semicolon here.
Devlin 2016/05/24 21:59:08 Done.
421 ExtensionService* extension_service = 421 ExtensionWebContentsObserver* extension_web_contents_observer =
422 ExtensionSystem::Get(profile)->extension_service(); 422 web_contents ?
423 bool has_permission = false; 423 ExtensionWebContentsObserver::GetForWebContents(web_contents) :
424 if (extension_service) { 424 nullptr;
425 const Extension* extension = 425 const Extension* extension =
426 extension_service->GetExtensionById(source_extension_id, false); 426 extension_web_contents_observer ?
427 has_permission = extension && 427 extension_web_contents_observer->GetExtensionFromFrame(source, true) :
428 extension->permissions_data()->HasAPIPermission( 428 nullptr;
429 APIPermission::kNativeMessaging); 429
430 } 430 bool has_permission = extension &&
431 extension->permissions_data()->HasAPIPermission(
432 APIPermission::kNativeMessaging);
431 433
432 if (!has_permission) { 434 if (!has_permission) {
433 DispatchOnDisconnect(source, receiver_port_id, kMissingPermissionError); 435 DispatchOnDisconnect(source, receiver_port_id, kMissingPermissionError);
434 return; 436 return;
435 } 437 }
436 438
437 PrefService* pref_service = profile->GetPrefs(); 439 PrefService* pref_service =
440 Profile::FromBrowserContext(source->GetProcess()->GetBrowserContext())->
441 GetPrefs();
438 442
439 // Verify that the host is not blocked by policies. 443 // Verify that the host is not blocked by policies.
440 PolicyPermission policy_permission = 444 PolicyPermission policy_permission =
441 IsNativeMessagingHostAllowed(pref_service, native_app_name); 445 IsNativeMessagingHostAllowed(pref_service, native_app_name);
442 if (policy_permission == DISALLOW) { 446 if (policy_permission == DISALLOW) {
443 DispatchOnDisconnect(source, receiver_port_id, kProhibitedByPoliciesError); 447 DispatchOnDisconnect(source, receiver_port_id, kProhibitedByPoliciesError);
444 return; 448 return;
445 } 449 }
446 450
447 std::unique_ptr<MessageChannel> channel(new MessageChannel()); 451 std::unique_ptr<MessageChannel> channel(new MessageChannel());
448 channel->opener.reset( 452 channel->opener.reset(
449 new ExtensionMessagePort(weak_factory_.GetWeakPtr(), 453 new ExtensionMessagePort(weak_factory_.GetWeakPtr(),
450 GET_OPPOSITE_PORT_ID(receiver_port_id), 454 GET_OPPOSITE_PORT_ID(receiver_port_id),
451 source_extension_id, source, false)); 455 extension->id(), source, false));
452 if (!channel->opener->IsValidPort()) 456 if (!channel->opener->IsValidPort())
453 return; 457 return;
454 channel->opener->OpenPort(source_process_id, source_routing_id); 458 channel->opener->OpenPort(source_process_id, source_routing_id);
455 459
456 // Get handle of the native view and pass it to the native messaging host. 460 // Get handle of the native view and pass it to the native messaging host.
457 gfx::NativeView native_view = source ? source->GetNativeView() : nullptr; 461 gfx::NativeView native_view = source ? source->GetNativeView() : nullptr;
458 462
459 std::string error = kReceivingEndDoesntExistError; 463 std::string error = kReceivingEndDoesntExistError;
460 std::unique_ptr<NativeMessageHost> native_host = NativeMessageHost::Create( 464 std::unique_ptr<NativeMessageHost> native_host = NativeMessageHost::Create(
461 native_view, source_extension_id, native_app_name, 465 native_view, extension->id(), native_app_name,
462 policy_permission == ALLOW_ALL, &error); 466 policy_permission == ALLOW_ALL, &error);
463 467
464 // Abandon the channel. 468 // Abandon the channel.
465 if (!native_host.get()) { 469 if (!native_host.get()) {
466 LOG(ERROR) << "Failed to create native process."; 470 LOG(ERROR) << "Failed to create native process.";
467 DispatchOnDisconnect(source, receiver_port_id, error); 471 DispatchOnDisconnect(source, receiver_port_id, error);
468 return; 472 return;
469 } 473 }
470 channel->receiver.reset(new NativeMessagePort( 474 channel->receiver.reset(new NativeMessagePort(
471 weak_factory_.GetWeakPtr(), receiver_port_id, std::move(native_host))); 475 weak_factory_.GetWeakPtr(), receiver_port_id, std::move(native_host)));
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 1014
1011 MessageChannelMap::iterator channel_iter = channels_.find(channel_id); 1015 MessageChannelMap::iterator channel_iter = channels_.find(channel_id);
1012 if (channel_iter != channels_.end()) { 1016 if (channel_iter != channels_.end()) {
1013 for (const PendingMessage& message : queue) { 1017 for (const PendingMessage& message : queue) {
1014 DispatchMessage(message.first, channel_iter->second, message.second); 1018 DispatchMessage(message.first, channel_iter->second, message.second);
1015 } 1019 }
1016 } 1020 }
1017 } 1021 }
1018 1022
1019 } // namespace extensions 1023 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698