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 #ifndef CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ | 5 #ifndef CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ |
6 #define CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ | 6 #define CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "chrome/browser/extensions/image_loading_tracker.h" |
13 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 14 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
14 | 15 |
15 class BrowserWindow; | 16 class BrowserWindow; |
16 class Profile; | 17 class Profile; |
17 class RenderViewHost; | 18 class RenderViewHost; |
18 class SkBitmap; | 19 class SkBitmap; |
19 class TabContents; | 20 class TabContents; |
20 | 21 |
21 /////////////////////////////////////////////////////////////////////////////// | 22 /////////////////////////////////////////////////////////////////////////////// |
22 // SidebarContainer | 23 // SidebarContainer |
23 // | 24 // |
24 // Stores one particular sidebar state: sidebar's content, its content id, | 25 // Stores one particular sidebar state: sidebar's content, its content id, |
25 // tab it is linked to, mini tab icon, title etc. | 26 // tab it is linked to, mini tab icon, title etc. |
26 // | 27 // |
27 class SidebarContainer | 28 class SidebarContainer |
28 : public TabContentsDelegate { | 29 : public TabContentsDelegate, |
| 30 private ImageLoadingTracker::Observer { |
29 public: | 31 public: |
30 // Interface to implement to listen for sidebar update notification. | 32 // Interface to implement to listen for sidebar update notification. |
31 class Delegate { | 33 class Delegate { |
32 public: | 34 public: |
33 Delegate() {} | 35 Delegate() {} |
34 virtual ~Delegate() {} | 36 virtual ~Delegate() {} |
35 virtual void UpdateSidebar(SidebarContainer* host) = 0; | 37 virtual void UpdateSidebar(SidebarContainer* host) = 0; |
36 private: | 38 private: |
37 DISALLOW_COPY_AND_ASSIGN(Delegate); | 39 DISALLOW_COPY_AND_ASSIGN(Delegate); |
38 }; | 40 }; |
39 | 41 |
40 SidebarContainer(TabContents* tab, const std::string& content_id, | 42 SidebarContainer(TabContents* tab, |
| 43 const std::string& content_id, |
41 Delegate* delegate); | 44 Delegate* delegate); |
42 virtual ~SidebarContainer(); | 45 virtual ~SidebarContainer(); |
43 | 46 |
44 // Called right before destroying this sidebar. | 47 // Called right before destroying this sidebar. |
45 // Does all the necessary cleanup. | 48 // Does all the necessary cleanup. |
46 void SidebarClosing(); | 49 void SidebarClosing(); |
47 | 50 |
| 51 // Sets default sidebar parameters, as specified in extension manifest. |
| 52 void LoadDefaults(); |
| 53 |
48 // Returns sidebar's content id. | 54 // Returns sidebar's content id. |
49 const std::string& content_id() const { return content_id_; } | 55 const std::string& content_id() const { return content_id_; } |
50 | 56 |
51 // Returns TabContents sidebar is linked to. | 57 // Returns TabContents sidebar is linked to. |
52 TabContents* tab_contents() const { return tab_; } | 58 TabContents* tab_contents() const { return tab_; } |
53 | 59 |
54 // Returns sidebar's TabContents. | 60 // Returns sidebar's TabContents. |
55 TabContents* sidebar_contents() const { return sidebar_contents_.get(); } | 61 TabContents* sidebar_contents() const { return sidebar_contents_.get(); } |
56 | 62 |
57 // Accessor for the badge text. | 63 // Accessor for the badge text. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 virtual void ActivateContents(TabContents* contents) {} | 109 virtual void ActivateContents(TabContents* contents) {} |
104 virtual void DeactivateContents(TabContents* contents) {} | 110 virtual void DeactivateContents(TabContents* contents) {} |
105 virtual void LoadingStateChanged(TabContents* source) {} | 111 virtual void LoadingStateChanged(TabContents* source) {} |
106 virtual void CloseContents(TabContents* source) {} | 112 virtual void CloseContents(TabContents* source) {} |
107 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} | 113 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} |
108 virtual bool IsPopup(const TabContents* source) const; | 114 virtual bool IsPopup(const TabContents* source) const; |
109 virtual void URLStarredChanged(TabContents* source, bool starred) {} | 115 virtual void URLStarredChanged(TabContents* source, bool starred) {} |
110 virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} | 116 virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} |
111 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} | 117 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} |
112 | 118 |
| 119 // Overridden from ImageLoadingTracker::Observer. |
| 120 virtual void OnImageLoaded(SkBitmap* image, |
| 121 ExtensionResource resource, |
| 122 int index); |
| 123 |
| 124 // Returns an extension this sidebar belongs to. |
| 125 const Extension* GetExtension() const; |
| 126 |
113 // Contents of the tab this sidebar is linked to. | 127 // Contents of the tab this sidebar is linked to. |
114 TabContents* tab_; | 128 TabContents* tab_; |
115 | 129 |
116 // Sidebar's content id. There might be more than one sidebar liked to each | 130 // Sidebar's content id. There might be more than one sidebar liked to each |
117 // particular tab and they are identified by their unique content id. | 131 // particular tab and they are identified by their unique content id. |
118 const std::string content_id_; | 132 const std::string content_id_; |
119 | 133 |
120 // Sidebar update notification listener. | 134 // Sidebar update notification listener. |
121 Delegate* delegate_; | 135 Delegate* delegate_; |
122 | 136 |
123 // Sidebar contents. | 137 // Sidebar contents. |
124 scoped_ptr<TabContents> sidebar_contents_; | 138 scoped_ptr<TabContents> sidebar_contents_; |
125 | 139 |
126 // Badge text displayed on the sidebar's mini tab. | 140 // Badge text displayed on the sidebar's mini tab. |
127 string16 badge_text_; | 141 string16 badge_text_; |
128 | 142 |
129 // Icon displayed on the sidebar's mini tab. | 143 // Icon displayed on the sidebar's mini tab. |
130 scoped_ptr<SkBitmap> icon_; | 144 scoped_ptr<SkBitmap> icon_; |
131 | 145 |
132 // Sidebar's title, displayed as a tooltip for sidebar's mini tab. | 146 // Sidebar's title, displayed as a tooltip for sidebar's mini tab. |
133 string16 title_; | 147 string16 title_; |
134 | 148 |
| 149 bool navigate_to_default_url_on_expand_; |
| 150 bool use_default_icon_; |
| 151 |
| 152 // The object that is waiting for the sidebar images loading to complete |
| 153 // asynchronously. |
| 154 scoped_ptr<ImageLoadingTracker> image_loading_tracker_; |
| 155 |
135 DISALLOW_COPY_AND_ASSIGN(SidebarContainer); | 156 DISALLOW_COPY_AND_ASSIGN(SidebarContainer); |
136 }; | 157 }; |
137 | 158 |
138 #endif // CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ | 159 #endif // CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ |
OLD | NEW |