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/bookmarks/bookmark_manager_extension_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/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/prefs/public/pref_service_base.h" | 10 #include "base/prefs/public/pref_service_base.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/bookmarks/bookmark_model.h" | 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
15 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 15 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
16 #include "chrome/browser/bookmarks/bookmark_utils.h" | 16 #include "chrome/browser/bookmarks/bookmark_utils.h" |
17 // TODO (rdevlin.cronin): Move BookmarkManagerAPI to | 17 #include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manage
r_private_api_constants.h" |
18 // chrome/browser/extensions/api so these two aren't interdependent. | |
19 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" | 18 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" |
20 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" | 19 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" |
21 #include "chrome/browser/extensions/event_router.h" | 20 #include "chrome/browser/extensions/event_router.h" |
22 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 21 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
23 #include "chrome/browser/extensions/extension_system.h" | 22 #include "chrome/browser/extensions/extension_system.h" |
24 #include "chrome/browser/extensions/extension_web_ui.h" | 23 #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/webui/chrome_url_data_manager.h" | 25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
27 #include "chrome/browser/view_type_utils.h" | 26 #include "chrome/browser/view_type_utils.h" |
28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
29 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
31 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
32 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
33 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
34 | 33 |
35 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
36 #include "win8/util/win8_util.h" | 35 #include "win8/util/win8_util.h" |
37 #endif // OS_WIN | 36 #endif // OS_WIN |
38 | 37 |
39 namespace keys = extensions::bookmark_api_constants; | 38 namespace extensions { |
| 39 |
| 40 namespace bookmark_keys = bookmark_api_constants; |
| 41 namespace manager_keys = bookmark_manager_api_constants; |
40 | 42 |
41 using content::WebContents; | 43 using content::WebContents; |
42 | 44 |
43 namespace { | 45 namespace { |
44 | 46 |
45 // Returns a single bookmark node from the argument ID. | 47 // Returns a single bookmark node from the argument ID. |
46 // This returns NULL in case of failure. | 48 // This returns NULL in case of failure. |
47 const BookmarkNode* GetNodeFromArguments(BookmarkModel* model, | 49 const BookmarkNode* GetNodeFromArguments(BookmarkModel* model, |
48 const ListValue* args) { | 50 const ListValue* args) { |
49 std::string id_string; | 51 std::string id_string; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 88 |
87 // Recursively adds a node to a list. This is by used |BookmarkNodeDataToJSON| | 89 // Recursively adds a node to a list. This is by used |BookmarkNodeDataToJSON| |
88 // when the data comes from the current profile. In this case we have a | 90 // when the data comes from the current profile. In this case we have a |
89 // BookmarkNode since we got the data from the current profile. | 91 // BookmarkNode since we got the data from the current profile. |
90 void AddNodeToList(ListValue* list, const BookmarkNode& node) { | 92 void AddNodeToList(ListValue* list, const BookmarkNode& node) { |
91 DictionaryValue* dict = new DictionaryValue(); | 93 DictionaryValue* dict = new DictionaryValue(); |
92 | 94 |
93 // Add id and parentId so we can associate the data with existing nodes on the | 95 // Add id and parentId so we can associate the data with existing nodes on the |
94 // client side. | 96 // client side. |
95 std::string id_string = base::Int64ToString(node.id()); | 97 std::string id_string = base::Int64ToString(node.id()); |
96 dict->SetString(keys::kIdKey, id_string); | 98 dict->SetString(bookmark_keys::kIdKey, id_string); |
97 | 99 |
98 std::string parent_id_string = base::Int64ToString(node.parent()->id()); | 100 std::string parent_id_string = base::Int64ToString(node.parent()->id()); |
99 dict->SetString(keys::kParentIdKey, parent_id_string); | 101 dict->SetString(bookmark_keys::kParentIdKey, parent_id_string); |
100 | 102 |
101 if (node.is_url()) | 103 if (node.is_url()) |
102 dict->SetString(keys::kUrlKey, node.url().spec()); | 104 dict->SetString(bookmark_keys::kUrlKey, node.url().spec()); |
103 | 105 |
104 dict->SetString(keys::kTitleKey, node.GetTitle()); | 106 dict->SetString(bookmark_keys::kTitleKey, node.GetTitle()); |
105 | 107 |
106 ListValue* children = new ListValue(); | 108 ListValue* children = new ListValue(); |
107 for (int i = 0; i < node.child_count(); ++i) | 109 for (int i = 0; i < node.child_count(); ++i) |
108 AddNodeToList(children, *node.GetChild(i)); | 110 AddNodeToList(children, *node.GetChild(i)); |
109 dict->Set(keys::kChildrenKey, children); | 111 dict->Set(bookmark_keys::kChildrenKey, children); |
110 | 112 |
111 list->Append(dict); | 113 list->Append(dict); |
112 } | 114 } |
113 | 115 |
114 // Recursively adds an element to a list. This is used by | 116 // Recursively adds an element to a list. This is used by |
115 // |BookmarkNodeDataToJSON| when the data comes from a different profile. When | 117 // |BookmarkNodeDataToJSON| when the data comes from a different profile. When |
116 // the data comes from a different profile we do not have any IDs or parent IDs. | 118 // the data comes from a different profile we do not have any IDs or parent IDs. |
117 void AddElementToList(ListValue* list, | 119 void AddElementToList(ListValue* list, |
118 const BookmarkNodeData::Element& element) { | 120 const BookmarkNodeData::Element& element) { |
119 DictionaryValue* dict = new DictionaryValue(); | 121 DictionaryValue* dict = new DictionaryValue(); |
120 | 122 |
121 if (element.is_url) | 123 if (element.is_url) |
122 dict->SetString(keys::kUrlKey, element.url.spec()); | 124 dict->SetString(bookmark_keys::kUrlKey, element.url.spec()); |
123 | 125 |
124 dict->SetString(keys::kTitleKey, element.title); | 126 dict->SetString(bookmark_keys::kTitleKey, element.title); |
125 | 127 |
126 ListValue* children = new ListValue(); | 128 ListValue* children = new ListValue(); |
127 for (size_t i = 0; i < element.children.size(); ++i) | 129 for (size_t i = 0; i < element.children.size(); ++i) |
128 AddElementToList(children, element.children[i]); | 130 AddElementToList(children, element.children[i]); |
129 dict->Set(keys::kChildrenKey, children); | 131 dict->Set(bookmark_keys::kChildrenKey, children); |
130 | 132 |
131 list->Append(dict); | 133 list->Append(dict); |
132 } | 134 } |
133 | 135 |
134 // Builds the JSON structure based on the BookmarksDragData. | 136 // Builds the JSON structure based on the BookmarksDragData. |
135 void BookmarkNodeDataToJSON(Profile* profile, const BookmarkNodeData& data, | 137 void BookmarkNodeDataToJSON(Profile* profile, const BookmarkNodeData& data, |
136 ListValue* args) { | 138 ListValue* args) { |
137 bool same_profile = data.IsFromProfile(profile); | 139 bool same_profile = data.IsFromProfile(profile); |
138 DictionaryValue* value = new DictionaryValue(); | 140 DictionaryValue* value = new DictionaryValue(); |
139 value->SetBoolean(keys::kSameProfileKey, same_profile); | 141 value->SetBoolean(manager_keys::kSameProfileKey, same_profile); |
140 | 142 |
141 ListValue* list = new ListValue(); | 143 ListValue* list = new ListValue(); |
142 if (same_profile) { | 144 if (same_profile) { |
143 std::vector<const BookmarkNode*> nodes = data.GetNodes(profile); | 145 std::vector<const BookmarkNode*> nodes = data.GetNodes(profile); |
144 for (size_t i = 0; i < nodes.size(); ++i) | 146 for (size_t i = 0; i < nodes.size(); ++i) |
145 AddNodeToList(list, *nodes[i]); | 147 AddNodeToList(list, *nodes[i]); |
146 } else { | 148 } else { |
147 // We do not have an node IDs when the data comes from a different profile. | 149 // We do not have an node IDs when the data comes from a different profile. |
148 std::vector<BookmarkNodeData::Element> elements = data.elements; | 150 std::vector<BookmarkNodeData::Element> elements = data.elements; |
149 for (size_t i = 0; i < elements.size(); ++i) | 151 for (size_t i = 0; i < elements.size(); ++i) |
150 AddElementToList(list, elements[i]); | 152 AddElementToList(list, elements[i]); |
151 } | 153 } |
152 value->Set(keys::kElementsKey, list); | 154 value->Set(manager_keys::kElementsKey, list); |
153 | 155 |
154 args->Append(value); | 156 args->Append(value); |
155 } | 157 } |
156 | 158 |
157 } // namespace | 159 } // namespace |
158 | 160 |
159 BookmarkManagerExtensionEventRouter::BookmarkManagerExtensionEventRouter( | 161 BookmarkManagerPrivateEventRouter::BookmarkManagerPrivateEventRouter( |
160 Profile* profile, | 162 Profile* profile, |
161 content::WebContents* web_contents) | 163 content::WebContents* web_contents) |
162 : profile_(profile), | 164 : profile_(profile), |
163 web_contents_(web_contents) { | 165 web_contents_(web_contents) { |
164 BookmarkTabHelper* bookmark_tab_helper = | 166 BookmarkTabHelper* bookmark_tab_helper = |
165 BookmarkTabHelper::FromWebContents(web_contents_); | 167 BookmarkTabHelper::FromWebContents(web_contents_); |
166 bookmark_tab_helper->set_bookmark_drag_delegate(this); | 168 bookmark_tab_helper->set_bookmark_drag_delegate(this); |
167 } | 169 } |
168 | 170 |
169 BookmarkManagerExtensionEventRouter::~BookmarkManagerExtensionEventRouter() { | 171 BookmarkManagerPrivateEventRouter::~BookmarkManagerPrivateEventRouter() { |
170 BookmarkTabHelper* bookmark_tab_helper = | 172 BookmarkTabHelper* bookmark_tab_helper = |
171 BookmarkTabHelper::FromWebContents(web_contents_); | 173 BookmarkTabHelper::FromWebContents(web_contents_); |
172 if (bookmark_tab_helper->bookmark_drag_delegate() == this) | 174 if (bookmark_tab_helper->bookmark_drag_delegate() == this) |
173 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); | 175 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); |
174 } | 176 } |
175 | 177 |
176 void BookmarkManagerExtensionEventRouter::DispatchEvent( | 178 void BookmarkManagerPrivateEventRouter::DispatchEvent( |
177 const char* event_name, | 179 const char* event_name, |
178 scoped_ptr<ListValue> args) { | 180 scoped_ptr<ListValue> args) { |
179 if (!extensions::ExtensionSystem::Get(profile_)->event_router()) | 181 if (!ExtensionSystem::Get(profile_)->event_router()) |
180 return; | 182 return; |
181 | 183 |
182 scoped_ptr<extensions::Event> event(new extensions::Event( | 184 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
183 event_name, args.Pass())); | 185 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); |
184 extensions::ExtensionSystem::Get(profile_)->event_router()-> | |
185 BroadcastEvent(event.Pass()); | |
186 } | 186 } |
187 | 187 |
188 void BookmarkManagerExtensionEventRouter::DispatchDragEvent( | 188 void BookmarkManagerPrivateEventRouter::DispatchDragEvent( |
189 const BookmarkNodeData& data, | 189 const BookmarkNodeData& data, |
190 const char* event_name) { | 190 const char* event_name) { |
191 if (data.size() == 0) | 191 if (data.size() == 0) |
192 return; | 192 return; |
193 | 193 |
194 scoped_ptr<ListValue> args(new ListValue()); | 194 scoped_ptr<ListValue> args(new ListValue()); |
195 BookmarkNodeDataToJSON(profile_, data, args.get()); | 195 BookmarkNodeDataToJSON(profile_, data, args.get()); |
196 DispatchEvent(event_name, args.Pass()); | 196 DispatchEvent(event_name, args.Pass()); |
197 } | 197 } |
198 | 198 |
199 void BookmarkManagerExtensionEventRouter::OnDragEnter( | 199 void BookmarkManagerPrivateEventRouter::OnDragEnter( |
200 const BookmarkNodeData& data) { | 200 const BookmarkNodeData& data) { |
201 DispatchDragEvent(data, keys::kOnBookmarkDragEnter); | 201 DispatchDragEvent(data, manager_keys::kOnBookmarkDragEnter); |
202 } | 202 } |
203 | 203 |
204 void BookmarkManagerExtensionEventRouter::OnDragOver( | 204 void BookmarkManagerPrivateEventRouter::OnDragOver( |
205 const BookmarkNodeData& data) { | 205 const BookmarkNodeData& data) { |
206 // Intentionally empty since these events happens too often and floods the | 206 // Intentionally empty since these events happens too often and floods the |
207 // message queue. We do not need this event for the bookmark manager anyway. | 207 // message queue. We do not need this event for the bookmark manager anyway. |
208 } | 208 } |
209 | 209 |
210 void BookmarkManagerExtensionEventRouter::OnDragLeave( | 210 void BookmarkManagerPrivateEventRouter::OnDragLeave( |
211 const BookmarkNodeData& data) { | 211 const BookmarkNodeData& data) { |
212 DispatchDragEvent(data, keys::kOnBookmarkDragLeave); | 212 DispatchDragEvent(data, manager_keys::kOnBookmarkDragLeave); |
213 } | 213 } |
214 | 214 |
215 void BookmarkManagerExtensionEventRouter::OnDrop( | 215 void BookmarkManagerPrivateEventRouter::OnDrop(const BookmarkNodeData& data) { |
216 const BookmarkNodeData& data) { | 216 DispatchDragEvent(data, manager_keys::kOnBookmarkDrop); |
217 DispatchDragEvent(data, keys::kOnBookmarkDrop); | |
218 | 217 |
219 // Make a copy that is owned by this instance. | 218 // Make a copy that is owned by this instance. |
220 ClearBookmarkNodeData(); | 219 ClearBookmarkNodeData(); |
221 bookmark_drag_data_ = data; | 220 bookmark_drag_data_ = data; |
222 } | 221 } |
223 | 222 |
224 const BookmarkNodeData* | 223 const BookmarkNodeData* |
225 BookmarkManagerExtensionEventRouter::GetBookmarkNodeData() { | 224 BookmarkManagerPrivateEventRouter::GetBookmarkNodeData() { |
226 if (bookmark_drag_data_.is_valid()) | 225 if (bookmark_drag_data_.is_valid()) |
227 return &bookmark_drag_data_; | 226 return &bookmark_drag_data_; |
228 return NULL; | 227 return NULL; |
229 } | 228 } |
230 | 229 |
231 void BookmarkManagerExtensionEventRouter::ClearBookmarkNodeData() { | 230 void BookmarkManagerPrivateEventRouter::ClearBookmarkNodeData() { |
232 bookmark_drag_data_.Clear(); | 231 bookmark_drag_data_.Clear(); |
233 } | 232 } |
234 | 233 |
235 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut) { | 234 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut) { |
236 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 235 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
237 std::vector<const BookmarkNode*> nodes; | 236 std::vector<const BookmarkNode*> nodes; |
238 EXTENSION_FUNCTION_VALIDATE(GetNodesFromArguments(model, args_.get(), | 237 EXTENSION_FUNCTION_VALIDATE(GetNodesFromArguments(model, args_.get(), |
239 0, &nodes)); | 238 0, &nodes)); |
240 bookmark_utils::CopyToClipboard(model, nodes, cut); | 239 bookmark_utils::CopyToClipboard(model, nodes, cut); |
241 return true; | 240 return true; |
242 } | 241 } |
243 | 242 |
244 bool CopyBookmarkManagerFunction::RunImpl() { | 243 bool CopyBookmarkManagerFunction::RunImpl() { |
245 return CopyOrCut(false); | 244 return CopyOrCut(false); |
246 } | 245 } |
247 | 246 |
248 bool CutBookmarkManagerFunction::RunImpl() { | 247 bool CutBookmarkManagerFunction::RunImpl() { |
249 if (!EditBookmarksEnabled()) | 248 if (!EditBookmarksEnabled()) |
250 return false; | 249 return false; |
251 return CopyOrCut(true); | 250 return CopyOrCut(true); |
252 } | 251 } |
253 | 252 |
254 bool PasteBookmarkManagerFunction::RunImpl() { | 253 bool PasteBookmarkManagerFunction::RunImpl() { |
255 if (!EditBookmarksEnabled()) | 254 if (!EditBookmarksEnabled()) |
256 return false; | 255 return false; |
257 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 256 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
258 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); | 257 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); |
259 if (!parent_node) { | 258 if (!parent_node) { |
260 error_ = keys::kNoParentError; | 259 error_ = bookmark_keys::kNoParentError; |
261 return false; | 260 return false; |
262 } | 261 } |
263 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); | 262 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); |
264 if (!can_paste) | 263 if (!can_paste) |
265 return false; | 264 return false; |
266 | 265 |
267 // We want to use the highest index of the selected nodes as a destination. | 266 // We want to use the highest index of the selected nodes as a destination. |
268 std::vector<const BookmarkNode*> nodes; | 267 std::vector<const BookmarkNode*> nodes; |
269 // No need to test return value, if we got an empty list, we insert at end. | 268 // No need to test return value, if we got an empty list, we insert at end. |
270 GetNodesFromArguments(model, args_.get(), 1, &nodes); | 269 GetNodesFromArguments(model, args_.get(), 1, &nodes); |
271 int highest_index = -1; // -1 means insert at end of list. | 270 int highest_index = -1; // -1 means insert at end of list. |
272 for (size_t node = 0; node < nodes.size(); ++node) { | 271 for (size_t node = 0; node < nodes.size(); ++node) { |
273 // + 1 so that we insert after the selection. | 272 // + 1 so that we insert after the selection. |
274 int this_node_index = parent_node->GetIndexOf(nodes[node]) + 1; | 273 int this_node_index = parent_node->GetIndexOf(nodes[node]) + 1; |
275 if (this_node_index > highest_index) | 274 if (this_node_index > highest_index) |
276 highest_index = this_node_index; | 275 highest_index = this_node_index; |
277 } | 276 } |
278 | 277 |
279 bookmark_utils::PasteFromClipboard(model, parent_node, highest_index); | 278 bookmark_utils::PasteFromClipboard(model, parent_node, highest_index); |
280 return true; | 279 return true; |
281 } | 280 } |
282 | 281 |
283 bool CanPasteBookmarkManagerFunction::RunImpl() { | 282 bool CanPasteBookmarkManagerFunction::RunImpl() { |
284 if (!EditBookmarksEnabled()) | 283 if (!EditBookmarksEnabled()) |
285 return false; | 284 return false; |
286 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 285 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
287 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); | 286 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); |
288 if (!parent_node) { | 287 if (!parent_node) { |
289 error_ = keys::kNoParentError; | 288 error_ = bookmark_keys::kNoParentError; |
290 return false; | 289 return false; |
291 } | 290 } |
292 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); | 291 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); |
293 SetResult(new base::FundamentalValue(can_paste)); | 292 SetResult(new base::FundamentalValue(can_paste)); |
294 return true; | 293 return true; |
295 } | 294 } |
296 | 295 |
297 bool SortChildrenBookmarkManagerFunction::RunImpl() { | 296 bool SortChildrenBookmarkManagerFunction::RunImpl() { |
298 if (!EditBookmarksEnabled()) | 297 if (!EditBookmarksEnabled()) |
299 return false; | 298 return false; |
300 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 299 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
301 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); | 300 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); |
302 if (!parent_node) { | 301 if (!parent_node) { |
303 error_ = keys::kNoParentError; | 302 error_ = bookmark_keys::kNoParentError; |
304 return false; | 303 return false; |
305 } | 304 } |
306 model->SortChildren(parent_node); | 305 model->SortChildren(parent_node); |
307 return true; | 306 return true; |
308 } | 307 } |
309 | 308 |
310 bool BookmarkManagerGetStringsFunction::RunImpl() { | 309 bool BookmarkManagerGetStringsFunction::RunImpl() { |
311 DictionaryValue* localized_strings = new DictionaryValue(); | 310 DictionaryValue* localized_strings = new DictionaryValue(); |
312 | 311 |
313 localized_strings->SetString("title", | 312 localized_strings->SetString("title", |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 if (!EditBookmarksEnabled()) | 417 if (!EditBookmarksEnabled()) |
419 return false; | 418 return false; |
420 | 419 |
421 BookmarkModel* model =BookmarkModelFactory::GetForProfile(profile()); | 420 BookmarkModel* model =BookmarkModelFactory::GetForProfile(profile()); |
422 | 421 |
423 int64 id; | 422 int64 id; |
424 std::string id_string; | 423 std::string id_string; |
425 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string)); | 424 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string)); |
426 | 425 |
427 if (!base::StringToInt64(id_string, &id)) { | 426 if (!base::StringToInt64(id_string, &id)) { |
428 error_ = keys::kInvalidIdError; | 427 error_ = bookmark_keys::kInvalidIdError; |
429 return false; | 428 return false; |
430 } | 429 } |
431 | 430 |
432 const BookmarkNode* drop_parent = model->GetNodeByID(id); | 431 const BookmarkNode* drop_parent = model->GetNodeByID(id); |
433 if (!drop_parent) { | 432 if (!drop_parent) { |
434 error_ = keys::kNoParentError; | 433 error_ = bookmark_keys::kNoParentError; |
435 return false; | 434 return false; |
436 } | 435 } |
437 | 436 |
438 int drop_index; | 437 int drop_index; |
439 if (HasOptionalArgument(1)) | 438 if (HasOptionalArgument(1)) |
440 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &drop_index)); | 439 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &drop_index)); |
441 else | 440 else |
442 drop_index = drop_parent->child_count(); | 441 drop_index = drop_parent->child_count(); |
443 | 442 |
444 WebContents* web_contents = | 443 WebContents* web_contents = |
445 WebContents::FromRenderViewHost(render_view_host_); | 444 WebContents::FromRenderViewHost(render_view_host_); |
446 if (chrome::GetViewType(web_contents) == chrome::VIEW_TYPE_TAB_CONTENTS) { | 445 if (chrome::GetViewType(web_contents) == chrome::VIEW_TYPE_TAB_CONTENTS) { |
447 WebContents* web_contents = | 446 WebContents* web_contents = |
448 dispatcher()->delegate()->GetAssociatedWebContents(); | 447 dispatcher()->delegate()->GetAssociatedWebContents(); |
449 CHECK(web_contents); | 448 CHECK(web_contents); |
450 ExtensionWebUI* web_ui = | 449 ExtensionWebUI* web_ui = |
451 static_cast<ExtensionWebUI*>(web_contents->GetWebUI()->GetController()); | 450 static_cast<ExtensionWebUI*>(web_contents->GetWebUI()->GetController()); |
452 CHECK(web_ui); | 451 CHECK(web_ui); |
453 BookmarkManagerExtensionEventRouter* router = | 452 BookmarkManagerPrivateEventRouter* router = |
454 web_ui->bookmark_manager_extension_event_router(); | 453 web_ui->bookmark_manager_private_event_router(); |
455 | 454 |
456 DCHECK(router); | 455 DCHECK(router); |
457 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); | 456 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); |
458 if (drag_data == NULL) { | 457 if (drag_data == NULL) { |
459 NOTREACHED() <<"Somehow we're dropping null bookmark data"; | 458 NOTREACHED() <<"Somehow we're dropping null bookmark data"; |
460 return false; | 459 return false; |
461 } | 460 } |
462 bookmark_utils::PerformBookmarkDrop(profile(), | 461 bookmark_utils::PerformBookmarkDrop(profile(), |
463 *drag_data, | 462 *drag_data, |
464 drop_parent, drop_index); | 463 drop_parent, drop_index); |
(...skipping 11 matching lines...) Expand all Loading... |
476 const BookmarkNode* node; | 475 const BookmarkNode* node; |
477 int64 id; | 476 int64 id; |
478 std::string id_string; | 477 std::string id_string; |
479 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string)); | 478 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string)); |
480 bool folders_only; | 479 bool folders_only; |
481 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &folders_only)); | 480 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &folders_only)); |
482 if (id_string == "") { | 481 if (id_string == "") { |
483 node = model->root_node(); | 482 node = model->root_node(); |
484 } else { | 483 } else { |
485 if (!base::StringToInt64(id_string, &id)) { | 484 if (!base::StringToInt64(id_string, &id)) { |
486 error_ = keys::kInvalidIdError; | 485 error_ = bookmark_keys::kInvalidIdError; |
487 return false; | 486 return false; |
488 } | 487 } |
489 node = model->GetNodeByID(id); | 488 node = model->GetNodeByID(id); |
490 } | 489 } |
491 if (!node) { | 490 if (!node) { |
492 error_ = keys::kNoNodeError; | 491 error_ = bookmark_keys::kNoNodeError; |
493 return false; | 492 return false; |
494 } | 493 } |
495 scoped_ptr<ListValue> json(new ListValue()); | 494 scoped_ptr<ListValue> json(new ListValue()); |
496 if (folders_only) { | 495 if (folders_only) |
497 extensions::bookmark_api_helpers::AddNodeFoldersOnly(node, | 496 bookmark_api_helpers::AddNodeFoldersOnly(node, json.get(), true); |
498 json.get(), | 497 else |
499 true); | 498 bookmark_api_helpers::AddNode(node, json.get(), true); |
500 } else { | |
501 extensions::bookmark_api_helpers::AddNode(node, json.get(), true); | |
502 } | |
503 SetResult(json.release()); | 499 SetResult(json.release()); |
504 return true; | 500 return true; |
505 } | 501 } |
506 | 502 |
507 bool CanEditBookmarkManagerFunction::RunImpl() { | 503 bool CanEditBookmarkManagerFunction::RunImpl() { |
508 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile_); | 504 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile_); |
509 SetResult(new base::FundamentalValue( | 505 SetResult(new base::FundamentalValue( |
510 prefs->GetBoolean(prefs::kEditBookmarksEnabled))); | 506 prefs->GetBoolean(prefs::kEditBookmarksEnabled))); |
511 return true; | 507 return true; |
512 } | 508 } |
513 | 509 |
514 bool RecordLaunchBookmarkFunction::RunImpl() { | 510 bool RecordLaunchBookmarkFunction::RunImpl() { |
515 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_MANAGER); | 511 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_MANAGER); |
516 return true; | 512 return true; |
517 } | 513 } |
518 | 514 |
519 bool CanOpenNewWindowsBookmarkFunction::RunImpl() { | 515 bool CanOpenNewWindowsBookmarkFunction::RunImpl() { |
520 bool can_open_new_windows = true; | 516 bool can_open_new_windows = true; |
521 | 517 |
522 #if defined(OS_WIN) | 518 #if defined(OS_WIN) |
523 if (win8::IsSingleWindowMetroMode()) | 519 if (win8::IsSingleWindowMetroMode()) |
524 can_open_new_windows = false; | 520 can_open_new_windows = false; |
525 #endif // OS_WIN | 521 #endif // OS_WIN |
526 | 522 |
527 SetResult(new base::FundamentalValue(can_open_new_windows)); | 523 SetResult(new base::FundamentalValue(can_open_new_windows)); |
528 return true; | 524 return true; |
529 } | 525 } |
| 526 |
| 527 } // namespace extensions |
OLD | NEW |