OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/bookmark_manager_private/bookmark_manage
r_private_api.h" | 5 #include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manage
r_private_api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/browser/undo/bookmark_undo_service.h" | 26 #include "chrome/browser/undo/bookmark_undo_service.h" |
27 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 27 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
28 #include "chrome/common/extensions/api/bookmark_manager_private.h" | 28 #include "chrome/common/extensions/api/bookmark_manager_private.h" |
29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
30 #include "components/user_prefs/user_prefs.h" | 30 #include "components/user_prefs/user_prefs.h" |
31 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
33 #include "content/public/browser/web_contents_view.h" | 33 #include "content/public/browser/web_contents_view.h" |
34 #include "content/public/browser/web_ui.h" | 34 #include "content/public/browser/web_ui.h" |
35 #include "extensions/browser/extension_function_dispatcher.h" | 35 #include "extensions/browser/extension_function_dispatcher.h" |
36 #include "extensions/browser/extension_system.h" | |
37 #include "extensions/browser/view_type_utils.h" | 36 #include "extensions/browser/view_type_utils.h" |
38 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
39 #include "ui/base/dragdrop/drag_drop_types.h" | 38 #include "ui/base/dragdrop/drag_drop_types.h" |
40 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
41 #include "ui/base/webui/web_ui_util.h" | 40 #include "ui/base/webui/web_ui_util.h" |
42 | 41 |
43 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
44 #include "win8/util/win8_util.h" | 43 #include "win8/util/win8_util.h" |
45 #endif // OS_WIN | 44 #endif // OS_WIN |
46 | 45 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 172 } |
174 | 173 |
175 BookmarkManagerPrivateEventRouter::~BookmarkManagerPrivateEventRouter() { | 174 BookmarkManagerPrivateEventRouter::~BookmarkManagerPrivateEventRouter() { |
176 if (bookmark_model_) | 175 if (bookmark_model_) |
177 bookmark_model_->RemoveObserver(this); | 176 bookmark_model_->RemoveObserver(this); |
178 } | 177 } |
179 | 178 |
180 void BookmarkManagerPrivateEventRouter::DispatchEvent( | 179 void BookmarkManagerPrivateEventRouter::DispatchEvent( |
181 const std::string& event_name, | 180 const std::string& event_name, |
182 scoped_ptr<base::ListValue> event_args) { | 181 scoped_ptr<base::ListValue> event_args) { |
183 extensions::ExtensionSystem::Get(browser_context_) | 182 extensions::EventRouter::Get(browser_context_)->BroadcastEvent( |
184 ->event_router() | 183 make_scoped_ptr(new extensions::Event(event_name, event_args.Pass()))); |
185 ->BroadcastEvent(make_scoped_ptr( | |
186 new extensions::Event(event_name, event_args.Pass()))); | |
187 } | 184 } |
188 | 185 |
189 void BookmarkManagerPrivateEventRouter::BookmarkModelChanged() {} | 186 void BookmarkManagerPrivateEventRouter::BookmarkModelChanged() {} |
190 | 187 |
191 void BookmarkManagerPrivateEventRouter::BookmarkModelBeingDeleted( | 188 void BookmarkManagerPrivateEventRouter::BookmarkModelBeingDeleted( |
192 BookmarkModel* model) { | 189 BookmarkModel* model) { |
193 bookmark_model_ = NULL; | 190 bookmark_model_ = NULL; |
194 } | 191 } |
195 | 192 |
196 void BookmarkManagerPrivateEventRouter::BookmarkMetaInfoChanged( | 193 void BookmarkManagerPrivateEventRouter::BookmarkMetaInfoChanged( |
197 BookmarkModel* model, | 194 BookmarkModel* model, |
198 const BookmarkNode* node) { | 195 const BookmarkNode* node) { |
199 DispatchEvent(bookmark_manager_private::OnMetaInfoChanged::kEventName, | 196 DispatchEvent(bookmark_manager_private::OnMetaInfoChanged::kEventName, |
200 bookmark_manager_private::OnMetaInfoChanged::Create( | 197 bookmark_manager_private::OnMetaInfoChanged::Create( |
201 base::Int64ToString(node->id()))); | 198 base::Int64ToString(node->id()))); |
202 } | 199 } |
203 | 200 |
204 BookmarkManagerPrivateAPI::BookmarkManagerPrivateAPI( | 201 BookmarkManagerPrivateAPI::BookmarkManagerPrivateAPI( |
205 content::BrowserContext* browser_context) | 202 content::BrowserContext* browser_context) |
206 : browser_context_(browser_context) { | 203 : browser_context_(browser_context) { |
207 EventRouter* event_router = | 204 EventRouter* event_router = EventRouter::Get(browser_context); |
208 ExtensionSystem::Get(browser_context)->event_router(); | |
209 event_router->RegisterObserver( | 205 event_router->RegisterObserver( |
210 this, bookmark_manager_private::OnMetaInfoChanged::kEventName); | 206 this, bookmark_manager_private::OnMetaInfoChanged::kEventName); |
211 } | 207 } |
212 | 208 |
213 BookmarkManagerPrivateAPI::~BookmarkManagerPrivateAPI() {} | 209 BookmarkManagerPrivateAPI::~BookmarkManagerPrivateAPI() {} |
214 | 210 |
215 void BookmarkManagerPrivateAPI::Shutdown() { | 211 void BookmarkManagerPrivateAPI::Shutdown() { |
216 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 212 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
217 this); | |
218 } | 213 } |
219 | 214 |
220 static base::LazyInstance< | 215 static base::LazyInstance< |
221 BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI> > g_factory = | 216 BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI> > g_factory = |
222 LAZY_INSTANCE_INITIALIZER; | 217 LAZY_INSTANCE_INITIALIZER; |
223 | 218 |
224 // static | 219 // static |
225 BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI>* | 220 BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI>* |
226 BookmarkManagerPrivateAPI::GetFactoryInstance() { | 221 BookmarkManagerPrivateAPI::GetFactoryInstance() { |
227 return g_factory.Pointer(); | 222 return g_factory.Pointer(); |
228 } | 223 } |
229 | 224 |
230 void BookmarkManagerPrivateAPI::OnListenerAdded( | 225 void BookmarkManagerPrivateAPI::OnListenerAdded( |
231 const EventListenerInfo& details) { | 226 const EventListenerInfo& details) { |
232 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 227 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
233 this); | |
234 event_router_.reset(new BookmarkManagerPrivateEventRouter( | 228 event_router_.reset(new BookmarkManagerPrivateEventRouter( |
235 browser_context_, | 229 browser_context_, |
236 BookmarkModelFactory::GetForProfile( | 230 BookmarkModelFactory::GetForProfile( |
237 Profile::FromBrowserContext(browser_context_)))); | 231 Profile::FromBrowserContext(browser_context_)))); |
238 } | 232 } |
239 | 233 |
240 BookmarkManagerPrivateDragEventRouter::BookmarkManagerPrivateDragEventRouter( | 234 BookmarkManagerPrivateDragEventRouter::BookmarkManagerPrivateDragEventRouter( |
241 Profile* profile, | 235 Profile* profile, |
242 content::WebContents* web_contents) | 236 content::WebContents* web_contents) |
243 : profile_(profile), web_contents_(web_contents) { | 237 : profile_(profile), web_contents_(web_contents) { |
244 BookmarkTabHelper* bookmark_tab_helper = | 238 BookmarkTabHelper* bookmark_tab_helper = |
245 BookmarkTabHelper::FromWebContents(web_contents_); | 239 BookmarkTabHelper::FromWebContents(web_contents_); |
246 bookmark_tab_helper->set_bookmark_drag_delegate(this); | 240 bookmark_tab_helper->set_bookmark_drag_delegate(this); |
247 } | 241 } |
248 | 242 |
249 BookmarkManagerPrivateDragEventRouter:: | 243 BookmarkManagerPrivateDragEventRouter:: |
250 ~BookmarkManagerPrivateDragEventRouter() { | 244 ~BookmarkManagerPrivateDragEventRouter() { |
251 BookmarkTabHelper* bookmark_tab_helper = | 245 BookmarkTabHelper* bookmark_tab_helper = |
252 BookmarkTabHelper::FromWebContents(web_contents_); | 246 BookmarkTabHelper::FromWebContents(web_contents_); |
253 if (bookmark_tab_helper->bookmark_drag_delegate() == this) | 247 if (bookmark_tab_helper->bookmark_drag_delegate() == this) |
254 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); | 248 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); |
255 } | 249 } |
256 | 250 |
257 void BookmarkManagerPrivateDragEventRouter::DispatchEvent( | 251 void BookmarkManagerPrivateDragEventRouter::DispatchEvent( |
258 const std::string& event_name, | 252 const std::string& event_name, |
259 scoped_ptr<base::ListValue> args) { | 253 scoped_ptr<base::ListValue> args) { |
260 if (!ExtensionSystem::Get(profile_)->event_router()) | 254 EventRouter* event_router = EventRouter::Get(profile_); |
| 255 if (!event_router) |
261 return; | 256 return; |
262 | 257 |
263 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 258 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
264 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 259 event_router->BroadcastEvent(event.Pass()); |
265 } | 260 } |
266 | 261 |
267 void BookmarkManagerPrivateDragEventRouter::OnDragEnter( | 262 void BookmarkManagerPrivateDragEventRouter::OnDragEnter( |
268 const BookmarkNodeData& data) { | 263 const BookmarkNodeData& data) { |
269 if (data.size() == 0) | 264 if (data.size() == 0) |
270 return; | 265 return; |
271 DispatchEvent(bookmark_manager_private::OnDragEnter::kEventName, | 266 DispatchEvent(bookmark_manager_private::OnDragEnter::kEventName, |
272 bookmark_manager_private::OnDragEnter::Create( | 267 bookmark_manager_private::OnDragEnter::Create( |
273 *CreateApiBookmarkNodeData(profile_, data))); | 268 *CreateApiBookmarkNodeData(profile_, data))); |
274 } | 269 } |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 result.enabled = undo_manager->redo_count() > 0; | 697 result.enabled = undo_manager->redo_count() > 0; |
703 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); | 698 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); |
704 | 699 |
705 results_ = RedoInfo::Results::Create(result); | 700 results_ = RedoInfo::Results::Create(result); |
706 #endif // !defined(OS_ANDROID) | 701 #endif // !defined(OS_ANDROID) |
707 | 702 |
708 return true; | 703 return true; |
709 } | 704 } |
710 | 705 |
711 } // namespace extensions | 706 } // namespace extensions |
OLD | NEW |