| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 if (client_) { | 136 if (client_) { |
| 137 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, client_); | 137 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, client_); |
| 138 client_ = NULL; | 138 client_ = NULL; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 void CrxInstaller::InstallCrx(const base::FilePath& source_file) { | 142 void CrxInstaller::InstallCrx(const base::FilePath& source_file) { |
| 143 source_file_ = source_file; | 143 source_file_ = source_file; |
| 144 | 144 |
| 145 scoped_refptr<SandboxedUnpacker> unpacker( | 145 scoped_refptr<SandboxedUnpacker> unpacker( |
| 146 new SandboxedUnpacker( | 146 new SandboxedUnpacker(source_file, |
| 147 source_file, | 147 content::ResourceDispatcherHost::Get() != NULL, |
| 148 content::ResourceDispatcherHost::Get() != NULL, | 148 install_source_, |
| 149 install_source_, | 149 creation_flags_, |
| 150 creation_flags_, | 150 install_directory_, |
| 151 install_directory_, | 151 installer_task_runner_.get(), |
| 152 installer_task_runner_, | 152 this)); |
| 153 this)); | |
| 154 | 153 |
| 155 if (!installer_task_runner_->PostTask( | 154 if (!installer_task_runner_->PostTask( |
| 156 FROM_HERE, | 155 FROM_HERE, |
| 157 base::Bind(&SandboxedUnpacker::Start, unpacker.get()))) | 156 base::Bind(&SandboxedUnpacker::Start, unpacker.get()))) |
| 158 NOTREACHED(); | 157 NOTREACHED(); |
| 159 } | 158 } |
| 160 | 159 |
| 161 void CrxInstaller::InstallUserScript(const base::FilePath& source_file, | 160 void CrxInstaller::InstallUserScript(const base::FilePath& source_file, |
| 162 const GURL& download_url) { | 161 const GURL& download_url) { |
| 163 DCHECK(!download_url.is_empty()); | 162 DCHECK(!download_url.is_empty()); |
| 164 | 163 |
| 165 source_file_ = source_file; | 164 source_file_ = source_file; |
| 166 download_url_ = download_url; | 165 download_url_ = download_url; |
| 167 | 166 |
| 168 if (!installer_task_runner_->PostTask( | 167 if (!installer_task_runner_->PostTask( |
| 169 FROM_HERE, | 168 FROM_HERE, |
| 170 base::Bind(&CrxInstaller::ConvertUserScriptOnFileThread, this))) | 169 base::Bind(&CrxInstaller::ConvertUserScriptOnFileThread, this))) |
| 171 NOTREACHED(); | 170 NOTREACHED(); |
| 172 } | 171 } |
| 173 | 172 |
| 174 void CrxInstaller::ConvertUserScriptOnFileThread() { | 173 void CrxInstaller::ConvertUserScriptOnFileThread() { |
| 175 string16 error; | 174 string16 error; |
| 176 scoped_refptr<Extension> extension = ConvertUserScriptToExtension( | 175 scoped_refptr<Extension> extension = ConvertUserScriptToExtension( |
| 177 source_file_, download_url_, install_directory_, &error); | 176 source_file_, download_url_, install_directory_, &error); |
| 178 if (!extension) { | 177 if (!extension.get()) { |
| 179 ReportFailureFromFileThread(CrxInstallerError(error)); | 178 ReportFailureFromFileThread(CrxInstallerError(error)); |
| 180 return; | 179 return; |
| 181 } | 180 } |
| 182 | 181 |
| 183 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension); | 182 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension.get()); |
| 184 } | 183 } |
| 185 | 184 |
| 186 void CrxInstaller::InstallWebApp(const WebApplicationInfo& web_app) { | 185 void CrxInstaller::InstallWebApp(const WebApplicationInfo& web_app) { |
| 187 if (!installer_task_runner_->PostTask( | 186 if (!installer_task_runner_->PostTask( |
| 188 FROM_HERE, | 187 FROM_HERE, |
| 189 base::Bind(&CrxInstaller::ConvertWebAppOnFileThread, | 188 base::Bind(&CrxInstaller::ConvertWebAppOnFileThread, |
| 190 this, | 189 this, |
| 191 web_app, | 190 web_app, |
| 192 install_directory_))) | 191 install_directory_))) |
| 193 NOTREACHED(); | 192 NOTREACHED(); |
| 194 } | 193 } |
| 195 | 194 |
| 196 void CrxInstaller::ConvertWebAppOnFileThread( | 195 void CrxInstaller::ConvertWebAppOnFileThread( |
| 197 const WebApplicationInfo& web_app, | 196 const WebApplicationInfo& web_app, |
| 198 const base::FilePath& install_directory) { | 197 const base::FilePath& install_directory) { |
| 199 string16 error; | 198 string16 error; |
| 200 scoped_refptr<Extension> extension( | 199 scoped_refptr<Extension> extension( |
| 201 ConvertWebAppToExtension(web_app, base::Time::Now(), install_directory)); | 200 ConvertWebAppToExtension(web_app, base::Time::Now(), install_directory)); |
| 202 if (!extension) { | 201 if (!extension.get()) { |
| 203 // Validation should have stopped any potential errors before getting here. | 202 // Validation should have stopped any potential errors before getting here. |
| 204 NOTREACHED() << "Could not convert web app to extension."; | 203 NOTREACHED() << "Could not convert web app to extension."; |
| 205 return; | 204 return; |
| 206 } | 205 } |
| 207 | 206 |
| 208 // TODO(aa): conversion data gets lost here :( | 207 // TODO(aa): conversion data gets lost here :( |
| 209 | 208 |
| 210 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension); | 209 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension.get()); |
| 211 } | 210 } |
| 212 | 211 |
| 213 CrxInstallerError CrxInstaller::AllowInstall(const Extension* extension) { | 212 CrxInstallerError CrxInstaller::AllowInstall(const Extension* extension) { |
| 214 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); | 213 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
| 215 | 214 |
| 216 // Make sure the expected ID matches if one was supplied or if we want to | 215 // Make sure the expected ID matches if one was supplied or if we want to |
| 217 // bypass the prompt. | 216 // bypass the prompt. |
| 218 if ((approved_ || !expected_id_.empty()) && | 217 if ((approved_ || !expected_id_.empty()) && |
| 219 expected_id_ != extension->id()) { | 218 expected_id_ != extension->id()) { |
| 220 return CrxInstallerError( | 219 return CrxInstallerError( |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 if (!prefs->DidExtensionEscalatePermissions(extension()->id())) | 788 if (!prefs->DidExtensionEscalatePermissions(extension()->id())) |
| 790 return; | 789 return; |
| 791 | 790 |
| 792 if (client_) { | 791 if (client_) { |
| 793 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). | 792 AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). |
| 794 client_->ConfirmReEnable(this, extension()); | 793 client_->ConfirmReEnable(this, extension()); |
| 795 } | 794 } |
| 796 } | 795 } |
| 797 | 796 |
| 798 } // namespace extensions | 797 } // namespace extensions |
| OLD | NEW |