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

Side by Side Diff: extensions/browser/app_window/app_window.cc

Issue 2209053004: Enhance chrome.app.window API with icon property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review v4 Created 4 years, 4 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
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "extensions/common/extension.h" 50 #include "extensions/common/extension.h"
51 #include "extensions/common/manifest_handlers/icons_handler.h" 51 #include "extensions/common/manifest_handlers/icons_handler.h"
52 #include "extensions/common/permissions/permissions_data.h" 52 #include "extensions/common/permissions/permissions_data.h"
53 #include "extensions/common/switches.h" 53 #include "extensions/common/switches.h"
54 #include "extensions/grit/extensions_browser_resources.h" 54 #include "extensions/grit/extensions_browser_resources.h"
55 #include "third_party/skia/include/core/SkRegion.h" 55 #include "third_party/skia/include/core/SkRegion.h"
56 #include "ui/base/resource/resource_bundle.h" 56 #include "ui/base/resource/resource_bundle.h"
57 #include "ui/display/display.h" 57 #include "ui/display/display.h"
58 #include "ui/display/screen.h" 58 #include "ui/display/screen.h"
59 #include "ui/events/keycodes/keyboard_codes.h" 59 #include "ui/events/keycodes/keyboard_codes.h"
60 #include "ui/gfx/image/image_skia_operations.h"
60 61
61 #if !defined(OS_MACOSX) 62 #if !defined(OS_MACOSX)
62 #include "components/prefs/pref_service.h" 63 #include "components/prefs/pref_service.h"
63 #include "extensions/browser/pref_names.h" 64 #include "extensions/browser/pref_names.h"
64 #endif 65 #endif
65 66
66 using content::BrowserContext; 67 using content::BrowserContext;
67 using content::ConsoleMessageLevel; 68 using content::ConsoleMessageLevel;
68 using content::WebContents; 69 using content::WebContents;
69 using web_modal::WebContentsModalDialogHost; 70 using web_modal::WebContentsModalDialogHost;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 window_key_ = new_params.window_key; 292 window_key_ = new_params.window_key;
292 293
293 // Windows cannot be always-on-top in fullscreen mode for security reasons. 294 // Windows cannot be always-on-top in fullscreen mode for security reasons.
294 cached_always_on_top_ = new_params.always_on_top; 295 cached_always_on_top_ = new_params.always_on_top;
295 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) 296 if (new_params.state == ui::SHOW_STATE_FULLSCREEN)
296 new_params.always_on_top = false; 297 new_params.always_on_top = false;
297 298
298 requested_alpha_enabled_ = new_params.alpha_enabled; 299 requested_alpha_enabled_ = new_params.alpha_enabled;
299 is_ime_window_ = params.is_ime_window; 300 is_ime_window_ = params.is_ime_window;
300 show_in_shelf_ = params.show_in_shelf; 301 show_in_shelf_ = params.show_in_shelf;
302 window_icon_url_ = params.window_icon_url;
301 303
302 AppWindowClient* app_window_client = AppWindowClient::Get(); 304 AppWindowClient* app_window_client = AppWindowClient::Get();
303 native_app_window_.reset( 305 native_app_window_.reset(
304 app_window_client->CreateNativeAppWindow(this, &new_params)); 306 app_window_client->CreateNativeAppWindow(this, &new_params));
305 307
306 helper_.reset(new AppWebContentsHelper( 308 helper_.reset(new AppWebContentsHelper(
307 browser_context_, extension_id_, web_contents(), app_delegate_.get())); 309 browser_context_, extension_id_, web_contents(), app_delegate_.get()));
308 310
309 UpdateExtensionAppIcon(); 311 UpdateExtensionAppIcon();
312 // Download showInShelf=true window icon.
313 if (window_icon_url_.is_valid()) {
314 image_loader_ptr_factory_.InvalidateWeakPtrs();
315 web_contents()->DownloadImage(
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 }
310 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); 323 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this);
311 324
312 if (new_params.hidden) { 325 if (new_params.hidden) {
313 // Although the window starts hidden by default, calling Hide() here 326 // Although the window starts hidden by default, calling Hide() here
314 // notifies observers of the window being hidden. 327 // notifies observers of the window being hidden.
315 Hide(); 328 Hide();
316 } else { 329 } else {
317 // Panels are not activated by default. 330 // Panels are not activated by default.
318 Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE 331 Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE
319 : SHOW_ACTIVE); 332 : SHOW_ACTIVE);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 } 611 }
599 612
600 void AppWindow::UpdateDraggableRegions( 613 void AppWindow::UpdateDraggableRegions(
601 const std::vector<DraggableRegion>& regions) { 614 const std::vector<DraggableRegion>& regions) {
602 native_app_window_->UpdateDraggableRegions(regions); 615 native_app_window_->UpdateDraggableRegions(regions);
603 } 616 }
604 617
605 void AppWindow::UpdateAppIcon(const gfx::Image& image) { 618 void AppWindow::UpdateAppIcon(const gfx::Image& image) {
606 if (image.IsEmpty()) 619 if (image.IsEmpty())
607 return; 620 return;
608 app_icon_ = image; 621 if (window_icon_url_.is_valid() && !app_icon_image_->image().IsEmpty()) {
622 app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge(
623 image.AsImageSkia(), app_icon_image_->image_skia()));
624 // Set default app icon placeholder with app_icon_image_ badge if
625 // the icon is empty.
626 if (app_icon_.IsEmpty()) {
stevenjb 2016/08/10 16:58:47 This will never happen since we already checked th
Andra Paraschiv 2016/08/11 07:20:55 Right, thank you for this, updated the CL.
627 image_loader_ptr_factory_.InvalidateWeakPtrs();
628 gfx::ImageSkia app_default_icon =
629 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
630 IDR_APP_DEFAULT_ICON);
631 app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge(
632 app_default_icon, app_icon_image_->image_skia()));
633 }
634 } else {
635 app_icon_ = image;
636 }
609 native_app_window_->UpdateWindowIcon(); 637 native_app_window_->UpdateWindowIcon();
610 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); 638 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this);
611 } 639 }
612 640
613 void AppWindow::SetFullscreen(FullscreenType type, bool enable) { 641 void AppWindow::SetFullscreen(FullscreenType type, bool enable) {
614 DCHECK_NE(FULLSCREEN_TYPE_NONE, type); 642 DCHECK_NE(FULLSCREEN_TYPE_NONE, type);
615 643
616 if (enable) { 644 if (enable) {
617 #if !defined(OS_MACOSX) 645 #if !defined(OS_MACOSX)
618 // Do not enter fullscreen mode if disallowed by pref. 646 // Do not enter fullscreen mode if disallowed by pref.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 835
808 //------------------------------------------------------------------------------ 836 //------------------------------------------------------------------------------
809 // Private methods 837 // Private methods
810 838
811 void AppWindow::DidDownloadFavicon( 839 void AppWindow::DidDownloadFavicon(
812 int id, 840 int id,
813 int http_status_code, 841 int http_status_code,
814 const GURL& image_url, 842 const GURL& image_url,
815 const std::vector<SkBitmap>& bitmaps, 843 const std::vector<SkBitmap>& bitmaps,
816 const std::vector<gfx::Size>& original_bitmap_sizes) { 844 const std::vector<gfx::Size>& original_bitmap_sizes) {
817 if (image_url != app_icon_url_ || bitmaps.empty()) 845 if (((image_url != app_icon_url_) && (image_url != window_icon_url_)) ||
846 bitmaps.empty()) {
818 return; 847 return;
848 }
819 849
820 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap 850 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap
821 // whose height >= the preferred size. 851 // whose height >= the preferred size.
822 int largest_index = 0; 852 int largest_index = 0;
823 for (size_t i = 1; i < bitmaps.size(); ++i) { 853 for (size_t i = 1; i < bitmaps.size(); ++i) {
824 if (bitmaps[i].height() < app_delegate_->PreferredIconSize()) 854 if (bitmaps[i].height() < app_delegate_->PreferredIconSize())
825 break; 855 break;
826 largest_index = i; 856 largest_index = i;
827 } 857 }
828 const SkBitmap& largest = bitmaps[largest_index]; 858 const SkBitmap& largest = bitmaps[largest_index];
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 region.bounds.x(), 1156 region.bounds.x(),
1127 region.bounds.y(), 1157 region.bounds.y(),
1128 region.bounds.right(), 1158 region.bounds.right(),
1129 region.bounds.bottom(), 1159 region.bounds.bottom(),
1130 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 1160 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
1131 } 1161 }
1132 return sk_region; 1162 return sk_region;
1133 } 1163 }
1134 1164
1135 } // namespace extensions 1165 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698