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

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 v5 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
« no previous file with comments | « extensions/browser/app_window/app_window.h ('k') | extensions/common/api/app_window.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 void AppWindow::UpdateShape(std::unique_ptr<SkRegion> region) { 609 void AppWindow::UpdateShape(std::unique_ptr<SkRegion> region) {
597 native_app_window_->UpdateShape(std::move(region)); 610 native_app_window_->UpdateShape(std::move(region));
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 // Set the showInShelf=true window icon and add the app_icon_image_
607 return; 620 // as a badge. If the image is empty, set the default app icon placeholder
608 app_icon_ = image; 621 // as the base image.
622 if (window_icon_url_.is_valid() && !app_icon_image_->image().IsEmpty()) {
623 gfx::Image base_image =
624 !image.IsEmpty()
625 ? image
626 : gfx::Image(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
627 IDR_APP_DEFAULT_ICON));
628 app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateIconWithBadge(
629 base_image.AsImageSkia(), app_icon_image_->image_skia()));
630 } else {
631 if (image.IsEmpty())
632 return;
633
634 app_icon_ = image;
635 }
609 native_app_window_->UpdateWindowIcon(); 636 native_app_window_->UpdateWindowIcon();
610 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); 637 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this);
611 } 638 }
612 639
613 void AppWindow::SetFullscreen(FullscreenType type, bool enable) { 640 void AppWindow::SetFullscreen(FullscreenType type, bool enable) {
614 DCHECK_NE(FULLSCREEN_TYPE_NONE, type); 641 DCHECK_NE(FULLSCREEN_TYPE_NONE, type);
615 642
616 if (enable) { 643 if (enable) {
617 #if !defined(OS_MACOSX) 644 #if !defined(OS_MACOSX)
618 // Do not enter fullscreen mode if disallowed by pref. 645 // Do not enter fullscreen mode if disallowed by pref.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 834
808 //------------------------------------------------------------------------------ 835 //------------------------------------------------------------------------------
809 // Private methods 836 // Private methods
810 837
811 void AppWindow::DidDownloadFavicon( 838 void AppWindow::DidDownloadFavicon(
812 int id, 839 int id,
813 int http_status_code, 840 int http_status_code,
814 const GURL& image_url, 841 const GURL& image_url,
815 const std::vector<SkBitmap>& bitmaps, 842 const std::vector<SkBitmap>& bitmaps,
816 const std::vector<gfx::Size>& original_bitmap_sizes) { 843 const std::vector<gfx::Size>& original_bitmap_sizes) {
817 if (image_url != app_icon_url_ || bitmaps.empty()) 844 if (((image_url != app_icon_url_) && (image_url != window_icon_url_)) ||
845 bitmaps.empty()) {
818 return; 846 return;
847 }
819 848
820 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap 849 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap
821 // whose height >= the preferred size. 850 // whose height >= the preferred size.
822 int largest_index = 0; 851 int largest_index = 0;
823 for (size_t i = 1; i < bitmaps.size(); ++i) { 852 for (size_t i = 1; i < bitmaps.size(); ++i) {
824 if (bitmaps[i].height() < app_delegate_->PreferredIconSize()) 853 if (bitmaps[i].height() < app_delegate_->PreferredIconSize())
825 break; 854 break;
826 largest_index = i; 855 largest_index = i;
827 } 856 }
828 const SkBitmap& largest = bitmaps[largest_index]; 857 const SkBitmap& largest = bitmaps[largest_index];
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 region.bounds.x(), 1155 region.bounds.x(),
1127 region.bounds.y(), 1156 region.bounds.y(),
1128 region.bounds.right(), 1157 region.bounds.right(),
1129 region.bounds.bottom(), 1158 region.bounds.bottom(),
1130 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 1159 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
1131 } 1160 }
1132 return sk_region; 1161 return sk_region;
1133 } 1162 }
1134 1163
1135 } // namespace extensions 1164 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/app_window/app_window.h ('k') | extensions/common/api/app_window.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698