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

Side by Side Diff: chrome/browser/download/download_commands.cc

Issue 2219953004: Refactor download image-MIME-type-detection code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add more tests Created 4 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_commands.h" 5 #include "chrome/browser/download/download_commands.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/download/download_crx_util.h" 16 #include "chrome/browser/download/download_crx_util.h"
17 #include "chrome/browser/download/download_item_model.h" 17 #include "chrome/browser/download/download_item_model.h"
18 #include "chrome/browser/download/download_prefs.h" 18 #include "chrome/browser/download/download_prefs.h"
19 #include "chrome/browser/image_decoder.h" 19 #include "chrome/browser/image_decoder.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/safe_browsing/download_protection_service.h" 21 #include "chrome/browser/safe_browsing/download_protection_service.h"
22 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
23 #include "chrome/browser/ui/browser_finder.h" 23 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 24 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
25 #include "chrome/common/safe_browsing/csd.pb.h" 25 #include "chrome/common/safe_browsing/csd.pb.h"
26 #include "chrome/common/safe_browsing/file_type_policies.h" 26 #include "chrome/common/safe_browsing/file_type_policies.h"
27 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
28 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
29 #include "components/google/core/browser/google_util.h" 29 #include "components/google/core/browser/google_util.h"
30 #include "components/mime_util/mime_util.h"
31 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
32 #include "net/base/url_util.h" 31 #include "net/base/url_util.h"
33 #include "ui/base/clipboard/scoped_clipboard_writer.h" 32 #include "ui/base/clipboard/scoped_clipboard_writer.h"
34 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
36 35
37 #if defined(OS_WIN) 36 #if defined(OS_WIN)
38 #include "chrome/browser/download/download_target_determiner.h" 37 #include "chrome/browser/download/download_target_determiner.h"
39 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" 38 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
40 #endif 39 #endif
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date 375 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date
377 : true); 376 : true);
378 #elif defined(OS_MACOSX) || defined(OS_LINUX) 377 #elif defined(OS_MACOSX) || defined(OS_LINUX)
379 return IsDownloadPdf(); 378 return IsDownloadPdf();
380 #endif 379 #endif
381 } 380 }
382 381
383 void DownloadCommands::CopyFileAsImageToClipboard() const { 382 void DownloadCommands::CopyFileAsImageToClipboard() const {
384 if (download_item_->GetState() != content::DownloadItem::COMPLETE || 383 if (download_item_->GetState() != content::DownloadItem::COMPLETE ||
385 download_item_->GetReceivedBytes() > kMaxImageClipboardSize) { 384 download_item_->GetReceivedBytes() > kMaxImageClipboardSize) {
386 return; 385 return;
387 } 386 }
388 387
389 // TODO(yoshiki): Refine the code by combining the common logic with the 388 if (!DownloadItemModel(download_item_).HasSupportedImageMimeType())
390 // preview in DownloadItemNotification. 389 return;
391 std::string mime = download_item_->GetMimeType();
392 if (!mime_util::IsSupportedImageMimeType(mime)) {
393 base::FilePath::StringType extension_with_dot =
394 download_item_->GetTargetFilePath().FinalExtension();
395 if (extension_with_dot.empty() ||
396 !net::GetWellKnownMimeTypeFromExtension(extension_with_dot.substr(1),
397 &mime) ||
398 !mime_util::IsSupportedImageMimeType(mime)) {
399 // It seems a non-image file.
400 return;
401 }
402 }
403 390
404 base::FilePath file_path = download_item_->GetFullPath(); 391 base::FilePath file_path = download_item_->GetFullPath();
405 ImageClipboardCopyManager::Start(file_path); 392 ImageClipboardCopyManager::Start(file_path);
406 } 393 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/note_taking_app_utils.cc ('k') | chrome/browser/download/download_item_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698