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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 137043005: Fix chrome.downloads.getFileIcon for hi-dpi and clarify docs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 6 years, 11 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
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/api/downloads/downloads_api.h" 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "components/web_modal/web_contents_modal_dialog_manager.h" 57 #include "components/web_modal/web_contents_modal_dialog_manager.h"
58 #include "content/public/browser/download_interrupt_reasons.h" 58 #include "content/public/browser/download_interrupt_reasons.h"
59 #include "content/public/browser/download_item.h" 59 #include "content/public/browser/download_item.h"
60 #include "content/public/browser/download_save_info.h" 60 #include "content/public/browser/download_save_info.h"
61 #include "content/public/browser/download_url_parameters.h" 61 #include "content/public/browser/download_url_parameters.h"
62 #include "content/public/browser/notification_details.h" 62 #include "content/public/browser/notification_details.h"
63 #include "content/public/browser/notification_service.h" 63 #include "content/public/browser/notification_service.h"
64 #include "content/public/browser/notification_source.h" 64 #include "content/public/browser/notification_source.h"
65 #include "content/public/browser/render_process_host.h" 65 #include "content/public/browser/render_process_host.h"
66 #include "content/public/browser/render_view_host.h" 66 #include "content/public/browser/render_view_host.h"
67 #include "content/public/browser/render_widget_host_view.h"
67 #include "content/public/browser/resource_context.h" 68 #include "content/public/browser/resource_context.h"
68 #include "content/public/browser/resource_dispatcher_host.h" 69 #include "content/public/browser/resource_dispatcher_host.h"
69 #include "content/public/browser/web_contents.h" 70 #include "content/public/browser/web_contents.h"
70 #include "content/public/browser/web_contents.h"
71 #include "content/public/browser/web_contents_view.h"
72 #include "content/public/browser/web_contents_view.h" 71 #include "content/public/browser/web_contents_view.h"
73 #include "extensions/browser/event_router.h" 72 #include "extensions/browser/event_router.h"
74 #include "extensions/common/extension.h" 73 #include "extensions/common/extension.h"
75 #include "extensions/common/permissions/permissions_data.h" 74 #include "extensions/common/permissions/permissions_data.h"
76 #include "net/base/load_flags.h" 75 #include "net/base/load_flags.h"
77 #include "net/base/net_util.h" 76 #include "net/base/net_util.h"
78 #include "net/http/http_util.h" 77 #include "net/http/http_util.h"
79 #include "net/url_request/url_request.h" 78 #include "net/url_request/url_request.h"
80 #include "third_party/skia/include/core/SkBitmap.h" 79 #include "third_party/skia/include/core/SkBitmap.h"
81 #include "ui/base/webui/web_ui_util.h" 80 #include "ui/base/webui/web_ui_util.h"
81 #include "ui/gfx/image/image_skia.h"
82 82
83 using content::BrowserContext; 83 using content::BrowserContext;
84 using content::BrowserThread; 84 using content::BrowserThread;
85 using content::DownloadItem; 85 using content::DownloadItem;
86 using content::DownloadManager; 86 using content::DownloadManager;
87 87
88 namespace download_extension_errors { 88 namespace download_extension_errors {
89 89
90 const char kEmptyFile[] = "Filename not yet determined"; 90 const char kEmptyFile[] = "Filename not yet determined";
91 const char kFileAlreadyDeleted[] = "Download file already deleted"; 91 const char kFileAlreadyDeleted[] = "Download file already deleted";
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return scoped_ptr<base::DictionaryValue>(json); 296 return scoped_ptr<base::DictionaryValue>(json);
297 } 297 }
298 298
299 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor { 299 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor {
300 public: 300 public:
301 DownloadFileIconExtractorImpl() {} 301 DownloadFileIconExtractorImpl() {}
302 302
303 virtual ~DownloadFileIconExtractorImpl() {} 303 virtual ~DownloadFileIconExtractorImpl() {}
304 304
305 virtual bool ExtractIconURLForPath(const base::FilePath& path, 305 virtual bool ExtractIconURLForPath(const base::FilePath& path,
306 float scale,
306 IconLoader::IconSize icon_size, 307 IconLoader::IconSize icon_size,
307 IconURLCallback callback) OVERRIDE; 308 IconURLCallback callback) OVERRIDE;
308 private: 309 private:
309 void OnIconLoadComplete(gfx::Image* icon); 310 void OnIconLoadComplete(
311 float scale, const IconURLCallback& callback, gfx::Image* icon);
310 312
311 CancelableTaskTracker cancelable_task_tracker_; 313 CancelableTaskTracker cancelable_task_tracker_;
312 IconURLCallback callback_;
313 }; 314 };
314 315
315 bool DownloadFileIconExtractorImpl::ExtractIconURLForPath( 316 bool DownloadFileIconExtractorImpl::ExtractIconURLForPath(
316 const base::FilePath& path, 317 const base::FilePath& path,
318 float scale,
317 IconLoader::IconSize icon_size, 319 IconLoader::IconSize icon_size,
318 IconURLCallback callback) { 320 IconURLCallback callback) {
319 callback_ = callback;
320 IconManager* im = g_browser_process->icon_manager(); 321 IconManager* im = g_browser_process->icon_manager();
321 // The contents of the file at |path| may have changed since a previous 322 // The contents of the file at |path| may have changed since a previous
322 // request, in which case the associated icon may also have changed. 323 // request, in which case the associated icon may also have changed.
323 // Therefore, always call LoadIcon instead of attempting a LookupIcon. 324 // Therefore, always call LoadIcon instead of attempting a LookupIcon.
324 im->LoadIcon(path, 325 im->LoadIcon(path,
325 icon_size, 326 icon_size,
326 base::Bind(&DownloadFileIconExtractorImpl::OnIconLoadComplete, 327 base::Bind(&DownloadFileIconExtractorImpl::OnIconLoadComplete,
327 base::Unretained(this)), 328 base::Unretained(this), scale, callback),
328 &cancelable_task_tracker_); 329 &cancelable_task_tracker_);
329 return true; 330 return true;
330 } 331 }
331 332
332 void DownloadFileIconExtractorImpl::OnIconLoadComplete(gfx::Image* icon) { 333 void DownloadFileIconExtractorImpl::OnIconLoadComplete(
334 float scale, const IconURLCallback& callback, gfx::Image* icon) {
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
334 std::string url; 336 callback.Run(!icon ? std::string() : webui::GetBitmapDataUrl(
335 if (icon) 337 icon->ToImageSkia()->GetRepresentation(scale).sk_bitmap()));
336 url = webui::GetBitmapDataUrl(icon->AsBitmap());
337 callback_.Run(url);
338 } 338 }
339 339
340 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) { 340 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) {
341 switch (pixel_size) { 341 switch (pixel_size) {
342 case 16: return IconLoader::SMALL; 342 case 16: return IconLoader::SMALL;
343 case 32: return IconLoader::NORMAL; 343 case 32: return IconLoader::NORMAL;
344 default: 344 default:
345 NOTREACHED(); 345 NOTREACHED();
346 return IconLoader::NORMAL; 346 return IconLoader::NORMAL;
347 } 347 }
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 GetDownload(GetProfile(), include_incognito(), params->download_id); 1493 GetDownload(GetProfile(), include_incognito(), params->download_id);
1494 if (InvalidId(download_item, &error_) || 1494 if (InvalidId(download_item, &error_) ||
1495 Fault(download_item->GetTargetFilePath().empty(), 1495 Fault(download_item->GetTargetFilePath().empty(),
1496 errors::kEmptyFile, &error_)) 1496 errors::kEmptyFile, &error_))
1497 return false; 1497 return false;
1498 // In-progress downloads return the intermediate filename for GetFullPath() 1498 // In-progress downloads return the intermediate filename for GetFullPath()
1499 // which doesn't have the final extension. Therefore a good file icon can't be 1499 // which doesn't have the final extension. Therefore a good file icon can't be
1500 // found, so use GetTargetFilePath() instead. 1500 // found, so use GetTargetFilePath() instead.
1501 DCHECK(icon_extractor_.get()); 1501 DCHECK(icon_extractor_.get());
1502 DCHECK(icon_size == 16 || icon_size == 32); 1502 DCHECK(icon_size == 16 || icon_size == 32);
1503 float scale = 1.0;
1504 content::WebContents* web_contents =
1505 dispatcher()->delegate()->GetVisibleWebContents();
1506 if (web_contents) {
1507 scale = ui::GetImageScale(ui::GetScaleFactorForNativeView(
1508 web_contents->GetRenderWidgetHostView()->GetNativeView()));
1509 }
1503 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( 1510 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath(
1504 download_item->GetTargetFilePath(), 1511 download_item->GetTargetFilePath(),
1512 scale,
1505 IconLoaderSizeFromPixelSize(icon_size), 1513 IconLoaderSizeFromPixelSize(icon_size),
1506 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); 1514 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this)));
1507 return true; 1515 return true;
1508 } 1516 }
1509 1517
1510 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { 1518 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) {
1511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1512 if (Fault(url.empty(), errors::kIconNotFound, &error_)) { 1520 if (Fault(url.empty(), errors::kIconNotFound, &error_)) {
1513 SendResponse(false); 1521 SendResponse(false);
1514 return; 1522 return;
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 extensions::UnloadedExtensionInfo* unloaded = 1914 extensions::UnloadedExtensionInfo* unloaded =
1907 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); 1915 content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
1908 std::set<const extensions::Extension*>::iterator iter = 1916 std::set<const extensions::Extension*>::iterator iter =
1909 shelf_disabling_extensions_.find(unloaded->extension); 1917 shelf_disabling_extensions_.find(unloaded->extension);
1910 if (iter != shelf_disabling_extensions_.end()) 1918 if (iter != shelf_disabling_extensions_.end())
1911 shelf_disabling_extensions_.erase(iter); 1919 shelf_disabling_extensions_.erase(iter);
1912 break; 1920 break;
1913 } 1921 }
1914 } 1922 }
1915 } 1923 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698