summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-31 23:53:28 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-31 23:53:28 +0000
commitfc38935ac4b8feccfe596476c0624c81ba7f007b (patch)
tree8bcf1cd0664aabe7af775c433f216925f4010027 /chrome
parent1af419c0f92c04b62ff997de1117309076f4eb17 (diff)
downloadchromium_src-fc38935ac4b8feccfe596476c0624c81ba7f007b.zip
chromium_src-fc38935ac4b8feccfe596476c0624c81ba7f007b.tar.gz
chromium_src-fc38935ac4b8feccfe596476c0624c81ba7f007b.tar.bz2
Enable experimental permissions for extensions from the store.
BUG=100895 Review URL: http://codereview.chromium.org/8423003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108039 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/crx_installer.cc11
-rw-r--r--chrome/browser/extensions/crx_installer.h12
-rw-r--r--chrome/browser/extensions/crx_installer_browsertest.cc7
-rw-r--r--chrome/browser/extensions/extension_browsertest.cc3
-rw-r--r--chrome/browser/extensions/sandboxed_extension_unpacker.cc12
-rw-r--r--chrome/browser/extensions/sandboxed_extension_unpacker.h5
-rw-r--r--chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc7
-rw-r--r--chrome/common/chrome_utility_messages.h7
-rw-r--r--chrome/common/extensions/extension_unpacker.cc11
-rw-r--r--chrome/common/extensions/extension_unpacker.h11
-rw-r--r--chrome/common/extensions/extension_unpacker_unittest.cc4
-rw-r--r--chrome/test/data/extensions/experimental.crx0
-rw-r--r--chrome/utility/chrome_content_utility_client.cc10
-rw-r--r--chrome/utility/chrome_content_utility_client.h3
14 files changed, 71 insertions, 32 deletions
diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc
index dfe55ea..cebc948 100644
--- a/chrome/browser/extensions/crx_installer.cc
+++ b/chrome/browser/extensions/crx_installer.cc
@@ -121,7 +121,6 @@ CrxInstaller::CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak,
install_source_(Extension::INTERNAL),
extensions_enabled_(frontend_weak->extensions_enabled()),
delete_source_(false),
- is_gallery_install_(false),
create_app_shortcut_(false),
page_index_(-1),
frontend_weak_(frontend_weak),
@@ -165,6 +164,7 @@ void CrxInstaller::InstallCrx(const FilePath& source_file) {
new SandboxedExtensionUnpacker(
source_file,
g_browser_process->resource_dispatcher_host(),
+ install_source_,
creation_flags_,
this));
@@ -274,7 +274,7 @@ bool CrxInstaller::AllowInstall(const Extension* extension,
// If the client_ is NULL, then the app is either being installed via
// an internal mechanism like sync, external_extensions, or default apps.
// In that case, we don't want to enforce things like the install origin.
- if (!is_gallery_install_ && client_) {
+ if (!is_gallery_install() && client_) {
// For apps with a gallery update URL, require that they be installed
// from the gallery.
// TODO(erikkay) Apply this rule for paid extensions and themes as well.
@@ -405,7 +405,7 @@ void CrxInstaller::ConfirmInstall() {
bool whitelisted = false;
scoped_ptr<CrxInstaller::WhitelistEntry> entry(
RemoveWhitelistEntry(extension_->id()));
- if (is_gallery_install_ && entry.get() && original_manifest_.get()) {
+ if (is_gallery_install() && entry.get() && original_manifest_.get()) {
if (!(original_manifest_->Equals(entry->parsed_manifest.get()))) {
ReportFailureFromUIThread(
l10n_util::GetStringUTF8(IDS_EXTENSION_MANIFEST_INVALID));
@@ -497,13 +497,10 @@ void CrxInstaller::CompleteInstall() {
// TODO(aa): All paths to resources inside extensions should be created
// lazily and based on the Extension's root path at that moment.
std::string error;
- int flags = extension_->creation_flags() | Extension::REQUIRE_KEY;
- if (is_gallery_install())
- flags |= Extension::FROM_WEBSTORE;
extension_ = extension_file_util::LoadExtension(
version_dir,
install_source_,
- flags,
+ extension_->creation_flags() | Extension::REQUIRE_KEY,
&error);
CHECK(error.empty()) << error;
diff --git a/chrome/browser/extensions/crx_installer.h b/chrome/browser/extensions/crx_installer.h
index e83342d..4e0474e 100644
--- a/chrome/browser/extensions/crx_installer.h
+++ b/chrome/browser/extensions/crx_installer.h
@@ -137,8 +137,13 @@ class CrxInstaller
bool allow_silent_install() const { return allow_silent_install_; }
void set_allow_silent_install(bool val) { allow_silent_install_ = val; }
- bool is_gallery_install() const { return is_gallery_install_; }
- void set_is_gallery_install(bool val) { is_gallery_install_ = val; }
+ bool is_gallery_install() const {
+ return (creation_flags_ & Extension::FROM_WEBSTORE) > 0;
+ }
+ void set_is_gallery_install(bool val) {
+ if (val) creation_flags_ |= Extension::FROM_WEBSTORE;
+ else creation_flags_ &= ~Extension::FROM_WEBSTORE;
+ }
// The original download URL should be set when the WebstoreInstaller is
// tracking the installation. The WebstoreInstaller uses this URL to match
@@ -247,9 +252,6 @@ class CrxInstaller
// to false.
bool delete_source_;
- // Whether the install originated from the gallery.
- bool is_gallery_install_;
-
// The download URL, before redirects, if this is a gallery install.
GURL original_download_url_;
diff --git a/chrome/browser/extensions/crx_installer_browsertest.cc b/chrome/browser/extensions/crx_installer_browsertest.cc
index 9353aa1..d108c56 100644
--- a/chrome/browser/extensions/crx_installer_browsertest.cc
+++ b/chrome/browser/extensions/crx_installer_browsertest.cc
@@ -73,3 +73,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) {
"hdgllgikmikobbofgnabhfimcfoopgnd"));
#endif // !defined(OS_CHROMEOS)
}
+
+IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
+ GalleryInstallGetsExperimental) {
+ InstallExtension(test_data_dir_.AppendASCII("experimental.crx"), 0);
+ InstallExtensionFromWebstore(
+ test_data_dir_.AppendASCII("experimental.crx"), 1);
+}
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc
index f96fd61..3c8a214 100644
--- a/chrome/browser/extensions/extension_browsertest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -176,7 +176,8 @@ FilePath ExtensionBrowserTest::PackExtension(const FilePath& dir_path) {
crx_path,
FilePath(), // no existing pem, use empty path
pem_path)) {
- ADD_FAILURE() << "ExtensionCreator::Run() failed.";
+ ADD_FAILURE() << "ExtensionCreator::Run() failed: "
+ << creator->error_message();
return FilePath();
}
diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.cc b/chrome/browser/extensions/sandboxed_extension_unpacker.cc
index 987eb8b..69dd6f9 100644
--- a/chrome/browser/extensions/sandboxed_extension_unpacker.cc
+++ b/chrome/browser/extensions/sandboxed_extension_unpacker.cc
@@ -20,7 +20,6 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_utility_messages.h"
-#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/common/extensions/extension_l10n_util.h"
@@ -112,12 +111,13 @@ void RecordSuccessfulUnpackTimeHistograms(
SandboxedExtensionUnpacker::SandboxedExtensionUnpacker(
const FilePath& crx_path,
ResourceDispatcherHost* rdh,
+ Extension::Location location,
int creation_flags,
SandboxedExtensionUnpackerClient* client)
: crx_path_(crx_path),
thread_identifier_(BrowserThread::ID_COUNT),
rdh_(rdh), client_(client), got_response_(false),
- creation_flags_(creation_flags) {
+ location_(location), creation_flags_(creation_flags) {
}
bool SandboxedExtensionUnpacker::CreateTempDirectory() {
@@ -214,7 +214,7 @@ void SandboxedExtensionUnpacker::Start() {
link_free_crx_path));
} else {
// Otherwise, unpack the extension in this process.
- ExtensionUnpacker unpacker(temp_crx_path);
+ ExtensionUnpacker unpacker(temp_crx_path, location_, creation_flags_);
if (unpacker.Run() && unpacker.DumpImagesToFile() &&
unpacker.DumpMessageCatalogsToFile()) {
OnUnpackExtensionSucceeded(*unpacker.parsed_manifest());
@@ -262,7 +262,9 @@ void SandboxedExtensionUnpacker::StartProcessOnIOThread(
// Grant the subprocess access to the entire subdir the extension file is
// in, so that it can unpack to that dir.
host->set_exposed_dir(temp_crx_path.DirName());
- host->Send(new ChromeUtilityMsg_UnpackExtension(temp_crx_path));
+ host->Send(
+ new ChromeUtilityMsg_UnpackExtension(
+ temp_crx_path, location_, creation_flags_));
}
void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded(
@@ -296,7 +298,7 @@ void SandboxedExtensionUnpacker::OnUnpackExtensionSucceeded(
extension_ = Extension::Create(
extension_root_,
- Extension::INTERNAL,
+ location_,
*final_manifest,
Extension::REQUIRE_KEY | creation_flags_,
&error);
diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.h b/chrome/browser/extensions/sandboxed_extension_unpacker.h
index f8230bc..43907ef 100644
--- a/chrome/browser/extensions/sandboxed_extension_unpacker.h
+++ b/chrome/browser/extensions/sandboxed_extension_unpacker.h
@@ -11,6 +11,7 @@
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/scoped_temp_dir.h"
+#include "chrome/common/extensions/extension.h"
#include "content/browser/utility_process_host.h"
class Extension;
@@ -101,6 +102,7 @@ class SandboxedExtensionUnpacker : public UtilityProcessHost::Client {
// sandboxed subprocess. Otherwise, it is done in-process.
SandboxedExtensionUnpacker(const FilePath& crx_path,
ResourceDispatcherHost* rdh,
+ Extension::Location location,
int creation_flags,
SandboxedExtensionUnpackerClient* client);
@@ -242,6 +244,9 @@ class SandboxedExtensionUnpacker : public UtilityProcessHost::Client {
// Time at which unpacking started. Used to compute the time unpacking takes.
base::TimeTicks unpack_start_time_;
+ // Location to use for the unpacked extension.
+ Extension::Location location_;
+
// Creation flags to use for the extension. These flags will be used
// when calling Extenion::Create() by the crx installer.
int creation_flags_;
diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc b/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc
index 3243e0a..e09d38e 100644
--- a/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc
+++ b/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc
@@ -90,7 +90,8 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
"Original path: " << original_path.value() <<
", Crx path: " << crx_path.value();
- unpacker_.reset(new ExtensionUnpacker(crx_path));
+ unpacker_.reset(new ExtensionUnpacker(
+ crx_path, Extension::INTERNAL, Extension::NO_FLAGS));
// Build a temp area where the extension will be unpacked.
temp_path_ =
@@ -98,8 +99,8 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
ASSERT_TRUE(file_util::CreateDirectory(temp_path_));
sandboxed_unpacker_ =
- new SandboxedExtensionUnpacker(crx_path, NULL, Extension::NO_FLAGS,
- client_);
+ new SandboxedExtensionUnpacker(crx_path, NULL, Extension::INTERNAL,
+ Extension::NO_FLAGS, client_);
// Hack since SandboxedExtensionUnpacker gets its background thread id from
// the Start call, but we don't call it here.
diff --git a/chrome/common/chrome_utility_messages.h b/chrome/common/chrome_utility_messages.h
index 8ec3c80..7b7fcb6 100644
--- a/chrome/common/chrome_utility_messages.h
+++ b/chrome/common/chrome_utility_messages.h
@@ -11,6 +11,7 @@
#include "base/file_path.h"
#include "base/platform_file.h"
#include "base/values.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/update_manifest.h"
#include "content/public/common/common_param_traits.h"
#include "content/public/common/serialized_script_value.h"
@@ -53,8 +54,10 @@ IPC_STRUCT_TRAITS_END()
// These are messages from the browser to the utility process.
// Tell the utility process to unpack the given extension file in its
// directory and verify that it is valid.
-IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_UnpackExtension,
- FilePath /* extension_filename */)
+IPC_MESSAGE_CONTROL3(ChromeUtilityMsg_UnpackExtension,
+ FilePath /* extension_filename */,
+ int /* Extension::Location */,
+ int /* InitFromValue flags */)
// Tell the utility process to parse the given JSON data and verify its
// validity.
diff --git a/chrome/common/extensions/extension_unpacker.cc b/chrome/common/extensions/extension_unpacker.cc
index 3c729a4..bf2452e 100644
--- a/chrome/common/extensions/extension_unpacker.cc
+++ b/chrome/common/extensions/extension_unpacker.cc
@@ -84,8 +84,11 @@ bool PathContainsParentDirectory(const FilePath& path) {
} // namespace
-ExtensionUnpacker::ExtensionUnpacker(const FilePath& extension_path)
- : extension_path_(extension_path) {
+ExtensionUnpacker::ExtensionUnpacker(const FilePath& extension_path,
+ Extension::Location location,
+ int creation_flags)
+ : extension_path_(extension_path), location_(location),
+ creation_flags_(creation_flags) {
}
ExtensionUnpacker::~ExtensionUnpacker() {
@@ -178,9 +181,9 @@ bool ExtensionUnpacker::Run() {
std::string error;
scoped_refptr<Extension> extension(Extension::Create(
temp_install_dir_,
- Extension::INVALID,
+ location_,
*parsed_manifest_,
- Extension::NO_FLAGS,
+ creation_flags_,
&error));
if (!extension.get()) {
SetError(error);
diff --git a/chrome/common/extensions/extension_unpacker.h b/chrome/common/extensions/extension_unpacker.h
index 2526a9e..3655a38 100644
--- a/chrome/common/extensions/extension_unpacker.h
+++ b/chrome/common/extensions/extension_unpacker.h
@@ -12,6 +12,7 @@
#include "base/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/tuple.h"
+#include "chrome/common/extensions/extension.h"
class SkBitmap;
@@ -27,7 +28,9 @@ class ExtensionUnpacker {
public:
typedef std::vector< Tuple2<SkBitmap, FilePath> > DecodedImages;
- explicit ExtensionUnpacker(const FilePath& extension_path);
+ explicit ExtensionUnpacker(const FilePath& extension_path,
+ Extension::Location location,
+ int creation_flags);
~ExtensionUnpacker();
// Install the extension file at |extension_path|. Returns true on success.
@@ -85,6 +88,12 @@ class ExtensionUnpacker {
// The extension to unpack.
FilePath extension_path_;
+ // The location to use for the created extension.
+ Extension::Location location_;
+
+ // The creation flags to use with the created extension.
+ int creation_flags_;
+
// The place we unpacked the extension to.
FilePath temp_install_dir_;
diff --git a/chrome/common/extensions/extension_unpacker_unittest.cc b/chrome/common/extensions/extension_unpacker_unittest.cc
index e53b5af..e86007b 100644
--- a/chrome/common/extensions/extension_unpacker_unittest.cc
+++ b/chrome/common/extensions/extension_unpacker_unittest.cc
@@ -35,7 +35,9 @@ public:
"Original path " << original_path.value() <<
", Crx path " << crx_path.value();
- unpacker_.reset(new ExtensionUnpacker(crx_path));
+ unpacker_.reset(
+ new ExtensionUnpacker(
+ crx_path, Extension::INTERNAL, Extension::NO_FLAGS));
}
protected:
diff --git a/chrome/test/data/extensions/experimental.crx b/chrome/test/data/extensions/experimental.crx
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/chrome/test/data/extensions/experimental.crx
diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc
index 497ba56..d203c67 100644
--- a/chrome/utility/chrome_content_utility_client.cc
+++ b/chrome/utility/chrome_content_utility_client.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/importer/profile_import_process_messages.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_utility_messages.h"
+#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension_unpacker.h"
#include "chrome/common/extensions/update_manifest.h"
@@ -93,8 +94,13 @@ bool ChromeContentUtilityClient::Send(IPC::Message* message) {
}
void ChromeContentUtilityClient::OnUnpackExtension(
- const FilePath& extension_path) {
- ExtensionUnpacker unpacker(extension_path);
+ const FilePath& extension_path, int location, int creation_flags) {
+ CHECK(location > Extension::INVALID);
+ CHECK(location < Extension::NUM_LOCATIONS);
+ ExtensionUnpacker unpacker(
+ extension_path,
+ static_cast<Extension::Location>(location),
+ creation_flags);
if (unpacker.Run() && unpacker.DumpImagesToFile() &&
unpacker.DumpMessageCatalogsToFile()) {
Send(new ChromeUtilityHostMsg_UnpackExtension_Succeeded(
diff --git a/chrome/utility/chrome_content_utility_client.h b/chrome/utility/chrome_content_utility_client.h
index fa419e0..4d6a752 100644
--- a/chrome/utility/chrome_content_utility_client.h
+++ b/chrome/utility/chrome_content_utility_client.h
@@ -48,7 +48,8 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient {
virtual bool Send(IPC::Message* message);
// IPC message handlers.
- void OnUnpackExtension(const FilePath& extension_path);
+ void OnUnpackExtension(const FilePath& extension_path,
+ int location, int creation_flags);
void OnUnpackWebResource(const std::string& resource_data);
void OnParseUpdateManifest(const std::string& xml);
void OnDecodeImage(const std::vector<unsigned char>& encoded_data);