| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 175 } |
| 177 | 176 |
| 178 BookmarkManagerPrivateEventRouter::~BookmarkManagerPrivateEventRouter() { | 177 BookmarkManagerPrivateEventRouter::~BookmarkManagerPrivateEventRouter() { |
| 179 if (bookmark_model_) | 178 if (bookmark_model_) |
| 180 bookmark_model_->RemoveObserver(this); | 179 bookmark_model_->RemoveObserver(this); |
| 181 } | 180 } |
| 182 | 181 |
| 183 void BookmarkManagerPrivateEventRouter::DispatchEvent( | 182 void BookmarkManagerPrivateEventRouter::DispatchEvent( |
| 184 const std::string& event_name, | 183 const std::string& event_name, |
| 185 scoped_ptr<base::ListValue> event_args) { | 184 scoped_ptr<base::ListValue> event_args) { |
| 186 extensions::ExtensionSystem::Get(browser_context_) | 185 extensions::EventRouter::Get(browser_context_)->BroadcastEvent( |
| 187 ->event_router() | 186 make_scoped_ptr(new extensions::Event(event_name, event_args.Pass()))); |
| 188 ->BroadcastEvent(make_scoped_ptr( | |
| 189 new extensions::Event(event_name, event_args.Pass()))); | |
| 190 } | 187 } |
| 191 | 188 |
| 192 void BookmarkManagerPrivateEventRouter::BookmarkModelChanged() {} | 189 void BookmarkManagerPrivateEventRouter::BookmarkModelChanged() {} |
| 193 | 190 |
| 194 void BookmarkManagerPrivateEventRouter::BookmarkModelBeingDeleted( | 191 void BookmarkManagerPrivateEventRouter::BookmarkModelBeingDeleted( |
| 195 BookmarkModel* model) { | 192 BookmarkModel* model) { |
| 196 bookmark_model_ = NULL; | 193 bookmark_model_ = NULL; |
| 197 } | 194 } |
| 198 | 195 |
| 199 void BookmarkManagerPrivateEventRouter::BookmarkMetaInfoChanged( | 196 void BookmarkManagerPrivateEventRouter::BookmarkMetaInfoChanged( |
| 200 BookmarkModel* model, | 197 BookmarkModel* model, |
| 201 const BookmarkNode* node) { | 198 const BookmarkNode* node) { |
| 202 DispatchEvent(bookmark_manager_private::OnMetaInfoChanged::kEventName, | 199 DispatchEvent(bookmark_manager_private::OnMetaInfoChanged::kEventName, |
| 203 bookmark_manager_private::OnMetaInfoChanged::Create( | 200 bookmark_manager_private::OnMetaInfoChanged::Create( |
| 204 base::Int64ToString(node->id()))); | 201 base::Int64ToString(node->id()))); |
| 205 } | 202 } |
| 206 | 203 |
| 207 BookmarkManagerPrivateAPI::BookmarkManagerPrivateAPI( | 204 BookmarkManagerPrivateAPI::BookmarkManagerPrivateAPI( |
| 208 content::BrowserContext* browser_context) | 205 content::BrowserContext* browser_context) |
| 209 : browser_context_(browser_context) { | 206 : browser_context_(browser_context) { |
| 210 EventRouter* event_router = | 207 EventRouter* event_router = EventRouter::Get(browser_context); |
| 211 ExtensionSystem::Get(browser_context)->event_router(); | |
| 212 event_router->RegisterObserver( | 208 event_router->RegisterObserver( |
| 213 this, bookmark_manager_private::OnMetaInfoChanged::kEventName); | 209 this, bookmark_manager_private::OnMetaInfoChanged::kEventName); |
| 214 } | 210 } |
| 215 | 211 |
| 216 BookmarkManagerPrivateAPI::~BookmarkManagerPrivateAPI() {} | 212 BookmarkManagerPrivateAPI::~BookmarkManagerPrivateAPI() {} |
| 217 | 213 |
| 218 void BookmarkManagerPrivateAPI::Shutdown() { | 214 void BookmarkManagerPrivateAPI::Shutdown() { |
| 219 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 215 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 220 this); | |
| 221 } | 216 } |
| 222 | 217 |
| 223 static base::LazyInstance< | 218 static base::LazyInstance< |
| 224 BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI> > g_factory = | 219 BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI> > g_factory = |
| 225 LAZY_INSTANCE_INITIALIZER; | 220 LAZY_INSTANCE_INITIALIZER; |
| 226 | 221 |
| 227 // static | 222 // static |
| 228 BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI>* | 223 BrowserContextKeyedAPIFactory<BookmarkManagerPrivateAPI>* |
| 229 BookmarkManagerPrivateAPI::GetFactoryInstance() { | 224 BookmarkManagerPrivateAPI::GetFactoryInstance() { |
| 230 return g_factory.Pointer(); | 225 return g_factory.Pointer(); |
| 231 } | 226 } |
| 232 | 227 |
| 233 void BookmarkManagerPrivateAPI::OnListenerAdded( | 228 void BookmarkManagerPrivateAPI::OnListenerAdded( |
| 234 const EventListenerInfo& details) { | 229 const EventListenerInfo& details) { |
| 235 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 230 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 236 this); | |
| 237 event_router_.reset(new BookmarkManagerPrivateEventRouter( | 231 event_router_.reset(new BookmarkManagerPrivateEventRouter( |
| 238 browser_context_, | 232 browser_context_, |
| 239 BookmarkModelFactory::GetForProfile( | 233 BookmarkModelFactory::GetForProfile( |
| 240 Profile::FromBrowserContext(browser_context_)))); | 234 Profile::FromBrowserContext(browser_context_)))); |
| 241 } | 235 } |
| 242 | 236 |
| 243 BookmarkManagerPrivateDragEventRouter::BookmarkManagerPrivateDragEventRouter( | 237 BookmarkManagerPrivateDragEventRouter::BookmarkManagerPrivateDragEventRouter( |
| 244 Profile* profile, | 238 Profile* profile, |
| 245 content::WebContents* web_contents) | 239 content::WebContents* web_contents) |
| 246 : profile_(profile), web_contents_(web_contents) { | 240 : profile_(profile), web_contents_(web_contents) { |
| 247 BookmarkTabHelper* bookmark_tab_helper = | 241 BookmarkTabHelper* bookmark_tab_helper = |
| 248 BookmarkTabHelper::FromWebContents(web_contents_); | 242 BookmarkTabHelper::FromWebContents(web_contents_); |
| 249 bookmark_tab_helper->set_bookmark_drag_delegate(this); | 243 bookmark_tab_helper->set_bookmark_drag_delegate(this); |
| 250 } | 244 } |
| 251 | 245 |
| 252 BookmarkManagerPrivateDragEventRouter:: | 246 BookmarkManagerPrivateDragEventRouter:: |
| 253 ~BookmarkManagerPrivateDragEventRouter() { | 247 ~BookmarkManagerPrivateDragEventRouter() { |
| 254 BookmarkTabHelper* bookmark_tab_helper = | 248 BookmarkTabHelper* bookmark_tab_helper = |
| 255 BookmarkTabHelper::FromWebContents(web_contents_); | 249 BookmarkTabHelper::FromWebContents(web_contents_); |
| 256 if (bookmark_tab_helper->bookmark_drag_delegate() == this) | 250 if (bookmark_tab_helper->bookmark_drag_delegate() == this) |
| 257 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); | 251 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); |
| 258 } | 252 } |
| 259 | 253 |
| 260 void BookmarkManagerPrivateDragEventRouter::DispatchEvent( | 254 void BookmarkManagerPrivateDragEventRouter::DispatchEvent( |
| 261 const std::string& event_name, | 255 const std::string& event_name, |
| 262 scoped_ptr<base::ListValue> args) { | 256 scoped_ptr<base::ListValue> args) { |
| 263 if (!ExtensionSystem::Get(profile_)->event_router()) | 257 EventRouter* event_router = EventRouter::Get(profile_); |
| 258 if (!event_router) |
| 264 return; | 259 return; |
| 265 | 260 |
| 266 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 261 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
| 267 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 262 event_router->BroadcastEvent(event.Pass()); |
| 268 } | 263 } |
| 269 | 264 |
| 270 void BookmarkManagerPrivateDragEventRouter::OnDragEnter( | 265 void BookmarkManagerPrivateDragEventRouter::OnDragEnter( |
| 271 const BookmarkNodeData& data) { | 266 const BookmarkNodeData& data) { |
| 272 if (data.size() == 0) | 267 if (data.size() == 0) |
| 273 return; | 268 return; |
| 274 DispatchEvent(bookmark_manager_private::OnDragEnter::kEventName, | 269 DispatchEvent(bookmark_manager_private::OnDragEnter::kEventName, |
| 275 bookmark_manager_private::OnDragEnter::Create( | 270 bookmark_manager_private::OnDragEnter::Create( |
| 276 *CreateApiBookmarkNodeData(profile_, data))); | 271 *CreateApiBookmarkNodeData(profile_, data))); |
| 277 } | 272 } |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 result.enabled = undo_manager->redo_count() > 0; | 700 result.enabled = undo_manager->redo_count() > 0; |
| 706 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); | 701 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); |
| 707 | 702 |
| 708 results_ = RedoInfo::Results::Create(result); | 703 results_ = RedoInfo::Results::Create(result); |
| 709 #endif // !defined(OS_ANDROID) | 704 #endif // !defined(OS_ANDROID) |
| 710 | 705 |
| 711 return true; | 706 return true; |
| 712 } | 707 } |
| 713 | 708 |
| 714 } // namespace extensions | 709 } // namespace extensions |
| OLD | NEW |