| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/sidebar/sidebar_container.h" | 5 #include "chrome/browser/sidebar/sidebar_container.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
| 10 #include "chrome/browser/tab_contents/navigation_controller.h" | 10 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 11 #include "chrome/browser/tab_contents/navigation_entry.h" | 11 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents_view.h" | 13 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 14 #include "chrome/common/bindings_policy.h" | 14 #include "chrome/common/bindings_policy.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/extension_resource.h" | 16 #include "chrome/common/extensions/extension_resource.h" |
| 17 #include "chrome/common/extensions/extension_sidebar_defaults.h" | 17 #include "chrome/common/extensions/extension_sidebar_defaults.h" |
| 18 #include "chrome/common/extensions/extension_sidebar_utils.h" | 18 #include "chrome/common/extensions/extension_sidebar_utils.h" |
| 19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 | 21 |
| 22 SidebarContainer::SidebarContainer(TabContents* tab, | 22 SidebarContainer::SidebarContainer(TabContents* tab, |
| 23 const std::string& content_id, | 23 const std::string& content_id, |
| 24 Delegate* delegate) | 24 Delegate* delegate) |
| 25 : tab_(tab), | 25 : tab_(tab), |
| 26 content_id_(content_id), | 26 content_id_(content_id), |
| 27 delegate_(delegate), | 27 delegate_(delegate), |
| 28 icon_(new SkBitmap), | 28 icon_(new SkBitmap), |
| 29 navigate_to_default_url_on_expand_(true), | 29 navigate_to_default_page_on_expand_(true), |
| 30 use_default_icon_(true) { | 30 use_default_icon_(true) { |
| 31 // Create TabContents for sidebar. | 31 // Create TabContents for sidebar. |
| 32 sidebar_contents_.reset( | 32 sidebar_contents_.reset( |
| 33 new TabContents(tab->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL)); | 33 new TabContents(tab->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL)); |
| 34 sidebar_contents_->render_view_host()->set_is_extension_process(true); | 34 sidebar_contents_->render_view_host()->set_is_extension_process(true); |
| 35 sidebar_contents_->render_view_host()->AllowBindings( | 35 sidebar_contents_->render_view_host()->AllowBindings( |
| 36 BindingsPolicy::EXTENSION); | 36 BindingsPolicy::EXTENSION); |
| 37 sidebar_contents_->set_delegate(this); | 37 sidebar_contents_->set_delegate(this); |
| 38 } | 38 } |
| 39 | 39 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 62 Extension::kSidebarIconMaxSize), | 62 Extension::kSidebarIconMaxSize), |
| 63 ImageLoadingTracker::CACHE); | 63 ImageLoadingTracker::CACHE); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void SidebarContainer::Show() { | 67 void SidebarContainer::Show() { |
| 68 delegate_->UpdateSidebar(this); | 68 delegate_->UpdateSidebar(this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void SidebarContainer::Expand() { | 71 void SidebarContainer::Expand() { |
| 72 if (navigate_to_default_url_on_expand_) { | 72 if (navigate_to_default_page_on_expand_) { |
| 73 navigate_to_default_url_on_expand_ = false; | 73 navigate_to_default_page_on_expand_ = false; |
| 74 // Check whether a default URL is specified for this sidebar. | 74 // Check whether a default page is specified for this sidebar. |
| 75 const Extension* extension = GetExtension(); | 75 const Extension* extension = GetExtension(); |
| 76 if (extension) { // Can be NULL in tests. | 76 if (extension) { // Can be NULL in tests. |
| 77 if (extension->sidebar_defaults()->default_url().is_valid()) | 77 if (extension->sidebar_defaults()->default_page().is_valid()) |
| 78 Navigate(extension->sidebar_defaults()->default_url()); | 78 Navigate(extension->sidebar_defaults()->default_page()); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 delegate_->UpdateSidebar(this); | 82 delegate_->UpdateSidebar(this); |
| 83 sidebar_contents_->view()->SetInitialFocus(); | 83 sidebar_contents_->view()->SetInitialFocus(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void SidebarContainer::Collapse() { | 86 void SidebarContainer::Collapse() { |
| 87 delegate_->UpdateSidebar(this); | 87 delegate_->UpdateSidebar(this); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SidebarContainer::Navigate(const GURL& url) { | 90 void SidebarContainer::Navigate(const GURL& url) { |
| 91 // TODO(alekseys): add a progress UI. | 91 // TODO(alekseys): add a progress UI. |
| 92 navigate_to_default_url_on_expand_ = false; | 92 navigate_to_default_page_on_expand_ = false; |
| 93 sidebar_contents_->controller().LoadURL( | 93 sidebar_contents_->controller().LoadURL( |
| 94 url, GURL(), PageTransition::START_PAGE); | 94 url, GURL(), PageTransition::START_PAGE); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void SidebarContainer::SetBadgeText(const string16& badge_text) { | 97 void SidebarContainer::SetBadgeText(const string16& badge_text) { |
| 98 badge_text_ = badge_text; | 98 badge_text_ = badge_text; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SidebarContainer::SetIcon(const SkBitmap& bitmap) { | 101 void SidebarContainer::SetIcon(const SkBitmap& bitmap) { |
| 102 use_default_icon_ = false; | 102 use_default_icon_ = false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 } | 121 } |
| 122 | 122 |
| 123 const Extension* SidebarContainer::GetExtension() const { | 123 const Extension* SidebarContainer::GetExtension() const { |
| 124 ExtensionService* service = | 124 ExtensionService* service = |
| 125 sidebar_contents_->profile()->GetExtensionService(); | 125 sidebar_contents_->profile()->GetExtensionService(); |
| 126 if (!service) | 126 if (!service) |
| 127 return NULL; | 127 return NULL; |
| 128 return service->GetExtensionById( | 128 return service->GetExtensionById( |
| 129 extension_sidebar_utils::GetExtensionIdByContentId(content_id_), false); | 129 extension_sidebar_utils::GetExtensionIdByContentId(content_id_), false); |
| 130 } | 130 } |
| OLD | NEW |