Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1506)

Unified Diff: chrome/browser/extensions/zipfile_installer.cc

Issue 406713002: Allow drag-and-drop of zipped extensions on chrome://extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add zipfile installer Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/zipfile_installer.cc
diff --git a/chrome/browser/extensions/zipfile_installer.cc b/chrome/browser/extensions/zipfile_installer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..59d8007401d09d7973484d51307060a6de312925
--- /dev/null
+++ b/chrome/browser/extensions/zipfile_installer.cc
@@ -0,0 +1,94 @@
+// Copyright 2014 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/zipfile_installer.h"
+
+#include "base/path_service.h"
+#include "chrome/browser/extensions/extension_error_reporter.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/unpacked_installer.h"
+#include "chrome/common/extensions/chrome_utility_extensions_messages.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/utility_process_host.h"
+
+using content::BrowserThread;
+using content::UtilityProcessHost;
+
+ZipFileInstaller::ZipFileInstaller(ExtensionService* extension_service)
+ : be_noisy_on_failure_(true),
+ extension_service_(extension_service->AsWeakPtr()) {
+}
+
+void ZipFileInstaller::LoadFromZipFile(const base::FilePath& path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ zip_path_ = path;
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&ZipFileInstaller::StartWorkOnIOThread, this));
+}
+
+ZipFileInstaller::~ZipFileInstaller() {
+}
+
+// static
+scoped_refptr<ZipFileInstaller> ZipFileInstaller::Create(
+ ExtensionService* extension_service) {
+ DCHECK(extension_service);
+ return scoped_refptr<ZipFileInstaller>(
+ new ZipFileInstaller(extension_service));
+}
+
+void ZipFileInstaller::StartWorkOnIOThread() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ UtilityProcessHost* host =
+ UtilityProcessHost::Create(this, base::MessageLoopProxy::current().get());
+ base::FilePath temp_dir;
+ PathService::Get(base::DIR_TEMP, &temp_dir);
+ host->SetExposedDir(temp_dir.DirName());
asargent_no_longer_on_chrome 2014/07/31 19:59:23 Instead of giving the host access to the entire te
elijahtaylor1 2014/08/06 00:31:54 Done
+ host->Send(new ChromeUtilityMsg_UnzipToDir(zip_path_, temp_dir));
+}
+
+void ZipFileInstaller::ReportSuccessOnUIThread(
+ const base::FilePath& unzipped_path) {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ extensions::UnpackedInstaller::Create(extension_service_.get())
+ ->Load(unzipped_path);
+}
+
+void ZipFileInstaller::ReportErrorOnUIThread(const std::string& error) {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (extension_service_.get()) {
+ ExtensionErrorReporter::GetInstance()->ReportLoadError(
+ zip_path_, error, extension_service_->profile(), be_noisy_on_failure_);
+ }
+}
+
+void ZipFileInstaller::OnUnzipSucceeded(const base::FilePath& unzipped_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(
+ &ZipFileInstaller::ReportSuccessOnUIThread, this, unzipped_path));
+}
+
+void ZipFileInstaller::OnUnzipFailed(const std::string& error) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&ZipFileInstaller::ReportErrorOnUIThread, this, error));
+}
+
+bool ZipFileInstaller::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(ZipFileInstaller, message)
+ IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnzipToDir_Succeeded,
+ OnUnzipSucceeded)
+ IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnzipToDir_Failed, OnUnzipFailed)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}

Powered by Google App Engine
This is Rietveld 408576698