Skip to content

Commit

Permalink
Add 'from_webstore' state to Extensions, so renderer code can enforce…
Browse files Browse the repository at this point in the history
… CWS restrictions.

Review URL: http://codereview.chromium.org/7384010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92752 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bbudge@chromium.org committed Jul 15, 2011
1 parent 819f753 commit 620db17
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
8 changes: 4 additions & 4 deletions chrome/browser/extensions/extension_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,6 @@ bool ExtensionService::IsDownloadFromGallery(const GURL& download_url,
return (referrer_valid && download_valid);
}

bool ExtensionService::IsFromWebStore(const std::string& id) const {
return extension_prefs_->IsFromWebStore(id);
}

bool ExtensionService::IsDownloadFromMiniGallery(const GURL& download_url) {
return StartsWithASCII(download_url.spec(),
extension_urls::kMiniGalleryDownloadPrefix,
Expand Down Expand Up @@ -1106,6 +1102,8 @@ void ExtensionService::LoadAllExtensions() {
flags |= Extension::STRICT_ERROR_CHECKS;
if (extension_prefs_->AllowFileAccess(info->extension_id))
flags |= Extension::ALLOW_FILE_ACCESS;
if (extension_prefs_->IsFromWebStore(info->extension_id))
flags |= Extension::FROM_WEBSTORE;
std::string error;
scoped_refptr<const Extension> extension(
extension_file_util::LoadExtension(
Expand Down Expand Up @@ -1257,6 +1255,8 @@ void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info,
flags |= Extension::STRICT_ERROR_CHECKS;
if (extension_prefs_->AllowFileAccess(info.extension_id))
flags |= Extension::ALLOW_FILE_ACCESS;
if (extension_prefs_->IsFromWebStore(info.extension_id))
flags |= Extension::FROM_WEBSTORE;
extension = Extension::Create(
info.extension_path,
info.extension_location,
Expand Down
3 changes: 0 additions & 3 deletions chrome/browser/extensions/extension_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ class ExtensionService
bool IsDownloadFromGallery(const GURL& download_url,
const GURL& referrer_url);

// Returns true if the extension was installed from the web store.
bool IsFromWebStore(const std::string& id) const;

// Determine if the downloaded extension came from the theme mini-gallery,
// Used to test if we need to show the "Loading" dialog for themes.
static bool IsDownloadFromMiniGallery(const GURL& download_url);
Expand Down
13 changes: 10 additions & 3 deletions chrome/browser/extensions/extension_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,8 @@ TEST_F(ExtensionServiceTest, Reinstall) {
ValidateIntegerPref(good_crx, "location", Extension::INTERNAL);
}

// Test that extension prefs remember if .crx came from web store.
// Test that we can determine if extensions came from the
// Chrome web store.
TEST_F(ExtensionServiceTest, FromWebStore) {
InitializeEmptyExtensionService();

Expand All @@ -1911,7 +1912,9 @@ TEST_F(ExtensionServiceTest, FromWebStore) {
ASSERT_EQ(0u, GetErrors().size());
ValidatePrefKeyCount(1);
ValidateBooleanPref(good_crx, "from_webstore", false);
ASSERT_FALSE(service_->IsFromWebStore(good_crx));

const Extension* extension = service_->extensions()->at(0);
ASSERT_FALSE(extension->from_webstore());

installed_ = NULL;
loaded_.clear();
Expand All @@ -1926,7 +1929,11 @@ TEST_F(ExtensionServiceTest, FromWebStore) {
ASSERT_EQ(0u, GetErrors().size());
ValidatePrefKeyCount(1);
ValidateBooleanPref(good_crx, "from_webstore", true);
ASSERT_TRUE(service_->IsFromWebStore(good_crx));

// Reload so extension gets reinitialized with new value.
service_->ReloadExtensions();
extension = service_->extensions()->at(0);
ASSERT_TRUE(extension->from_webstore());
}

// Test upgrading a signed extension.
Expand Down
5 changes: 4 additions & 1 deletion chrome/common/extensions/extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,8 @@ Extension::Extension(const FilePath& path, Location location)
launch_container_(extension_misc::LAUNCH_TAB),
launch_width_(0),
launch_height_(0),
wants_file_access_(false) {
wants_file_access_(false),
from_webstore_(false) {
DCHECK(path.empty() || path.IsAbsolute());
path_ = MaybeNormalizePath(path);
}
Expand Down Expand Up @@ -1400,6 +1401,8 @@ bool Extension::InitFromValue(const DictionaryValue& source, int flags,
}
}

from_webstore_ = (flags & FROM_WEBSTORE) != 0;

// Make a copy of the manifest so we can store it in prefs.
manifest_value_.reset(source.DeepCopy());

Expand Down
8 changes: 8 additions & 0 deletions chrome/common/extensions/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// to have file access. If it's not present, then permissions and content
// scripts that match file:/// URLs will be filtered out.
ALLOW_FILE_ACCESS = 1 << 2,

// |FROM_WEBSTORE| indicates that the extension was installed from the
// Chrome Web Store.
FROM_WEBSTORE = 1 << 3,
};

static scoped_refptr<Extension> Create(const FilePath& path,
Expand Down Expand Up @@ -503,6 +507,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }

bool wants_file_access() const { return wants_file_access_; }
bool from_webstore() const { return from_webstore_; }

const std::string& content_security_policy() const {
return content_security_policy_;
Expand Down Expand Up @@ -789,6 +794,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// granted it that access).
bool wants_file_access_;

// Whether the extension was installed from the web store.
bool from_webstore_;

// The Content-Security-Policy for this extension. Extensions can use
// Content-Security-Policies to mitigate cross-site scripting and other
// vulnerabilities.
Expand Down

0 comments on commit 620db17

Please sign in to comment.