Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // A view that implements one download on the Download shelf. | 5 // A view that implements one download on the Download shelf. |
| 6 // Each DownloadItemView contains an application icon, a text label | 6 // Each DownloadItemView contains an application icon, a text label |
| 7 // indicating the download's file name, a text label indicating the | 7 // indicating the download's file name, a text label indicating the |
| 8 // download's status (such as the number of bytes downloaded so far) | 8 // download's status (such as the number of bytes downloaded so far) |
| 9 // and a button for canceling an in progress download, or opening | 9 // and a button for canceling an in progress download, or opening |
| 10 // the completed download. | 10 // the completed download. |
| 11 // | 11 // |
| 12 // The DownloadItemView lives in the Browser, and has a corresponding | 12 // The DownloadItemView lives in the Browser, and has a corresponding |
| 13 // DownloadController that receives / writes data which lives in the | 13 // DownloadController that receives / writes data which lives in the |
| 14 // Renderer. | 14 // Renderer. |
| 15 | 15 |
| 16 #ifndef CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ | 16 #ifndef CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ |
| 17 #define CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ | 17 #define CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ |
| 18 | 18 |
| 19 #include <memory> | 19 #include <memory> |
| 20 #include <string> | 20 #include <string> |
| 21 | 21 |
| 22 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
| 24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 25 #include "base/task/cancelable_task_tracker.h" | 25 #include "base/task/cancelable_task_tracker.h" |
| 26 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 27 #include "base/timer/timer.h" | 27 #include "base/timer/timer.h" |
| 28 #include "chrome/browser/download/download_commands.h" | |
| 28 #include "chrome/browser/download/download_item_model.h" | 29 #include "chrome/browser/download/download_item_model.h" |
| 29 #include "chrome/browser/icon_manager.h" | 30 #include "chrome/browser/icon_manager.h" |
| 30 #include "content/public/browser/download_item.h" | 31 #include "content/public/browser/download_item.h" |
| 31 #include "content/public/browser/download_manager.h" | 32 #include "content/public/browser/download_manager.h" |
| 32 #include "ui/gfx/animation/animation_delegate.h" | 33 #include "ui/gfx/animation/animation_delegate.h" |
| 33 #include "ui/gfx/font_list.h" | 34 #include "ui/gfx/font_list.h" |
| 34 #include "ui/views/animation/ink_drop_host_view.h" | 35 #include "ui/views/animation/ink_drop_host_view.h" |
| 35 #include "ui/views/context_menu_controller.h" | 36 #include "ui/views/context_menu_controller.h" |
| 36 #include "ui/views/controls/button/vector_icon_button_delegate.h" | 37 #include "ui/views/controls/button/vector_icon_button_delegate.h" |
| 37 | 38 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 | 78 |
| 78 // Returns the base color for text on this download item, based on |theme|. | 79 // Returns the base color for text on this download item, based on |theme|. |
| 79 static SkColor GetTextColorForThemeProvider(const ui::ThemeProvider* theme); | 80 static SkColor GetTextColorForThemeProvider(const ui::ThemeProvider* theme); |
| 80 | 81 |
| 81 // IconManager::Client interface. | 82 // IconManager::Client interface. |
| 82 void OnExtractIconComplete(gfx::Image* icon); | 83 void OnExtractIconComplete(gfx::Image* icon); |
| 83 | 84 |
| 84 // Returns the DownloadItem model object belonging to this item. | 85 // Returns the DownloadItem model object belonging to this item. |
| 85 content::DownloadItem* download() { return model_.download(); } | 86 content::DownloadItem* download() { return model_.download(); } |
| 86 | 87 |
| 88 // Submit download to download feedback service if the user has approved and | |
|
Peter Kasting
2016/11/01 23:48:32
Nit: Verbs in function comments should be descript
Jialiu Lin
2016/11/03 20:16:50
Done.
| |
| 89 // the download is suitable for submission, then apply |download_command|. | |
| 90 // If user hasn't seen SBER opt-in text before, show SBER opt-in dialog first. | |
|
Peter Kasting
2016/11/01 23:48:32
Does this function delete |this|? If so it should
Jialiu Lin
2016/11/03 20:16:50
Agree, I don't think it deletes |this|. Will fix c
| |
| 91 void MaybeSubmitDownloadToFeedbackService( | |
| 92 DownloadCommands::Command download_command); | |
| 93 | |
| 87 // DownloadItem::Observer methods | 94 // DownloadItem::Observer methods |
| 88 void OnDownloadUpdated(content::DownloadItem* download) override; | 95 void OnDownloadUpdated(content::DownloadItem* download) override; |
| 89 void OnDownloadOpened(content::DownloadItem* download) override; | 96 void OnDownloadOpened(content::DownloadItem* download) override; |
| 90 void OnDownloadDestroyed(content::DownloadItem* download) override; | 97 void OnDownloadDestroyed(content::DownloadItem* download) override; |
| 91 | 98 |
| 92 // Overridden from views::View: | 99 // Overridden from views::View: |
| 93 void Layout() override; | 100 void Layout() override; |
| 94 gfx::Size GetPreferredSize() const override; | 101 gfx::Size GetPreferredSize() const override; |
| 95 bool OnMousePressed(const ui::MouseEvent& event) override; | 102 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 96 bool OnMouseDragged(const ui::MouseEvent& event) override; | 103 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 142 |
| 136 enum Mode { | 143 enum Mode { |
| 137 NORMAL_MODE = 0, // Showing download item. | 144 NORMAL_MODE = 0, // Showing download item. |
| 138 DANGEROUS_MODE, // Displaying the dangerous download warning. | 145 DANGEROUS_MODE, // Displaying the dangerous download warning. |
| 139 MALICIOUS_MODE // Displaying the malicious download warning. | 146 MALICIOUS_MODE // Displaying the malicious download warning. |
| 140 }; | 147 }; |
| 141 | 148 |
| 142 void OpenDownload(); | 149 void OpenDownload(); |
| 143 | 150 |
| 144 // Submits the downloaded file to the safebrowsing download feedback service. | 151 // Submits the downloaded file to the safebrowsing download feedback service. |
| 145 // Returns whether submission was successful. On successful submission, | 152 // Returns whether submission was successful. On successful submission, apply |
| 146 // |this| and the DownloadItem will have been deleted. | 153 // |download_command|, and |this| will have been deleted. |
|
Peter Kasting
2016/11/01 23:48:32
This comment doesn't seem to accurately describe w
Jialiu Lin
2016/11/03 20:16:50
I agree. If the "make a temp copy" strategy works
| |
| 147 bool SubmitDownloadToFeedbackService(); | 154 bool SubmitDownloadToFeedbackService( |
| 155 DownloadCommands::Command download_command); | |
| 148 | 156 |
| 149 // If the user has |enabled| uploading, calls SubmitDownloadToFeedbackService. | 157 // If the user has |enabled| uploading, calls SubmitDownloadToFeedbackService. |
| 150 // Otherwise, it simply removes the DownloadItem without uploading. | 158 // Otherwise, apply |download_command|. |
| 151 void PossiblySubmitDownloadToFeedbackService(bool enabled); | 159 void SubmitDownloadWhenFeedbackServiceEnabled( |
| 160 DownloadCommands::Command download_command, | |
| 161 bool feedback_enabled); | |
| 152 | 162 |
| 153 // This function calculates the vertical coordinate to draw the file name text | 163 // This function calculates the vertical coordinate to draw the file name text |
| 154 // relative to local bounds. | 164 // relative to local bounds. |
| 155 int GetYForFilenameText() const; | 165 int GetYForFilenameText() const; |
| 156 | 166 |
| 157 // Painting of various download item bits. | 167 // Painting of various download item bits. |
| 158 void DrawStatusText(gfx::Canvas* canvas); | 168 void DrawStatusText(gfx::Canvas* canvas); |
| 159 void DrawFilename(gfx::Canvas* canvas); | 169 void DrawFilename(gfx::Canvas* canvas); |
| 160 void DrawIcon(gfx::Canvas* canvas); | 170 void DrawIcon(gfx::Canvas* canvas); |
| 161 | 171 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; | 330 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; |
| 321 | 331 |
| 322 // Method factory used to delay reenabling of the item when opening the | 332 // Method factory used to delay reenabling of the item when opening the |
| 323 // downloaded file. | 333 // downloaded file. |
| 324 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; | 334 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; |
| 325 | 335 |
| 326 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); | 336 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); |
| 327 }; | 337 }; |
| 328 | 338 |
| 329 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ | 339 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ |
| OLD | NEW |