| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/panels/panel.h" | 5 #include "chrome/browser/ui/panels/panel.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/devtools/devtools_window.h" | 11 #include "chrome/browser/devtools/devtools_window.h" |
| 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 13 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" | 13 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" |
| 14 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" | 14 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
| 17 #include "chrome/browser/extensions/extension_tab_util.h" | 17 #include "chrome/browser/extensions/extension_tab_util.h" |
| 18 #include "chrome/browser/extensions/image_loader.h" |
| 18 #include "chrome/browser/extensions/window_controller.h" | 19 #include "chrome/browser/extensions/window_controller.h" |
| 19 #include "chrome/browser/extensions/window_controller_list.h" | 20 #include "chrome/browser/extensions/window_controller_list.h" |
| 20 #include "chrome/browser/lifetime/application_lifetime.h" | 21 #include "chrome/browser/lifetime/application_lifetime.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/themes/theme_service.h" | 23 #include "chrome/browser/themes/theme_service.h" |
| 23 #include "chrome/browser/themes/theme_service_factory.h" | 24 #include "chrome/browser/themes/theme_service_factory.h" |
| 24 #include "chrome/browser/ui/panels/native_panel.h" | 25 #include "chrome/browser/ui/panels/native_panel.h" |
| 25 #include "chrome/browser/ui/panels/panel_collection.h" | 26 #include "chrome/browser/ui/panels/panel_collection.h" |
| 26 #include "chrome/browser/ui/panels/panel_host.h" | 27 #include "chrome/browser/ui/panels/panel_host.h" |
| 27 #include "chrome/browser/ui/panels/panel_manager.h" | 28 #include "chrome/browser/ui/panels/panel_manager.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 collection_(NULL), | 143 collection_(NULL), |
| 143 initialized_(false), | 144 initialized_(false), |
| 144 min_size_(min_size), | 145 min_size_(min_size), |
| 145 max_size_(max_size), | 146 max_size_(max_size), |
| 146 max_size_policy_(DEFAULT_MAX_SIZE), | 147 max_size_policy_(DEFAULT_MAX_SIZE), |
| 147 auto_resizable_(false), | 148 auto_resizable_(false), |
| 148 in_preview_mode_(false), | 149 in_preview_mode_(false), |
| 149 native_panel_(NULL), | 150 native_panel_(NULL), |
| 150 attention_mode_(USE_PANEL_ATTENTION), | 151 attention_mode_(USE_PANEL_ATTENTION), |
| 151 expansion_state_(EXPANDED), | 152 expansion_state_(EXPANDED), |
| 152 command_updater_(this) { | 153 command_updater_(this), |
| 154 ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_ptr_factory_(this)) { |
| 153 } | 155 } |
| 154 | 156 |
| 155 Panel::~Panel() { | 157 Panel::~Panel() { |
| 156 DCHECK(!collection_); | 158 DCHECK(!collection_); |
| 157 // Invoked by native panel destructor. Do not access native_panel_ here. | 159 // Invoked by native panel destructor. Do not access native_panel_ here. |
| 158 browser::EndKeepAlive(); // Remove shutdown prevention. | 160 browser::EndKeepAlive(); // Remove shutdown prevention. |
| 159 } | 161 } |
| 160 | 162 |
| 161 void Panel::Initialize(Profile* profile, const GURL& url, | 163 void Panel::Initialize(Profile* profile, const GURL& url, |
| 162 const gfx::Rect& bounds) { | 164 const gfx::Rect& bounds) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 command_updater_.UpdateCommandEnabled(IDC_COPY, true); | 219 command_updater_.UpdateCommandEnabled(IDC_COPY, true); |
| 218 command_updater_.UpdateCommandEnabled(IDC_CUT, true); | 220 command_updater_.UpdateCommandEnabled(IDC_CUT, true); |
| 219 command_updater_.UpdateCommandEnabled(IDC_PASTE, true); | 221 command_updater_.UpdateCommandEnabled(IDC_PASTE, true); |
| 220 | 222 |
| 221 // DevTools | 223 // DevTools |
| 222 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, true); | 224 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, true); |
| 223 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, true); | 225 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, true); |
| 224 } | 226 } |
| 225 | 227 |
| 226 void Panel::OnNativePanelClosed() { | 228 void Panel::OnNativePanelClosed() { |
| 227 app_icon_loader_.reset(); | 229 // Ensure previously enqueued OnImageLoaded callbacks are ignored. |
| 230 image_loader_ptr_factory_.InvalidateWeakPtrs(); |
| 228 registrar_.RemoveAll(); | 231 registrar_.RemoveAll(); |
| 229 manager()->OnPanelClosed(this); | 232 manager()->OnPanelClosed(this); |
| 230 DCHECK(!collection_); | 233 DCHECK(!collection_); |
| 231 } | 234 } |
| 232 | 235 |
| 233 PanelManager* Panel::manager() const { | 236 PanelManager* Panel::manager() const { |
| 234 return PanelManager::GetInstance(); | 237 return PanelManager::GetInstance(); |
| 235 } | 238 } |
| 236 | 239 |
| 237 CommandUpdater* Panel::command_updater() { | 240 CommandUpdater* Panel::command_updater() { |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 if (!extension_service || !extension_service->is_ready()) | 825 if (!extension_service || !extension_service->is_ready()) |
| 823 return NULL; | 826 return NULL; |
| 824 return extension_service->GetExtensionById(extension_id(), false); | 827 return extension_service->GetExtensionById(extension_id(), false); |
| 825 } | 828 } |
| 826 | 829 |
| 827 void Panel::UpdateAppIcon() { | 830 void Panel::UpdateAppIcon() { |
| 828 const extensions::Extension* extension = GetExtension(); | 831 const extensions::Extension* extension = GetExtension(); |
| 829 if (!extension) | 832 if (!extension) |
| 830 return; | 833 return; |
| 831 | 834 |
| 832 app_icon_loader_.reset(new ImageLoadingTracker(this)); | 835 extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile()); |
| 833 app_icon_loader_->LoadImage( | 836 loader->LoadImageAsync( |
| 834 extension, | 837 extension, |
| 835 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALL, | 838 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALL, |
| 836 ExtensionIconSet::MATCH_BIGGER), | 839 ExtensionIconSet::MATCH_BIGGER), |
| 837 gfx::Size(extension_misc::EXTENSION_ICON_SMALL, | 840 gfx::Size(extension_misc::EXTENSION_ICON_SMALL, |
| 838 extension_misc::EXTENSION_ICON_SMALL), | 841 extension_misc::EXTENSION_ICON_SMALL), |
| 839 ImageLoadingTracker::CACHE); | 842 base::Bind(&Panel::OnImageLoaded, |
| 843 image_loader_ptr_factory_.GetWeakPtr())); |
| 840 } | 844 } |
| 841 | 845 |
| 842 void Panel::OnImageLoaded(const gfx::Image& image, | 846 void Panel::OnImageLoaded(const gfx::Image& image) { |
| 843 const std::string& extension_id, | |
| 844 int index) { | |
| 845 if (!image.IsEmpty()) { | 847 if (!image.IsEmpty()) { |
| 846 app_icon_ = image; | 848 app_icon_ = image; |
| 847 native_panel_->UpdatePanelTitleBar(); | 849 native_panel_->UpdatePanelTitleBar(); |
| 848 } | 850 } |
| 849 app_icon_loader_.reset(); | |
| 850 | 851 |
| 851 content::NotificationService::current()->Notify( | 852 content::NotificationService::current()->Notify( |
| 852 chrome::NOTIFICATION_PANEL_APP_ICON_LOADED, | 853 chrome::NOTIFICATION_PANEL_APP_ICON_LOADED, |
| 853 content::Source<Panel>(this), | 854 content::Source<Panel>(this), |
| 854 content::NotificationService::NoDetails()); | 855 content::NotificationService::NoDetails()); |
| 855 } | 856 } |
| OLD | NEW |