Chromium Code Reviews| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 collection_(NULL), | 142 collection_(NULL), |
| 142 initialized_(false), | 143 initialized_(false), |
| 143 min_size_(min_size), | 144 min_size_(min_size), |
| 144 max_size_(max_size), | 145 max_size_(max_size), |
| 145 max_size_policy_(DEFAULT_MAX_SIZE), | 146 max_size_policy_(DEFAULT_MAX_SIZE), |
| 146 auto_resizable_(false), | 147 auto_resizable_(false), |
| 147 in_preview_mode_(false), | 148 in_preview_mode_(false), |
| 148 native_panel_(NULL), | 149 native_panel_(NULL), |
| 149 attention_mode_(USE_PANEL_ATTENTION), | 150 attention_mode_(USE_PANEL_ATTENTION), |
| 150 expansion_state_(EXPANDED), | 151 expansion_state_(EXPANDED), |
| 151 command_updater_(this) { | 152 command_updater_(this), |
| 153 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | |
| 152 } | 154 } |
| 153 | 155 |
| 154 Panel::~Panel() { | 156 Panel::~Panel() { |
| 155 DCHECK(!collection_); | 157 DCHECK(!collection_); |
| 156 // Invoked by native panel destructor. Do not access native_panel_ here. | 158 // Invoked by native panel destructor. Do not access native_panel_ here. |
| 157 browser::EndKeepAlive(); // Remove shutdown prevention. | 159 browser::EndKeepAlive(); // Remove shutdown prevention. |
| 158 } | 160 } |
| 159 | 161 |
| 160 void Panel::Initialize(Profile* profile, const GURL& url, | 162 void Panel::Initialize(Profile* profile, const GURL& url, |
| 161 const gfx::Rect& bounds) { | 163 const gfx::Rect& bounds) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 command_updater_.UpdateCommandEnabled(IDC_COPY, true); | 218 command_updater_.UpdateCommandEnabled(IDC_COPY, true); |
| 217 command_updater_.UpdateCommandEnabled(IDC_CUT, true); | 219 command_updater_.UpdateCommandEnabled(IDC_CUT, true); |
| 218 command_updater_.UpdateCommandEnabled(IDC_PASTE, true); | 220 command_updater_.UpdateCommandEnabled(IDC_PASTE, true); |
| 219 | 221 |
| 220 // DevTools | 222 // DevTools |
| 221 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, true); | 223 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, true); |
| 222 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, true); | 224 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, true); |
| 223 } | 225 } |
| 224 | 226 |
| 225 void Panel::OnNativePanelClosed() { | 227 void Panel::OnNativePanelClosed() { |
| 226 app_icon_loader_.reset(); | |
|
jianli
2013/01/15 01:58:04
Do we need to do the similar thing here by calling
rpaquay
2013/01/16 20:49:11
I believe you are correct. Fixed.
| |
| 227 registrar_.RemoveAll(); | 228 registrar_.RemoveAll(); |
| 228 manager()->OnPanelClosed(this); | 229 manager()->OnPanelClosed(this); |
| 229 DCHECK(!collection_); | 230 DCHECK(!collection_); |
| 230 } | 231 } |
| 231 | 232 |
| 232 PanelManager* Panel::manager() const { | 233 PanelManager* Panel::manager() const { |
| 233 return PanelManager::GetInstance(); | 234 return PanelManager::GetInstance(); |
| 234 } | 235 } |
| 235 | 236 |
| 236 CommandUpdater* Panel::command_updater() { | 237 CommandUpdater* Panel::command_updater() { |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 if (!extension_service || !extension_service->is_ready()) | 816 if (!extension_service || !extension_service->is_ready()) |
| 816 return NULL; | 817 return NULL; |
| 817 return extension_service->GetExtensionById(extension_id(), false); | 818 return extension_service->GetExtensionById(extension_id(), false); |
| 818 } | 819 } |
| 819 | 820 |
| 820 void Panel::UpdateAppIcon() { | 821 void Panel::UpdateAppIcon() { |
| 821 const extensions::Extension* extension = GetExtension(); | 822 const extensions::Extension* extension = GetExtension(); |
| 822 if (!extension) | 823 if (!extension) |
| 823 return; | 824 return; |
| 824 | 825 |
| 825 app_icon_loader_.reset(new ImageLoadingTracker(this)); | 826 extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile()); |
| 826 app_icon_loader_->LoadImage( | 827 loader->LoadImageAsync( |
| 827 extension, | 828 extension, |
| 828 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALL, | 829 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALL, |
| 829 ExtensionIconSet::MATCH_BIGGER), | 830 ExtensionIconSet::MATCH_BIGGER), |
| 830 gfx::Size(extension_misc::EXTENSION_ICON_SMALL, | 831 gfx::Size(extension_misc::EXTENSION_ICON_SMALL, |
| 831 extension_misc::EXTENSION_ICON_SMALL), | 832 extension_misc::EXTENSION_ICON_SMALL), |
| 832 ImageLoadingTracker::CACHE); | 833 base::Bind(&Panel::OnImageLoaded, weak_ptr_factory_.GetWeakPtr())); |
| 833 } | 834 } |
| 834 | 835 |
| 835 void Panel::OnImageLoaded(const gfx::Image& image, | 836 void Panel::OnImageLoaded(const gfx::Image& image) { |
| 836 const std::string& extension_id, | |
| 837 int index) { | |
| 838 if (!image.IsEmpty()) { | 837 if (!image.IsEmpty()) { |
| 839 app_icon_ = image; | 838 app_icon_ = image; |
| 840 native_panel_->UpdatePanelTitleBar(); | 839 native_panel_->UpdatePanelTitleBar(); |
| 841 } | 840 } |
| 842 app_icon_loader_.reset(); | |
| 843 | 841 |
| 844 content::NotificationService::current()->Notify( | 842 content::NotificationService::current()->Notify( |
| 845 chrome::NOTIFICATION_PANEL_APP_ICON_LOADED, | 843 chrome::NOTIFICATION_PANEL_APP_ICON_LOADED, |
| 846 content::Source<Panel>(this), | 844 content::Source<Panel>(this), |
| 847 content::NotificationService::NoDetails()); | 845 content::NotificationService::NoDetails()); |
| 848 } | 846 } |
| OLD | NEW |