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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 window_key_ = new_params.window_key; | 291 window_key_ = new_params.window_key; |
292 | 292 |
293 // Windows cannot be always-on-top in fullscreen mode for security reasons. | 293 // Windows cannot be always-on-top in fullscreen mode for security reasons. |
294 cached_always_on_top_ = new_params.always_on_top; | 294 cached_always_on_top_ = new_params.always_on_top; |
295 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) | 295 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) |
296 new_params.always_on_top = false; | 296 new_params.always_on_top = false; |
297 | 297 |
298 requested_alpha_enabled_ = new_params.alpha_enabled; | 298 requested_alpha_enabled_ = new_params.alpha_enabled; |
299 is_ime_window_ = params.is_ime_window; | 299 is_ime_window_ = params.is_ime_window; |
300 show_in_shelf_ = params.show_in_shelf; | 300 show_in_shelf_ = params.show_in_shelf; |
301 window_icon_url_ = params.window_icon_url; | |
301 | 302 |
302 AppWindowClient* app_window_client = AppWindowClient::Get(); | 303 AppWindowClient* app_window_client = AppWindowClient::Get(); |
303 native_app_window_.reset( | 304 native_app_window_.reset( |
304 app_window_client->CreateNativeAppWindow(this, &new_params)); | 305 app_window_client->CreateNativeAppWindow(this, &new_params)); |
305 | 306 |
306 helper_.reset(new AppWebContentsHelper( | 307 helper_.reset(new AppWebContentsHelper( |
307 browser_context_, extension_id_, web_contents(), app_delegate_.get())); | 308 browser_context_, extension_id_, web_contents(), app_delegate_.get())); |
308 | 309 |
309 UpdateExtensionAppIcon(); | 310 UpdateExtensionAppIcon(); |
311 // Download showInShelf=true window icon. | |
312 image_loader_ptr_factory_.InvalidateWeakPtrs(); | |
313 web_contents()->DownloadImage( | |
Andra Paraschiv
2016/08/04 11:32:57
This function can fetch the icon in an async way a
| |
314 window_icon_url_, | |
315 true, // is a favicon | |
316 0, // no maximum size | |
317 false, // normal cache policy | |
318 base::Bind(&AppWindow::DidDownloadFavicon, | |
319 image_loader_ptr_factory_.GetWeakPtr())); | |
310 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); | 320 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); |
311 | 321 |
312 if (new_params.hidden) { | 322 if (new_params.hidden) { |
313 // Although the window starts hidden by default, calling Hide() here | 323 // Although the window starts hidden by default, calling Hide() here |
314 // notifies observers of the window being hidden. | 324 // notifies observers of the window being hidden. |
315 Hide(); | 325 Hide(); |
316 } else { | 326 } else { |
317 // Panels are not activated by default. | 327 // Panels are not activated by default. |
318 Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE | 328 Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE |
319 : SHOW_ACTIVE); | 329 : SHOW_ACTIVE); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 } | 613 } |
604 | 614 |
605 void AppWindow::UpdateAppIcon(const gfx::Image& image) { | 615 void AppWindow::UpdateAppIcon(const gfx::Image& image) { |
606 if (image.IsEmpty()) | 616 if (image.IsEmpty()) |
607 return; | 617 return; |
608 app_icon_ = image; | 618 app_icon_ = image; |
609 native_app_window_->UpdateWindowIcon(); | 619 native_app_window_->UpdateWindowIcon(); |
610 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); | 620 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); |
611 } | 621 } |
612 | 622 |
623 void AppWindow::UpdateWindowIcon(const gfx::Image& image) { | |
624 if (image.IsEmpty()) | |
625 return; | |
626 window_icon_ = image; | |
Andra Paraschiv
2016/08/04 11:32:57
Currently, the window icon is the image with the u
| |
627 native_app_window_->UpdateWindowIcon(); | |
628 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); | |
629 } | |
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. |
619 // TODO(bartfab): Add a test once it becomes possible to simulate a user | 637 // TODO(bartfab): Add a test once it becomes possible to simulate a user |
620 // gesture. http://crbug.com/174178 | 638 // gesture. http://crbug.com/174178 |
621 if (type != FULLSCREEN_TYPE_FORCED) { | 639 if (type != FULLSCREEN_TYPE_FORCED) { |
622 PrefService* prefs = | 640 PrefService* prefs = |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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; |
819 | 838 |
820 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap | 839 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap |
821 // whose height >= the preferred size. | 840 // whose height >= the preferred size. |
822 int largest_index = 0; | 841 int largest_index = 0; |
823 for (size_t i = 1; i < bitmaps.size(); ++i) { | 842 for (size_t i = 1; i < bitmaps.size(); ++i) { |
824 if (bitmaps[i].height() < app_delegate_->PreferredIconSize()) | 843 if (bitmaps[i].height() < app_delegate_->PreferredIconSize()) |
825 break; | 844 break; |
826 largest_index = i; | 845 largest_index = i; |
827 } | 846 } |
828 const SkBitmap& largest = bitmaps[largest_index]; | 847 const SkBitmap& largest = bitmaps[largest_index]; |
829 UpdateAppIcon(gfx::Image::CreateFrom1xBitmap(largest)); | 848 if (image_url == app_icon_url_) |
849 UpdateAppIcon(gfx::Image::CreateFrom1xBitmap(largest)); | |
850 // Update icon for showInShelf=true window. | |
851 if (image_url == window_icon_url_) | |
852 UpdateWindowIcon(gfx::Image::CreateFrom1xBitmap(largest)); | |
830 } | 853 } |
831 | 854 |
832 void AppWindow::OnExtensionIconImageChanged(IconImage* image) { | 855 void AppWindow::OnExtensionIconImageChanged(IconImage* image) { |
833 DCHECK_EQ(app_icon_image_.get(), image); | 856 DCHECK_EQ(app_icon_image_.get(), image); |
834 | 857 |
835 UpdateAppIcon(gfx::Image(app_icon_image_->image_skia())); | 858 UpdateAppIcon(gfx::Image(app_icon_image_->image_skia())); |
836 } | 859 } |
837 | 860 |
838 void AppWindow::UpdateExtensionAppIcon() { | 861 void AppWindow::UpdateExtensionAppIcon() { |
839 // Avoid using any previous app icons were being downloaded. | 862 // Avoid using any previous app icons were being downloaded. |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1126 region.bounds.x(), | 1149 region.bounds.x(), |
1127 region.bounds.y(), | 1150 region.bounds.y(), |
1128 region.bounds.right(), | 1151 region.bounds.right(), |
1129 region.bounds.bottom(), | 1152 region.bounds.bottom(), |
1130 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 1153 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
1131 } | 1154 } |
1132 return sk_region; | 1155 return sk_region; |
1133 } | 1156 } |
1134 | 1157 |
1135 } // namespace extensions | 1158 } // namespace extensions |
OLD | NEW |