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

Side by Side Diff: chrome/browser/extensions/webstore_installer.cc

Issue 10876089: Guard against more NULL pointers in WebstoreInstaller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/webstore_installer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/webstore_installer.h" 5 #include "chrome/browser/extensions/webstore_installer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 17 matching lines...) Expand all
28 #include "chrome/common/extensions/extension_constants.h" 28 #include "chrome/common/extensions/extension_constants.h"
29 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/download_manager.h" 30 #include "content/public/browser/download_manager.h"
31 #include "content/public/browser/download_save_info.h" 31 #include "content/public/browser/download_save_info.h"
32 #include "content/public/browser/download_url_parameters.h" 32 #include "content/public/browser/download_url_parameters.h"
33 #include "content/public/browser/navigation_controller.h" 33 #include "content/public/browser/navigation_controller.h"
34 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
35 #include "content/public/browser/notification_details.h" 35 #include "content/public/browser/notification_details.h"
36 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/notification_source.h" 37 #include "content/public/browser/notification_source.h"
38 #include "content/public/browser/web_contents.h"
38 #include "googleurl/src/gurl.h" 39 #include "googleurl/src/gurl.h"
39 #include "net/base/escape.h" 40 #include "net/base/escape.h"
40 41
41 #if defined(OS_CHROMEOS) 42 #if defined(OS_CHROMEOS)
42 #include "chrome/browser/chromeos/gdata/gdata_util.h" 43 #include "chrome/browser/chromeos/gdata/gdata_util.h"
43 #endif 44 #endif
44 45
45 using content::BrowserContext; 46 using content::BrowserContext;
46 using content::BrowserThread; 47 using content::BrowserThread;
47 using content::DownloadId; 48 using content::DownloadId;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 Delegate* delegate, 175 Delegate* delegate,
175 NavigationController* controller, 176 NavigationController* controller,
176 const std::string& id, 177 const std::string& id,
177 scoped_ptr<Approval> approval, 178 scoped_ptr<Approval> approval,
178 int flags) 179 int flags)
179 : profile_(profile), 180 : profile_(profile),
180 delegate_(delegate), 181 delegate_(delegate),
181 controller_(controller), 182 controller_(controller),
182 id_(id), 183 id_(id),
183 download_item_(NULL), 184 download_item_(NULL),
184 flags_(flags),
185 approval_(approval.release()) { 185 approval_(approval.release()) {
186 // TODO(benjhayden): Change this CHECK to DCHECK after http://crbug.com/126013 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
187 CHECK(controller_); 187 DCHECK(controller_);
188 download_url_ = GetWebstoreInstallURL(id, flags & FLAG_INLINE_INSTALL ? 188 download_url_ = GetWebstoreInstallURL(id, flags & FLAG_INLINE_INSTALL ?
189 kInlineInstallSource : kDefaultInstallSource); 189 kInlineInstallSource : kDefaultInstallSource);
190 190
191 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
192 registrar_.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE, 191 registrar_.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE,
193 content::NotificationService::AllSources()); 192 content::NotificationService::AllSources());
194 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 193 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
195 content::Source<Profile>(profile->GetOriginalProfile())); 194 content::Source<Profile>(profile->GetOriginalProfile()));
196 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, 195 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
197 content::Source<CrxInstaller>(NULL)); 196 content::Source<CrxInstaller>(NULL));
198 } 197 }
199 198
200 void WebstoreInstaller::Start() { 199 void WebstoreInstaller::Start() {
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 void WebstoreInstaller::OnDownloadStarted(DownloadId id, net::Error error) { 272 void WebstoreInstaller::OnDownloadStarted(DownloadId id, net::Error error) {
274 if (error != net::OK) { 273 if (error != net::OK) {
275 ReportFailure(net::ErrorToString(error)); 274 ReportFailure(net::ErrorToString(error));
276 return; 275 return;
277 } 276 }
278 277
279 CHECK(id.IsValid()); 278 CHECK(id.IsValid());
280 279
281 DownloadManager* download_manager = 280 DownloadManager* download_manager =
282 BrowserContext::GetDownloadManager(profile_); 281 BrowserContext::GetDownloadManager(profile_);
283 download_item_ = download_manager->GetActiveDownloadItem(id.local()); 282 if (!download_manager)
284 download_item_->AddObserver(this); 283 return;
285 if (approval_.get()) 284 download_item_ = download_manager->GetDownload(id.local());
286 download_item_->SetUserData(kApprovalKey, approval_.release()); 285 if (download_item_) {
286 download_item_->AddObserver(this);
287 if (approval_.get())
288 download_item_->SetUserData(kApprovalKey, approval_.release());
289 }
287 } 290 }
288 291
289 void WebstoreInstaller::OnDownloadUpdated(DownloadItem* download) { 292 void WebstoreInstaller::OnDownloadUpdated(DownloadItem* download) {
290 CHECK_EQ(download_item_, download); 293 CHECK_EQ(download_item_, download);
291 294
292 switch (download->GetState()) { 295 switch (download->GetState()) {
293 case DownloadItem::CANCELLED: 296 case DownloadItem::CANCELLED:
294 ReportFailure(kDownloadCanceledError); 297 ReportFailure(kDownloadCanceledError);
295 break; 298 break;
296 case DownloadItem::INTERRUPTED: 299 case DownloadItem::INTERRUPTED:
(...skipping 12 matching lines...) Expand all
309 312
310 void WebstoreInstaller::OnDownloadDestroyed(DownloadItem* download) { 313 void WebstoreInstaller::OnDownloadDestroyed(DownloadItem* download) {
311 CHECK_EQ(download_item_, download); 314 CHECK_EQ(download_item_, download);
312 download_item_->RemoveObserver(this); 315 download_item_->RemoveObserver(this);
313 download_item_ = NULL; 316 download_item_ = NULL;
314 } 317 }
315 318
316 void WebstoreInstaller::StartDownload(const FilePath& file) { 319 void WebstoreInstaller::StartDownload(const FilePath& file) {
317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
318 321
319 if (file.empty() || !controller_->GetWebContents()) { 322 DownloadManager* download_manager =
323 BrowserContext::GetDownloadManager(profile_);
324 if (file.empty() ||
325 !download_manager ||
326 !controller_->GetWebContents() ||
327 !controller_->GetWebContents()->GetRenderProcessHost() ||
328 !controller_->GetWebContents()->GetRenderViewHost() ||
329 !controller_->GetWebContents()->GetBrowserContext() ||
330 !controller_->GetWebContents()->GetBrowserContext()
331 ->GetResourceContext()) {
320 ReportFailure(kDownloadDirectoryError); 332 ReportFailure(kDownloadDirectoryError);
321 return; 333 return;
322 } 334 }
323 335
324 content::DownloadSaveInfo save_info; 336 content::DownloadSaveInfo save_info;
325 save_info.file_path = file; 337 save_info.file_path = file;
326 338
327 // The download url for the given extension is contained in |download_url_|. 339 // The download url for the given extension is contained in |download_url_|.
328 // We will navigate the current tab to this url to start the download. The 340 // We will navigate the current tab to this url to start the download. The
329 // download system will then pass the crx to the CrxInstaller. 341 // download system will then pass the crx to the CrxInstaller.
330 download_util::RecordDownloadSource( 342 download_util::RecordDownloadSource(
331 download_util::INITIATED_BY_WEBSTORE_INSTALLER); 343 download_util::INITIATED_BY_WEBSTORE_INSTALLER);
332 scoped_ptr<DownloadUrlParameters> params( 344 scoped_ptr<DownloadUrlParameters> params(
333 DownloadUrlParameters::FromWebContents( 345 DownloadUrlParameters::FromWebContents(
334 controller_->GetWebContents(), download_url_, save_info)); 346 controller_->GetWebContents(), download_url_, save_info));
335 if (controller_->GetActiveEntry()) 347 if (controller_->GetActiveEntry())
336 params->set_referrer( 348 params->set_referrer(
337 content::Referrer(controller_->GetActiveEntry()->GetURL(), 349 content::Referrer(controller_->GetActiveEntry()->GetURL(),
338 WebKit::WebReferrerPolicyDefault)); 350 WebKit::WebReferrerPolicyDefault));
339 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this)); 351 params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this));
340 BrowserContext::GetDownloadManager(profile_)->DownloadUrl(params.Pass()); 352 download_manager->DownloadUrl(params.Pass());
341 } 353 }
342 354
343 void WebstoreInstaller::ReportFailure(const std::string& error) { 355 void WebstoreInstaller::ReportFailure(const std::string& error) {
344 if (delegate_) { 356 if (delegate_) {
345 delegate_->OnExtensionInstallFailure(id_, error); 357 delegate_->OnExtensionInstallFailure(id_, error);
346 delegate_ = NULL; 358 delegate_ = NULL;
347 } 359 }
348 360
349 Release(); // Balanced in Start(). 361 Release(); // Balanced in Start().
350 } 362 }
351 363
352 void WebstoreInstaller::ReportSuccess() { 364 void WebstoreInstaller::ReportSuccess() {
353 if (delegate_) { 365 if (delegate_) {
354 delegate_->OnExtensionInstallSuccess(id_); 366 delegate_->OnExtensionInstallSuccess(id_);
355 delegate_ = NULL; 367 delegate_ = NULL;
356 } 368 }
357 369
358 Release(); // Balanced in Start(). 370 Release(); // Balanced in Start().
359 } 371 }
360 372
361 } // namespace extensions 373 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/webstore_installer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698