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

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

Issue 344543006: Disable ephemeral apps after they stop running (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 4 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 "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 "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "content/public/browser/child_process_security_policy.h" 15 #include "content/public/browser/child_process_security_policy.h"
16 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "extensions/browser/api_activity_monitor.h" 18 #include "extensions/browser/api_activity_monitor.h"
19 #include "extensions/browser/extension_host.h" 19 #include "extensions/browser/extension_host.h"
20 #include "extensions/browser/extension_prefs.h" 20 #include "extensions/browser/extension_prefs.h"
21 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
23 #include "extensions/browser/extension_util.h"
24 #include "extensions/browser/extensions_browser_client.h" 23 #include "extensions/browser/extensions_browser_client.h"
25 #include "extensions/browser/lazy_background_task_queue.h" 24 #include "extensions/browser/lazy_background_task_queue.h"
26 #include "extensions/browser/process_manager.h" 25 #include "extensions/browser/process_manager.h"
27 #include "extensions/browser/process_map.h" 26 #include "extensions/browser/process_map.h"
28 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
29 #include "extensions/common/extension_api.h" 28 #include "extensions/common/extension_api.h"
30 #include "extensions/common/extension_messages.h" 29 #include "extensions/common/extension_messages.h"
31 #include "extensions/common/extension_urls.h" 30 #include "extensions/common/extension_urls.h"
32 #include "extensions/common/manifest_handlers/background_info.h" 31 #include "extensions/common/manifest_handlers/background_info.h"
33 #include "extensions/common/manifest_handlers/incognito_info.h" 32 #include "extensions/common/manifest_handlers/incognito_info.h"
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 if (!cross_incognito) 593 if (!cross_incognito)
595 return true; 594 return true;
596 return ExtensionsBrowserClient::Get()->CanExtensionCrossIncognito( 595 return ExtensionsBrowserClient::Get()->CanExtensionCrossIncognito(
597 extension, context); 596 extension, context);
598 } 597 }
599 598
600 bool EventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent( 599 bool EventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent(
601 BrowserContext* context, 600 BrowserContext* context,
602 const Extension* extension, 601 const Extension* extension,
603 const linked_ptr<Event>& event) { 602 const linked_ptr<Event>& event) {
604 if (util::IsEphemeralApp(extension->id(), context) &&
605 !event->can_load_ephemeral_apps) {
606 // Most events can only be dispatched to ephemeral apps that are already
607 // running.
608 ProcessManager* pm = ExtensionSystem::Get(context)->process_manager();
609 if (!pm->GetBackgroundHostForExtension(extension->id()))
610 return false;
611 }
612
613 if (!CanDispatchEventToBrowserContext(context, extension, event)) 603 if (!CanDispatchEventToBrowserContext(context, extension, event))
614 return false; 604 return false;
615 605
616 LazyBackgroundTaskQueue* queue = ExtensionSystem::Get( 606 LazyBackgroundTaskQueue* queue = ExtensionSystem::Get(
617 context)->lazy_background_task_queue(); 607 context)->lazy_background_task_queue();
618 if (queue->ShouldEnqueueTask(context, extension)) { 608 if (queue->ShouldEnqueueTask(context, extension)) {
619 linked_ptr<Event> dispatched_event(event); 609 linked_ptr<Event> dispatched_event(event);
620 610
621 // If there's a dispatch callback, call it now (rather than dispatch time) 611 // If there's a dispatch callback, call it now (rather than dispatch time)
622 // to avoid lifetime issues. Use a separate copy of the event args, so they 612 // to avoid lifetime issues. Use a separate copy of the event args, so they
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 NOTREACHED(); 736 NOTREACHED();
747 return; 737 return;
748 } 738 }
749 } 739 }
750 740
751 Event::Event(const std::string& event_name, 741 Event::Event(const std::string& event_name,
752 scoped_ptr<base::ListValue> event_args) 742 scoped_ptr<base::ListValue> event_args)
753 : event_name(event_name), 743 : event_name(event_name),
754 event_args(event_args.Pass()), 744 event_args(event_args.Pass()),
755 restrict_to_browser_context(NULL), 745 restrict_to_browser_context(NULL),
756 user_gesture(EventRouter::USER_GESTURE_UNKNOWN), 746 user_gesture(EventRouter::USER_GESTURE_UNKNOWN) {
757 can_load_ephemeral_apps(false) {
758 DCHECK(this->event_args.get()); 747 DCHECK(this->event_args.get());
759 } 748 }
760 749
761 Event::Event(const std::string& event_name, 750 Event::Event(const std::string& event_name,
762 scoped_ptr<base::ListValue> event_args, 751 scoped_ptr<base::ListValue> event_args,
763 BrowserContext* restrict_to_browser_context) 752 BrowserContext* restrict_to_browser_context)
764 : event_name(event_name), 753 : event_name(event_name),
765 event_args(event_args.Pass()), 754 event_args(event_args.Pass()),
766 restrict_to_browser_context(restrict_to_browser_context), 755 restrict_to_browser_context(restrict_to_browser_context),
767 user_gesture(EventRouter::USER_GESTURE_UNKNOWN), 756 user_gesture(EventRouter::USER_GESTURE_UNKNOWN) {
768 can_load_ephemeral_apps(false) {
769 DCHECK(this->event_args.get()); 757 DCHECK(this->event_args.get());
770 } 758 }
771 759
772 Event::Event(const std::string& event_name, 760 Event::Event(const std::string& event_name,
773 scoped_ptr<ListValue> event_args, 761 scoped_ptr<ListValue> event_args,
774 BrowserContext* restrict_to_browser_context, 762 BrowserContext* restrict_to_browser_context,
775 const GURL& event_url, 763 const GURL& event_url,
776 EventRouter::UserGestureState user_gesture, 764 EventRouter::UserGestureState user_gesture,
777 const EventFilteringInfo& filter_info) 765 const EventFilteringInfo& filter_info)
778 : event_name(event_name), 766 : event_name(event_name),
779 event_args(event_args.Pass()), 767 event_args(event_args.Pass()),
780 restrict_to_browser_context(restrict_to_browser_context), 768 restrict_to_browser_context(restrict_to_browser_context),
781 event_url(event_url), 769 event_url(event_url),
782 user_gesture(user_gesture), 770 user_gesture(user_gesture),
783 filter_info(filter_info), 771 filter_info(filter_info) {
784 can_load_ephemeral_apps(false) {
785 DCHECK(this->event_args.get()); 772 DCHECK(this->event_args.get());
786 } 773 }
787 774
788 Event::~Event() {} 775 Event::~Event() {}
789 776
790 Event* Event::DeepCopy() { 777 Event* Event::DeepCopy() {
791 Event* copy = new Event(event_name, 778 Event* copy = new Event(event_name,
792 scoped_ptr<base::ListValue>(event_args->DeepCopy()), 779 scoped_ptr<base::ListValue>(event_args->DeepCopy()),
793 restrict_to_browser_context, 780 restrict_to_browser_context,
794 event_url, 781 event_url,
795 user_gesture, 782 user_gesture,
796 filter_info); 783 filter_info);
797 copy->will_dispatch_callback = will_dispatch_callback; 784 copy->will_dispatch_callback = will_dispatch_callback;
798 return copy; 785 return copy;
799 } 786 }
800 787
801 EventListenerInfo::EventListenerInfo(const std::string& event_name, 788 EventListenerInfo::EventListenerInfo(const std::string& event_name,
802 const std::string& extension_id, 789 const std::string& extension_id,
803 content::BrowserContext* browser_context) 790 content::BrowserContext* browser_context)
804 : event_name(event_name), 791 : event_name(event_name),
805 extension_id(extension_id), 792 extension_id(extension_id),
806 browser_context(browser_context) {} 793 browser_context(browser_context) {}
807 794
808 } // namespace extensions 795 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698