| 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/ui/views/bookmarks/bookmark_editor_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_utils.h" | 12 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 13 #include "chrome/browser/history/history.h" | 13 #include "chrome/browser/history/history.h" |
| 14 #include "chrome/browser/net/url_fixer_upper.h" | 14 #include "chrome/browser/net/url_fixer_upper.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" |
| 18 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 19 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
| 20 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 21 #include "grit/locale_settings.h" | 24 #include "grit/locale_settings.h" |
| 22 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "views/background.h" | 27 #include "views/background.h" |
| 25 #include "views/controls/button/text_button.h" | 28 #include "views/controls/button/text_button.h" |
| 26 #include "views/controls/label.h" | 29 #include "views/controls/label.h" |
| 27 #include "views/controls/menu/menu_2.h" | 30 #include "views/controls/menu/menu_2.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 263 |
| 261 void BookmarkEditorView::Init() { | 264 void BookmarkEditorView::Init() { |
| 262 bb_model_ = profile_->GetBookmarkModel(); | 265 bb_model_ = profile_->GetBookmarkModel(); |
| 263 DCHECK(bb_model_); | 266 DCHECK(bb_model_); |
| 264 bb_model_->AddObserver(this); | 267 bb_model_->AddObserver(this); |
| 265 | 268 |
| 266 url_tf_.set_parent_owned(false); | 269 url_tf_.set_parent_owned(false); |
| 267 title_tf_.set_parent_owned(false); | 270 title_tf_.set_parent_owned(false); |
| 268 | 271 |
| 269 std::wstring title; | 272 std::wstring title; |
| 270 if (details_.type == EditDetails::EXISTING_NODE) | 273 GURL url; |
| 274 if (details_.type == EditDetails::EXISTING_NODE) { |
| 271 title = details_.existing_node->GetTitle(); | 275 title = details_.existing_node->GetTitle(); |
| 272 else if (details_.type == EditDetails::NEW_FOLDER) | 276 url = details_.existing_node->GetURL(); |
| 277 } else if (details_.type == EditDetails::NEW_FOLDER) { |
| 273 title = UTF16ToWide( | 278 title = UTF16ToWide( |
| 274 l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME)); | 279 l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME)); |
| 280 } else if (details_.type == EditDetails::NEW_URL) { |
| 281 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 282 TabContents* tab_contents = browser ? browser->GetSelectedTabContents() |
| 283 : NULL; |
| 284 if (tab_contents) { |
| 285 title = UTF16ToWide(tab_contents->GetTitle()); |
| 286 url = tab_contents->GetURL(); |
| 287 } |
| 288 } |
| 275 title_tf_.SetText(title); | 289 title_tf_.SetText(title); |
| 276 title_tf_.SetController(this); | 290 title_tf_.SetController(this); |
| 277 | 291 |
| 278 title_label_ = new views::Label( | 292 title_label_ = new views::Label( |
| 279 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_NAME_LABEL))); | 293 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_NAME_LABEL))); |
| 280 title_tf_.SetAccessibleName(WideToUTF16Hack(title_label_->GetText())); | 294 title_tf_.SetAccessibleName(WideToUTF16Hack(title_label_->GetText())); |
| 281 | 295 |
| 282 string16 url_text; | 296 string16 url_text; |
| 283 if (details_.type == EditDetails::EXISTING_NODE) { | 297 if (details_.type != EditDetails::NEW_FOLDER) { |
| 284 std::string languages = profile_ | 298 std::string languages = profile_ |
| 285 ? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) | 299 ? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) |
| 286 : std::string(); | 300 : std::string(); |
| 287 // Because this gets parsed by FixupURL(), it's safe to omit the scheme or | 301 // Because this gets parsed by FixupURL(), it's safe to omit the scheme or |
| 288 // trailing slash, and unescape most characters, but we need to not drop any | 302 // trailing slash, and unescape most characters, but we need to not drop any |
| 289 // username/password, or unescape anything that changes the meaning. | 303 // username/password, or unescape anything that changes the meaning. |
| 290 url_text = net::FormatUrl(details_.existing_node->GetURL(), languages, | 304 url_text = net::FormatUrl(url, languages, |
| 291 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, | 305 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, |
| 292 UnescapeRule::SPACES, NULL, NULL, NULL); | 306 UnescapeRule::SPACES, NULL, NULL, NULL); |
| 293 } | 307 } |
| 294 url_tf_.SetText(UTF16ToWide(url_text)); | 308 url_tf_.SetText(UTF16ToWide(url_text)); |
| 295 url_tf_.SetController(this); | 309 url_tf_.SetController(this); |
| 296 | 310 |
| 297 url_label_ = new views::Label( | 311 url_label_ = new views::Label( |
| 298 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_URL_LABEL))); | 312 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_URL_LABEL))); |
| 299 url_tf_.SetAccessibleName(WideToUTF16Hack(url_label_->GetText())); | 313 url_tf_.SetAccessibleName(WideToUTF16Hack(url_label_->GetText())); |
| 300 | 314 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 break; | 592 break; |
| 579 } | 593 } |
| 580 } | 594 } |
| 581 DCHECK(child_bb_node); | 595 DCHECK(child_bb_node); |
| 582 bb_model_->SetTitle(child_bb_node, child_b_node->GetTitle()); | 596 bb_model_->SetTitle(child_bb_node, child_b_node->GetTitle()); |
| 583 } | 597 } |
| 584 ApplyNameChangesAndCreateNewFolders(child_bb_node, child_b_node, | 598 ApplyNameChangesAndCreateNewFolders(child_bb_node, child_b_node, |
| 585 parent_b_node, parent_bb_node); | 599 parent_b_node, parent_bb_node); |
| 586 } | 600 } |
| 587 } | 601 } |
| OLD | NEW |