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

Side by Side Diff: extensions/browser/event_router.cc

Issue 802653003: Convert EventRouter to use ProcessMap::GetMostLikelyContextType rather than (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: delete some code! Created 6 years 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 "extensions/browser/event_router.h" 5 #include "extensions/browser/event_router.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "content/public/browser/child_process_security_policy.h"
15 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
17 #include "extensions/browser/api_activity_monitor.h" 16 #include "extensions/browser/api_activity_monitor.h"
18 #include "extensions/browser/extension_host.h" 17 #include "extensions/browser/extension_host.h"
19 #include "extensions/browser/extension_prefs.h" 18 #include "extensions/browser/extension_prefs.h"
20 #include "extensions/browser/extension_registry.h" 19 #include "extensions/browser/extension_registry.h"
21 #include "extensions/browser/extension_system.h" 20 #include "extensions/browser/extension_system.h"
22 #include "extensions/browser/extensions_browser_client.h" 21 #include "extensions/browser/extensions_browser_client.h"
23 #include "extensions/browser/lazy_background_task_queue.h" 22 #include "extensions/browser/lazy_background_task_queue.h"
24 #include "extensions/browser/notification_types.h" 23 #include "extensions/browser/notification_types.h"
25 #include "extensions/browser/process_manager.h" 24 #include "extensions/browser/process_manager.h"
26 #include "extensions/browser/process_map.h" 25 #include "extensions/browser/process_map.h"
27 #include "extensions/common/extension.h" 26 #include "extensions/common/extension.h"
28 #include "extensions/common/extension_api.h" 27 #include "extensions/common/extension_api.h"
29 #include "extensions/common/extension_messages.h" 28 #include "extensions/common/extension_messages.h"
30 #include "extensions/common/extension_urls.h" 29 #include "extensions/common/extension_urls.h"
30 #include "extensions/common/features/feature.h"
31 #include "extensions/common/features/feature_provider.h"
31 #include "extensions/common/manifest_handlers/background_info.h" 32 #include "extensions/common/manifest_handlers/background_info.h"
32 #include "extensions/common/manifest_handlers/incognito_info.h" 33 #include "extensions/common/manifest_handlers/incognito_info.h"
33 #include "extensions/common/permissions/permissions_data.h" 34 #include "extensions/common/permissions/permissions_data.h"
34 35
35 using base::DictionaryValue; 36 using base::DictionaryValue;
36 using base::ListValue; 37 using base::ListValue;
37 using content::BrowserContext; 38 using content::BrowserContext;
38 using content::BrowserThread; 39 using content::BrowserThread;
39 40
40 namespace extensions { 41 namespace extensions {
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 } 533 }
533 } 534 }
534 535
535 void EventRouter::DispatchEventToProcess(const std::string& extension_id, 536 void EventRouter::DispatchEventToProcess(const std::string& extension_id,
536 const GURL& listener_url, 537 const GURL& listener_url,
537 content::RenderProcessHost* process, 538 content::RenderProcessHost* process,
538 const linked_ptr<Event>& event) { 539 const linked_ptr<Event>& event) {
539 BrowserContext* listener_context = process->GetBrowserContext(); 540 BrowserContext* listener_context = process->GetBrowserContext();
540 ProcessMap* process_map = ProcessMap::Get(listener_context); 541 ProcessMap* process_map = ProcessMap::Get(listener_context);
541 542
542 // TODO(kalman): Convert this method to use 543 // NOTE: |extension| being NULL does not necessarily imply that this event
543 // ProcessMap::GetMostLikelyContextType. 544 // shouldn't be dispatched. Events can be dispatched to WebUI and webviews as
544 545 // well. It all depends on what GetMostLikelyContextType returns.
545 const Extension* extension = 546 const Extension* extension =
546 ExtensionRegistry::Get(browser_context_)->enabled_extensions().GetByID( 547 ExtensionRegistry::Get(browser_context_)->enabled_extensions().GetByID(
547 extension_id); 548 extension_id);
548 // NOTE: |extension| being NULL does not necessarily imply that this event
549 // shouldn't be dispatched. Events can be dispatched to WebUI as well.
550 549
551 if (!extension && !extension_id.empty()) { 550 if (!extension && !extension_id.empty()) {
552 // Trying to dispatch an event to an extension that doesn't exist. The 551 // Trying to dispatch an event to an extension that doesn't exist. The
553 // extension could have been removed, but we do not unregister it until the 552 // extension could have been removed, but we do not unregister it until the
554 // extension process is unloaded. 553 // extension process is unloaded.
555 return; 554 return;
556 } 555 }
557 556
558 if (extension) { 557 if (extension) {
559 // Dispatching event to an extension. 558 // Extension-specific checks.
560 // If the event is privileged, only send to extension processes. Otherwise, 559 // Firstly, if the event is for a URL, the Extension must have permission
561 // it's OK to send to normal renderers (e.g., for content scripts). 560 // to access that URL.
562 if (!process_map->Contains(extension->id(), process->GetID()) &&
563 !ExtensionAPI::GetSharedInstance()->IsAvailableInUntrustedContext(
564 event->event_name, extension)) {
565 return;
566 }
567
568 // If the event is restricted to a URL, only dispatch if the extension has
569 // permission for it (or if the event originated from itself).
570 if (!event->event_url.is_empty() && 561 if (!event->event_url.is_empty() &&
571 event->event_url.host() != extension->id() && 562 event->event_url.host() != extension->id() && // event for self is ok
572 !extension->permissions_data() 563 !extension->permissions_data()
573 ->active_permissions() 564 ->active_permissions()
574 ->HasEffectiveAccessToURL(event->event_url)) { 565 ->HasEffectiveAccessToURL(event->event_url)) {
575 return; 566 return;
576 } 567 }
577 568 // Secondly, if the event is for incognito mode, the Extension must be
569 // enabled in incognito mode.
578 if (!CanDispatchEventToBrowserContext(listener_context, extension, event)) { 570 if (!CanDispatchEventToBrowserContext(listener_context, extension, event)) {
579 return; 571 return;
580 } 572 }
581 } else if (content::ChildProcessSecurityPolicy::GetInstance() 573 }
582 ->HasWebUIBindings(process->GetID())) { 574
583 // Dispatching event to WebUI. 575 Feature::Context target_context =
584 if (!ExtensionAPI::GetSharedInstance()->IsAvailableToWebUI( 576 process_map->GetMostLikelyContextType(extension, process->GetID());
585 event->event_name, listener_url)) { 577
586 return; 578 // We shouldn't be dispatching an event to a webpage, since all such events
587 } 579 // (e.g. messaging) don't go through EventRouter.
588 } else { 580 DCHECK_NE(Feature::WEB_PAGE_CONTEXT, target_context)
589 // Dispatching event to a webpage - however, all such events (e.g. 581 << "Trying to dispatch event " << event->event_name << " to a webpage,"
590 // messaging) don't go through EventRouter so this should be impossible. 582 << " but this shouldn't be possible";
591 NOTREACHED(); 583
584 Feature::Availability availability =
585 ExtensionAPI::GetSharedInstance()->IsAvailable(
586 event->event_name, extension, target_context, listener_url);
587 if (!availability.is_available()) {
588 // It shouldn't be possible to reach here, because access is checked on
589 // registration. However, for paranoia, check on dispatch as well.
590 NOTREACHED() << "Trying to dispatch event " << event->event_name
591 << " which the target does not have access to: "
592 << availability.message();
592 return; 593 return;
593 } 594 }
594 595
595 if (!event->will_dispatch_callback.is_null() && 596 if (!event->will_dispatch_callback.is_null() &&
596 !event->will_dispatch_callback.Run(listener_context, extension, 597 !event->will_dispatch_callback.Run(listener_context, extension,
597 event->event_args.get())) { 598 event->event_args.get())) {
598 return; 599 return;
599 } 600 }
600 601
601 DispatchExtensionMessage(process, 602 DispatchExtensionMessage(process,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 const std::string& extension_id, 818 const std::string& extension_id,
818 const GURL& listener_url, 819 const GURL& listener_url,
819 content::BrowserContext* browser_context) 820 content::BrowserContext* browser_context)
820 : event_name(event_name), 821 : event_name(event_name),
821 extension_id(extension_id), 822 extension_id(extension_id),
822 listener_url(listener_url), 823 listener_url(listener_url),
823 browser_context(browser_context) { 824 browser_context(browser_context) {
824 } 825 }
825 826
826 } // namespace extensions 827 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/extension_api_unittest.cc ('k') | extensions/common/extension_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698