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/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 Loading... | |
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 return scoped_ptr<base::DictionaryValue>(json); | 294 return scoped_ptr<base::DictionaryValue>(json); |
295 } | 295 } |
296 | 296 |
297 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor { | 297 class DownloadFileIconExtractorImpl : public DownloadFileIconExtractor { |
298 public: | 298 public: |
299 DownloadFileIconExtractorImpl() {} | 299 DownloadFileIconExtractorImpl() {} |
300 | 300 |
301 virtual ~DownloadFileIconExtractorImpl() {} | 301 virtual ~DownloadFileIconExtractorImpl() {} |
302 | 302 |
303 virtual bool ExtractIconURLForPath(const base::FilePath& path, | 303 virtual bool ExtractIconURLForPath(const base::FilePath& path, |
304 float scale, | |
304 IconLoader::IconSize icon_size, | 305 IconLoader::IconSize icon_size, |
305 IconURLCallback callback) OVERRIDE; | 306 IconURLCallback callback) OVERRIDE; |
306 private: | 307 private: |
307 void OnIconLoadComplete(gfx::Image* icon); | 308 void OnIconLoadComplete(gfx::Image* icon); |
308 | 309 |
309 CancelableTaskTracker cancelable_task_tracker_; | 310 CancelableTaskTracker cancelable_task_tracker_; |
311 float scale_; | |
310 IconURLCallback callback_; | 312 IconURLCallback callback_; |
311 }; | 313 }; |
312 | 314 |
313 bool DownloadFileIconExtractorImpl::ExtractIconURLForPath( | 315 bool DownloadFileIconExtractorImpl::ExtractIconURLForPath( |
314 const base::FilePath& path, | 316 const base::FilePath& path, |
317 float scale, | |
315 IconLoader::IconSize icon_size, | 318 IconLoader::IconSize icon_size, |
316 IconURLCallback callback) { | 319 IconURLCallback callback) { |
320 scale_ = scale; | |
317 callback_ = callback; | 321 callback_ = callback; |
318 IconManager* im = g_browser_process->icon_manager(); | 322 IconManager* im = g_browser_process->icon_manager(); |
319 // The contents of the file at |path| may have changed since a previous | 323 // The contents of the file at |path| may have changed since a previous |
320 // request, in which case the associated icon may also have changed. | 324 // request, in which case the associated icon may also have changed. |
321 // Therefore, always call LoadIcon instead of attempting a LookupIcon. | 325 // Therefore, always call LoadIcon instead of attempting a LookupIcon. |
322 im->LoadIcon(path, | 326 im->LoadIcon(path, |
323 icon_size, | 327 icon_size, |
324 base::Bind(&DownloadFileIconExtractorImpl::OnIconLoadComplete, | 328 base::Bind(&DownloadFileIconExtractorImpl::OnIconLoadComplete, |
pkotwicz
2014/01/15 02:33:37
Would it be possible to pass |scale| as a paramete
benjhayden
2014/01/15 23:58:20
Done.
| |
325 base::Unretained(this)), | 329 base::Unretained(this)), |
326 &cancelable_task_tracker_); | 330 &cancelable_task_tracker_); |
327 return true; | 331 return true; |
328 } | 332 } |
329 | 333 |
330 void DownloadFileIconExtractorImpl::OnIconLoadComplete(gfx::Image* icon) { | 334 void DownloadFileIconExtractorImpl::OnIconLoadComplete(gfx::Image* icon) { |
331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
332 std::string url; | 336 callback_.Run(!icon ? std::string() : webui::GetBitmapDataUrl( |
333 if (icon) | 337 icon->ToImageSkia()->GetRepresentation(scale_).sk_bitmap())); |
334 url = webui::GetBitmapDataUrl(icon->AsBitmap()); | |
335 callback_.Run(url); | |
336 } | 338 } |
337 | 339 |
338 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) { | 340 IconLoader::IconSize IconLoaderSizeFromPixelSize(int pixel_size) { |
339 switch (pixel_size) { | 341 switch (pixel_size) { |
340 case 16: return IconLoader::SMALL; | 342 case 16: return IconLoader::SMALL; |
341 case 32: return IconLoader::NORMAL; | 343 case 32: return IconLoader::NORMAL; |
342 default: | 344 default: |
343 NOTREACHED(); | 345 NOTREACHED(); |
344 return IconLoader::NORMAL; | 346 return IconLoader::NORMAL; |
345 } | 347 } |
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1491 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1493 GetDownload(GetProfile(), include_incognito(), params->download_id); |
1492 if (InvalidId(download_item, &error_) || | 1494 if (InvalidId(download_item, &error_) || |
1493 Fault(download_item->GetTargetFilePath().empty(), | 1495 Fault(download_item->GetTargetFilePath().empty(), |
1494 errors::kEmptyFile, &error_)) | 1496 errors::kEmptyFile, &error_)) |
1495 return false; | 1497 return false; |
1496 // In-progress downloads return the intermediate filename for GetFullPath() | 1498 // In-progress downloads return the intermediate filename for GetFullPath() |
1497 // 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 |
1498 // found, so use GetTargetFilePath() instead. | 1500 // found, so use GetTargetFilePath() instead. |
1499 DCHECK(icon_extractor_.get()); | 1501 DCHECK(icon_extractor_.get()); |
1500 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 } | |
1501 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( | 1510 EXTENSION_FUNCTION_VALIDATE(icon_extractor_->ExtractIconURLForPath( |
1502 download_item->GetTargetFilePath(), | 1511 download_item->GetTargetFilePath(), |
1512 scale, | |
1503 IconLoaderSizeFromPixelSize(icon_size), | 1513 IconLoaderSizeFromPixelSize(icon_size), |
1504 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); | 1514 base::Bind(&DownloadsGetFileIconFunction::OnIconURLExtracted, this))); |
1505 return true; | 1515 return true; |
1506 } | 1516 } |
1507 | 1517 |
1508 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { | 1518 void DownloadsGetFileIconFunction::OnIconURLExtracted(const std::string& url) { |
1509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1510 if (Fault(url.empty(), errors::kIconNotFound, &error_)) { | 1520 if (Fault(url.empty(), errors::kIconNotFound, &error_)) { |
1511 SendResponse(false); | 1521 SendResponse(false); |
1512 return; | 1522 return; |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1904 extensions::UnloadedExtensionInfo* unloaded = | 1914 extensions::UnloadedExtensionInfo* unloaded = |
1905 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 1915 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
1906 std::set<const extensions::Extension*>::iterator iter = | 1916 std::set<const extensions::Extension*>::iterator iter = |
1907 shelf_disabling_extensions_.find(unloaded->extension); | 1917 shelf_disabling_extensions_.find(unloaded->extension); |
1908 if (iter != shelf_disabling_extensions_.end()) | 1918 if (iter != shelf_disabling_extensions_.end()) |
1909 shelf_disabling_extensions_.erase(iter); | 1919 shelf_disabling_extensions_.erase(iter); |
1910 break; | 1920 break; |
1911 } | 1921 } |
1912 } | 1922 } |
1913 } | 1923 } |
OLD | NEW |