| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 20 #include "chrome/browser/bookmarks/bookmark_stats.h" | 20 #include "chrome/browser/bookmarks/bookmark_stats.h" |
| 21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" | 22 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" |
| 23 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" | 23 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" |
| 24 #include "chrome/browser/extensions/extension_web_ui.h" | |
| 25 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" | 25 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" |
| 27 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 26 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
| 28 #include "chrome/common/extensions/api/bookmark_manager_private.h" | 27 #include "chrome/common/extensions/api/bookmark_manager_private.h" |
| 28 #include "chrome/common/extensions/extension_constants.h" |
| 29 #include "chrome/grit/generated_resources.h" | 29 #include "chrome/grit/generated_resources.h" |
| 30 #include "components/bookmarks/browser/bookmark_model.h" | 30 #include "components/bookmarks/browser/bookmark_model.h" |
| 31 #include "components/bookmarks/browser/bookmark_node_data.h" | 31 #include "components/bookmarks/browser/bookmark_node_data.h" |
| 32 #include "components/bookmarks/browser/bookmark_utils.h" | 32 #include "components/bookmarks/browser/bookmark_utils.h" |
| 33 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" | 33 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" |
| 34 #include "components/bookmarks/common/bookmark_pref_names.h" | 34 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 35 #include "components/bookmarks/managed/managed_bookmark_service.h" | 35 #include "components/bookmarks/managed/managed_bookmark_service.h" |
| 36 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 37 #include "components/strings/grit/components_strings.h" | 37 #include "components/strings/grit/components_strings.h" |
| 38 #include "components/undo/bookmark_undo_service.h" | 38 #include "components/undo/bookmark_undo_service.h" |
| 39 #include "components/user_prefs/user_prefs.h" | 39 #include "components/user_prefs/user_prefs.h" |
| 40 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
| 41 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 42 #include "content/public/browser/web_ui.h" | 42 #include "content/public/browser/web_ui.h" |
| 43 #include "extensions/browser/extension_function_dispatcher.h" | 43 #include "extensions/browser/extension_function_dispatcher.h" |
| 44 #include "extensions/browser/extension_registry.h" |
| 44 #include "extensions/browser/view_type_utils.h" | 45 #include "extensions/browser/view_type_utils.h" |
| 45 #include "ui/base/dragdrop/drag_drop_types.h" | 46 #include "ui/base/dragdrop/drag_drop_types.h" |
| 46 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 47 #include "ui/base/webui/web_ui_util.h" | 48 #include "ui/base/webui/web_ui_util.h" |
| 48 | 49 |
| 49 using bookmarks::BookmarkModel; | 50 using bookmarks::BookmarkModel; |
| 50 using bookmarks::BookmarkNode; | 51 using bookmarks::BookmarkNode; |
| 51 using bookmarks::BookmarkNodeData; | 52 using bookmarks::BookmarkNodeData; |
| 52 using content::WebContents; | 53 using content::WebContents; |
| 53 | 54 |
| 55 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 56 extensions::BookmarkManagerPrivateDragEventRouter); |
| 57 |
| 54 namespace extensions { | 58 namespace extensions { |
| 55 | 59 |
| 56 namespace bookmark_keys = bookmark_api_constants; | 60 namespace bookmark_keys = bookmark_api_constants; |
| 57 namespace bookmark_manager_private = api::bookmark_manager_private; | 61 namespace bookmark_manager_private = api::bookmark_manager_private; |
| 58 namespace CanPaste = api::bookmark_manager_private::CanPaste; | 62 namespace CanPaste = api::bookmark_manager_private::CanPaste; |
| 59 namespace Copy = api::bookmark_manager_private::Copy; | 63 namespace Copy = api::bookmark_manager_private::Copy; |
| 60 namespace CreateWithMetaInfo = | 64 namespace CreateWithMetaInfo = |
| 61 api::bookmark_manager_private::CreateWithMetaInfo; | 65 api::bookmark_manager_private::CreateWithMetaInfo; |
| 62 namespace Cut = api::bookmark_manager_private::Cut; | 66 namespace Cut = api::bookmark_manager_private::Cut; |
| 63 namespace Drop = api::bookmark_manager_private::Drop; | 67 namespace Drop = api::bookmark_manager_private::Drop; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 280 |
| 277 void BookmarkManagerPrivateAPI::OnListenerAdded( | 281 void BookmarkManagerPrivateAPI::OnListenerAdded( |
| 278 const EventListenerInfo& details) { | 282 const EventListenerInfo& details) { |
| 279 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 283 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 280 event_router_.reset(new BookmarkManagerPrivateEventRouter( | 284 event_router_.reset(new BookmarkManagerPrivateEventRouter( |
| 281 browser_context_, | 285 browser_context_, |
| 282 BookmarkModelFactory::GetForBrowserContext(browser_context_))); | 286 BookmarkModelFactory::GetForBrowserContext(browser_context_))); |
| 283 } | 287 } |
| 284 | 288 |
| 285 BookmarkManagerPrivateDragEventRouter::BookmarkManagerPrivateDragEventRouter( | 289 BookmarkManagerPrivateDragEventRouter::BookmarkManagerPrivateDragEventRouter( |
| 286 Profile* profile, | |
| 287 content::WebContents* web_contents) | 290 content::WebContents* web_contents) |
| 288 : profile_(profile), web_contents_(web_contents) { | 291 : web_contents_(web_contents), |
| 292 profile_( |
| 293 Profile::FromBrowserContext(web_contents_->GetBrowserContext())) { |
| 289 BookmarkTabHelper* bookmark_tab_helper = | 294 BookmarkTabHelper* bookmark_tab_helper = |
| 290 BookmarkTabHelper::FromWebContents(web_contents_); | 295 BookmarkTabHelper::FromWebContents(web_contents_); |
| 291 bookmark_tab_helper->set_bookmark_drag_delegate(this); | 296 bookmark_tab_helper->set_bookmark_drag_delegate(this); |
| 292 } | 297 } |
| 293 | 298 |
| 294 BookmarkManagerPrivateDragEventRouter:: | 299 BookmarkManagerPrivateDragEventRouter:: |
| 295 ~BookmarkManagerPrivateDragEventRouter() { | 300 ~BookmarkManagerPrivateDragEventRouter() { |
| 296 BookmarkTabHelper* bookmark_tab_helper = | 301 BookmarkTabHelper* bookmark_tab_helper = |
| 297 BookmarkTabHelper::FromWebContents(web_contents_); | 302 BookmarkTabHelper::FromWebContents(web_contents_); |
| 298 if (bookmark_tab_helper->bookmark_drag_delegate() == this) | 303 if (bookmark_tab_helper->bookmark_drag_delegate() == this) |
| 299 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); | 304 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); |
| 300 } | 305 } |
| 301 | 306 |
| 307 void BookmarkManagerPrivateDragEventRouter::MaybeCreateForWebContents( |
| 308 content::WebContents* web_contents) { |
| 309 content::BrowserContext* context = web_contents->GetBrowserContext(); |
| 310 const Extension* extension = |
| 311 ExtensionRegistry::Get(context) |
| 312 ->enabled_extensions() |
| 313 .GetExtensionOrAppByURL( |
| 314 web_contents->GetSiteInstance()->GetSiteURL()); |
| 315 if (extension && extension->id() == extension_misc::kBookmarkManagerId) |
| 316 CreateForWebContents(web_contents); |
| 317 } |
| 318 |
| 302 void BookmarkManagerPrivateDragEventRouter::DispatchEvent( | 319 void BookmarkManagerPrivateDragEventRouter::DispatchEvent( |
| 303 events::HistogramValue histogram_value, | 320 events::HistogramValue histogram_value, |
| 304 const std::string& event_name, | 321 const std::string& event_name, |
| 305 std::unique_ptr<base::ListValue> args) { | 322 std::unique_ptr<base::ListValue> args) { |
| 306 EventRouter* event_router = EventRouter::Get(profile_); | 323 EventRouter* event_router = EventRouter::Get(profile_); |
| 307 if (!event_router) | 324 if (!event_router) |
| 308 return; | 325 return; |
| 309 | 326 |
| 310 std::unique_ptr<Event> event( | 327 std::unique_ptr<Event> event( |
| 311 new Event(histogram_value, event_name, std::move(args))); | 328 new Event(histogram_value, event_name, std::move(args))); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 } | 610 } |
| 594 | 611 |
| 595 int drop_index; | 612 int drop_index; |
| 596 if (params->index) | 613 if (params->index) |
| 597 drop_index = *params->index; | 614 drop_index = *params->index; |
| 598 else | 615 else |
| 599 drop_index = drop_parent->child_count(); | 616 drop_index = drop_parent->child_count(); |
| 600 | 617 |
| 601 WebContents* web_contents = GetAssociatedWebContents(); | 618 WebContents* web_contents = GetAssociatedWebContents(); |
| 602 CHECK(web_contents); | 619 CHECK(web_contents); |
| 603 ExtensionWebUI* web_ui = | |
| 604 static_cast<ExtensionWebUI*>(web_contents->GetWebUI()->GetController()); | |
| 605 CHECK(web_ui); | |
| 606 BookmarkManagerPrivateDragEventRouter* router = | 620 BookmarkManagerPrivateDragEventRouter* router = |
| 607 web_ui->bookmark_manager_private_drag_event_router(); | 621 BookmarkManagerPrivateDragEventRouter::FromWebContents(web_contents); |
| 608 | 622 |
| 609 DCHECK(router); | 623 DCHECK(router); |
| 610 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); | 624 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); |
| 611 if (drag_data == NULL) { | 625 if (drag_data == NULL) { |
| 612 NOTREACHED() <<"Somehow we're dropping null bookmark data"; | 626 NOTREACHED() <<"Somehow we're dropping null bookmark data"; |
| 613 return false; | 627 return false; |
| 614 } | 628 } |
| 615 const bool copy = false; | 629 const bool copy = false; |
| 616 chrome::DropBookmarks( | 630 chrome::DropBookmarks( |
| 617 GetProfile(), *drag_data, drop_parent, drop_index, copy); | 631 GetProfile(), *drag_data, drop_parent, drop_index, copy); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 | 872 |
| 859 RedoInfo::Results::Result result; | 873 RedoInfo::Results::Result result; |
| 860 result.enabled = undo_manager->redo_count() > 0; | 874 result.enabled = undo_manager->redo_count() > 0; |
| 861 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); | 875 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); |
| 862 | 876 |
| 863 results_ = RedoInfo::Results::Create(result); | 877 results_ = RedoInfo::Results::Create(result); |
| 864 return true; | 878 return true; |
| 865 } | 879 } |
| 866 | 880 |
| 867 } // namespace extensions | 881 } // namespace extensions |
| OLD | NEW |