OLD | NEW |
| (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 #ifndef CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ | |
6 #define CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/string16.h" | |
14 #include "chrome/browser/extensions/image_loading_tracker.h" | |
15 #include "content/public/browser/web_contents_delegate.h" | |
16 | |
17 class SkBitmap; | |
18 class TabContents; | |
19 | |
20 /////////////////////////////////////////////////////////////////////////////// | |
21 // SidebarContainer | |
22 // | |
23 // Stores one particular sidebar state: sidebar's content, its content id, | |
24 // tab it is linked to, mini tab icon, title etc. | |
25 // | |
26 class SidebarContainer : public content::WebContentsDelegate, | |
27 private ImageLoadingTracker::Observer { | |
28 public: | |
29 // Interface to implement to listen for sidebar update notification. | |
30 class Delegate { | |
31 public: | |
32 Delegate() {} | |
33 virtual ~Delegate() {} | |
34 virtual void UpdateSidebar(SidebarContainer* host) = 0; | |
35 private: | |
36 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
37 }; | |
38 | |
39 SidebarContainer(TabContents* tab, | |
40 const std::string& content_id, | |
41 Delegate* delegate); | |
42 virtual ~SidebarContainer(); | |
43 | |
44 // Called right before destroying this sidebar. | |
45 // Does all the necessary cleanup. | |
46 void SidebarClosing(); | |
47 | |
48 // Sets default sidebar parameters, as specified in extension manifest. | |
49 void LoadDefaults(); | |
50 | |
51 // Returns sidebar's content id. | |
52 const std::string& content_id() const { return content_id_; } | |
53 | |
54 // Returns TabContents sidebar is linked to. | |
55 TabContents* tab_contents() const { return tab_; } | |
56 | |
57 // Returns sidebar's TabContents. | |
58 TabContents* sidebar_contents() const { return sidebar_contents_.get(); } | |
59 | |
60 // Accessor for the badge text. | |
61 const string16& badge_text() const { return badge_text_; } | |
62 | |
63 // Accessor for the icon. | |
64 const SkBitmap& icon() const { return *icon_; } | |
65 | |
66 // Accessor for the title. | |
67 const string16& title() const { return title_; } | |
68 | |
69 // Functions supporting chrome.experimental.sidebar API. | |
70 | |
71 // Notifies hosting window that this sidebar was expanded. | |
72 void Show(); | |
73 | |
74 // Notifies hosting window that this sidebar was expanded. | |
75 void Expand(); | |
76 | |
77 // Notifies hosting window that this sidebar was collapsed. | |
78 void Collapse(); | |
79 | |
80 // Navigates sidebar contents to the |url|. | |
81 void Navigate(const GURL& url); | |
82 | |
83 // Changes sidebar's badge text. | |
84 void SetBadgeText(const string16& badge_text); | |
85 | |
86 // Changes sidebar's icon. | |
87 void SetIcon(const SkBitmap& bitmap); | |
88 | |
89 // Changes sidebar's title. | |
90 void SetTitle(const string16& title); | |
91 | |
92 private: | |
93 // Overridden from content::WebContentsDelegate: | |
94 virtual content::JavaScriptDialogCreator* | |
95 GetJavaScriptDialogCreator() OVERRIDE; | |
96 | |
97 // Overridden from ImageLoadingTracker::Observer: | |
98 virtual void OnImageLoaded(SkBitmap* image, | |
99 const ExtensionResource& resource, | |
100 int index) OVERRIDE; | |
101 | |
102 // Returns an extension this sidebar belongs to. | |
103 const Extension* GetExtension() const; | |
104 | |
105 // Contents of the tab this sidebar is linked to. | |
106 TabContents* tab_; | |
107 | |
108 // Sidebar's content id. There might be more than one sidebar liked to each | |
109 // particular tab and they are identified by their unique content id. | |
110 const std::string content_id_; | |
111 | |
112 // Sidebar update notification listener. | |
113 Delegate* delegate_; | |
114 | |
115 // Sidebar contents. | |
116 scoped_ptr<TabContents> sidebar_contents_; | |
117 | |
118 // Badge text displayed on the sidebar's mini tab. | |
119 string16 badge_text_; | |
120 | |
121 // Icon displayed on the sidebar's mini tab. | |
122 scoped_ptr<SkBitmap> icon_; | |
123 | |
124 // Sidebar's title, displayed as a tooltip for sidebar's mini tab. | |
125 string16 title_; | |
126 | |
127 // On the first expand sidebar will be automatically navigated to the default | |
128 // page (specified in the extension manifest), but only if the extension has | |
129 // not explicitly navigated it yet. This variable is set to false on the first | |
130 // sidebar navigation. | |
131 bool navigate_to_default_page_on_expand_; | |
132 // Since the default icon (specified in the extension manifest) is loaded | |
133 // asynchronously, sidebar icon can already be set by the extension | |
134 // by the time it's loaded. This variable tracks whether the loaded default | |
135 // icon should be used or discarded. | |
136 bool use_default_icon_; | |
137 | |
138 // Helper to load icons from extension asynchronously. | |
139 scoped_ptr<ImageLoadingTracker> image_loading_tracker_; | |
140 | |
141 DISALLOW_COPY_AND_ASSIGN(SidebarContainer); | |
142 }; | |
143 | |
144 #endif // CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ | |
OLD | NEW |