Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/home_button.h" | 5 #include "chrome/browser/ui/views/toolbar/home_button.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 13 #include "components/user_prefs/user_prefs.h" | 13 #include "components/user_prefs/user_prefs.h" |
| 14 #include "ui/base/dragdrop/drag_and_drop_url_utils.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/views/bubble/bubble_dialog_delegate.h" | 16 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 16 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/controls/link.h" | 18 #include "ui/views/controls/link.h" |
| 18 #include "ui/views/controls/link_listener.h" | 19 #include "ui/views/controls/link_listener.h" |
| 19 #include "ui/views/layout/grid_layout.h" | 20 #include "ui/views/layout/grid_layout.h" |
| 20 #include "ui/views/layout/layout_constants.h" | 21 #include "ui/views/layout/layout_constants.h" |
| 21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 22 | 23 |
| 23 // HomePageUndoBubble -------------------------------------------------------- | 24 // HomePageUndoBubble -------------------------------------------------------- |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 } | 153 } |
| 153 | 154 |
| 154 bool HomeButton::GetDropFormats( | 155 bool HomeButton::GetDropFormats( |
| 155 int* formats, | 156 int* formats, |
| 156 std::set<ui::Clipboard::FormatType>* format_types) { | 157 std::set<ui::Clipboard::FormatType>* format_types) { |
| 157 *formats = ui::OSExchangeData::URL; | 158 *formats = ui::OSExchangeData::URL; |
| 158 return true; | 159 return true; |
| 159 } | 160 } |
| 160 | 161 |
| 161 bool HomeButton::CanDrop(const OSExchangeData& data) { | 162 bool HomeButton::CanDrop(const OSExchangeData& data) { |
| 162 return data.HasURL(ui::OSExchangeData::CONVERT_FILENAMES); | 163 return ui::CanBeInterpretedAsURL(data, ui::OSExchangeData::CONVERT_FILENAMES); |
|
dyaroshev
2016/09/14 17:12:05
Here we don't check for URL validity, but in OnPer
Peter Kasting
2016/09/15 21:26:53
I would suggest that:
* CanBeInterpretedAsURL() s
| |
| 163 } | 164 } |
| 164 | 165 |
| 165 int HomeButton::OnDragUpdated(const ui::DropTargetEvent& event) { | 166 int HomeButton::OnDragUpdated(const ui::DropTargetEvent& event) { |
| 166 return event.source_operations(); | 167 return event.source_operations(); |
| 167 } | 168 } |
| 168 | 169 |
| 169 int HomeButton::OnPerformDrop(const ui::DropTargetEvent& event) { | 170 int HomeButton::OnPerformDrop(const ui::DropTargetEvent& event) { |
| 170 GURL new_homepage_url; | 171 auto url_and_title = ui::TryToInterpretAsURL( |
| 171 base::string16 title; | 172 event.data(), ui::OSExchangeData::CONVERT_FILENAMES); |
| 172 if (event.data().GetURLAndTitle( | 173 if (!url_and_title) |
| 173 ui::OSExchangeData::CONVERT_FILENAMES, &new_homepage_url, &title) && | 174 return ui::DragDropTypes::DRAG_NONE; |
| 174 new_homepage_url.is_valid()) { | 175 |
| 176 GURL& new_homepage_url = url_and_title->first; | |
| 177 if (new_homepage_url.is_valid()) { | |
| 175 PrefService* prefs = browser_->profile()->GetPrefs(); | 178 PrefService* prefs = browser_->profile()->GetPrefs(); |
| 176 bool old_is_ntp = prefs->GetBoolean(prefs::kHomePageIsNewTabPage); | 179 bool old_is_ntp = prefs->GetBoolean(prefs::kHomePageIsNewTabPage); |
| 177 GURL old_homepage(prefs->GetString(prefs::kHomePage)); | 180 GURL old_homepage(prefs->GetString(prefs::kHomePage)); |
| 178 | 181 |
| 179 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); | 182 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
| 180 prefs->SetString(prefs::kHomePage, new_homepage_url.spec()); | 183 prefs->SetString(prefs::kHomePage, new_homepage_url.spec()); |
| 181 | 184 |
| 182 HomePageUndoBubble::ShowBubble(browser_, old_is_ntp, old_homepage, this); | 185 HomePageUndoBubble::ShowBubble(browser_, old_is_ntp, old_homepage, this); |
| 183 } | 186 } |
| 184 return ui::DragDropTypes::DRAG_NONE; | 187 return ui::DragDropTypes::DRAG_NONE; |
| 185 } | 188 } |
| OLD | NEW |