| 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/extensions/api/tabs/tabs_constants.h" | 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 12 #include "chrome/browser/extensions/extension_panel_event_router.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/extensions/extension_window_controller.h" | 15 #include "chrome/browser/extensions/extension_window_controller.h" |
| 13 #include "chrome/browser/lifetime/application_lifetime.h" | 16 #include "chrome/browser/lifetime/application_lifetime.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/panels/native_panel.h" | 18 #include "chrome/browser/ui/panels/native_panel.h" |
| 16 #include "chrome/browser/ui/panels/panel_host.h" | 19 #include "chrome/browser/ui/panels/panel_host.h" |
| 17 #include "chrome/browser/ui/panels/panel_manager.h" | 20 #include "chrome/browser/ui/panels/panel_manager.h" |
| 18 #include "chrome/browser/ui/panels/panel_strip.h" | 21 #include "chrome/browser/ui/panels/panel_strip.h" |
| 19 #include "chrome/browser/web_applications/web_app.h" | 22 #include "chrome/browser/web_applications/web_app.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 native_panel_->AttachWebContents(GetWebContents()); | 147 native_panel_->AttachWebContents(GetWebContents()); |
| 145 | 148 |
| 146 // Close when the extension is unloaded or the browser is exiting. | 149 // Close when the extension is unloaded or the browser is exiting. |
| 147 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 150 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 148 content::Source<Profile>(profile)); | 151 content::Source<Profile>(profile)); |
| 149 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, | 152 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING, |
| 150 content::NotificationService::AllSources()); | 153 content::NotificationService::AllSources()); |
| 151 | 154 |
| 152 // Prevent the browser process from shutting down while this window is open. | 155 // Prevent the browser process from shutting down while this window is open. |
| 153 browser::StartKeepAlive(); | 156 browser::StartKeepAlive(); |
| 157 |
| 158 // Send extension event about newly created panel. |
| 159 ExtensionPanelEventRouter* event_router = GetEventRouter(); |
| 160 if (event_router) |
| 161 event_router->OnPanelOpened(this); |
| 154 } | 162 } |
| 155 | 163 |
| 156 void Panel::InitCommandState() { | 164 void Panel::InitCommandState() { |
| 157 // All supported commands whose state isn't set automagically some other way | 165 // All supported commands whose state isn't set automagically some other way |
| 158 // (like Stop during a page load) must have their state initialized here, | 166 // (like Stop during a page load) must have their state initialized here, |
| 159 // otherwise they will be forever disabled. | 167 // otherwise they will be forever disabled. |
| 160 | 168 |
| 161 // Navigation commands | 169 // Navigation commands |
| 162 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); | 170 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
| 163 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); | 171 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 174 | 182 |
| 175 // Clipboard | 183 // Clipboard |
| 176 command_updater_.UpdateCommandEnabled(IDC_COPY, true); | 184 command_updater_.UpdateCommandEnabled(IDC_COPY, true); |
| 177 command_updater_.UpdateCommandEnabled(IDC_CUT, true); | 185 command_updater_.UpdateCommandEnabled(IDC_CUT, true); |
| 178 command_updater_.UpdateCommandEnabled(IDC_PASTE, true); | 186 command_updater_.UpdateCommandEnabled(IDC_PASTE, true); |
| 179 } | 187 } |
| 180 | 188 |
| 181 void Panel::OnNativePanelClosed() { | 189 void Panel::OnNativePanelClosed() { |
| 182 manager()->OnPanelClosed(this); | 190 manager()->OnPanelClosed(this); |
| 183 DCHECK(!panel_strip_); | 191 DCHECK(!panel_strip_); |
| 192 |
| 193 // Send extension event about closed panel. |
| 194 ExtensionPanelEventRouter* event_router = GetEventRouter(); |
| 195 if (event_router) |
| 196 event_router->OnPanelClosed(this); |
| 184 } | 197 } |
| 185 | 198 |
| 186 PanelManager* Panel::manager() const { | 199 PanelManager* Panel::manager() const { |
| 187 return PanelManager::GetInstance(); | 200 return PanelManager::GetInstance(); |
| 188 } | 201 } |
| 189 | 202 |
| 190 Browser* Panel::browser() const { | 203 Browser* Panel::browser() const { |
| 191 return NULL; | 204 return NULL; |
| 192 } | 205 } |
| 193 | 206 |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 // its expansion state. However, we don't want to clear draw attention if | 616 // its expansion state. However, we don't want to clear draw attention if |
| 604 // contents are not visible. In that scenario, if the mouse-down results | 617 // contents are not visible. In that scenario, if the mouse-down results |
| 605 // in a mouse-click, draw attention will be cleared then. | 618 // in a mouse-click, draw attention will be cleared then. |
| 606 // See Panel::OnTitlebarClicked(). | 619 // See Panel::OnTitlebarClicked(). |
| 607 if (active && IsDrawingAttention() && !IsMinimized()) | 620 if (active && IsDrawingAttention() && !IsMinimized()) |
| 608 FlashFrame(false); | 621 FlashFrame(false); |
| 609 | 622 |
| 610 if (panel_strip_) | 623 if (panel_strip_) |
| 611 panel_strip_->OnPanelActiveStateChanged(this); | 624 panel_strip_->OnPanelActiveStateChanged(this); |
| 612 | 625 |
| 626 // Send extension event about focus change. |
| 627 ExtensionPanelEventRouter* event_router = GetEventRouter(); |
| 628 if (event_router) |
| 629 event_router->OnPanelActiveStatusChanged(this, active); |
| 630 |
| 613 content::NotificationService::current()->Notify( | 631 content::NotificationService::current()->Notify( |
| 614 chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, | 632 chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, |
| 615 content::Source<Panel>(this), | 633 content::Source<Panel>(this), |
| 616 content::NotificationService::NoDetails()); | 634 content::NotificationService::NoDetails()); |
| 617 } | 635 } |
| 618 | 636 |
| 619 void Panel::ConfigureAutoResize(content::WebContents* web_contents) { | 637 void Panel::ConfigureAutoResize(content::WebContents* web_contents) { |
| 620 if (!auto_resizable_ || !web_contents) | 638 if (!auto_resizable_ || !web_contents) |
| 621 return; | 639 return; |
| 622 | 640 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 | 736 |
| 719 void Panel::UpdateTitleBar() { | 737 void Panel::UpdateTitleBar() { |
| 720 native_panel_->UpdatePanelTitleBar(); | 738 native_panel_->UpdatePanelTitleBar(); |
| 721 } | 739 } |
| 722 | 740 |
| 723 void Panel::LoadingStateChanged(bool is_loading) { | 741 void Panel::LoadingStateChanged(bool is_loading) { |
| 724 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | 742 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| 725 native_panel_->UpdatePanelLoadingAnimations(is_loading); | 743 native_panel_->UpdatePanelLoadingAnimations(is_loading); |
| 726 UpdateTitleBar(); | 744 UpdateTitleBar(); |
| 727 } | 745 } |
| 746 |
| 747 ExtensionPanelEventRouter* Panel::GetEventRouter() { |
| 748 ExtensionService* service = |
| 749 extensions::ExtensionSystem::Get(profile())->extension_service(); |
| 750 return service ? service->GetPanelEventRouter() : NULL; |
| 751 } |
| OLD | NEW |