OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); | 679 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
680 installer->InstallCrx(extension_path); | 680 installer->InstallCrx(extension_path); |
681 | 681 |
682 if (out_crx_installer) | 682 if (out_crx_installer) |
683 *out_crx_installer = installer; | 683 *out_crx_installer = installer; |
684 | 684 |
685 return true; | 685 return true; |
686 } | 686 } |
687 | 687 |
688 void ExtensionService::ReloadExtension(const std::string& extension_id) { | 688 void ExtensionService::ReloadExtension(const std::string& extension_id) { |
689 int events = HasShellWindows(extension_id) ? EVENT_LAUNCHED : EVENT_NONE; | |
690 ReloadExtensionWithEvents(extension_id, events); | |
691 } | |
692 | |
693 void ExtensionService::RestartExtension(const std::string& extension_id) { | |
694 ReloadExtensionWithEvents(extension_id, EVENT_RESTARTED); | |
695 } | |
696 | |
697 void ExtensionService::ReloadExtensionWithEvents( | |
698 const std::string& extension_id, | |
699 int events) { | |
700 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 689 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
701 | 690 |
702 // If the extension is already reloading, don't reload again. | 691 // If the extension is already reloading, don't reload again. |
703 if (extension_prefs_->GetDisableReasons(extension_id) & | 692 if (extension_prefs_->GetDisableReasons(extension_id) & |
704 Extension::DISABLE_RELOAD) { | 693 Extension::DISABLE_RELOAD) { |
705 return; | 694 return; |
706 } | 695 } |
707 | 696 |
708 base::FilePath path; | 697 base::FilePath path; |
709 const Extension* current_extension = GetExtensionById(extension_id, false); | 698 const Extension* current_extension = GetExtensionById(extension_id, false); |
(...skipping 15 matching lines...) Expand all Loading... |
725 orphaned_dev_tools_[extension_id] = devtools_cookie; | 714 orphaned_dev_tools_[extension_id] = devtools_cookie; |
726 } | 715 } |
727 | 716 |
728 path = current_extension->path(); | 717 path = current_extension->path(); |
729 DisableExtension(extension_id, Extension::DISABLE_RELOAD); | 718 DisableExtension(extension_id, Extension::DISABLE_RELOAD); |
730 reloading_extensions_.insert(extension_id); | 719 reloading_extensions_.insert(extension_id); |
731 } else { | 720 } else { |
732 path = unloaded_extension_paths_[extension_id]; | 721 path = unloaded_extension_paths_[extension_id]; |
733 } | 722 } |
734 | 723 |
735 on_load_events_[extension_id] = events; | |
736 | |
737 if (delayed_updates_for_idle_.Contains(extension_id)) { | 724 if (delayed_updates_for_idle_.Contains(extension_id)) { |
738 FinishDelayedInstallation(extension_id); | 725 FinishDelayedInstallation(extension_id); |
739 return; | 726 return; |
740 } | 727 } |
741 | 728 |
742 // If we're reloading a component extension, use the component extension | 729 // If we're reloading a component extension, use the component extension |
743 // loader's reloader. | 730 // loader's reloader. |
744 if (component_loader_->Exists(extension_id)) { | 731 if (component_loader_->Exists(extension_id)) { |
745 component_loader_->Reload(extension_id); | 732 component_loader_->Reload(extension_id); |
746 return; | 733 return; |
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 // Show the extension disabled error if a permissions increase was the | 2076 // Show the extension disabled error if a permissions increase was the |
2090 // only reason it was disabled. | 2077 // only reason it was disabled. |
2091 if (extension_prefs_->GetDisableReasons(extension->id()) == | 2078 if (extension_prefs_->GetDisableReasons(extension->id()) == |
2092 Extension::DISABLE_PERMISSIONS_INCREASE) { | 2079 Extension::DISABLE_PERMISSIONS_INCREASE) { |
2093 extensions::AddExtensionDisabledError(this, extension); | 2080 extensions::AddExtensionDisabledError(this, extension); |
2094 } | 2081 } |
2095 } else if (reloading) { | 2082 } else if (reloading) { |
2096 // Replace the old extension with the new version. | 2083 // Replace the old extension with the new version. |
2097 CHECK(!disabled_extensions_.Insert(extension)); | 2084 CHECK(!disabled_extensions_.Insert(extension)); |
2098 EnableExtension(extension->id()); | 2085 EnableExtension(extension->id()); |
2099 DoPostLoadTasks(extension); | |
2100 } else { | 2086 } else { |
2101 // All apps that are displayed in the launcher are ordered by their ordinals | 2087 // All apps that are displayed in the launcher are ordered by their ordinals |
2102 // so we must ensure they have valid ordinals. | 2088 // so we must ensure they have valid ordinals. |
2103 if (extension->RequiresSortOrdinal()) { | 2089 if (extension->RequiresSortOrdinal()) { |
2104 if (!extension->ShouldDisplayInNewTabPage()) { | 2090 if (!extension->ShouldDisplayInNewTabPage()) { |
2105 extension_prefs_->extension_sorting()->MarkExtensionAsHidden( | 2091 extension_prefs_->extension_sorting()->MarkExtensionAsHidden( |
2106 extension->id()); | 2092 extension->id()); |
2107 } | 2093 } |
2108 extension_prefs_->extension_sorting()->EnsureValidOrdinals( | 2094 extension_prefs_->extension_sorting()->EnsureValidOrdinals( |
2109 extension->id(), syncer::StringOrdinal()); | 2095 extension->id(), syncer::StringOrdinal()); |
2110 } | 2096 } |
2111 | 2097 |
2112 extensions_.Insert(extension); | 2098 extensions_.Insert(extension); |
2113 SyncExtensionChangeIfNeeded(*extension); | 2099 SyncExtensionChangeIfNeeded(*extension); |
2114 NotifyExtensionLoaded(extension); | 2100 NotifyExtensionLoaded(extension); |
2115 DoPostLoadTasks(extension); | |
2116 } | 2101 } |
2117 SetBeingUpgraded(extension, false); | 2102 SetBeingUpgraded(extension, false); |
2118 } | 2103 } |
2119 | 2104 |
2120 void ExtensionService::AddComponentExtension(const Extension* extension) { | 2105 void ExtensionService::AddComponentExtension(const Extension* extension) { |
2121 const std::string old_version_string( | 2106 const std::string old_version_string( |
2122 extension_prefs_->GetVersionString(extension->id())); | 2107 extension_prefs_->GetVersionString(extension->id())); |
2123 const Version old_version(old_version_string); | 2108 const Version old_version(old_version_string); |
2124 | 2109 |
2125 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { | 2110 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 2253 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
2269 iter != extensions_.end(); ++iter) { | 2254 iter != extensions_.end(); ++iter) { |
2270 const Extension* extension = *iter; | 2255 const Extension* extension = *iter; |
2271 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT) | 2256 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT) |
2272 extension_ids.insert(extension->id()); | 2257 extension_ids.insert(extension->id()); |
2273 } | 2258 } |
2274 | 2259 |
2275 child_process_logging::SetActiveExtensions(extension_ids); | 2260 child_process_logging::SetActiveExtensions(extension_ids); |
2276 } | 2261 } |
2277 | 2262 |
2278 void ExtensionService::ScheduleLaunchOnLoad(const std::string& extension_id) { | |
2279 on_load_events_[extension_id] = EVENT_LAUNCHED; | |
2280 } | |
2281 | |
2282 void ExtensionService::OnExtensionInstalled( | 2263 void ExtensionService::OnExtensionInstalled( |
2283 const Extension* extension, | 2264 const Extension* extension, |
2284 const syncer::StringOrdinal& page_ordinal, | 2265 const syncer::StringOrdinal& page_ordinal, |
2285 bool has_requirement_errors, | 2266 bool has_requirement_errors, |
2286 bool wait_for_idle) { | 2267 bool wait_for_idle) { |
2287 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2268 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2288 | 2269 |
2289 const std::string& id = extension->id(); | 2270 const std::string& id = extension->id(); |
2290 bool initial_enable = ShouldEnableOnInstall(extension); | 2271 bool initial_enable = ShouldEnableOnInstall(extension); |
2291 const extensions::PendingExtensionInfo* pending_extension_info = NULL; | 2272 const extensions::PendingExtensionInfo* pending_extension_info = NULL; |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2883 ExtensionService::NaClModuleInfoList::iterator | 2864 ExtensionService::NaClModuleInfoList::iterator |
2884 ExtensionService::FindNaClModule(const GURL& url) { | 2865 ExtensionService::FindNaClModule(const GURL& url) { |
2885 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2866 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
2886 iter != nacl_module_list_.end(); ++iter) { | 2867 iter != nacl_module_list_.end(); ++iter) { |
2887 if (iter->url == url) | 2868 if (iter->url == url) |
2888 return iter; | 2869 return iter; |
2889 } | 2870 } |
2890 return nacl_module_list_.end(); | 2871 return nacl_module_list_.end(); |
2891 } | 2872 } |
2892 | 2873 |
2893 void ExtensionService::DoPostLoadTasks(const Extension* extension) { | |
2894 std::map<std::string, int>::iterator it = | |
2895 on_load_events_.find(extension->id()); | |
2896 if (it == on_load_events_.end()) | |
2897 return; | |
2898 | |
2899 int events_to_fire = it->second; | |
2900 extensions::LazyBackgroundTaskQueue* queue = | |
2901 system_->lazy_background_task_queue(); | |
2902 if (queue->ShouldEnqueueTask(profile(), extension)) { | |
2903 if (events_to_fire & EVENT_LAUNCHED) | |
2904 queue->AddPendingTask(profile(), extension->id(), | |
2905 base::Bind(&ExtensionService::LaunchApplication)); | |
2906 if (events_to_fire & EVENT_RESTARTED) { | |
2907 queue->AddPendingTask(profile(), extension->id(), | |
2908 base::Bind(&ExtensionService::RestartApplication)); | |
2909 } | |
2910 } | |
2911 | |
2912 on_load_events_.erase(it); | |
2913 } | |
2914 | |
2915 // static | |
2916 void ExtensionService::LaunchApplication( | |
2917 extensions::ExtensionHost* extension_host) { | |
2918 if (!extension_host) | |
2919 return; | |
2920 | |
2921 #if !defined(OS_ANDROID) | |
2922 extensions::LaunchPlatformApp(extension_host->profile(), | |
2923 extension_host->extension(), | |
2924 NULL, base::FilePath()); | |
2925 #endif | |
2926 } | |
2927 | |
2928 // static | |
2929 void ExtensionService::RestartApplication( | |
2930 extensions::ExtensionHost* extension_host) { | |
2931 if (!extension_host) | |
2932 return; | |
2933 | |
2934 #if !defined(OS_ANDROID) | |
2935 extensions::RestartPlatformApp( | |
2936 extension_host->profile(), extension_host->extension()); | |
2937 #endif | |
2938 } | |
2939 | |
2940 bool ExtensionService::HasShellWindows(const std::string& extension_id) { | |
2941 const Extension* current_extension = GetExtensionById(extension_id, false); | |
2942 return current_extension && current_extension->is_platform_app() && | |
2943 !extensions::ShellWindowRegistry::Get(profile_)-> | |
2944 GetShellWindowsForApp(extension_id).empty(); | |
2945 } | |
2946 | |
2947 void ExtensionService::InspectExtensionHost( | 2874 void ExtensionService::InspectExtensionHost( |
2948 extensions::ExtensionHost* host) { | 2875 extensions::ExtensionHost* host) { |
2949 if (host) | 2876 if (host) |
2950 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); | 2877 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); |
2951 } | 2878 } |
2952 | 2879 |
2953 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { | 2880 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { |
2954 // Extensions installed by policy can't be disabled. So even if a previous | 2881 // Extensions installed by policy can't be disabled. So even if a previous |
2955 // installation disabled the extension, make sure it is now enabled. | 2882 // installation disabled the extension, make sure it is now enabled. |
2956 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) | 2883 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3102 } | 3029 } |
3103 | 3030 |
3104 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 3031 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
3105 update_observers_.AddObserver(observer); | 3032 update_observers_.AddObserver(observer); |
3106 } | 3033 } |
3107 | 3034 |
3108 void ExtensionService::RemoveUpdateObserver( | 3035 void ExtensionService::RemoveUpdateObserver( |
3109 extensions::UpdateObserver* observer) { | 3036 extensions::UpdateObserver* observer) { |
3110 update_observers_.RemoveObserver(observer); | 3037 update_observers_.RemoveObserver(observer); |
3111 } | 3038 } |
OLD | NEW |