| 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/extension_web_ui.h" | 5 #include "chrome/browser/extensions/extension_web_ui.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ImageLoadingTracker::DONT_CACHE); | 105 ImageLoadingTracker::DONT_CACHE); |
| 106 } else { | 106 } else { |
| 107 ForwardResult(NULL); | 107 ForwardResult(NULL); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 virtual void OnImageLoaded(const gfx::Image& image, | 111 virtual void OnImageLoaded(const gfx::Image& image, |
| 112 const std::string& extension_id, | 112 const std::string& extension_id, |
| 113 int index) OVERRIDE { | 113 int index) OVERRIDE { |
| 114 if (!image.IsEmpty()) { | 114 if (!image.IsEmpty()) { |
| 115 std::vector<unsigned char> image_data; | 115 std::vector<unsigned char> bitmap_data; |
| 116 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*image.ToSkBitmap(), false, | 116 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*image.ToSkBitmap(), false, |
| 117 &image_data)) { | 117 &bitmap_data)) { |
| 118 NOTREACHED() << "Could not encode extension favicon"; | 118 NOTREACHED() << "Could not encode extension favicon"; |
| 119 } | 119 } |
| 120 ForwardResult(base::RefCountedBytes::TakeVector(&image_data)); | 120 ForwardResult(base::RefCountedBytes::TakeVector(&bitmap_data)); |
| 121 } else { | 121 } else { |
| 122 ForwardResult(NULL); | 122 ForwardResult(NULL); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 ~ExtensionWebUIImageLoadingTracker() {} | 127 ~ExtensionWebUIImageLoadingTracker() {} |
| 128 | 128 |
| 129 // Forwards the result on the request. If no favicon was available then | 129 // Forwards the result on the request. If no favicon was available then |
| 130 // |icon_data| may be backed by NULL. Once the result has been forwarded the | 130 // |icon_data| may be backed by NULL. Once the result has been forwarded the |
| 131 // instance is deleted. | 131 // instance is deleted. |
| 132 void ForwardResult(scoped_refptr<base::RefCountedMemory> icon_data) { | 132 void ForwardResult(scoped_refptr<base::RefCountedMemory> icon_data) { |
| 133 history::FaviconData favicon; | 133 history::FaviconData favicon; |
| 134 favicon.known_icon = icon_data.get() != NULL && icon_data->size() > 0; | 134 favicon.known_icon = icon_data.get() != NULL && icon_data->size() > 0; |
| 135 favicon.image_data = icon_data; | 135 favicon.bitmap_data = icon_data; |
| 136 favicon.icon_type = history::FAVICON; | 136 favicon.icon_type = history::FAVICON; |
| 137 request_->ForwardResultAsync(request_->handle(), favicon); | 137 request_->ForwardResultAsync(request_->handle(), favicon); |
| 138 delete this; | 138 delete this; |
| 139 } | 139 } |
| 140 | 140 |
| 141 ImageLoadingTracker tracker_; | 141 ImageLoadingTracker tracker_; |
| 142 scoped_refptr<FaviconService::GetFaviconRequest> request_; | 142 scoped_refptr<FaviconService::GetFaviconRequest> request_; |
| 143 const Extension* extension_; | 143 const Extension* extension_; |
| 144 | 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker); | 145 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 420 } |
| 421 | 421 |
| 422 // static | 422 // static |
| 423 void ExtensionWebUI::GetFaviconForURL(Profile* profile, | 423 void ExtensionWebUI::GetFaviconForURL(Profile* profile, |
| 424 FaviconService::GetFaviconRequest* request, const GURL& page_url) { | 424 FaviconService::GetFaviconRequest* request, const GURL& page_url) { |
| 425 // tracker deletes itself when done. | 425 // tracker deletes itself when done. |
| 426 ExtensionWebUIImageLoadingTracker* tracker = | 426 ExtensionWebUIImageLoadingTracker* tracker = |
| 427 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); | 427 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); |
| 428 tracker->Init(); | 428 tracker->Init(); |
| 429 } | 429 } |
| OLD | NEW |