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 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" | 5 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 for (size_t i = 0; i < elements.size(); ++i) | 139 for (size_t i = 0; i < elements.size(); ++i) |
140 AddElementToList(list, elements[i]); | 140 AddElementToList(list, elements[i]); |
141 } | 141 } |
142 value->Set(keys::kElementsKey, list); | 142 value->Set(keys::kElementsKey, list); |
143 | 143 |
144 args->Append(value); | 144 args->Append(value); |
145 } | 145 } |
146 | 146 |
147 } // namespace | 147 } // namespace |
148 | 148 |
149 ExtensionBookmarkManagerEventRouter::ExtensionBookmarkManagerEventRouter( | 149 BookmarkManagerExtensionEventRouter::BookmarkManagerExtensionEventRouter( |
150 Profile* profile, TabContentsWrapper* tab) | 150 Profile* profile, TabContentsWrapper* tab) |
151 : profile_(profile), | 151 : profile_(profile), |
152 tab_(tab) { | 152 tab_(tab) { |
153 tab_->bookmark_tab_helper()->SetBookmarkDragDelegate(this); | 153 tab_->bookmark_tab_helper()->SetBookmarkDragDelegate(this); |
154 } | 154 } |
155 | 155 |
156 ExtensionBookmarkManagerEventRouter::~ExtensionBookmarkManagerEventRouter() { | 156 BookmarkManagerExtensionEventRouter::~BookmarkManagerExtensionEventRouter() { |
157 if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate() == this) | 157 if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate() == this) |
158 tab_->bookmark_tab_helper()->SetBookmarkDragDelegate(NULL); | 158 tab_->bookmark_tab_helper()->SetBookmarkDragDelegate(NULL); |
159 } | 159 } |
160 | 160 |
161 void ExtensionBookmarkManagerEventRouter::DispatchEvent(const char* event_name, | 161 void BookmarkManagerExtensionEventRouter::DispatchEvent(const char* event_name, |
162 const ListValue* args) { | 162 const ListValue* args) { |
163 if (!profile_->GetExtensionEventRouter()) | 163 if (!profile_->GetExtensionEventRouter()) |
164 return; | 164 return; |
165 | 165 |
166 std::string json_args; | 166 std::string json_args; |
167 base::JSONWriter::Write(args, false, &json_args); | 167 base::JSONWriter::Write(args, false, &json_args); |
168 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 168 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
169 event_name, json_args, NULL, GURL()); | 169 event_name, json_args, NULL, GURL()); |
170 } | 170 } |
171 | 171 |
172 void ExtensionBookmarkManagerEventRouter::DispatchDragEvent( | 172 void BookmarkManagerExtensionEventRouter::DispatchDragEvent( |
173 const BookmarkNodeData& data, const char* event_name) { | 173 const BookmarkNodeData& data, const char* event_name) { |
174 if (data.size() == 0) | 174 if (data.size() == 0) |
175 return; | 175 return; |
176 | 176 |
177 ListValue args; | 177 ListValue args; |
178 BookmarkNodeDataToJSON(profile_, data, &args); | 178 BookmarkNodeDataToJSON(profile_, data, &args); |
179 DispatchEvent(event_name, &args); | 179 DispatchEvent(event_name, &args); |
180 } | 180 } |
181 | 181 |
182 void ExtensionBookmarkManagerEventRouter::OnDragEnter( | 182 void BookmarkManagerExtensionEventRouter::OnDragEnter( |
183 const BookmarkNodeData& data) { | 183 const BookmarkNodeData& data) { |
184 DispatchDragEvent(data, keys::kOnBookmarkDragEnter); | 184 DispatchDragEvent(data, keys::kOnBookmarkDragEnter); |
185 } | 185 } |
186 | 186 |
187 void ExtensionBookmarkManagerEventRouter::OnDragOver( | 187 void BookmarkManagerExtensionEventRouter::OnDragOver( |
188 const BookmarkNodeData& data) { | 188 const BookmarkNodeData& data) { |
189 // Intentionally empty since these events happens too often and floods the | 189 // Intentionally empty since these events happens too often and floods the |
190 // message queue. We do not need this event for the bookmark manager anyway. | 190 // message queue. We do not need this event for the bookmark manager anyway. |
191 } | 191 } |
192 | 192 |
193 void ExtensionBookmarkManagerEventRouter::OnDragLeave( | 193 void BookmarkManagerExtensionEventRouter::OnDragLeave( |
194 const BookmarkNodeData& data) { | 194 const BookmarkNodeData& data) { |
195 DispatchDragEvent(data, keys::kOnBookmarkDragLeave); | 195 DispatchDragEvent(data, keys::kOnBookmarkDragLeave); |
196 } | 196 } |
197 | 197 |
198 void ExtensionBookmarkManagerEventRouter::OnDrop( | 198 void BookmarkManagerExtensionEventRouter::OnDrop( |
199 const BookmarkNodeData& data) { | 199 const BookmarkNodeData& data) { |
200 DispatchDragEvent(data, keys::kOnBookmarkDrop); | 200 DispatchDragEvent(data, keys::kOnBookmarkDrop); |
201 | 201 |
202 // Make a copy that is owned by this instance. | 202 // Make a copy that is owned by this instance. |
203 ClearBookmarkNodeData(); | 203 ClearBookmarkNodeData(); |
204 bookmark_drag_data_ = data; | 204 bookmark_drag_data_ = data; |
205 } | 205 } |
206 | 206 |
207 const BookmarkNodeData* | 207 const BookmarkNodeData* |
208 ExtensionBookmarkManagerEventRouter::GetBookmarkNodeData() { | 208 BookmarkManagerExtensionEventRouter::GetBookmarkNodeData() { |
209 if (bookmark_drag_data_.is_valid()) | 209 if (bookmark_drag_data_.is_valid()) |
210 return &bookmark_drag_data_; | 210 return &bookmark_drag_data_; |
211 return NULL; | 211 return NULL; |
212 } | 212 } |
213 | 213 |
214 void ExtensionBookmarkManagerEventRouter::ClearBookmarkNodeData() { | 214 void BookmarkManagerExtensionEventRouter::ClearBookmarkNodeData() { |
215 bookmark_drag_data_.Clear(); | 215 bookmark_drag_data_.Clear(); |
216 } | 216 } |
217 | 217 |
218 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut) { | 218 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut) { |
219 BookmarkModel* model = profile()->GetBookmarkModel(); | 219 BookmarkModel* model = profile()->GetBookmarkModel(); |
220 std::vector<const BookmarkNode*> nodes; | 220 std::vector<const BookmarkNode*> nodes; |
221 EXTENSION_FUNCTION_VALIDATE(GetNodesFromArguments(model, args_.get(), | 221 EXTENSION_FUNCTION_VALIDATE(GetNodesFromArguments(model, args_.get(), |
222 0, &nodes)); | 222 0, &nodes)); |
223 bookmark_utils::CopyToClipboard(model, nodes, cut); | 223 bookmark_utils::CopyToClipboard(model, nodes, cut); |
224 return true; | 224 return true; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 drop_index = drop_parent->child_count(); | 413 drop_index = drop_parent->child_count(); |
414 | 414 |
415 if (render_view_host_->delegate()->GetRenderViewType() == | 415 if (render_view_host_->delegate()->GetRenderViewType() == |
416 content::VIEW_TYPE_TAB_CONTENTS) { | 416 content::VIEW_TYPE_TAB_CONTENTS) { |
417 TabContents* tab_contents = | 417 TabContents* tab_contents = |
418 dispatcher()->delegate()->GetAssociatedTabContents(); | 418 dispatcher()->delegate()->GetAssociatedTabContents(); |
419 CHECK(tab_contents); | 419 CHECK(tab_contents); |
420 ExtensionWebUI* web_ui = | 420 ExtensionWebUI* web_ui = |
421 static_cast<ExtensionWebUI*>(tab_contents->web_ui()); | 421 static_cast<ExtensionWebUI*>(tab_contents->web_ui()); |
422 CHECK(web_ui); | 422 CHECK(web_ui); |
423 ExtensionBookmarkManagerEventRouter* router = | 423 BookmarkManagerExtensionEventRouter* router = |
424 web_ui->extension_bookmark_manager_event_router(); | 424 web_ui->bookmark_manager_extension_event_router(); |
425 | 425 |
426 DCHECK(router); | 426 DCHECK(router); |
427 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); | 427 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); |
428 if (drag_data == NULL) { | 428 if (drag_data == NULL) { |
429 NOTREACHED() <<"Somehow we're dropping null bookmark data"; | 429 NOTREACHED() <<"Somehow we're dropping null bookmark data"; |
430 return false; | 430 return false; |
431 } | 431 } |
432 bookmark_utils::PerformBookmarkDrop(profile(), | 432 bookmark_utils::PerformBookmarkDrop(profile(), |
433 *drag_data, | 433 *drag_data, |
434 drop_parent, drop_index); | 434 drop_parent, drop_index); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 bool CanEditBookmarkManagerFunction::RunImpl() { | 478 bool CanEditBookmarkManagerFunction::RunImpl() { |
479 result_.reset(Value::CreateBooleanValue( | 479 result_.reset(Value::CreateBooleanValue( |
480 profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled))); | 480 profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled))); |
481 return true; | 481 return true; |
482 } | 482 } |
483 | 483 |
484 bool RecordLaunchBookmarkFunction::RunImpl() { | 484 bool RecordLaunchBookmarkFunction::RunImpl() { |
485 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_MANAGER); | 485 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_MANAGER); |
486 return true; | 486 return true; |
487 } | 487 } |
OLD | NEW |