diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-26 04:09:23 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-26 04:09:23 +0000 |
commit | 9ceb0734baeac21d1560023475f381b8a21e6cfa (patch) | |
tree | fa92103aa16e6ff04e90206c6ac99710c3c2d7ca /chrome/browser/extensions | |
parent | 97cdbad260d0a97b1a57dc4e863607c409533412 (diff) | |
download | chromium_src-9ceb0734baeac21d1560023475f381b8a21e6cfa.zip chromium_src-9ceb0734baeac21d1560023475f381b8a21e6cfa.tar.gz chromium_src-9ceb0734baeac21d1560023475f381b8a21e6cfa.tar.bz2 |
Revert revisions 21622-21624.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
5 files changed, 45 insertions, 167 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 38947aa..ee5fc8c 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -28,9 +28,7 @@ #include "chrome/browser/extensions/extension_updater.h" #include "chrome/browser/extensions/external_extension_provider.h" #include "chrome/browser/extensions/external_pref_extension_provider.h" -#include "chrome/browser/extensions/theme_preview_infobar_delegate.h" #include "chrome/browser/profile.h" -#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/utility_process_host.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" @@ -87,7 +85,6 @@ const char* kSignatureVerificationFailed = "Signature verification failed"; const char* kSignatureVerificationInitFailed = "Signature verification initialization failed. This is most likely " "caused by a public key in the wrong format (should encode algorithm)."; - } // static @@ -252,8 +249,7 @@ ExtensionsService::ExtensionsService(Profile* profile, MessageLoop* frontend_loop, MessageLoop* backend_loop, bool autoupdate_enabled) - : profile_(profile), - extension_prefs_(new ExtensionPrefs(prefs, install_directory)), + : extension_prefs_(new ExtensionPrefs(prefs, install_directory)), backend_loop_(backend_loop), install_directory_(install_directory), extensions_enabled_(false), @@ -516,14 +512,10 @@ void ExtensionsService::OnExtensionInstalled(const FilePath& path, // If the extension is a theme, tell the profile (and therefore ThemeProvider) // to apply it. if (extension->IsTheme()) { - if (ShowThemePreviewInfobar(extension)) { - NotificationService::current()->Notify( - NotificationType::THEME_INSTALLED, - Source<ExtensionsService>(this), - Details<Extension>(extension)); - } else { - UninstallExtension(extension->id(), false); // not an external uninstall - } + NotificationService::current()->Notify( + NotificationType::THEME_INSTALLED, + Source<ExtensionsService>(this), + Details<Extension>(extension)); } else { NotificationService::current()->Notify( NotificationType::EXTENSION_INSTALLED, @@ -551,14 +543,10 @@ void ExtensionsService::OnExtensionOverinstallAttempted(const std::string& id, FireInstallCallback(path, NULL); Extension* extension = GetExtensionById(id); if (extension && extension->IsTheme()) { - if (ShowThemePreviewInfobar(extension)) { - NotificationService::current()->Notify( - NotificationType::THEME_INSTALLED, - Source<ExtensionsService>(this), - Details<Extension>(extension)); - } else { - UninstallExtension(extension->id(), false); // not an external uninstall - } + NotificationService::current()->Notify( + NotificationType::THEME_INSTALLED, + Source<ExtensionsService>(this), + Details<Extension>(extension)); } } @@ -589,23 +577,6 @@ void ExtensionsService::SetProviderForTesting( location, test_provider)); } -bool ExtensionsService::ShowThemePreviewInfobar(Extension* extension) { - if (!profile_) - return false; - - Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); - if (!browser) - return false; - - TabContents* tab_contents = browser->GetSelectedTabContents(); - if (!tab_contents) - return false; - - tab_contents->AddInfoBar(new ThemePreviewInfobarDelegate(tab_contents, - extension->name())); - return true; -} - // ExtensionsServicesBackend ExtensionsServiceBackend::ExtensionsServiceBackend( @@ -1154,15 +1125,15 @@ void ExtensionsServiceBackend::OnExtensionUnpacked( Extension::Location location = Extension::INTERNAL; LookupExternalExtension(extension.id(), NULL, &location); + // We allow themes from our minigallery or externally-registered + // extensions to be installed, even without --enable-extensions. bool allow_install = false; if (extensions_enabled_) allow_install = true; - // Always allow themes. - if (extension.IsTheme()) + if (extension.IsTheme() && from_gallery) allow_install = true; - // Always allow externally installed extensions (partners use this). if (Extension::IsExternalLocation(location)) allow_install = true; @@ -1175,12 +1146,12 @@ void ExtensionsServiceBackend::OnExtensionUnpacked( // TODO(extensions): Make better extensions UI. http://crbug.com/12116 // We also skip the dialog for a few special cases: - // - themes (because we show the preview infobar for them) + // - themes from the gallery // - externally registered extensions // - during tests (!frontend->show_extension_prompts()) // - autoupdate (silent). bool show_dialog = true; - if (extension.IsTheme()) + if (extension.IsTheme() && from_gallery) show_dialog = false; if (Extension::IsExternalLocation(location)) diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 4a57e41..8e0305f 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -208,9 +208,6 @@ class ExtensionsService return show_extensions_prompts_; } - // Profile calls this when it is destroyed so that we know not to call it. - void ProfileDestroyed() { profile_ = NULL; } - ExtensionPrefs* extension_prefs() { return extension_prefs_.get(); } // Whether the extension service is ready. @@ -242,15 +239,6 @@ class ExtensionsService void OnExtensionOverinstallAttempted(const std::string& id, const FilePath& path); - // Show a confirm installation infobar on the currently active tab. - // TODO(aa): This should be moved up into the UI and attached to the tab it - // actually occured in. This requires some modularization of - // ExtensionsService. - bool ShowThemePreviewInfobar(Extension* extension); - - // The profile this ExtensionsService is part of. - Profile* profile_; - // Preferences for the owning profile. scoped_ptr<ExtensionPrefs> extension_prefs_; diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index f997894..99e43ea 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -342,8 +342,15 @@ class ExtensionsServiceTest void InstallExtension(const FilePath& path, bool should_succeed) { + InstallExtension(path, should_succeed, GURL(), GURL()); + } + + void InstallExtension(const FilePath& path, + bool should_succeed, + const GURL& download_url, + const GURL& referrer_url) { ASSERT_TRUE(file_util::PathExists(path)); - service_->InstallExtension(path); + service_->InstallExtension(path, download_url, referrer_url); loop_.RunAllPending(); std::vector<std::string> errors = GetErrors(); if (should_succeed) { @@ -796,15 +803,35 @@ TEST_F(ExtensionsServiceTest, InstallTheme) { ValidatePref(theme_crx, L"state", Extension::ENABLED); ValidatePref(theme_crx, L"location", Extension::INTERNAL); - // A theme when extensions are disabled. Themes can be installed, even when - // extensions are disabled. + // A theme when extensions are disabled. Themes cannot be installed when + // extensions are disabled... SetExtensionsEnabled(false); path = extensions_path.AppendASCII("theme2.crx"); - InstallExtension(path, true); + InstallExtension(path, false); + ValidatePrefKeyCount(pref_count); + + // ... unless they come from the gallery URL. + SetExtensionsEnabled(false); + path = extensions_path.AppendASCII("theme2.crx"); + InstallExtension(path, true, + GURL(std::string(ExtensionsService::kGalleryDownloadURLPrefix) + "f.crx"), + GURL(std::string(ExtensionsService::kGalleryURLPrefix) + "foobar")); ValidatePrefKeyCount(++pref_count); ValidatePref(theme2_crx, L"state", Extension::ENABLED); ValidatePref(theme2_crx, L"location", Extension::INTERNAL); + // also test this fails if either of the URLs is not correct + path = extensions_path.AppendASCII("theme2.crx"); + InstallExtension(path, false, + GURL(std::string(ExtensionsService::kGalleryDownloadURLPrefix) + "f.crx"), + GURL()); + ValidatePrefKeyCount(pref_count); + + path = extensions_path.AppendASCII("theme2.crx"); + InstallExtension(path, false, + GURL(), GURL(std::string(ExtensionsService::kGalleryURLPrefix) + "foobar")); + ValidatePrefKeyCount(pref_count); + // A theme with extension elements. Themes cannot have extension elements so // this test should fail. SetExtensionsEnabled(true); diff --git a/chrome/browser/extensions/theme_preview_infobar_delegate.cc b/chrome/browser/extensions/theme_preview_infobar_delegate.cc deleted file mode 100644 index f985c1b..0000000 --- a/chrome/browser/extensions/theme_preview_infobar_delegate.cc +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/extensions/theme_preview_infobar_delegate.h" - -#include "app/l10n_util.h" -#include "base/string_util.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "grit/generated_resources.h" - -ThemePreviewInfobarDelegate::ThemePreviewInfobarDelegate( - TabContents* tab_contents, const std::string& name) - : ConfirmInfoBarDelegate(tab_contents), - profile_(tab_contents->profile()), name_(name), - selection_made_(false) { -} - -void ThemePreviewInfobarDelegate::InfoBarClosed() { - if (!selection_made_) - profile_->ClearTheme(); - - delete this; -} - -std::wstring ThemePreviewInfobarDelegate::GetMessageText() const { - return l10n_util::GetStringF(IDS_THEME_PREVIEW_INFOBAR_LABEL, - UTF8ToWide(name_)); -} - -SkBitmap* ThemePreviewInfobarDelegate::GetIcon() const { - // TODO(aa): Reply with the theme's icon, but this requires reading it - // asynchronously from disk. - return NULL; -} - -int ThemePreviewInfobarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - -std::wstring ThemePreviewInfobarDelegate::GetButtonLabel( - ConfirmInfoBarDelegate::InfoBarButton button) const { - switch (button) { - case BUTTON_OK: - return l10n_util::GetString(IDS_THEME_PREVIEW_INFOBAR_OK_BUTTON); - case BUTTON_CANCEL: - return l10n_util::GetString(IDS_THEME_PREVIEW_INFOBAR_CANCEL_BUTTON); - default: - NOTREACHED(); - return L""; - } -} - -bool ThemePreviewInfobarDelegate::Accept() { - selection_made_ = true; - return true; -} - -bool ThemePreviewInfobarDelegate::Cancel() { - selection_made_ = true; - - // Blech, this is a total hack. - // - // a) We should be uninstalling via ExtensionsService, not - // Profile::ClearTheme(). - // b) We should be able to view the theme without installing it. This would - // help in edge cases like the user closing the window or tab before making - // a decision. - profile_->ClearTheme(); - return true; -} diff --git a/chrome/browser/extensions/theme_preview_infobar_delegate.h b/chrome/browser/extensions/theme_preview_infobar_delegate.h deleted file mode 100644 index 4fa4dd2..0000000 --- a/chrome/browser/extensions/theme_preview_infobar_delegate.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_VIEWS_EXTENSIONS_THEME_PREVIEW_INFOBAR_DELEGATE_H_ -#define CHROME_BROWSER_VIEWS_EXTENSIONS_THEME_PREVIEW_INFOBAR_DELEGATE_H_ - -#include "chrome/browser/tab_contents/infobar_delegate.h" - -class Extension; -class ExtensionsService; -class SkBitmap; -class TabContents; - -// When a user installs a theme, we display it immediately, but provide an -// infobar allowing them to cancel. -class ThemePreviewInfobarDelegate : public ConfirmInfoBarDelegate { - public: - ThemePreviewInfobarDelegate(TabContents* tab_contents, - const std::string& name); - virtual void InfoBarClosed(); - virtual std::wstring GetMessageText() const; - virtual SkBitmap* GetIcon() const; - virtual int GetButtons() const; - virtual std::wstring GetButtonLabel( - ConfirmInfoBarDelegate::InfoBarButton button) const; - virtual bool Accept(); - virtual bool Cancel(); - - private: - Profile* profile_; - std::string name_; // name of theme to install - bool selection_made_; // whether the user has made a selection yet -}; - -#endif // CHROME_BROWSER_VIEWS_EXTENSIONS_THEME_PREVIEW_INFOBAR_DELEGATE_H_ |