| 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/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/browser/ui/panels/panel_host.h" | 26 #include "chrome/browser/ui/panels/panel_host.h" |
| 27 #include "chrome/browser/ui/panels/panel_manager.h" | 27 #include "chrome/browser/ui/panels/panel_manager.h" |
| 28 #include "chrome/browser/ui/panels/stacked_panel_collection.h" | 28 #include "chrome/browser/ui/panels/stacked_panel_collection.h" |
| 29 #include "chrome/browser/web_applications/web_app.h" | 29 #include "chrome/browser/web_applications/web_app.h" |
| 30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
| 32 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
| 33 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
| 34 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
| 35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "extensions/browser/extension_registry.h" |
| 36 #include "extensions/browser/extension_system.h" | 37 #include "extensions/browser/extension_system.h" |
| 37 #include "extensions/browser/image_loader.h" | 38 #include "extensions/browser/image_loader.h" |
| 38 #include "extensions/common/constants.h" | 39 #include "extensions/common/constants.h" |
| 39 #include "extensions/common/extension.h" | 40 #include "extensions/common/extension.h" |
| 40 #include "extensions/common/manifest_handlers/icons_handler.h" | 41 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 41 #include "ui/gfx/image/image.h" | 42 #include "ui/gfx/image/image.h" |
| 42 #include "ui/gfx/rect.h" | 43 #include "ui/gfx/rect.h" |
| 43 | 44 |
| 44 using base::UserMetricsAction; | 45 using base::UserMetricsAction; |
| 45 using content::RenderViewHost; | 46 using content::RenderViewHost; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 433 } |
| 433 } | 434 } |
| 434 | 435 |
| 435 void Panel::Observe(int type, | 436 void Panel::Observe(int type, |
| 436 const content::NotificationSource& source, | 437 const content::NotificationSource& source, |
| 437 const content::NotificationDetails& details) { | 438 const content::NotificationDetails& details) { |
| 438 switch (type) { | 439 switch (type) { |
| 439 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: | 440 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: |
| 440 ConfigureAutoResize(content::Source<content::WebContents>(source).ptr()); | 441 ConfigureAutoResize(content::Source<content::WebContents>(source).ptr()); |
| 441 break; | 442 break; |
| 442 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: | |
| 443 if (content::Details<extensions::UnloadedExtensionInfo>( | |
| 444 details)->extension->id() == extension_id()) | |
| 445 Close(); | |
| 446 break; | |
| 447 case chrome::NOTIFICATION_APP_TERMINATING: | 443 case chrome::NOTIFICATION_APP_TERMINATING: |
| 448 Close(); | 444 Close(); |
| 449 break; | 445 break; |
| 450 default: | 446 default: |
| 451 NOTREACHED() << "Received unexpected notification " << type; | 447 NOTREACHED() << "Received unexpected notification " << type; |
| 452 } | 448 } |
| 453 } | 449 } |
| 454 | 450 |
| 451 void Panel::OnExtensionUnloaded( |
| 452 content::BrowserContext* browser_context, |
| 453 const extensions::Extension* extension, |
| 454 extensions::UnloadedExtensionInfo::Reason reason) { |
| 455 if (extension->id() == extension_id()) |
| 456 Close(); |
| 457 } |
| 458 |
| 455 void Panel::OnTitlebarClicked(panel::ClickModifier modifier) { | 459 void Panel::OnTitlebarClicked(panel::ClickModifier modifier) { |
| 456 if (collection_) | 460 if (collection_) |
| 457 collection_->OnPanelTitlebarClicked(this, modifier); | 461 collection_->OnPanelTitlebarClicked(this, modifier); |
| 458 | 462 |
| 459 // Normally the system activates a window when the titlebar is clicked. | 463 // Normally the system activates a window when the titlebar is clicked. |
| 460 // However, we prevent system activation of minimized panels, thus the | 464 // However, we prevent system activation of minimized panels, thus the |
| 461 // activation may not have occurred. Also, some OSes (Windows) will | 465 // activation may not have occurred. Also, some OSes (Windows) will |
| 462 // activate a minimized panel on mouse-down regardless of our attempts to | 466 // activate a minimized panel on mouse-down regardless of our attempts to |
| 463 // prevent system activation. Attention state is not cleared in that case. | 467 // prevent system activation. Attention state is not cleared in that case. |
| 464 // See Panel::OnActiveStateChanged(). | 468 // See Panel::OnActiveStateChanged(). |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 529 |
| 526 // Set up hosting for web contents. | 530 // Set up hosting for web contents. |
| 527 panel_host_.reset(new PanelHost(this, profile_)); | 531 panel_host_.reset(new PanelHost(this, profile_)); |
| 528 panel_host_->Init(url); | 532 panel_host_->Init(url); |
| 529 content::WebContents* web_contents = GetWebContents(); | 533 content::WebContents* web_contents = GetWebContents(); |
| 530 // The contents might be NULL for most of our tests. | 534 // The contents might be NULL for most of our tests. |
| 531 if (web_contents) | 535 if (web_contents) |
| 532 native_panel_->AttachWebContents(web_contents); | 536 native_panel_->AttachWebContents(web_contents); |
| 533 | 537 |
| 534 // Close when the extension is unloaded or the browser is exiting. | 538 // Close when the extension is unloaded or the browser is exiting. |
| 535 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 539 extension_registry_observer_.Add( |
| 536 content::Source<Profile>(profile_)); | 540 extensions::ExtensionRegistry::Get(profile_)); |
| 537 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 541 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 538 content::NotificationService::AllSources()); | 542 content::NotificationService::AllSources()); |
| 539 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 543 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 540 content::Source<ThemeService>( | 544 content::Source<ThemeService>( |
| 541 ThemeServiceFactory::GetForProfile(profile_))); | 545 ThemeServiceFactory::GetForProfile(profile_))); |
| 542 | 546 |
| 543 #if !defined(USE_AURA) | 547 #if !defined(USE_AURA) |
| 544 // Keep alive for AURA has been moved to panel_view. | 548 // Keep alive for AURA has been moved to panel_view. |
| 545 // Prevent the browser process from shutting down while this window is open. | 549 // Prevent the browser process from shutting down while this window is open. |
| 546 chrome::IncrementKeepAliveCount(); | 550 chrome::IncrementKeepAliveCount(); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 initialized_(false), | 812 initialized_(false), |
| 809 min_size_(min_size), | 813 min_size_(min_size), |
| 810 max_size_(max_size), | 814 max_size_(max_size), |
| 811 max_size_policy_(DEFAULT_MAX_SIZE), | 815 max_size_policy_(DEFAULT_MAX_SIZE), |
| 812 auto_resizable_(false), | 816 auto_resizable_(false), |
| 813 in_preview_mode_(false), | 817 in_preview_mode_(false), |
| 814 native_panel_(NULL), | 818 native_panel_(NULL), |
| 815 attention_mode_(USE_PANEL_ATTENTION), | 819 attention_mode_(USE_PANEL_ATTENTION), |
| 816 expansion_state_(EXPANDED), | 820 expansion_state_(EXPANDED), |
| 817 command_updater_(this), | 821 command_updater_(this), |
| 822 extension_registry_observer_(this), |
| 818 image_loader_ptr_factory_(this) { | 823 image_loader_ptr_factory_(this) { |
| 819 } | 824 } |
| 820 | 825 |
| 821 void Panel::OnImageLoaded(const gfx::Image& image) { | 826 void Panel::OnImageLoaded(const gfx::Image& image) { |
| 822 if (!image.IsEmpty()) { | 827 if (!image.IsEmpty()) { |
| 823 app_icon_ = image; | 828 app_icon_ = image; |
| 824 native_panel_->UpdatePanelTitleBar(); | 829 native_panel_->UpdatePanelTitleBar(); |
| 825 } | 830 } |
| 826 | 831 |
| 827 content::NotificationService::current()->Notify( | 832 content::NotificationService::current()->Notify( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 // static | 899 // static |
| 895 void Panel::FormatTitleForDisplay(base::string16* title) { | 900 void Panel::FormatTitleForDisplay(base::string16* title) { |
| 896 size_t current_index = 0; | 901 size_t current_index = 0; |
| 897 size_t match_index; | 902 size_t match_index; |
| 898 while ((match_index = title->find(L'\n', current_index)) != | 903 while ((match_index = title->find(L'\n', current_index)) != |
| 899 base::string16::npos) { | 904 base::string16::npos) { |
| 900 title->replace(match_index, 1, base::string16()); | 905 title->replace(match_index, 1, base::string16()); |
| 901 current_index = match_index; | 906 current_index = match_index; |
| 902 } | 907 } |
| 903 } | 908 } |
| OLD | NEW |