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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 11150002: New post-sideload UI: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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 | Annotate | Revision Log
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/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "chrome/browser/extensions/extension_error_reporter.h" 53 #include "chrome/browser/extensions/extension_error_reporter.h"
54 #include "chrome/browser/extensions/extension_error_ui.h" 54 #include "chrome/browser/extensions/extension_error_ui.h"
55 #include "chrome/browser/extensions/extension_host.h" 55 #include "chrome/browser/extensions/extension_host.h"
56 #include "chrome/browser/extensions/extension_install_ui.h" 56 #include "chrome/browser/extensions/extension_install_ui.h"
57 #include "chrome/browser/extensions/extension_process_manager.h" 57 #include "chrome/browser/extensions/extension_process_manager.h"
58 #include "chrome/browser/extensions/extension_sorting.h" 58 #include "chrome/browser/extensions/extension_sorting.h"
59 #include "chrome/browser/extensions/extension_special_storage_policy.h" 59 #include "chrome/browser/extensions/extension_special_storage_policy.h"
60 #include "chrome/browser/extensions/extension_sync_data.h" 60 #include "chrome/browser/extensions/extension_sync_data.h"
61 #include "chrome/browser/extensions/extension_system.h" 61 #include "chrome/browser/extensions/extension_system.h"
62 #include "chrome/browser/extensions/extension_web_ui.h" 62 #include "chrome/browser/extensions/extension_web_ui.h"
63 #include "chrome/browser/extensions/external_install_ui.h"
63 #include "chrome/browser/extensions/external_provider_impl.h" 64 #include "chrome/browser/extensions/external_provider_impl.h"
64 #include "chrome/browser/extensions/external_provider_interface.h" 65 #include "chrome/browser/extensions/external_provider_interface.h"
65 #include "chrome/browser/extensions/installed_loader.h" 66 #include "chrome/browser/extensions/installed_loader.h"
66 #include "chrome/browser/extensions/lazy_background_task_queue.h" 67 #include "chrome/browser/extensions/lazy_background_task_queue.h"
67 #include "chrome/browser/extensions/pending_extension_manager.h" 68 #include "chrome/browser/extensions/pending_extension_manager.h"
68 #include "chrome/browser/extensions/permissions_updater.h" 69 #include "chrome/browser/extensions/permissions_updater.h"
69 #include "chrome/browser/extensions/platform_app_launcher.h" 70 #include "chrome/browser/extensions/platform_app_launcher.h"
70 #include "chrome/browser/extensions/settings/settings_frontend.h" 71 #include "chrome/browser/extensions/settings/settings_frontend.h"
71 #include "chrome/browser/extensions/shell_window_registry.h" 72 #include "chrome/browser/extensions/shell_window_registry.h"
72 #include "chrome/browser/extensions/unpacked_installer.h" 73 #include "chrome/browser/extensions/unpacked_installer.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 static const int kOmniboxIconPaddingLeft = 2; 150 static const int kOmniboxIconPaddingLeft = 2;
150 static const int kOmniboxIconPaddingRight = 2; 151 static const int kOmniboxIconPaddingRight = 2;
151 #elif defined(OS_MACOSX) 152 #elif defined(OS_MACOSX)
152 static const int kOmniboxIconPaddingLeft = 0; 153 static const int kOmniboxIconPaddingLeft = 0;
153 static const int kOmniboxIconPaddingRight = 2; 154 static const int kOmniboxIconPaddingRight = 2;
154 #else 155 #else
155 static const int kOmniboxIconPaddingLeft = 0; 156 static const int kOmniboxIconPaddingLeft = 0;
156 static const int kOmniboxIconPaddingRight = 0; 157 static const int kOmniboxIconPaddingRight = 0;
157 #endif 158 #endif
158 159
160 // Prompt the user this many times before considering an extension acknowledged.
161 static const int kMaxExtensionAcknowledgePromptCount = 3;
162
159 const char* kNaClPluginMimeType = "application/x-nacl"; 163 const char* kNaClPluginMimeType = "application/x-nacl";
160 164
161 static bool IsSyncableExtension(const Extension& extension) { 165 static bool IsSyncableExtension(const Extension& extension) {
162 return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION; 166 return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION;
163 } 167 }
164 168
165 static bool IsSyncableApp(const Extension& extension) { 169 static bool IsSyncableApp(const Extension& extension) {
166 return extension.GetSyncType() == Extension::SYNC_TYPE_APP; 170 return extension.GetSyncType() == Extension::SYNC_TYPE_APP;
167 } 171 }
168 172
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 // enabled unless otherwise noted. 847 // enabled unless otherwise noted.
844 return !extension_prefs_->IsExtensionDisabled(extension_id) && 848 return !extension_prefs_->IsExtensionDisabled(extension_id) &&
845 !extension_prefs_->IsExternalExtensionUninstalled(extension_id); 849 !extension_prefs_->IsExternalExtensionUninstalled(extension_id);
846 } 850 }
847 851
848 bool ExtensionService::IsExternalExtensionUninstalled( 852 bool ExtensionService::IsExternalExtensionUninstalled(
849 const std::string& extension_id) const { 853 const std::string& extension_id) const {
850 return extension_prefs_->IsExternalExtensionUninstalled(extension_id); 854 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
851 } 855 }
852 856
853 void ExtensionService::EnableExtension(const std::string& extension_id) { 857 void ExtensionService::EnableExtension(const std::string& extension_id) {
Jeffrey Yasskin 2012/10/15 00:43:59 Is there a comment somewhere saying that this func
Matt Perry 2012/10/15 19:13:38 I'm not sure what you're asking. EnableExtension i
854 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 858 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
855 859
856 if (IsExtensionEnabled(extension_id)) 860 if (IsExtensionEnabled(extension_id))
857 return; 861 return;
858 862
859 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); 863 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
860 extension_prefs_->ClearDisableReasons(extension_id); 864 extension_prefs_->ClearDisableReasons(extension_id);
861 865
862 const Extension* extension = GetExtensionByIdInternal(extension_id, 866 const Extension* extension = GetExtensionByIdInternal(extension_id,
863 INCLUDE_DISABLED); 867 INCLUDE_DISABLED);
864 // This can happen if sync enables an extension that is not 868 // This can happen if sync enables an extension that is not
865 // installed yet. 869 // installed yet.
866 if (!extension) 870 if (!extension)
867 return; 871 return;
868 872
873 if (Extension::IsExternalLocation(extension->location()))
874 AcknowledgeExternalExtension(extension->id());
875
869 // Move it over to the enabled list. 876 // Move it over to the enabled list.
870 extensions_.Insert(make_scoped_refptr(extension)); 877 extensions_.Insert(make_scoped_refptr(extension));
871 disabled_extensions_.Remove(extension->id()); 878 disabled_extensions_.Remove(extension->id());
872 879
873 // Make sure any browser action contained within it is not hidden. 880 // Make sure any browser action contained within it is not hidden.
874 extension_prefs_->SetBrowserActionVisibility(extension, true); 881 extension_prefs_->SetBrowserActionVisibility(extension, true);
875 882
876 NotifyExtensionLoaded(extension); 883 NotifyExtensionLoaded(extension);
877 884
878 // Notify listeners that the extension was enabled. 885 // Notify listeners that the extension was enabled.
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1763 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1757 did_show_alert = extension_error_ui_->ShowErrorInBubbleView(); 1764 did_show_alert = extension_error_ui_->ShowErrorInBubbleView();
1758 } else { 1765 } else {
1759 // First run. Just acknowledge all the extensions, silently, by 1766 // First run. Just acknowledge all the extensions, silently, by
1760 // shortcutting the display of the UI and going straight to the 1767 // shortcutting the display of the UI and going straight to the
1761 // callback for pressing the Accept button. 1768 // callback for pressing the Accept button.
1762 HandleExtensionAlertAccept(); 1769 HandleExtensionAlertAccept();
1763 } 1770 }
1764 } 1771 }
1765 1772
1773 UpdateExternalExtensionAlert();
1774
1766 if (!did_show_alert) 1775 if (!did_show_alert)
1767 extension_error_ui_.reset(); 1776 extension_error_ui_.reset();
1768 } 1777 }
1769 1778
1770 bool ExtensionService::PopulateExtensionErrorUI( 1779 bool ExtensionService::PopulateExtensionErrorUI(
1771 ExtensionErrorUI* extension_error_ui) { 1780 ExtensionErrorUI* extension_error_ui) {
1772 bool needs_alert = false; 1781 bool needs_alert = false;
1773 for (ExtensionSet::const_iterator iter = extensions_.begin(); 1782 for (ExtensionSet::const_iterator iter = extensions_.begin();
1774 iter != extensions_.end(); ++iter) { 1783 iter != extensions_.end(); ++iter) {
1775 const Extension* e = *iter; 1784 const Extension* e = *iter;
1776 if (Extension::IsExternalLocation(e->location())) {
1777 if (!e->is_hosted_app()) {
1778 if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) {
1779 extension_error_ui->AddExternalExtension(e->id());
1780 needs_alert = true;
1781 }
1782 }
1783 }
1784 if (!extension_prefs_->UserMayLoad(e, NULL)) { 1785 if (!extension_prefs_->UserMayLoad(e, NULL)) {
1785 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) { 1786 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) {
1786 extension_error_ui->AddBlacklistedExtension(e->id()); 1787 extension_error_ui->AddBlacklistedExtension(e->id());
1787 needs_alert = true; 1788 needs_alert = true;
1788 } 1789 }
1789 } 1790 }
1790 if (extension_prefs_->IsExtensionOrphaned(e->id())) { 1791 if (extension_prefs_->IsExtensionOrphaned(e->id())) {
1791 if (!extension_prefs_->IsOrphanedExtensionAcknowledged(e->id())) { 1792 if (!extension_prefs_->IsOrphanedExtensionAcknowledged(e->id())) {
1792 extension_error_ui->AddOrphanedExtension(e->id()); 1793 extension_error_ui->AddOrphanedExtension(e->id());
1793 needs_alert = true; 1794 needs_alert = true;
1794 } 1795 }
1795 } 1796 }
1796 } 1797 }
1797 return needs_alert; 1798 return needs_alert;
1798 } 1799 }
1799 1800
1800 void ExtensionService::HandleExtensionAlertClosed() { 1801 void ExtensionService::HandleExtensionAlertClosed() {
1801 extension_error_ui_.reset(); 1802 extension_error_ui_.reset();
1802 } 1803 }
1803 1804
1804 void ExtensionService::HandleExtensionAlertAccept() { 1805 void ExtensionService::HandleExtensionAlertAccept() {
1805 const ExtensionIdSet *extension_ids = 1806 const ExtensionIdSet* extension_ids =
1806 extension_error_ui_->get_external_extension_ids(); 1807 extension_error_ui_->get_blacklisted_extension_ids();
1807 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1808 iter != extension_ids->end(); ++iter) {
1809 AcknowledgeExternalExtension(*iter);
1810 }
1811 extension_ids = extension_error_ui_->get_blacklisted_extension_ids();
1812 for (ExtensionIdSet::const_iterator iter = extension_ids->begin(); 1808 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1813 iter != extension_ids->end(); ++iter) { 1809 iter != extension_ids->end(); ++iter) {
1814 extension_prefs_->AcknowledgeBlacklistedExtension(*iter); 1810 extension_prefs_->AcknowledgeBlacklistedExtension(*iter);
1815 } 1811 }
1816 extension_ids = extension_error_ui_->get_orphaned_extension_ids(); 1812 extension_ids = extension_error_ui_->get_orphaned_extension_ids();
1817 for (ExtensionIdSet::const_iterator iter = extension_ids->begin(); 1813 for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
1818 iter != extension_ids->end(); ++iter) { 1814 iter != extension_ids->end(); ++iter) {
1819 extension_prefs_->AcknowledgeOrphanedExtension(*iter); 1815 extension_prefs_->AcknowledgeOrphanedExtension(*iter);
1820 } 1816 }
1821 } 1817 }
1822 1818
1823 void ExtensionService::AcknowledgeExternalExtension(const std::string& id) { 1819 void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
1824 extension_prefs_->AcknowledgeExternalExtension(id); 1820 extension_prefs_->AcknowledgeExternalExtension(id);
1821 UpdateExternalExtensionAlert();
1825 } 1822 }
1826 1823
1827 void ExtensionService::HandleExtensionAlertDetails() { 1824 void ExtensionService::HandleExtensionAlertDetails() {
1828 extension_error_ui_->ShowExtensions(); 1825 extension_error_ui_->ShowExtensions();
1829 } 1826 }
1830 1827
1828 void ExtensionService::UpdateExternalExtensionAlert() {
1829 const Extension* extension = NULL;
1830 if (!extension) {
Jeffrey Yasskin 2012/10/13 21:17:35 extension is definitely NULL here.
Matt Perry 2012/10/15 19:13:38 You can never be too sure... :) Fixed.
1831 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
1832 iter != disabled_extensions_.end(); ++iter) {
1833 const Extension* e = *iter;
1834 if (Extension::IsExternalLocation(e->location())) {
1835 if (!e->is_hosted_app()) {
1836 if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) {
1837 extension = e;
1838 break;
1839 }
1840 }
1841 }
1842 }
1843 }
1844
1845 if (extension) {
1846 if (extensions::AddExternalInstallError(this, extension)) {
1847 // Note: this can sometimes overcount if there are multiple external
1848 // extensions installed on a single restart of Chrome (since
1849 // UpdateExternalExtensionAlert may get called multiple times). But that
Jeffrey Yasskin 2012/10/13 21:17:35 Won't it get called for different extensions in th
Matt Perry 2012/10/15 19:13:38 Not necessarily. This method is called both on sta
1850 // is rare, so for simplicity, we ignore that case.
1851 if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) >=
1852 kMaxExtensionAcknowledgePromptCount) {
1853 // This will be the last time we prompt for this extension.
1854 extension_prefs_->AcknowledgeExternalExtension(extension->id());
1855 }
1856 }
1857 } else {
1858 extensions::RemoveExternalInstallError(this);
1859 }
1860 }
1861
1831 void ExtensionService::UnloadExtension( 1862 void ExtensionService::UnloadExtension(
1832 const std::string& extension_id, 1863 const std::string& extension_id,
1833 extension_misc::UnloadedExtensionReason reason) { 1864 extension_misc::UnloadedExtensionReason reason) {
1834 // Make sure the extension gets deleted after we return from this function. 1865 // Make sure the extension gets deleted after we return from this function.
1835 int include_mask = INCLUDE_ENABLED | INCLUDE_DISABLED; 1866 int include_mask = INCLUDE_ENABLED | INCLUDE_DISABLED;
1836 scoped_refptr<const Extension> extension( 1867 scoped_refptr<const Extension> extension(
1837 GetExtensionByIdInternal(extension_id, include_mask)); 1868 GetExtensionByIdInternal(extension_id, include_mask));
1838 1869
1839 // This method can be called via PostTask, so the extension may have been 1870 // This method can be called via PostTask, so the extension may have been
1840 // unloaded by the time this runs. 1871 // unloaded by the time this runs.
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2159 bool has_requirement_errors) { 2190 bool has_requirement_errors) {
2160 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2191 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2161 2192
2162 // Ensure extension is deleted unless we transfer ownership. 2193 // Ensure extension is deleted unless we transfer ownership.
2163 scoped_refptr<const Extension> scoped_extension(extension); 2194 scoped_refptr<const Extension> scoped_extension(extension);
2164 const std::string& id = extension->id(); 2195 const std::string& id = extension->id();
2165 // Extensions installed by policy can't be disabled. So even if a previous 2196 // Extensions installed by policy can't be disabled. So even if a previous
2166 // installation disabled the extension, make sure it is now enabled. 2197 // installation disabled the extension, make sure it is now enabled.
2167 bool initial_enable = 2198 bool initial_enable =
2168 !extension_prefs_->IsExtensionDisabled(id) || 2199 !extension_prefs_->IsExtensionDisabled(id) ||
2169 system_->management_policy()->MustRemainEnabled(extension, NULL); 2200 system_->management_policy()->MustRemainEnabled(extension, NULL);
Jeffrey Yasskin 2012/10/15 00:43:59 Seems odd to override the management policy with t
Matt Perry 2012/10/15 19:13:38 You're right - management policy should win out he
2201 if (Extension::IsExternalLocation(extension->location()) &&
2202 !extension_prefs_->IsExternalExtensionAcknowledged(id)) {
2203 initial_enable = false;
2204 }
2170 const extensions::PendingExtensionInfo* pending_extension_info = NULL; 2205 const extensions::PendingExtensionInfo* pending_extension_info = NULL;
2171 if ((pending_extension_info = pending_extension_manager()->GetById(id))) { 2206 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
2172 if (!pending_extension_info->ShouldAllowInstall(*extension)) { 2207 if (!pending_extension_info->ShouldAllowInstall(*extension)) {
2173 pending_extension_manager()->Remove(id); 2208 pending_extension_manager()->Remove(id);
2174 2209
2175 LOG(WARNING) << "ShouldAllowInstall() returned false for " 2210 LOG(WARNING) << "ShouldAllowInstall() returned false for "
2176 << id << " of type " << extension->GetType() 2211 << id << " of type " << extension->GetType()
2177 << " and update URL " << extension->update_url().spec() 2212 << " and update URL " << extension->update_url().spec()
2178 << "; not installing"; 2213 << "; not installing";
2179 2214
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 extension_prefs_->SetAllowFileAccess(id, true); 2278 extension_prefs_->SetAllowFileAccess(id, true);
2244 } 2279 }
2245 2280
2246 content::NotificationService::current()->Notify( 2281 content::NotificationService::current()->Notify(
2247 chrome::NOTIFICATION_EXTENSION_INSTALLED, 2282 chrome::NOTIFICATION_EXTENSION_INSTALLED,
2248 content::Source<Profile>(profile_), 2283 content::Source<Profile>(profile_),
2249 content::Details<const Extension>(extension)); 2284 content::Details<const Extension>(extension));
2250 2285
2251 // Transfer ownership of |extension| to AddExtension. 2286 // Transfer ownership of |extension| to AddExtension.
2252 AddExtension(scoped_extension); 2287 AddExtension(scoped_extension);
2288
2289 if (Extension::IsExternalLocation(extension->location()))
2290 UpdateExternalExtensionAlert();
2253 } 2291 }
2254 2292
2255 const Extension* ExtensionService::GetExtensionByIdInternal( 2293 const Extension* ExtensionService::GetExtensionByIdInternal(
2256 const std::string& id, int include_mask) const { 2294 const std::string& id, int include_mask) const {
2257 std::string lowercase_id = StringToLowerASCII(id); 2295 std::string lowercase_id = StringToLowerASCII(id);
2258 if (include_mask & INCLUDE_ENABLED) { 2296 if (include_mask & INCLUDE_ENABLED) {
2259 const Extension* extension = extensions_.GetByID(lowercase_id); 2297 const Extension* extension = extensions_.GetByID(lowercase_id);
2260 if (extension) 2298 if (extension)
2261 return extension; 2299 return extension;
2262 } 2300 }
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
2685 extension_host->extension(), 2723 extension_host->extension(),
2686 NULL, FilePath()); 2724 NULL, FilePath());
2687 #endif 2725 #endif
2688 } 2726 }
2689 2727
2690 void ExtensionService::InspectExtensionHost( 2728 void ExtensionService::InspectExtensionHost(
2691 extensions::ExtensionHost* host) { 2729 extensions::ExtensionHost* host) {
2692 if (host) 2730 if (host)
2693 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); 2731 DevToolsWindow::OpenDevToolsWindow(host->render_view_host());
2694 } 2732 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698