Index: chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc |
diff --git a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc |
index bfe4f352c373da4af3575d6c001dae5a4421ee87..b27b6cd135a4ee1c7c5f2477e5978c8bec6d4838 100644 |
--- a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc |
+++ b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc |
@@ -21,11 +21,11 @@ |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" |
#include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" |
-#include "chrome/browser/extensions/extension_web_ui.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" |
#include "chrome/browser/undo/bookmark_undo_service_factory.h" |
#include "chrome/common/extensions/api/bookmark_manager_private.h" |
+#include "chrome/common/extensions/extension_constants.h" |
#include "chrome/grit/generated_resources.h" |
#include "components/bookmarks/browser/bookmark_model.h" |
#include "components/bookmarks/browser/bookmark_node_data.h" |
@@ -41,6 +41,7 @@ |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_ui.h" |
#include "extensions/browser/extension_function_dispatcher.h" |
+#include "extensions/browser/extension_registry.h" |
#include "extensions/browser/view_type_utils.h" |
#include "ui/base/dragdrop/drag_drop_types.h" |
#include "ui/base/l10n/l10n_util.h" |
@@ -51,6 +52,9 @@ using bookmarks::BookmarkNode; |
using bookmarks::BookmarkNodeData; |
using content::WebContents; |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
+ extensions::BookmarkManagerPrivateDragEventRouter); |
+ |
namespace extensions { |
namespace bookmark_keys = bookmark_api_constants; |
@@ -283,9 +287,10 @@ void BookmarkManagerPrivateAPI::OnListenerAdded( |
} |
BookmarkManagerPrivateDragEventRouter::BookmarkManagerPrivateDragEventRouter( |
- Profile* profile, |
content::WebContents* web_contents) |
- : profile_(profile), web_contents_(web_contents) { |
+ : web_contents_(web_contents), |
+ profile_( |
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext())) { |
BookmarkTabHelper* bookmark_tab_helper = |
BookmarkTabHelper::FromWebContents(web_contents_); |
bookmark_tab_helper->set_bookmark_drag_delegate(this); |
@@ -299,6 +304,18 @@ BookmarkManagerPrivateDragEventRouter:: |
bookmark_tab_helper->set_bookmark_drag_delegate(NULL); |
} |
+void BookmarkManagerPrivateDragEventRouter::MaybeCreateForWebContents( |
+ content::WebContents* web_contents) { |
+ content::BrowserContext* context = web_contents->GetBrowserContext(); |
+ const Extension* extension = |
+ ExtensionRegistry::Get(context) |
+ ->enabled_extensions() |
+ .GetExtensionOrAppByURL( |
+ web_contents->GetSiteInstance()->GetSiteURL()); |
+ if (extension && extension->id() == extension_misc::kBookmarkManagerId) |
+ CreateForWebContents(web_contents); |
+} |
+ |
void BookmarkManagerPrivateDragEventRouter::DispatchEvent( |
events::HistogramValue histogram_value, |
const std::string& event_name, |
@@ -600,11 +617,8 @@ bool BookmarkManagerPrivateDropFunction::RunOnReady() { |
WebContents* web_contents = GetAssociatedWebContents(); |
CHECK(web_contents); |
- ExtensionWebUI* web_ui = |
- static_cast<ExtensionWebUI*>(web_contents->GetWebUI()->GetController()); |
- CHECK(web_ui); |
BookmarkManagerPrivateDragEventRouter* router = |
- web_ui->bookmark_manager_private_drag_event_router(); |
+ BookmarkManagerPrivateDragEventRouter::FromWebContents(web_contents); |
DCHECK(router); |
const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); |