| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_utils.h" | 5 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 6 | 6 |
| 7 #include "app/drag_drop_types.h" | 7 #include "app/drag_drop_types.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 // TODO(port): Port these files. | |
| 10 #if defined(OS_WIN) | |
| 11 #include "app/os_exchange_data.h" | |
| 12 #else | |
| 13 #include "chrome/common/temp_scaffolding_stubs.h" | |
| 14 #endif | |
| 15 #include "app/tree_node_iterator.h" | 9 #include "app/tree_node_iterator.h" |
| 16 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/clipboard.h" |
| 17 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 18 #include "base/time.h" | 13 #include "base/time.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 14 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
| 20 #include "chrome/browser/bookmarks/bookmark_model.h" | 15 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 21 #include "chrome/browser/browser.h" | 16 #include "chrome/browser/browser.h" |
| 22 #include "chrome/browser/browser_list.h" | 17 #include "chrome/browser/browser_list.h" |
| 18 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/browser_window.h" | 19 #include "chrome/browser/browser_window.h" |
| 24 #include "chrome/browser/history/query_parser.h" | 20 #include "chrome/browser/history/query_parser.h" |
| 25 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 26 #include "chrome/browser/tab_contents/page_navigator.h" | 22 #include "chrome/browser/tab_contents/page_navigator.h" |
| 27 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
| 28 #include "chrome/common/notification_service.h" | 24 #include "chrome/common/notification_service.h" |
| 29 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/pref_service.h" | 26 #include "chrome/common/pref_service.h" |
| 31 #include "grit/app_strings.h" | 27 #include "grit/app_strings.h" |
| 32 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 const BookmarkNode* node, | 344 const BookmarkNode* node, |
| 349 WindowOpenDisposition initial_disposition) { | 345 WindowOpenDisposition initial_disposition) { |
| 350 std::vector<const BookmarkNode*> nodes; | 346 std::vector<const BookmarkNode*> nodes; |
| 351 nodes.push_back(node); | 347 nodes.push_back(node); |
| 352 OpenAll(parent, profile, navigator, nodes, initial_disposition); | 348 OpenAll(parent, profile, navigator, nodes, initial_disposition); |
| 353 } | 349 } |
| 354 | 350 |
| 355 void CopyToClipboard(BookmarkModel* model, | 351 void CopyToClipboard(BookmarkModel* model, |
| 356 const std::vector<const BookmarkNode*>& nodes, | 352 const std::vector<const BookmarkNode*>& nodes, |
| 357 bool remove_nodes) { | 353 bool remove_nodes) { |
| 354 #if defined(OS_WIN) || defined(OS_LINUX) |
| 358 if (nodes.empty()) | 355 if (nodes.empty()) |
| 359 return; | 356 return; |
| 360 | 357 |
| 361 #if defined(OS_WIN) | 358 BookmarkDragData(nodes).WriteToClipboard(NULL); |
| 362 OSExchangeData* data = new OSExchangeData(); | |
| 363 BookmarkDragData(nodes).Write(NULL, data); | |
| 364 OleSetClipboard(data); | |
| 365 // OLE takes ownership of OSExchangeData. | |
| 366 #else | |
| 367 // TODO(port): Clipboard integration. Don't we have clipboard | |
| 368 // implemented somewhere else? | |
| 369 #endif | |
| 370 | 359 |
| 371 // The following works cross-platform but I'm disabling it for now so that | |
| 372 // users who Cut a bookmark or folder won't lose it without being able to | |
| 373 // paste it. | |
| 374 #if defined(OS_WIN) | |
| 375 if (remove_nodes) { | 360 if (remove_nodes) { |
| 376 for (size_t i = 0; i < nodes.size(); ++i) { | 361 for (size_t i = 0; i < nodes.size(); ++i) { |
| 377 model->Remove(nodes[i]->GetParent(), | 362 model->Remove(nodes[i]->GetParent(), |
| 378 nodes[i]->GetParent()->IndexOfChild(nodes[i])); | 363 nodes[i]->GetParent()->IndexOfChild(nodes[i])); |
| 379 } | 364 } |
| 380 } | 365 } |
| 366 #else |
| 367 // Not implemented on mac yet. |
| 381 #endif | 368 #endif |
| 382 } | 369 } |
| 383 | 370 |
| 384 void PasteFromClipboard(BookmarkModel* model, | 371 void PasteFromClipboard(BookmarkModel* model, |
| 385 const BookmarkNode* parent, | 372 const BookmarkNode* parent, |
| 386 int index) { | 373 int index) { |
| 374 #if defined(OS_WIN) || defined(OS_LINUX) |
| 387 if (!parent) | 375 if (!parent) |
| 388 return; | 376 return; |
| 389 | 377 |
| 390 #if defined(OS_WIN) | |
| 391 IDataObject* data; | |
| 392 if (OleGetClipboard(&data) != S_OK) | |
| 393 return; | |
| 394 | |
| 395 OSExchangeData data_wrapper(data); | |
| 396 BookmarkDragData bookmark_data; | 378 BookmarkDragData bookmark_data; |
| 397 if (!bookmark_data.Read(data_wrapper)) | 379 if (!bookmark_data.ReadFromClipboard()) |
| 398 return; | 380 return; |
| 399 | 381 |
| 400 if (index == -1) | 382 if (index == -1) |
| 401 index = parent->GetChildCount(); | 383 index = parent->GetChildCount(); |
| 402 bookmark_utils::CloneDragData(model, bookmark_data.elements, parent, index); | 384 bookmark_utils::CloneDragData(model, bookmark_data.elements, parent, index); |
| 403 #else | 385 #else |
| 404 // TODO(port): Clipboard integration. | 386 // Not implemented on mac yet. |
| 405 #endif | 387 #endif |
| 406 } | 388 } |
| 407 | 389 |
| 408 bool CanPasteFromClipboard(const BookmarkNode* node) { | 390 bool CanPasteFromClipboard(const BookmarkNode* node) { |
| 409 if (!node) | 391 if (!node) |
| 410 return false; | 392 return false; |
| 411 | 393 |
| 412 #if defined(OS_WIN) | 394 return g_browser_process->clipboard()->IsFormatAvailable( |
| 413 IDataObject* data; | 395 BookmarkDragData::kClipboardFormatString); |
| 414 if (OleGetClipboard(&data) != S_OK) | |
| 415 return false; | |
| 416 | |
| 417 OSExchangeData data_wrapper(data); | |
| 418 BookmarkDragData bookmark_data; | |
| 419 return bookmark_data.Read(data_wrapper); | |
| 420 #else | |
| 421 // TODO(port): Clipboard integration. | |
| 422 return false; | |
| 423 #endif | |
| 424 } | 396 } |
| 425 | 397 |
| 426 std::string GetNameForURL(const GURL& url) { | 398 std::string GetNameForURL(const GURL& url) { |
| 427 if (url.is_valid()) { | 399 if (url.is_valid()) { |
| 428 return WideToUTF8(net::GetSuggestedFilename( | 400 return WideToUTF8(net::GetSuggestedFilename( |
| 429 url, std::string(), std::string(), std::wstring())); | 401 url, std::string(), std::string(), std::wstring())); |
| 430 } else { | 402 } else { |
| 431 return l10n_util::GetStringUTF8(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); | 403 return l10n_util::GetStringUTF8(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); |
| 432 } | 404 } |
| 433 } | 405 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 602 |
| 631 // Formerly in BookmarkTableView | 603 // Formerly in BookmarkTableView |
| 632 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth1, -1); | 604 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth1, -1); |
| 633 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth1, -1); | 605 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth1, -1); |
| 634 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth2, -1); | 606 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth2, -1); |
| 635 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth2, -1); | 607 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth2, -1); |
| 636 prefs->RegisterIntegerPref(prefs::kBookmarkTablePathWidth, -1); | 608 prefs->RegisterIntegerPref(prefs::kBookmarkTablePathWidth, -1); |
| 637 } | 609 } |
| 638 | 610 |
| 639 } // namespace bookmark_utils | 611 } // namespace bookmark_utils |
| OLD | NEW |