| Index: chrome/browser/media/desktop_media_list.cc
|
| diff --git a/chrome/browser/media/desktop_media_list.cc b/chrome/browser/media/desktop_media_list.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..366f95b790a555f276d70f4aa2ab995ffa755b23
|
| --- /dev/null
|
| +++ b/chrome/browser/media/desktop_media_list.cc
|
| @@ -0,0 +1,84 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/media/desktop_media_list.h"
|
| +
|
| +#include "third_party/skia/include/core/SkCanvas.h"
|
| +#include "third_party/skia/include/core/SkImage.h"
|
| +
|
| +gfx::ImageSkia CreateEnlargedFaviconImage(gfx::Size size, gfx::Image& favicon) {
|
| + if (size.width() < 30 || size.height() < 30)
|
| + return gfx::ImageSkia();
|
| +
|
| + // Create a bitmap.
|
| + SkBitmap result;
|
| + result.allocN32Pixels(size.width(), size.height(), true);
|
| + SkCanvas canvas(result);
|
| +
|
| + // Fill with white.
|
| + canvas.drawARGB(255, 255, 255, 255);
|
| +
|
| + // Draw black border.
|
| + const int thickness = result.width() / 30;
|
| + SkPaint paint;
|
| + paint.setARGB(255, 0, 0, 0);
|
| + paint.setStyle(SkPaint::kStroke_Style);
|
| + paint.setStrokeWidth(thickness);
|
| + canvas.drawRectCoords(thickness, // left
|
| + thickness, // top
|
| + result.width() - thickness, // right
|
| + result.height() - thickness, // bottom
|
| + paint);
|
| +
|
| + // Draw a scaled favicon image into the center of result image to take up to
|
| + // 3/4 of result image.
|
| + const double scale = fmin(3.0 / 4 * result.width() / favicon.Width(),
|
| + 3.0 / 4 * result.height() / favicon.Height());
|
| + SkRect dest_rect;
|
| + dest_rect.set(result.width() / 2 - favicon.Width() * scale / 2, // left
|
| + result.height() / 2 - favicon.Height() * scale / 2, // top
|
| + result.width() / 2 + favicon.Width() * scale / 2, // right
|
| + result.height() / 2 + favicon.Height() * scale / 2); // bottom
|
| + const scoped_ptr<SkImage> temp_image(
|
| + SkImage::NewFromBitmap(favicon.AsBitmap()));
|
| + canvas.drawImageRect(temp_image.get(), dest_rect, nullptr);
|
| +
|
| + // Create a skia image.
|
| + return gfx::ImageSkia::CreateFrom1xBitmap(result);
|
| +}
|
| +
|
| +WebContentsRegistry* WebContentsRegistry::GetInstance() {
|
| + return base::Singleton<WebContentsRegistry>::get();
|
| +}
|
| +
|
| +int WebContentsRegistry::RegisterWebContents(
|
| + content::WebContents* web_contents) {
|
| + IDMap<content::WebContents>::const_iterator it(®istered_web_contents_);
|
| + for (; !it.IsAtEnd(); it.Advance()) {
|
| + if (it.GetCurrentValue() == web_contents)
|
| + return it.GetCurrentKey();
|
| + }
|
| +
|
| + Observe(web_contents);
|
| + return registered_web_contents_.Add(web_contents);
|
| +}
|
| +
|
| +content::WebContents* WebContentsRegistry::GetWebContentsById(int id) {
|
| + return registered_web_contents_.Lookup(id);
|
| +}
|
| +
|
| +WebContentsRegistry::WebContentsRegistry(){};
|
| +WebContentsRegistry::~WebContentsRegistry(){};
|
| +
|
| +void WebContentsRegistry::WebContentsDestroyed(
|
| + content::WebContents* web_contents) {
|
| + IDMap<content::WebContents>::iterator it(®istered_web_contents_);
|
| + for (; !it.IsAtEnd(); it.Advance()) {
|
| + if (it.GetCurrentValue() == web_contents) {
|
| + registered_web_contents_.Remove(it.GetCurrentKey());
|
| + return;
|
| + }
|
| + }
|
| + NOTREACHED();
|
| +}
|
|
|