Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: chrome/browser/sidebar/sidebar_container.cc

Issue 9006027: Rip Out the Sidebar API (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sidebar/sidebar_container.h ('k') | chrome/browser/sidebar/sidebar_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sidebar/sidebar_container.h"
6
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_resource.h"
12 #include "chrome/common/extensions/extension_sidebar_defaults.h"
13 #include "chrome/common/extensions/extension_sidebar_utils.h"
14 #include "content/browser/renderer_host/render_view_host.h"
15 #include "content/browser/tab_contents/tab_contents.h"
16 #include "content/browser/tab_contents/tab_contents_view.h"
17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/render_process_host.h"
19 #include "googleurl/src/gurl.h"
20 #include "third_party/skia/include/core/SkBitmap.h"
21
22 SidebarContainer::SidebarContainer(TabContents* tab,
23 const std::string& content_id,
24 Delegate* delegate)
25 : tab_(tab),
26 content_id_(content_id),
27 delegate_(delegate),
28 icon_(new SkBitmap),
29 navigate_to_default_page_on_expand_(true),
30 use_default_icon_(true) {
31 // Create TabContents for sidebar.
32 sidebar_contents_.reset(
33 new TabContents(Profile::FromBrowserContext(tab->GetBrowserContext()),
34 NULL, MSG_ROUTING_NONE, NULL, NULL));
35 sidebar_contents_->SetDelegate(this);
36 }
37
38 SidebarContainer::~SidebarContainer() {
39 }
40
41 void SidebarContainer::SidebarClosing() {
42 delegate_->UpdateSidebar(this);
43 }
44
45 void SidebarContainer::LoadDefaults() {
46 const Extension* extension = GetExtension();
47 if (!extension)
48 return; // Can be NULL in tests.
49 const ExtensionSidebarDefaults* sidebar_defaults =
50 extension->sidebar_defaults();
51
52 title_ = sidebar_defaults->default_title();
53
54 if (!sidebar_defaults->default_icon_path().empty()) {
55 image_loading_tracker_.reset(new ImageLoadingTracker(this));
56 image_loading_tracker_->LoadImage(
57 extension,
58 extension->GetResource(sidebar_defaults->default_icon_path()),
59 gfx::Size(Extension::kSidebarIconMaxSize,
60 Extension::kSidebarIconMaxSize),
61 ImageLoadingTracker::CACHE);
62 }
63 }
64
65 void SidebarContainer::Show() {
66 delegate_->UpdateSidebar(this);
67 }
68
69 void SidebarContainer::Expand() {
70 if (navigate_to_default_page_on_expand_) {
71 navigate_to_default_page_on_expand_ = false;
72 // Check whether a default page is specified for this sidebar.
73 const Extension* extension = GetExtension();
74 if (extension) { // Can be NULL in tests.
75 if (extension->sidebar_defaults()->default_page().is_valid())
76 Navigate(extension->sidebar_defaults()->default_page());
77 }
78 }
79
80 delegate_->UpdateSidebar(this);
81 sidebar_contents_->GetView()->SetInitialFocus();
82 }
83
84 void SidebarContainer::Collapse() {
85 delegate_->UpdateSidebar(this);
86 }
87
88 void SidebarContainer::Navigate(const GURL& url) {
89 // TODO(alekseys): add a progress UI.
90 navigate_to_default_page_on_expand_ = false;
91 sidebar_contents_->GetController().LoadURL(
92 url, content::Referrer(), content::PAGE_TRANSITION_START_PAGE,
93 std::string());
94 }
95
96 void SidebarContainer::SetBadgeText(const string16& badge_text) {
97 badge_text_ = badge_text;
98 }
99
100 void SidebarContainer::SetIcon(const SkBitmap& bitmap) {
101 use_default_icon_ = false;
102 *icon_ = bitmap;
103 }
104
105 void SidebarContainer::SetTitle(const string16& title) {
106 title_ = title;
107 }
108
109 content::JavaScriptDialogCreator*
110 SidebarContainer::GetJavaScriptDialogCreator() {
111 return GetJavaScriptDialogCreatorInstance();
112 }
113
114 void SidebarContainer::OnImageLoaded(SkBitmap* image,
115 const ExtensionResource& resource,
116 int index) {
117 if (image && use_default_icon_) {
118 *icon_ = *image;
119 delegate_->UpdateSidebar(this);
120 }
121 }
122
123 const Extension* SidebarContainer::GetExtension() const {
124 Profile* profile =
125 Profile::FromBrowserContext(sidebar_contents_->GetBrowserContext());
126 ExtensionService* service = profile->GetExtensionService();
127 if (!service)
128 return NULL;
129 return service->GetExtensionById(
130 extension_sidebar_utils::GetExtensionIdByContentId(content_id_), false);
131 }
OLDNEW
« no previous file with comments | « chrome/browser/sidebar/sidebar_container.h ('k') | chrome/browser/sidebar/sidebar_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698