Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/app_window/app_window.h" | 5 #include "extensions/browser/app_window/app_window.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 303 |
| 304 AppWindowClient* app_window_client = AppWindowClient::Get(); | 304 AppWindowClient* app_window_client = AppWindowClient::Get(); |
| 305 native_app_window_.reset( | 305 native_app_window_.reset( |
| 306 app_window_client->CreateNativeAppWindow(this, &new_params)); | 306 app_window_client->CreateNativeAppWindow(this, &new_params)); |
| 307 | 307 |
| 308 helper_.reset(new AppWebContentsHelper( | 308 helper_.reset(new AppWebContentsHelper( |
| 309 browser_context_, extension_id_, web_contents(), app_delegate_.get())); | 309 browser_context_, extension_id_, web_contents(), app_delegate_.get())); |
| 310 | 310 |
| 311 UpdateExtensionAppIcon(); | 311 UpdateExtensionAppIcon(); |
| 312 // Download showInShelf=true window icon. | 312 // Download showInShelf=true window icon. |
| 313 if (window_icon_url_.is_valid()) { | 313 if (window_icon_url_.is_valid()) |
| 314 image_loader_ptr_factory_.InvalidateWeakPtrs(); | 314 SetAppIconUrl(window_icon_url_); |
| 315 web_contents()->DownloadImage( | 315 |
| 316 window_icon_url_, | |
| 317 true, // is a favicon | |
| 318 0, // no maximum size | |
| 319 false, // normal cache policy | |
| 320 base::Bind(&AppWindow::DidDownloadFavicon, | |
| 321 image_loader_ptr_factory_.GetWeakPtr())); | |
| 322 } | |
| 323 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); | 316 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); |
| 324 | 317 |
| 325 if (new_params.hidden) { | 318 if (new_params.hidden) { |
| 326 // Although the window starts hidden by default, calling Hide() here | 319 // Although the window starts hidden by default, calling Hide() here |
| 327 // notifies observers of the window being hidden. | 320 // notifies observers of the window being hidden. |
| 328 Hide(); | 321 Hide(); |
| 329 } else { | 322 } else { |
| 330 // Panels are not activated by default. | 323 // Panels are not activated by default. |
| 331 Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE | 324 Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE |
| 332 : SHOW_ACTIVE); | 325 : SHOW_ACTIVE); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 } | 587 } |
| 595 base::RemoveChars(title, base::ASCIIToUTF16("\n"), &title); | 588 base::RemoveChars(title, base::ASCIIToUTF16("\n"), &title); |
| 596 return title; | 589 return title; |
| 597 } | 590 } |
| 598 | 591 |
| 599 void AppWindow::SetAppIconUrl(const GURL& url) { | 592 void AppWindow::SetAppIconUrl(const GURL& url) { |
| 600 // Avoid using any previous icons that were being downloaded. | 593 // Avoid using any previous icons that were being downloaded. |
| 601 image_loader_ptr_factory_.InvalidateWeakPtrs(); | 594 image_loader_ptr_factory_.InvalidateWeakPtrs(); |
| 602 | 595 |
| 603 // Reset |app_icon_image_| to abort pending image load (if any). | 596 // Reset |app_icon_image_| to abort pending image load (if any). |
| 604 app_icon_image_.reset(); | 597 if (!show_in_shelf_) { |
| 598 app_icon_image_.reset(); | |
| 599 app_icon_url_ = url; | |
| 600 } else { | |
| 601 window_icon_url_ = url; | |
| 602 } | |
| 605 | 603 |
| 606 app_icon_url_ = url; | |
| 607 web_contents()->DownloadImage( | 604 web_contents()->DownloadImage( |
| 608 url, | 605 url, |
| 609 true, // is a favicon | 606 true, // is a favicon |
| 610 0, // no maximum size | 607 0, // no maximum size |
| 611 false, // normal cache policy | 608 false, // normal cache policy |
| 612 base::Bind(&AppWindow::DidDownloadFavicon, | 609 base::Bind(&AppWindow::DidDownloadFavicon, |
| 613 image_loader_ptr_factory_.GetWeakPtr())); | 610 image_loader_ptr_factory_.GetWeakPtr())); |
| 614 } | 611 } |
| 615 | 612 |
| 616 void AppWindow::UpdateShape(std::unique_ptr<SkRegion> region) { | 613 void AppWindow::UpdateShape(std::unique_ptr<SkRegion> region) { |
| 617 native_app_window_->UpdateShape(std::move(region)); | 614 native_app_window_->UpdateShape(std::move(region)); |
| 618 } | 615 } |
| 619 | 616 |
| 620 void AppWindow::UpdateDraggableRegions( | 617 void AppWindow::UpdateDraggableRegions( |
| 621 const std::vector<DraggableRegion>& regions) { | 618 const std::vector<DraggableRegion>& regions) { |
| 622 native_app_window_->UpdateDraggableRegions(regions); | 619 native_app_window_->UpdateDraggableRegions(regions); |
| 623 } | 620 } |
| 624 | 621 |
| 625 void AppWindow::UpdateAppIcon(const gfx::Image& image) { | 622 void AppWindow::UpdateAppIcon(const gfx::Image& image) { |
| 626 // Set the showInShelf=true window icon and add the app_icon_image_ | 623 // Set the showInShelf=true window icon and add the app_icon_image_ |
| 627 // as a badge. If the image is empty, set the default app icon placeholder | 624 // as a badge. If the image is empty, set the default app icon placeholder |
| 628 // as the base image. | 625 // as the base image. |
| 629 if (window_icon_url_.is_valid() && !app_icon_image_->image().IsEmpty()) { | 626 if (window_icon_url_.is_valid() && !app_icon_image_->image().IsEmpty()) { |
| 630 gfx::Image base_image = | 627 gfx::Image base_image = |
| 631 !image.IsEmpty() | 628 !image.IsEmpty() |
| 632 ? image | 629 ? image |
| 633 : gfx::Image(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 630 : gfx::Image(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 634 IDR_APP_DEFAULT_ICON)); | 631 IDR_APP_DEFAULT_ICON)); |
| 635 app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge( | 632 // Scale down/up the icon size to large. |
|
stevenjb
2016/12/05 16:51:11
nit: // Scale the icon to EXTENSION_ICON_LARGE
Andra Paraschiv
2016/12/06 08:43:43
Done.
| |
| 636 base_image.AsImageSkia(), app_icon_image_->image_skia())); | 633 int large_icon_size = extension_misc::EXTENSION_ICON_LARGE; |
| 634 if (base_image.Width() != large_icon_size || | |
| 635 base_image.Height() != large_icon_size) { | |
| 636 gfx::Image resized_image(base_image); | |
| 637 resized_image = gfx::Image(gfx::ImageSkiaOperations::CreateResizedImage( | |
| 638 resized_image.AsImageSkia(), skia::ImageOperations::RESIZE_BEST, | |
| 639 gfx::Size(large_icon_size, large_icon_size))); | |
| 640 app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge( | |
| 641 resized_image.AsImageSkia(), app_icon_image_->image_skia())); | |
| 642 } else { | |
| 643 app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge( | |
| 644 base_image.AsImageSkia(), app_icon_image_->image_skia())); | |
| 645 } | |
| 637 } else { | 646 } else { |
| 638 if (image.IsEmpty()) | 647 if (image.IsEmpty()) |
| 639 return; | 648 return; |
| 640 | 649 |
| 641 app_icon_ = image; | 650 app_icon_ = image; |
| 642 } | 651 } |
| 643 native_app_window_->UpdateWindowIcon(); | 652 native_app_window_->UpdateWindowIcon(); |
| 644 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); | 653 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); |
| 645 } | 654 } |
| 646 | 655 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 break; | 870 break; |
| 862 largest_index = i; | 871 largest_index = i; |
| 863 } | 872 } |
| 864 const SkBitmap& largest = bitmaps[largest_index]; | 873 const SkBitmap& largest = bitmaps[largest_index]; |
| 865 UpdateAppIcon(gfx::Image::CreateFrom1xBitmap(largest)); | 874 UpdateAppIcon(gfx::Image::CreateFrom1xBitmap(largest)); |
| 866 } | 875 } |
| 867 | 876 |
| 868 void AppWindow::OnExtensionIconImageChanged(IconImage* image) { | 877 void AppWindow::OnExtensionIconImageChanged(IconImage* image) { |
| 869 DCHECK_EQ(app_icon_image_.get(), image); | 878 DCHECK_EQ(app_icon_image_.get(), image); |
| 870 | 879 |
| 871 UpdateAppIcon(gfx::Image(app_icon_image_->image_skia())); | 880 // Update app_icon if no valid window icon url is set. |
| 881 if (!window_icon_url_.is_valid()) | |
| 882 UpdateAppIcon(gfx::Image(app_icon_image_->image_skia())); | |
| 872 } | 883 } |
| 873 | 884 |
| 874 void AppWindow::UpdateExtensionAppIcon() { | 885 void AppWindow::UpdateExtensionAppIcon() { |
| 875 // Avoid using any previous app icons were being downloaded. | 886 // Avoid using any previous app icons were being downloaded. |
| 876 image_loader_ptr_factory_.InvalidateWeakPtrs(); | 887 image_loader_ptr_factory_.InvalidateWeakPtrs(); |
| 877 | 888 |
| 878 const Extension* extension = GetExtension(); | 889 const Extension* extension = GetExtension(); |
| 879 if (!extension) | 890 if (!extension) |
| 880 return; | 891 return; |
| 881 | 892 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1162 region.bounds.x(), | 1173 region.bounds.x(), |
| 1163 region.bounds.y(), | 1174 region.bounds.y(), |
| 1164 region.bounds.right(), | 1175 region.bounds.right(), |
| 1165 region.bounds.bottom(), | 1176 region.bounds.bottom(), |
| 1166 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 1177 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
| 1167 } | 1178 } |
| 1168 return sk_region; | 1179 return sk_region; |
| 1169 } | 1180 } |
| 1170 | 1181 |
| 1171 } // namespace extensions | 1182 } // namespace extensions |
| OLD | NEW |