| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/download/download_target_determiner.h" | 5 #include "chrome/browser/download/download_target_determiner.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 22 #include "components/history/core/browser/history_service.h" | 22 #include "components/history/core/browser/history_service.h" |
| 23 #include "components/mime_util/mime_util.h" | 23 #include "components/mime_util/mime_util.h" |
| 24 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
| 25 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/download_interrupt_reasons.h" | 27 #include "content/public/browser/download_interrupt_reasons.h" |
| 28 #include "extensions/common/constants.h" | 28 #include "extensions/common/constants.h" |
| 29 #include "extensions/features/features.h" | 29 #include "extensions/features/features.h" |
| 30 #include "net/base/filename_util.h" | 30 #include "net/base/filename_util.h" |
| 31 #include "ppapi/features/features.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "url/origin.h" | 33 #include "url/origin.h" |
| 33 | 34 |
| 34 #if BUILDFLAG(ENABLE_EXTENSIONS) | 35 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 35 #include "chrome/browser/extensions/webstore_installer.h" | 36 #include "chrome/browser/extensions/webstore_installer.h" |
| 36 #include "extensions/common/feature_switch.h" | 37 #include "extensions/common/feature_switch.h" |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 39 #if defined(ENABLE_PLUGINS) | 40 #if BUILDFLAG(ENABLE_PLUGINS) |
| 40 #include "chrome/browser/plugins/plugin_prefs.h" | 41 #include "chrome/browser/plugins/plugin_prefs.h" |
| 41 #include "content/public/browser/plugin_service.h" | 42 #include "content/public/browser/plugin_service.h" |
| 42 #include "content/public/common/webplugininfo.h" | 43 #include "content/public/common/webplugininfo.h" |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
| 46 #include "chrome/browser/android/download/download_controller.h" | 47 #include "chrome/browser/android/download/download_controller.h" |
| 47 #include "chrome/browser/android/download/download_manager_service.h" | 48 #include "chrome/browser/android/download/download_manager_service.h" |
| 48 #endif | 49 #endif |
| 49 | 50 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 void DownloadTargetDeterminer::DetermineMimeTypeDone( | 438 void DownloadTargetDeterminer::DetermineMimeTypeDone( |
| 438 const std::string& mime_type) { | 439 const std::string& mime_type) { |
| 439 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 440 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 440 DVLOG(20) << "MIME type: " << mime_type; | 441 DVLOG(20) << "MIME type: " << mime_type; |
| 441 DCHECK_EQ(STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER, next_state_); | 442 DCHECK_EQ(STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER, next_state_); |
| 442 | 443 |
| 443 mime_type_ = mime_type; | 444 mime_type_ = mime_type; |
| 444 DoLoop(); | 445 DoLoop(); |
| 445 } | 446 } |
| 446 | 447 |
| 447 #if defined(ENABLE_PLUGINS) | 448 #if BUILDFLAG(ENABLE_PLUGINS) |
| 448 // The code below is used by DoDetermineIfHandledSafely to determine if the | 449 // The code below is used by DoDetermineIfHandledSafely to determine if the |
| 449 // file type is handled by a sandboxed plugin. | 450 // file type is handled by a sandboxed plugin. |
| 450 namespace { | 451 namespace { |
| 451 | 452 |
| 452 void InvokeClosureAfterGetPluginCallback( | 453 void InvokeClosureAfterGetPluginCallback( |
| 453 const base::Closure& closure, | 454 const base::Closure& closure, |
| 454 const std::vector<content::WebPluginInfo>& unused) { | 455 const std::vector<content::WebPluginInfo>& unused) { |
| 455 closure.Run(); | 456 closure.Run(); |
| 456 } | 457 } |
| 457 | 458 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 bool is_handled_safely = | 498 bool is_handled_safely = |
| 498 plugin_found && | 499 plugin_found && |
| 499 (plugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS || | 500 (plugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS || |
| 500 plugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS || | 501 plugin_info.type == WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS || |
| 501 plugin_info.type == WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN); | 502 plugin_info.type == WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN); |
| 502 BrowserThread::PostTask( | 503 BrowserThread::PostTask( |
| 503 BrowserThread::UI, FROM_HERE, base::Bind(callback, is_handled_safely)); | 504 BrowserThread::UI, FROM_HERE, base::Bind(callback, is_handled_safely)); |
| 504 } | 505 } |
| 505 | 506 |
| 506 } // namespace | 507 } // namespace |
| 507 #endif // defined(ENABLE_PLUGINS) | 508 #endif // BUILDFLAG(ENABLE_PLUGINS) |
| 508 | 509 |
| 509 DownloadTargetDeterminer::Result | 510 DownloadTargetDeterminer::Result |
| 510 DownloadTargetDeterminer::DoDetermineIfHandledSafely() { | 511 DownloadTargetDeterminer::DoDetermineIfHandledSafely() { |
| 511 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 512 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 512 DCHECK(!virtual_path_.empty()); | 513 DCHECK(!virtual_path_.empty()); |
| 513 DCHECK(!local_path_.empty()); | 514 DCHECK(!local_path_.empty()); |
| 514 DCHECK(!is_filetype_handled_safely_); | 515 DCHECK(!is_filetype_handled_safely_); |
| 515 | 516 |
| 516 next_state_ = STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE; | 517 next_state_ = STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE; |
| 517 | 518 |
| 518 if (mime_type_.empty()) | 519 if (mime_type_.empty()) |
| 519 return CONTINUE; | 520 return CONTINUE; |
| 520 | 521 |
| 521 if (mime_util::IsSupportedMimeType(mime_type_)) { | 522 if (mime_util::IsSupportedMimeType(mime_type_)) { |
| 522 is_filetype_handled_safely_ = true; | 523 is_filetype_handled_safely_ = true; |
| 523 return CONTINUE; | 524 return CONTINUE; |
| 524 } | 525 } |
| 525 | 526 |
| 526 #if defined(ENABLE_PLUGINS) | 527 #if BUILDFLAG(ENABLE_PLUGINS) |
| 527 BrowserThread::PostTask( | 528 BrowserThread::PostTask( |
| 528 BrowserThread::IO, | 529 BrowserThread::IO, |
| 529 FROM_HERE, | 530 FROM_HERE, |
| 530 base::Bind( | 531 base::Bind( |
| 531 &IsHandledBySafePlugin, | 532 &IsHandledBySafePlugin, |
| 532 GetProfile()->GetResourceContext(), | 533 GetProfile()->GetResourceContext(), |
| 533 net::FilePathToFileURL(local_path_), | 534 net::FilePathToFileURL(local_path_), |
| 534 mime_type_, | 535 mime_type_, |
| 535 RETRY_IF_STALE_PLUGIN_LIST, | 536 RETRY_IF_STALE_PLUGIN_LIST, |
| 536 base::Bind(&DownloadTargetDeterminer::DetermineIfHandledSafelyDone, | 537 base::Bind(&DownloadTargetDeterminer::DetermineIfHandledSafelyDone, |
| 537 weak_ptr_factory_.GetWeakPtr()))); | 538 weak_ptr_factory_.GetWeakPtr()))); |
| 538 return QUIT_DOLOOP; | 539 return QUIT_DOLOOP; |
| 539 #else | 540 #else |
| 540 return CONTINUE; | 541 return CONTINUE; |
| 541 #endif | 542 #endif |
| 542 } | 543 } |
| 543 | 544 |
| 544 #if defined(ENABLE_PLUGINS) | 545 #if BUILDFLAG(ENABLE_PLUGINS) |
| 545 void DownloadTargetDeterminer::DetermineIfHandledSafelyDone( | 546 void DownloadTargetDeterminer::DetermineIfHandledSafelyDone( |
| 546 bool is_handled_safely) { | 547 bool is_handled_safely) { |
| 547 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 548 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 548 DVLOG(20) << "Is file type handled safely: " << is_filetype_handled_safely_; | 549 DVLOG(20) << "Is file type handled safely: " << is_filetype_handled_safely_; |
| 549 DCHECK_EQ(STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE, next_state_); | 550 DCHECK_EQ(STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE, next_state_); |
| 550 is_filetype_handled_safely_ = is_handled_safely; | 551 is_filetype_handled_safely_ = is_handled_safely; |
| 551 DoLoop(); | 552 DoLoop(); |
| 552 } | 553 } |
| 553 #endif | 554 #endif |
| 554 | 555 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 const base::FilePath& suggested_path) { | 943 const base::FilePath& suggested_path) { |
| 943 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); | 944 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); |
| 944 } | 945 } |
| 945 | 946 |
| 946 #if defined(OS_WIN) | 947 #if defined(OS_WIN) |
| 947 // static | 948 // static |
| 948 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { | 949 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { |
| 949 return g_is_adobe_reader_up_to_date_; | 950 return g_is_adobe_reader_up_to_date_; |
| 950 } | 951 } |
| 951 #endif | 952 #endif |
| OLD | NEW |