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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 image_loader_ptr_factory_.InvalidateWeakPtrs(); | |
| 314 web_contents()->DownloadImage( | |
| 315 window_icon_url_, | |
|
stevenjb
2016/08/08 22:26:46
We should test that window_icon_url_ is valid firs
Andra Paraschiv
2016/08/09 11:34:47
Done.
| |
| 316 true, // is a favicon | |
| 317 0, // no maximum size | |
| 318 false, // normal cache policy | |
| 319 base::Bind(&AppWindow::DidDownloadFavicon, | |
| 320 image_loader_ptr_factory_.GetWeakPtr())); | |
| 310 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); | 321 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); |
| 311 | 322 |
| 312 if (new_params.hidden) { | 323 if (new_params.hidden) { |
| 313 // Although the window starts hidden by default, calling Hide() here | 324 // Although the window starts hidden by default, calling Hide() here |
| 314 // notifies observers of the window being hidden. | 325 // notifies observers of the window being hidden. |
| 315 Hide(); | 326 Hide(); |
| 316 } else { | 327 } else { |
| 317 // Panels are not activated by default. | 328 // Panels are not activated by default. |
| 318 Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE | 329 Show(window_type_is_panel() || !new_params.focused ? SHOW_INACTIVE |
| 319 : SHOW_ACTIVE); | 330 : SHOW_ACTIVE); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 } | 609 } |
| 599 | 610 |
| 600 void AppWindow::UpdateDraggableRegions( | 611 void AppWindow::UpdateDraggableRegions( |
| 601 const std::vector<DraggableRegion>& regions) { | 612 const std::vector<DraggableRegion>& regions) { |
| 602 native_app_window_->UpdateDraggableRegions(regions); | 613 native_app_window_->UpdateDraggableRegions(regions); |
| 603 } | 614 } |
| 604 | 615 |
| 605 void AppWindow::UpdateAppIcon(const gfx::Image& image) { | 616 void AppWindow::UpdateAppIcon(const gfx::Image& image) { |
| 606 if (image.IsEmpty()) | 617 if (image.IsEmpty()) |
| 607 return; | 618 return; |
| 608 app_icon_ = image; | 619 if (!window_icon_url_.is_empty()) { |
|
stevenjb
2016/08/08 22:26:45
We should test that app_icon_image_ is valid.
Andra Paraschiv
2016/08/09 11:34:47
Done.
| |
| 620 app_icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateImageWithBadge( | |
| 621 image.AsImageSkia(), app_icon_image_->image_skia())); | |
| 622 } else { | |
| 623 app_icon_ = image; | |
| 624 } | |
| 609 native_app_window_->UpdateWindowIcon(); | 625 native_app_window_->UpdateWindowIcon(); |
| 610 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); | 626 AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this); |
| 611 } | 627 } |
| 612 | 628 |
| 613 void AppWindow::SetFullscreen(FullscreenType type, bool enable) { | 629 void AppWindow::SetFullscreen(FullscreenType type, bool enable) { |
| 614 DCHECK_NE(FULLSCREEN_TYPE_NONE, type); | 630 DCHECK_NE(FULLSCREEN_TYPE_NONE, type); |
| 615 | 631 |
| 616 if (enable) { | 632 if (enable) { |
| 617 #if !defined(OS_MACOSX) | 633 #if !defined(OS_MACOSX) |
| 618 // Do not enter fullscreen mode if disallowed by pref. | 634 // Do not enter fullscreen mode if disallowed by pref. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 | 823 |
| 808 //------------------------------------------------------------------------------ | 824 //------------------------------------------------------------------------------ |
| 809 // Private methods | 825 // Private methods |
| 810 | 826 |
| 811 void AppWindow::DidDownloadFavicon( | 827 void AppWindow::DidDownloadFavicon( |
| 812 int id, | 828 int id, |
| 813 int http_status_code, | 829 int http_status_code, |
| 814 const GURL& image_url, | 830 const GURL& image_url, |
| 815 const std::vector<SkBitmap>& bitmaps, | 831 const std::vector<SkBitmap>& bitmaps, |
| 816 const std::vector<gfx::Size>& original_bitmap_sizes) { | 832 const std::vector<gfx::Size>& original_bitmap_sizes) { |
| 817 if (image_url != app_icon_url_ || bitmaps.empty()) | 833 if (((image_url != app_icon_url_) && (image_url != window_icon_url_)) || |
| 834 bitmaps.empty()) | |
| 818 return; | 835 return; |
|
stevenjb
2016/08/08 22:26:46
{}
Andra Paraschiv
2016/08/09 11:34:47
Done.
| |
| 819 | 836 |
| 820 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap | 837 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap |
| 821 // whose height >= the preferred size. | 838 // whose height >= the preferred size. |
| 822 int largest_index = 0; | 839 int largest_index = 0; |
| 823 for (size_t i = 1; i < bitmaps.size(); ++i) { | 840 for (size_t i = 1; i < bitmaps.size(); ++i) { |
| 824 if (bitmaps[i].height() < app_delegate_->PreferredIconSize()) | 841 if (bitmaps[i].height() < app_delegate_->PreferredIconSize()) |
| 825 break; | 842 break; |
| 826 largest_index = i; | 843 largest_index = i; |
| 827 } | 844 } |
| 828 const SkBitmap& largest = bitmaps[largest_index]; | 845 const SkBitmap& largest = bitmaps[largest_index]; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1126 region.bounds.x(), | 1143 region.bounds.x(), |
| 1127 region.bounds.y(), | 1144 region.bounds.y(), |
| 1128 region.bounds.right(), | 1145 region.bounds.right(), |
| 1129 region.bounds.bottom(), | 1146 region.bounds.bottom(), |
| 1130 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 1147 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
| 1131 } | 1148 } |
| 1132 return sk_region; | 1149 return sk_region; |
| 1133 } | 1150 } |
| 1134 | 1151 |
| 1135 } // namespace extensions | 1152 } // namespace extensions |
| OLD | NEW |