OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/extensions/image_loading_tracker.h" |
14 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 14 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
15 | 15 |
16 class BrowserWindow; | 16 class SidebarContainer; |
17 class Profile; | |
18 class RenderViewHost; | |
19 class SkBitmap; | 17 class SkBitmap; |
20 class TabContents; | 18 class TabContents; |
| 19 class TabContentsWrapper; |
| 20 |
| 21 struct SidebarChangedDetails { |
| 22 enum UpdateType { |
| 23 SIDEBAR_STATE_CHANGED, |
| 24 SIDEBAR_PROPS_CHANGED, |
| 25 SIDEBAR_LOADING_STATE_CHANGED |
| 26 }; |
| 27 SidebarContainer* source; |
| 28 UpdateType update_type; |
| 29 }; |
21 | 30 |
22 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
23 // SidebarContainer | 32 // SidebarContainer |
24 // | 33 // |
25 // Stores one particular sidebar state: sidebar's content, its content id, | 34 // Stores one particular sidebar state: sidebar's content, its content id, |
26 // tab it is linked to, mini tab icon, title etc. | 35 // tab it is linked to, mini tab icon, title etc. |
27 // | 36 // |
28 class SidebarContainer | 37 class SidebarContainer |
29 : public TabContentsDelegate, | 38 : public TabContentsDelegate, |
30 private ImageLoadingTracker::Observer { | 39 private ImageLoadingTracker::Observer { |
31 public: | 40 public: |
32 // Interface to implement to listen for sidebar update notification. | 41 // Interface to implement to listen for sidebar update notification. |
33 class Delegate { | 42 class Delegate { |
34 public: | 43 public: |
35 Delegate() {} | 44 Delegate() {} |
36 virtual ~Delegate() {} | 45 virtual ~Delegate() {} |
37 virtual void UpdateSidebar(SidebarContainer* host) = 0; | 46 virtual void UpdateSidebar(SidebarChangedDetails* details) = 0; |
38 private: | 47 private: |
39 DISALLOW_COPY_AND_ASSIGN(Delegate); | 48 DISALLOW_COPY_AND_ASSIGN(Delegate); |
40 }; | 49 }; |
41 | 50 |
42 SidebarContainer(TabContents* tab, | 51 SidebarContainer(TabContentsWrapper* tab, |
43 const std::string& content_id, | 52 const std::string& content_id, |
44 Delegate* delegate); | 53 Delegate* delegate); |
45 virtual ~SidebarContainer(); | 54 virtual ~SidebarContainer(); |
46 | 55 |
47 // Called right before destroying this sidebar. | 56 // Called right before destroying this sidebar. |
48 // Does all the necessary cleanup. | 57 // Does all the necessary cleanup. |
49 void SidebarClosing(); | 58 void SidebarClosing(); |
50 | 59 |
51 // Sets default sidebar parameters, as specified in extension manifest. | 60 // Sets default sidebar parameters, as specified in extension manifest. |
52 void LoadDefaults(); | 61 void LoadDefaults(); |
53 | 62 |
54 // Returns sidebar's content id. | 63 // Returns sidebar's content id. |
55 const std::string& content_id() const { return content_id_; } | 64 const std::string& content_id() const { return content_id_; } |
56 | 65 |
57 // Returns TabContents sidebar is linked to. | 66 // Returns TabContentsWrapper this sidebar is linked to. |
58 TabContents* tab_contents() const { return tab_; } | 67 TabContentsWrapper* tab() const { return tab_; } |
59 | 68 |
60 // Returns sidebar's TabContents. | 69 // Returns sidebar's TabContents. |
61 TabContents* sidebar_contents() const { return sidebar_contents_.get(); } | 70 TabContents* sidebar_contents() const { return sidebar_contents_.get(); } |
62 | 71 |
63 // Accessor for the badge text. | 72 // Accessor for the badge text. |
64 const string16& badge_text() const { return badge_text_; } | 73 const string16& badge_text() const { return badge_text_; } |
65 | 74 |
66 // Accessor for the icon. | 75 // Accessor for the icon. |
67 const SkBitmap& icon() const { return *icon_; } | 76 const SkBitmap& icon() const { return *icon_; } |
68 | 77 |
(...skipping 24 matching lines...) Expand all Loading... |
93 void SetTitle(const string16& title); | 102 void SetTitle(const string16& title); |
94 | 103 |
95 private: | 104 private: |
96 // Overridden from TabContentsDelegate. | 105 // Overridden from TabContentsDelegate. |
97 virtual void OpenURLFromTab(TabContents* source, | 106 virtual void OpenURLFromTab(TabContents* source, |
98 const GURL& url, | 107 const GURL& url, |
99 const GURL& referrer, | 108 const GURL& referrer, |
100 WindowOpenDisposition disposition, | 109 WindowOpenDisposition disposition, |
101 PageTransition::Type transition) {} | 110 PageTransition::Type transition) {} |
102 virtual void NavigationStateChanged(const TabContents* source, | 111 virtual void NavigationStateChanged(const TabContents* source, |
103 unsigned changed_flags) {} | 112 unsigned changed_flags); |
104 virtual void AddNewContents(TabContents* source, | 113 virtual void AddNewContents(TabContents* source, |
105 TabContents* new_contents, | 114 TabContents* new_contents, |
106 WindowOpenDisposition disposition, | 115 WindowOpenDisposition disposition, |
107 const gfx::Rect& initial_pos, | 116 const gfx::Rect& initial_pos, |
108 bool user_gesture) {} | 117 bool user_gesture) {} |
109 virtual void ActivateContents(TabContents* contents) {} | 118 virtual void ActivateContents(TabContents* contents) {} |
110 virtual void DeactivateContents(TabContents* contents) {} | 119 virtual void DeactivateContents(TabContents* contents) {} |
111 virtual void LoadingStateChanged(TabContents* source) {} | 120 virtual void LoadingStateChanged(TabContents* source) {} |
112 virtual void CloseContents(TabContents* source) {} | 121 virtual void CloseContents(TabContents* source) {} |
113 virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {} | 122 virtual void MoveContents(TabContents* source, |
114 virtual bool IsPopup(const TabContents* source) const; | 123 const gfx::Rect& pos) {} |
| 124 virtual void ToolbarSizeChanged(TabContents* source, |
| 125 bool is_animating) {} |
115 virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} | 126 virtual void UpdateTargetURL(TabContents* source, const GURL& url) {} |
116 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {} | 127 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 128 bool* is_keyboard_shortcut) OVERRIDE; |
| 129 virtual void HandleKeyboardEvent( |
| 130 const NativeWebKeyboardEvent& event) OVERRIDE; |
117 | 131 |
118 // Overridden from ImageLoadingTracker::Observer. | 132 // Overridden from ImageLoadingTracker::Observer. |
119 virtual void OnImageLoaded(SkBitmap* image, | 133 virtual void OnImageLoaded(SkBitmap* image, |
120 ExtensionResource resource, | 134 ExtensionResource resource, |
121 int index); | 135 int index); |
122 | 136 |
| 137 // Forwards update notification to delegate_. |
| 138 void NotifyUpdate(SidebarChangedDetails::UpdateType update_type); |
| 139 |
123 // Returns an extension this sidebar belongs to. | 140 // Returns an extension this sidebar belongs to. |
124 const Extension* GetExtension() const; | 141 const Extension* GetExtension() const; |
125 | 142 |
126 // Contents of the tab this sidebar is linked to. | 143 // Contents of the tab this sidebar is linked to. |
127 TabContents* tab_; | 144 TabContentsWrapper* tab_; |
128 | 145 |
129 // Sidebar's content id. There might be more than one sidebar liked to each | 146 // Sidebar's content id. There might be more than one sidebar liked to each |
130 // particular tab and they are identified by their unique content id. | 147 // particular tab and they are identified by their unique content id. |
131 const std::string content_id_; | 148 const std::string content_id_; |
132 | 149 |
133 // Sidebar update notification listener. | 150 // Sidebar update notification listener. |
134 Delegate* delegate_; | 151 Delegate* delegate_; |
135 | 152 |
136 // Sidebar contents. | 153 // Sidebar contents. |
137 scoped_ptr<TabContents> sidebar_contents_; | 154 scoped_ptr<TabContents> sidebar_contents_; |
(...skipping 18 matching lines...) Expand all Loading... |
156 // icon should be used or discarded. | 173 // icon should be used or discarded. |
157 bool use_default_icon_; | 174 bool use_default_icon_; |
158 | 175 |
159 // Helper to load icons from extension asynchronously. | 176 // Helper to load icons from extension asynchronously. |
160 scoped_ptr<ImageLoadingTracker> image_loading_tracker_; | 177 scoped_ptr<ImageLoadingTracker> image_loading_tracker_; |
161 | 178 |
162 DISALLOW_COPY_AND_ASSIGN(SidebarContainer); | 179 DISALLOW_COPY_AND_ASSIGN(SidebarContainer); |
163 }; | 180 }; |
164 | 181 |
165 #endif // CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ | 182 #endif // CHROME_BROWSER_SIDEBAR_SIDEBAR_CONTAINER_H_ |
OLD | NEW |