summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-25 01:06:42 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-25 01:06:42 +0000
commit494c06ed7762ad06d70d83ce2c3c459944b3dfcd (patch)
treea88cfc109eb6d1b06258987e7f37432baea399ba /chrome
parent97b3aef453bcfa1771bebcd68d8bc76a6c113826 (diff)
downloadchromium_src-494c06ed7762ad06d70d83ce2c3c459944b3dfcd.zip
chromium_src-494c06ed7762ad06d70d83ce2c3c459944b3dfcd.tar.gz
chromium_src-494c06ed7762ad06d70d83ce2c3c459944b3dfcd.tar.bz2
Use referrer_url instead of download url to decide whether a
theme installation can happens sans-prompt. Review URL: http://codereview.chromium.org/160087 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21603 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/download/download_manager.cc14
-rw-r--r--chrome/browser/download/download_manager.h8
-rw-r--r--chrome/browser/download/save_package.cc2
-rw-r--r--chrome/browser/extensions/extensions_service.cc13
-rw-r--r--chrome/browser/extensions/extensions_service.h10
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc24
6 files changed, 53 insertions, 18 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index ccd986c..01ea2d0 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -141,6 +141,7 @@ DownloadItem::DownloadItem(int32 download_id,
const FilePath& path,
int path_uniquifier,
const GURL& url,
+ const GURL& referrer_url,
const FilePath& original_name,
const base::Time start_time,
int64 download_size,
@@ -151,6 +152,7 @@ DownloadItem::DownloadItem(int32 download_id,
full_path_(path),
path_uniquifier_(path_uniquifier),
url_(url),
+ referrer_url_(referrer_url),
total_bytes_(download_size),
received_bytes_(0),
start_tick_(base::TimeTicks::Now()),
@@ -674,6 +676,7 @@ void DownloadManager::ContinueStartDownload(DownloadCreateInfo* info,
info->path,
info->path_uniquifier,
info->url,
+ info->referrer_url,
info->original_name,
info->start_time,
info->total_bytes,
@@ -839,7 +842,8 @@ void DownloadManager::ContinueDownloadFinished(DownloadItem* download) {
// Handle chrome extensions explicitly and skip the shell execute.
if (Extension::IsExtension(download->full_path())) {
- OpenChromeExtension(download->full_path(), download->url());
+ OpenChromeExtension(download->full_path(), download->url(),
+ download->referrer_url());
download->set_auto_opened(true);
} else if (download->open_when_complete() ||
ShouldOpenFileExtension(extension)) {
@@ -1208,16 +1212,18 @@ void DownloadManager::OpenDownload(const DownloadItem* download,
// Open Chrome extensions with ExtensionsService. For everything else do shell
// execute.
if (Extension::IsExtension(download->full_path())) {
- OpenChromeExtension(download->full_path(), download->url());
+ OpenChromeExtension(download->full_path(), download->url(),
+ download->referrer_url());
} else {
OpenDownloadInShell(download, parent_window);
}
}
void DownloadManager::OpenChromeExtension(const FilePath& full_path,
- const GURL& download_url) {
+ const GURL& download_url,
+ const GURL& referrer_url) {
profile_->GetOriginalProfile()->GetExtensionsService()->
- InstallExtension(full_path, download_url);
+ InstallExtension(full_path, download_url, referrer_url);
}
void DownloadManager::OpenDownloadInShell(const DownloadItem* download,
diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h
index dad535e..f1b1030 100644
--- a/chrome/browser/download/download_manager.h
+++ b/chrome/browser/download/download_manager.h
@@ -108,6 +108,7 @@ class DownloadItem {
const FilePath& path,
int path_uniquifier,
const GURL& url,
+ const GURL& referrer_url,
const FilePath& original_name,
const base::Time start_time,
int64 download_size,
@@ -184,6 +185,7 @@ class DownloadItem {
int path_uniquifier() const { return path_uniquifier_; }
void set_path_uniquifier(int uniquifier) { path_uniquifier_ = uniquifier; }
GURL url() const { return url_; }
+ GURL referrer_url() const { return referrer_url_; }
int64 total_bytes() const { return total_bytes_; }
void set_total_bytes(int64 total_bytes) { total_bytes_ = total_bytes; }
int64 received_bytes() const { return received_bytes_; }
@@ -233,6 +235,9 @@ class DownloadItem {
// The URL from whence we came.
GURL url_;
+ // The URL of the page that initiated the download.
+ GURL referrer_url_;
+
// Total bytes expected
int64 total_bytes_;
@@ -448,7 +453,8 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>,
gfx::NativeView parent_window);
// Opens downloaded Chrome extension file (*.crx).
- void OpenChromeExtension(const FilePath& full_path, const GURL& download_url);
+ void OpenChromeExtension(const FilePath& full_path, const GURL& download_url,
+ const GURL& referrer_url);
// Shutdown the download manager. This call is needed only after Init.
void Shutdown();
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index f36b388..566ed63 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -256,7 +256,7 @@ bool SavePackage::Init() {
}
// Create the fake DownloadItem and display the view.
- download_ = new DownloadItem(1, saved_main_file_path_, 0, page_url_,
+ download_ = new DownloadItem(1, saved_main_file_path_, 0, page_url_, GURL(),
FilePath(), Time::Now(), 0, -1, -1, false);
download_->set_manager(tab_contents_->profile()->GetDownloadManager());
tab_contents_->OnStartDownload(download_);
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 486926d..2810b66 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -61,6 +61,9 @@ const char ExtensionsService::kExtensionHeaderMagic[] = "Cr24";
const char* ExtensionsService::kInstallDirectoryName = "Extensions";
const char* ExtensionsService::kCurrentVersionFileName = "Current Version";
+
+const char* ExtensionsService::kGalleryDownloadURLPrefix =
+ "https://dl-ssl.google.com/chrome/";
const char* ExtensionsService::kGalleryURLPrefix =
"https://tools.google.com/chrome/";
@@ -293,13 +296,15 @@ void ExtensionsService::Init() {
}
void ExtensionsService::InstallExtension(const FilePath& extension_path) {
- InstallExtension(extension_path, GURL());
+ InstallExtension(extension_path, GURL(), GURL());
}
void ExtensionsService::InstallExtension(const FilePath& extension_path,
+ const GURL& download_url,
const GURL& referrer_url) {
- bool from_gallery = StartsWithASCII(referrer_url.spec(), kGalleryURLPrefix,
- false);
+ bool from_gallery =
+ StartsWithASCII(download_url.spec(), kGalleryDownloadURLPrefix, false) &&
+ StartsWithASCII(referrer_url.spec(), kGalleryURLPrefix, false);
backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(),
&ExtensionsServiceBackend::InstallExtension, extension_path, from_gallery,
@@ -1142,8 +1147,6 @@ void ExtensionsServiceBackend::OnExtensionUnpacked(
L"You should only install extensions from sources you trust.",
l10n_util::GetString(IDS_PRODUCT_NAME).c_str(),
MB_OKCANCEL) != IDOK) {
- ReportExtensionInstallError(extension_path,
- "User did not allow extension to be installed.");
return;
}
#elif defined(OS_MACOSX)
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index f7fad70..29cf798 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -123,7 +123,9 @@ class ExtensionsService
// XXX Hack: This is a temporary nasty hack to get theme installation working
// without a dialog. Will be fixed by making ExtensionsService more modular.
- void InstallExtension(const FilePath& extension_path, const GURL& url);
+ void InstallExtension(const FilePath& extension_path,
+ const GURL& download_url,
+ const GURL& referrer_url);
// Updates a currently-installed extension with the contents from
// |extension_path|. The |alert_on_error| parameter controls whether the
@@ -183,7 +185,11 @@ class ExtensionsService
// The name of the file that the current active version number is stored in.
static const char* kCurrentVersionFileName;
- // A special URL that allows theme installation without prompts.
+ // Hack:
+ // Extensions downloaded from kGalleryDownloadURLPrefix initiated from pages
+ // with kGalleryURLPrefix will not require --enable-extensions and will be
+ // prompt-free.
+ static const char* kGalleryDownloadURLPrefix;
static const char* kGalleryURLPrefix;
void SetExtensionsEnabled(bool enabled);
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index cdb4d18..57799fa 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -342,14 +342,15 @@ class ExtensionsServiceTest
void InstallExtension(const FilePath& path,
bool should_succeed) {
- InstallExtension(path, should_succeed, GURL());
+ 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, referrer_url);
+ service_->InstallExtension(path, download_url, referrer_url);
loop_.RunAllPending();
std::vector<std::string> errors = GetErrors();
if (should_succeed) {
@@ -809,15 +810,28 @@ TEST_F(ExtensionsServiceTest, InstallTheme) {
// ... unless they come from the gallery URL.
SetExtensionsEnabled(false);
path = extensions_path.AppendASCII("theme2.crx");
- InstallExtension(path, true, GURL(
- std::string(ExtensionsService::kGalleryURLPrefix) + "foobar"));
+ 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);
- SetExtensionsEnabled(true);
+
+ // 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);
path = extensions_path.AppendASCII("theme_with_extension.crx");
InstallExtension(path, false);
ValidatePrefKeyCount(pref_count);