Chromium Code Reviews| Index: chrome/browser/sidebar/sidebar_container.cc |
| =================================================================== |
| --- chrome/browser/sidebar/sidebar_container.cc (revision 71703) |
| +++ chrome/browser/sidebar/sidebar_container.cc (working copy) |
| @@ -4,12 +4,18 @@ |
| #include "chrome/browser/sidebar/sidebar_container.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/renderer_host/render_view_host.h" |
| #include "chrome/browser/tab_contents/navigation_controller.h" |
| #include "chrome/browser/tab_contents/navigation_entry.h" |
| #include "chrome/browser/tab_contents/tab_contents.h" |
| #include "chrome/browser/tab_contents/tab_contents_view.h" |
| #include "chrome/common/bindings_policy.h" |
| +#include "chrome/common/extensions/extension.h" |
| +#include "chrome/common/extensions/extension_resource.h" |
| +#include "chrome/common/extensions/extension_sidebar_defaults.h" |
| +#include "chrome/common/extensions/extension_sidebar_utils.h" |
| #include "googleurl/src/gurl.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| @@ -19,7 +25,9 @@ |
| : tab_(tab), |
| content_id_(content_id), |
| delegate_(delegate), |
| - icon_(new SkBitmap) { |
| + icon_(new SkBitmap), |
| + navigate_to_default_url_on_expand_(true), |
| + use_default_icon_(true) { |
| // Create TabContents for sidebar. |
| sidebar_contents_.reset( |
| new TabContents(tab->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL)); |
| @@ -36,11 +44,41 @@ |
| delegate_->UpdateSidebar(this); |
| } |
| +void SidebarContainer::LoadDefaults() { |
| + const Extension* extension = GetExtension(); |
| + if (!extension) |
| + return; // Can be NULL in tests. |
| + const ExtensionSidebarDefaults* sidebar_defaults = |
| + extension->sidebar_defaults(); |
| + |
| + title_ = sidebar_defaults->default_title(); |
| + |
| + if (!sidebar_defaults->default_icon_path().empty()) { |
| + image_loading_tracker_.reset(new ImageLoadingTracker(this)); |
| + image_loading_tracker_->LoadImage( |
| + extension, |
| + extension->GetResource(sidebar_defaults->default_icon_path()), |
| + gfx::Size(Extension::kSidebarIconMaxSize, |
|
Aaron Boodman
2011/01/20 00:36:11
Is this constant used anywhere else besides here?
Aleksey Shlyapnikov
2011/01/20 02:41:43
Not in this CL, but sidebar tabs UI needs to know
|
| + Extension::kSidebarIconMaxSize), |
| + ImageLoadingTracker::CACHE); |
| + } |
| +} |
| + |
| void SidebarContainer::Show() { |
| delegate_->UpdateSidebar(this); |
| } |
| void SidebarContainer::Expand() { |
| + if (navigate_to_default_url_on_expand_) { |
| + navigate_to_default_url_on_expand_ = false; |
| + // Check whether a default URL is specified for this sidebar. |
| + const Extension* extension = GetExtension(); |
| + if (extension) { // Can be NULL in tests. |
| + if (extension->sidebar_defaults()->default_url().is_valid()) |
| + Navigate(extension->sidebar_defaults()->default_url()); |
| + } |
| + } |
| + |
| delegate_->UpdateSidebar(this); |
| sidebar_contents_->view()->SetInitialFocus(); |
| } |
| @@ -50,8 +88,8 @@ |
| } |
| void SidebarContainer::Navigate(const GURL& url) { |
| - DCHECK(sidebar_contents_.get()); |
| // TODO(alekseys): add a progress UI. |
| + navigate_to_default_url_on_expand_ = false; |
| sidebar_contents_->controller().LoadURL( |
| url, GURL(), PageTransition::START_PAGE); |
| } |
| @@ -61,6 +99,7 @@ |
| } |
| void SidebarContainer::SetIcon(const SkBitmap& bitmap) { |
| + use_default_icon_ = false; |
| *icon_ = bitmap; |
| } |
| @@ -72,3 +111,20 @@ |
| return false; |
| } |
| +void SidebarContainer::OnImageLoaded(SkBitmap* image, |
| + ExtensionResource resource, |
| + int index) { |
| + if (image && use_default_icon_) { |
| + *icon_ = *image; |
| + delegate_->UpdateSidebar(this); |
| + } |
| +} |
| + |
| +const Extension* SidebarContainer::GetExtension() const { |
| + ExtensionService* service = |
| + sidebar_contents_->profile()->GetExtensionService(); |
| + if (!service) |
| + return NULL; |
| + return service->GetExtensionById( |
| + extension_sidebar_utils::GetExtensionIdByContentId(content_id_), false); |
| +} |