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

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: Fix AppWindow Comment 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 } else {
625 app_icon_ = image;
626 }
609 native_app_window_->UpdateWindowIcon(); 627 native_app_window_->UpdateWindowIcon();
610 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); 628 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this);
611 } 629 }
612 630
613 void AppWindow::SetFullscreen(FullscreenType type, bool enable) { 631 void AppWindow::SetFullscreen(FullscreenType type, bool enable) {
614 DCHECK_NE(FULLSCREEN_TYPE_NONE, type); 632 DCHECK_NE(FULLSCREEN_TYPE_NONE, type);
615 633
616 if (enable) { 634 if (enable) {
617 #if !defined(OS_MACOSX) 635 #if !defined(OS_MACOSX)
618 // Do not enter fullscreen mode if disallowed by pref. 636 // Do not enter fullscreen mode if disallowed by pref.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 825
808 //------------------------------------------------------------------------------ 826 //------------------------------------------------------------------------------
809 // Private methods 827 // Private methods
810 828
811 void AppWindow::DidDownloadFavicon( 829 void AppWindow::DidDownloadFavicon(
812 int id, 830 int id,
813 int http_status_code, 831 int http_status_code,
814 const GURL& image_url, 832 const GURL& image_url,
815 const std::vector<SkBitmap>& bitmaps, 833 const std::vector<SkBitmap>& bitmaps,
816 const std::vector<gfx::Size>& original_bitmap_sizes) { 834 const std::vector<gfx::Size>& original_bitmap_sizes) {
817 if (image_url != app_icon_url_ || bitmaps.empty()) 835 if (((image_url != app_icon_url_) && (image_url != window_icon_url_)) ||
836 bitmaps.empty()) {
818 return; 837 return;
838 }
819 839
820 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap 840 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap
821 // whose height >= the preferred size. 841 // whose height >= the preferred size.
822 int largest_index = 0; 842 int largest_index = 0;
823 for (size_t i = 1; i < bitmaps.size(); ++i) { 843 for (size_t i = 1; i < bitmaps.size(); ++i) {
824 if (bitmaps[i].height() < app_delegate_->PreferredIconSize()) 844 if (bitmaps[i].height() < app_delegate_->PreferredIconSize())
825 break; 845 break;
826 largest_index = i; 846 largest_index = i;
827 } 847 }
828 const SkBitmap& largest = bitmaps[largest_index]; 848 const SkBitmap& largest = bitmaps[largest_index];
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 region.bounds.x(), 1146 region.bounds.x(),
1127 region.bounds.y(), 1147 region.bounds.y(),
1128 region.bounds.right(), 1148 region.bounds.right(),
1129 region.bounds.bottom(), 1149 region.bounds.bottom(),
1130 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 1150 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
1131 } 1151 }
1132 return sk_region; 1152 return sk_region;
1133 } 1153 }
1134 1154
1135 } // namespace extensions 1155 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698