diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-08 07:38:26 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-08 07:38:26 +0000 |
commit | 93d973a3dc873112e5df401a1826f1235dff66a6 (patch) | |
tree | f161750c6aa9069733ee91b4c3bc0bc7a2f112e5 | |
parent | d57720f97e9a4e71e0ac7d8df9628a0d56ddcddf (diff) | |
download | chromium_src-93d973a3dc873112e5df401a1826f1235dff66a6.zip chromium_src-93d973a3dc873112e5df401a1826f1235dff66a6.tar.gz chromium_src-93d973a3dc873112e5df401a1826f1235dff66a6.tar.bz2 |
Warn before overwriting CRX files in extension pack UI.
BUG=35194
TEST=Try packing an extension from the browser, both overwriting and not overwriting an existing crx. And do a commandline browser extension pack.
Review URL: http://codereview.chromium.org/8947025
Patch from Clint Staley <clintstaley@chromium.org>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116839 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | chrome/app/generated_resources.grd | 9 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_creator.cc | 23 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_creator.h | 27 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service_unittest.cc | 49 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_startup.cc | 9 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_startup.h | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/pack_extension_job.cc | 20 | ||||
-rw-r--r-- | chrome/browser/extensions/pack_extension_job.h | 12 | ||||
-rw-r--r-- | chrome/browser/resources/options/extension_settings.js | 19 | ||||
-rw-r--r-- | chrome/browser/resources/options/pack_extension_overlay.js | 2 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/pack_extension_handler.cc | 44 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/pack_extension_handler.h | 9 |
14 files changed, 180 insertions, 50 deletions
@@ -150,6 +150,7 @@ Intel Corporation <*@intel.com> Halton Huo <halton.huo@gmail.com> Shiliu Wang <aofdwsl@gmail.com> Gao Chun <gaochun.dev@gmail.com> +Clinton Staley <clintstaley@gmail.com> Devlin Cronin <rdevlin.cronin@gmail.com> Junmin Zhu <junmin.zhu@intel.com> Cem Kocagil <cem.kocagil@gmail.com> diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 2eb52bc..4a3317a 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4088,6 +4088,15 @@ Update checks have repeatedly failed for the extension "<ph name="EXTENSION_NAME <message name="IDS_EXTENSION_PRIVATE_KEY_NO_EXISTS" desc="Warning displayed in pack dialog when the private key for the extension does not exist."> Input value for private key must exist. </message> + <message name="IDS_EXTENSION_PACK_WARNING_TITLE" desc="Warning title message for pack extension"> + Pack Extension Warning + </message> + <message name="IDS_EXTENSION_CRX_EXISTS" desc="Warning displayed in pack dialog when the crx file already exists."> + There is already a CRX file present with this name. + </message> + <message name="IDS_EXTENSION_PROCEED_ANYWAY" desc="Button to continue with operation in extension packing"> + Proceed anyway + </message> <message name="IDS_EXTENSION_PRIVATE_KEY_FAILED_TO_READ" desc="Warning displayed in pack dialog when was not possible to read the private key of the extension."> Failed to read private key. </message> diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index f660393..101e524 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -190,7 +190,8 @@ FilePath ExtensionBrowserTest::PackExtensionWithOptions( if (!creator->Run(dir_path, crx_path, pem_path, - pem_out_path)) { + pem_out_path, + ExtensionCreator::kOverwriteCRX)) { ADD_FAILURE() << "ExtensionCreator::Run() failed: " << creator->error_message(); return FilePath(); diff --git a/chrome/browser/extensions/extension_creator.cc b/chrome/browser/extensions/extension_creator.cc index 97a5d5f..f7e38e0 100644 --- a/chrome/browser/extensions/extension_creator.cc +++ b/chrome/browser/extensions/extension_creator.cc @@ -27,10 +27,15 @@ namespace { const int kRSAKeySize = 1024; }; +ExtensionCreator::ExtensionCreator() : error_type_(kOtherError) { +} + bool ExtensionCreator::InitializeInput( const FilePath& extension_dir, + const FilePath& crx_path, const FilePath& private_key_path, - const FilePath& private_key_output_path) { + const FilePath& private_key_output_path, + int run_flags) { // Validate input |extension_dir|. if (extension_dir.value().empty() || !file_util::DirectoryExists(extension_dir)) { @@ -64,6 +69,15 @@ bool ExtensionCreator::InitializeInput( return false; } + // Check whether crx file already exists. Should be last check, as this is + // a warning only. + if (!(run_flags & kOverwriteCRX) && file_util::PathExists(crx_path)) { + error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_CRX_EXISTS); + error_type_ = kCRXExists; + + return false; + } + // Load the extension once. We don't really need it, but this does a lot of // useful validation of the structure. scoped_refptr<Extension> extension( @@ -248,10 +262,11 @@ bool ExtensionCreator::WriteCRX(const FilePath& zip_path, bool ExtensionCreator::Run(const FilePath& extension_dir, const FilePath& crx_path, const FilePath& private_key_path, - const FilePath& output_private_key_path) { + const FilePath& output_private_key_path, + int run_flags) { // Check input diretory and read manifest. - if (!InitializeInput(extension_dir, private_key_path, - output_private_key_path)) { + if (!InitializeInput(extension_dir, crx_path, private_key_path, + output_private_key_path, run_flags)) { return false; } diff --git a/chrome/browser/extensions/extension_creator.h b/chrome/browser/extensions/extension_creator.h index 0499821..dd57621 100644 --- a/chrome/browser/extensions/extension_creator.h +++ b/chrome/browser/extensions/extension_creator.h @@ -24,25 +24,41 @@ class FilePath; // generated randomly (and optionally written to |output_private_key_path|. class ExtensionCreator { public: - ExtensionCreator() {} + ExtensionCreator(); + + // Settings to specify treatment of special or ignorable error conditions. + enum RunFlags { + kNoRunFlags = 0x0, + kOverwriteCRX = 0x1 + }; + + // Categories of error that may need special handling on the UI end. + enum ErrorType { kOtherError, kCRXExists }; bool Run(const FilePath& extension_dir, const FilePath& crx_path, const FilePath& private_key_path, - const FilePath& private_key_output_path); + const FilePath& private_key_output_path, + int run_flags); // Returns the error message that will be present if Run(...) returned false. std::string error_message() { return error_message_; } + ErrorType error_type() { return error_type_; } + private: // Verifies input directory's existence. |extension_dir| is the source - // directory that should contain all the extension resources. + // directory that should contain all the extension resources. |crx_path| is + // the path to which final crx will be written. // |private_key_path| is the optional path to an existing private key to sign // the extension. If not provided, a random key will be created (in which case // it is written to |private_key_output_path| -- if provided). + // |flags| is a bitset of RunFlags values. bool InitializeInput(const FilePath& extension_dir, + const FilePath& crx_path, const FilePath& private_key_path, - const FilePath& private_key_output_path); + const FilePath& private_key_output_path, + int run_flags); // Reads private key from |private_key_path|. crypto::RSAPrivateKey* ReadInputKey(const FilePath& private_key_path); @@ -69,6 +85,9 @@ class ExtensionCreator { // Holds a message for any error that is raised during Run(...). std::string error_message_; + // Type of error that was raised, if any. + ErrorType error_type_; + DISALLOW_COPY_AND_ASSIGN(ExtensionCreator); }; diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index 5877b2a..7494b0a 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -579,7 +579,8 @@ class ExtensionServiceTest ASSERT_TRUE(creator->Run(dir_path, crx_path, pem_path, - pem_output_path)); + pem_output_path, + ExtensionCreator::kOverwriteCRX)); ASSERT_TRUE(file_util::PathExists(crx_path)); } @@ -978,7 +979,8 @@ class PackExtensionTestClient : public PackExtensionJob::Client { const FilePath& expected_private_key_path); virtual void OnPackSuccess(const FilePath& crx_path, const FilePath& private_key_path); - virtual void OnPackFailure(const std::string& error_message); + virtual void OnPackFailure(const std::string& error_message, + ExtensionCreator::ErrorType type); private: const FilePath expected_crx_path_; @@ -1008,8 +1010,13 @@ void PackExtensionTestClient::OnPackSuccess(const FilePath& crx_path, } // The tests are designed so that we never expect to see a packing error. -void PackExtensionTestClient::OnPackFailure(const std::string& error_message) { - FAIL() << "Packing should not fail."; +void PackExtensionTestClient::OnPackFailure(const std::string& error_message, + ExtensionCreator::ErrorType type) { + if (type == ExtensionCreator::kCRXExists) + FAIL() << "Packing should not fail."; + else + FAIL() << "Existing CRX should have been overwritten."; + } // Test loading good extensions from the profile directory. @@ -1638,14 +1645,32 @@ TEST_F(ExtensionServiceTest, PackExtension) { scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), - privkey_path)); + privkey_path, ExtensionCreator::kNoRunFlags)); + ASSERT_TRUE(file_util::PathExists(crx_path)); + ASSERT_TRUE(file_util::PathExists(privkey_path)); + + // Repeat the run with the pem file gone, and no special flags + // Should refuse to overwrite the existing crx. + file_util::Delete(privkey_path, false); + ASSERT_FALSE(creator->Run(input_directory, crx_path, FilePath(), + privkey_path, ExtensionCreator::kNoRunFlags)); + + // OK, now try it with a flag to overwrite existing crx. Should work. + ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), + privkey_path, ExtensionCreator::kOverwriteCRX)); + + // Repeat the run allowing existing crx, but the existing pem is still + // an error. Should fail. + ASSERT_FALSE(creator->Run(input_directory, crx_path, FilePath(), + privkey_path, ExtensionCreator::kOverwriteCRX)); ASSERT_TRUE(file_util::PathExists(privkey_path)); InstallCRX(crx_path, INSTALL_NEW); // Try packing with invalid paths. creator.reset(new ExtensionCreator()); - ASSERT_FALSE(creator->Run(FilePath(), FilePath(), FilePath(), FilePath())); + ASSERT_FALSE(creator->Run(FilePath(), FilePath(), FilePath(), FilePath(), + ExtensionCreator::kOverwriteCRX)); // Try packing an empty directory. Should fail because an empty directory is // not a valid extension. @@ -1653,7 +1678,7 @@ TEST_F(ExtensionServiceTest, PackExtension) { ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); creator.reset(new ExtensionCreator()); ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, - FilePath())); + FilePath(), ExtensionCreator::kOverwriteCRX)); // Try packing with an invalid manifest. std::string invalid_manifest_content = "I am not a manifest."; @@ -1662,7 +1687,7 @@ TEST_F(ExtensionServiceTest, PackExtension) { invalid_manifest_content.c_str(), invalid_manifest_content.size())); creator.reset(new ExtensionCreator()); ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, - FilePath())); + FilePath(), ExtensionCreator::kOverwriteCRX)); } // Test Packaging and installing an extension whose name contains punctuation. @@ -1717,9 +1742,9 @@ TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { temp_dir.path().Append(expected_private_key_names[i]); PackExtensionTestClient pack_client(expected_crx_path, expected_private_key_path); - scoped_refptr<PackExtensionJob> packer(new PackExtensionJob(&pack_client, - output_dir, - FilePath())); + scoped_refptr<PackExtensionJob> packer( + new PackExtensionJob(&pack_client, output_dir, FilePath(), + ExtensionCreator::kOverwriteCRX)); packer->Start(); // The packer will post a notification task to the current thread's message @@ -1761,7 +1786,7 @@ TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, - FilePath())); + FilePath(), ExtensionCreator::kOverwriteCRX)); InstallCRX(crx_path, INSTALL_NEW); } diff --git a/chrome/browser/extensions/extensions_startup.cc b/chrome/browser/extensions/extensions_startup.cc index 5d505ac..9d1a472 100644 --- a/chrome/browser/extensions/extensions_startup.cc +++ b/chrome/browser/extensions/extensions_startup.cc @@ -27,7 +27,8 @@ void ExtensionsStartupUtil::OnPackSuccess( crx_path, output_private_key_path))); } -void ExtensionsStartupUtil::OnPackFailure(const std::string& error_message) { +void ExtensionsStartupUtil::OnPackFailure(const std::string& error_message, + ExtensionCreator::ErrorType type) { ShowPackExtensionMessage(L"Extension Packaging Error", UTF8ToWide(error_message)); } @@ -58,8 +59,10 @@ bool ExtensionsStartupUtil::PackExtension(const CommandLine& cmd_line) { private_key_path = cmd_line.GetSwitchValuePath(switches::kPackExtensionKey); } - // Launch a job to perform the packing on the file thread. - pack_job_ = new PackExtensionJob(this, src_dir, private_key_path); + // Launch a job to perform the packing on the file thread. Ignore warnings + // from the packing process. (e.g. Overwrite any existing crx file.) + pack_job_ = new PackExtensionJob(this, src_dir, private_key_path, + ExtensionCreator::kOverwriteCRX); pack_job_->set_asynchronous(false); pack_job_->Start(); diff --git a/chrome/browser/extensions/extensions_startup.h b/chrome/browser/extensions/extensions_startup.h index 12f59d9..3cefd3e 100644 --- a/chrome/browser/extensions/extensions_startup.h +++ b/chrome/browser/extensions/extensions_startup.h @@ -20,7 +20,8 @@ class ExtensionsStartupUtil : public PackExtensionJob::Client { virtual void OnPackSuccess(const FilePath& crx_path, const FilePath& output_private_key_path) OVERRIDE; - virtual void OnPackFailure(const std::string& error_message) OVERRIDE; + virtual void OnPackFailure(const std::string& error_message, + ExtensionCreator::ErrorType type) OVERRIDE; // Handle --pack-extension flag from the |cmd_line| by packing the specified // extension. Returns false if the pack job failed. diff --git a/chrome/browser/extensions/pack_extension_job.cc b/chrome/browser/extensions/pack_extension_job.cc index e7d58be..93152a7 100644 --- a/chrome/browser/extensions/pack_extension_job.cc +++ b/chrome/browser/extensions/pack_extension_job.cc @@ -17,8 +17,10 @@ using content::BrowserThread; PackExtensionJob::PackExtensionJob(Client* client, const FilePath& root_directory, - const FilePath& key_file) - : client_(client), key_file_(key_file), asynchronous_(true) { + const FilePath& key_file, + int run_flags) + : client_(client), key_file_(key_file), asynchronous_(true), + run_flags_(run_flags) { root_directory_ = root_directory.StripTrailingSeparators(); CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); } @@ -50,7 +52,8 @@ void PackExtensionJob::Run() { // TODO(aa): Need to internationalize the errors that ExtensionCreator // returns. See bug 20734. ExtensionCreator creator; - if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) { + if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_, + run_flags_)) { if (asynchronous_) { BrowserThread::PostTask( client_thread_id_, FROM_HERE, @@ -64,9 +67,10 @@ void PackExtensionJob::Run() { client_thread_id_, FROM_HERE, base::Bind( &PackExtensionJob::ReportFailureOnClientThread, this, - creator.error_message())); + creator.error_message(), creator.error_type())); } else { - ReportFailureOnClientThread(creator.error_message()); + ReportFailureOnClientThread(creator.error_message(), + creator.error_type()); } } } @@ -76,9 +80,11 @@ void PackExtensionJob::ReportSuccessOnClientThread() { client_->OnPackSuccess(crx_file_out_, key_file_out_); } -void PackExtensionJob::ReportFailureOnClientThread(const std::string& error) { +void PackExtensionJob::ReportFailureOnClientThread( + const std::string& error, + ExtensionCreator::ErrorType error_type) { if (client_) - client_->OnPackFailure(error); + client_->OnPackFailure(error, error_type); } // static diff --git a/chrome/browser/extensions/pack_extension_job.h b/chrome/browser/extensions/pack_extension_job.h index ed479cf..f6b99d7 100644 --- a/chrome/browser/extensions/pack_extension_job.h +++ b/chrome/browser/extensions/pack_extension_job.h @@ -12,19 +12,20 @@ #include "base/memory/ref_counted.h" #include "base/string16.h" #include "content/public/browser/browser_thread.h" +#include "chrome/browser/extensions/extension_creator.h" // Manages packing an extension on the file thread and reporting the result // back to the UI. class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> { public: - // Interface for people who want to use PackExtensionJob to implement. class Client { public: virtual void OnPackSuccess(const FilePath& crx_file, const FilePath& key_file) = 0; - virtual void OnPackFailure(const std::string& message) = 0; + virtual void OnPackFailure(const std::string& message, + ExtensionCreator::ErrorType error_type) = 0; protected: virtual ~Client() {} @@ -32,7 +33,8 @@ class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> { PackExtensionJob(Client* client, const FilePath& root_directory, - const FilePath& key_file); + const FilePath& key_file, + int run_flags); // Starts the packing job. void Start(); @@ -55,7 +57,8 @@ class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> { // If |asynchronous_| is false, this is run on whichever thread calls it. void Run(); void ReportSuccessOnClientThread(); - void ReportFailureOnClientThread(const std::string& error); + void ReportFailureOnClientThread(const std::string& error, + ExtensionCreator::ErrorType error_type); content::BrowserThread::ID client_thread_id_; Client* client_; @@ -64,6 +67,7 @@ class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> { FilePath crx_file_out_; FilePath key_file_out_; bool asynchronous_; + int run_flags_; // Bitset of ExtensionCreator::RunFlags values DISALLOW_COPY_AND_ASSIGN(PackExtensionJob); }; diff --git a/chrome/browser/resources/options/extension_settings.js b/chrome/browser/resources/options/extension_settings.js index 06c009f..401f04b 100644 --- a/chrome/browser/resources/options/extension_settings.js +++ b/chrome/browser/resources/options/extension_settings.js @@ -177,6 +177,25 @@ cr.define('options', function() { ExtensionsList.decorate(extensionList); } + // Indicate that warning |message| has occured for pack of |crx_path| and + // |pem_path| files. Ask if user wants override the warning. Send + // |overrideFlags| to repeated 'pack' call to accomplish the override. + ExtensionSettings.askToOverrideWarning + = function(message, crx_path, pem_path, overrideFlags) { + OptionsPage.closeOverlay(); + AlertOverlay.show( + localStrings.getString('packExtensionWarningTitle'), + message, + localStrings.getString('packExtensionProceedAnyway'), + localStrings.getString('cancel'), + function() { + chrome.send('pack', [crx_path, pem_path, overrideFlags]); + }, + function() { + OptionsPage.closeOverlay(); + }); + } + // Export return { ExtensionSettings: ExtensionSettings diff --git a/chrome/browser/resources/options/pack_extension_overlay.js b/chrome/browser/resources/options/pack_extension_overlay.js index 530c6ab..c698748 100644 --- a/chrome/browser/resources/options/pack_extension_overlay.js +++ b/chrome/browser/resources/options/pack_extension_overlay.js @@ -35,7 +35,7 @@ cr.define('options', function() { $('packExtensionCommit').onclick = function(event) { var extensionPath = $('extensionRootDir').value; var privateKeyPath = $('extensionPrivateKey').value; - chrome.send('pack', [extensionPath, privateKeyPath]); + chrome.send('pack', [extensionPath, privateKeyPath, 0]); }; $('browseExtensionDir').addEventListener('click', this.handleBrowseExtensionDir_.bind(this)); diff --git a/chrome/browser/ui/webui/options/pack_extension_handler.cc b/chrome/browser/ui/webui/options/pack_extension_handler.cc index e42e34a..87491d3 100644 --- a/chrome/browser/ui/webui/options/pack_extension_handler.cc +++ b/chrome/browser/ui/webui/options/pack_extension_handler.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/webui/options/pack_extension_handler.h" +#include "chrome/browser/extensions/extension_creator.h" #include "base/bind.h" #include "base/utf_string_conversions.h" #include "grit/generated_resources.h" @@ -39,6 +40,10 @@ void PackExtensionHandler::GetLocalizedValues( l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_PRIVATE_KEY_LABEL)); localized_strings->SetString("packExtensionBrowseButton", l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_DIALOG_BROWSE)); + localized_strings->SetString("packExtensionProceedAnyway", + l10n_util::GetStringUTF16(IDS_EXTENSION_PROCEED_ANYWAY)); + localized_strings->SetString("packExtensionWarningTitle", + l10n_util::GetStringUTF16(IDS_EXTENSION_PACK_WARNING_TITLE)); } void PackExtensionHandler::RegisterMessages() { @@ -58,23 +63,38 @@ void PackExtensionHandler::OnPackSuccess(const FilePath& crx_file, "PackExtensionOverlay.showSuccessMessage", arguments); } -void PackExtensionHandler::OnPackFailure(const std::string& error) { - ShowAlert(error); +void PackExtensionHandler::OnPackFailure(const std::string& error, + ExtensionCreator::ErrorType type) { + if (type == ExtensionCreator::kCRXExists) { + base::StringValue error_str(error); + base::StringValue extension_path_str(extension_path_); + base::StringValue key_path_str(private_key_path_); + base::FundamentalValue overwrite_flag(ExtensionCreator::kOverwriteCRX); + + web_ui()->CallJavascriptFunction( + "ExtensionSettings.askToOverrideWarning", error_str, extension_path_str, + key_path_str, overwrite_flag); + } else { + ShowAlert(error); + } } void PackExtensionHandler::HandlePackMessage(const ListValue* args) { - std::string extension_path; - std::string private_key_path; - CHECK_EQ(2U, args->GetSize()); - CHECK(args->GetString(0, &extension_path)); - CHECK(args->GetString(1, &private_key_path)); + + CHECK_EQ(3U, args->GetSize()); + CHECK(args->GetString(0, &extension_path_)); + CHECK(args->GetString(1, &private_key_path_)); + + double flags_double = 0.0; + CHECK(args->GetDouble(2, &flags_double)); + int run_flags = static_cast<int>(flags_double); FilePath root_directory = - FilePath::FromWStringHack(UTF8ToWide(extension_path)); - FilePath key_file = FilePath::FromWStringHack(UTF8ToWide(private_key_path)); + FilePath::FromWStringHack(UTF8ToWide(extension_path_)); + FilePath key_file = FilePath::FromWStringHack(UTF8ToWide(private_key_path_)); if (root_directory.empty()) { - if (extension_path.empty()) { + if (extension_path_.empty()) { ShowAlert(l10n_util::GetStringUTF8( IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED)); } else { @@ -85,13 +105,13 @@ void PackExtensionHandler::HandlePackMessage(const ListValue* args) { return; } - if (!private_key_path.empty() && key_file.empty()) { + if (!private_key_path_.empty() && key_file.empty()) { ShowAlert(l10n_util::GetStringUTF8( IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID)); return; } - pack_job_ = new PackExtensionJob(this, root_directory, key_file); + pack_job_ = new PackExtensionJob(this, root_directory, key_file, run_flags); pack_job_->Start(); } diff --git a/chrome/browser/ui/webui/options/pack_extension_handler.h b/chrome/browser/ui/webui/options/pack_extension_handler.h index e25b37d..84d6dda 100644 --- a/chrome/browser/ui/webui/options/pack_extension_handler.h +++ b/chrome/browser/ui/webui/options/pack_extension_handler.h @@ -31,7 +31,8 @@ class PackExtensionHandler : public OptionsPageUIHandler, virtual void OnPackSuccess(const FilePath& crx_file, const FilePath& key_file) OVERRIDE; - virtual void OnPackFailure(const std::string& error) OVERRIDE; + virtual void OnPackFailure(const std::string& error, + ExtensionCreator::ErrorType) OVERRIDE; private: // Javascript callback to start packing an extension. @@ -43,6 +44,12 @@ class PackExtensionHandler : public OptionsPageUIHandler, // Used to package the extension. scoped_refptr<PackExtensionJob> pack_job_; + // Path to root directory of extension + std::string extension_path_; + + // Path to private key file, or null if none specified + std::string private_key_path_; + DISALLOW_COPY_AND_ASSIGN(PackExtensionHandler); }; |