OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/download_item_gtk.h" | 5 #include "chrome/browser/gtk/download_item_gtk.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/gfx/canvas_paint.h" | 8 #include "app/gfx/canvas_paint.h" |
9 #include "app/gfx/font.h" | 9 #include "app/gfx/font.h" |
10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 DownloadShelfContextMenuGtk(BaseDownloadItemModel* model, | 83 DownloadShelfContextMenuGtk(BaseDownloadItemModel* model, |
84 DownloadItemGtk* download_item) | 84 DownloadItemGtk* download_item) |
85 : DownloadShelfContextMenu(model), | 85 : DownloadShelfContextMenu(model), |
86 download_item_(download_item), | 86 download_item_(download_item), |
87 menu_is_for_complete_download_(false) { | 87 menu_is_for_complete_download_(false) { |
88 } | 88 } |
89 | 89 |
90 ~DownloadShelfContextMenuGtk() { | 90 ~DownloadShelfContextMenuGtk() { |
91 } | 91 } |
92 | 92 |
93 GtkWidget* widget() { | |
94 return menu_->widget(); | |
95 } | |
96 | |
97 void Popup(GtkWidget* widget, GdkEvent* event) { | 93 void Popup(GtkWidget* widget, GdkEvent* event) { |
98 // Create the menu if we have not created it yet or we created it for | 94 // Create the menu if we have not created it yet or we created it for |
99 // an in-progress download that has since completed. | 95 // an in-progress download that has since completed. |
100 bool download_is_complete = download_->state() == DownloadItem::COMPLETE; | 96 bool download_is_complete = download_->state() == DownloadItem::COMPLETE; |
101 if (menu_.get() == NULL || | 97 if (menu_.get() == NULL || |
102 (download_is_complete && !menu_is_for_complete_download_)) { | 98 (download_is_complete && !menu_is_for_complete_download_)) { |
103 menu_.reset(new MenuGtk(this, download_is_complete ? | 99 menu_.reset(new MenuGtk(this, download_is_complete ? |
104 finished_download_menu : in_progress_download_menu, NULL)); | 100 finished_download_menu : in_progress_download_menu, NULL)); |
105 menu_is_for_complete_download_ = download_is_complete; | 101 menu_is_for_complete_download_ = download_is_complete; |
106 } | 102 } |
107 menu_->Popup(widget, event); | 103 menu_->Popup(widget, event); |
108 } | 104 } |
109 | 105 |
110 // MenuGtk::Delegate implementation ------------------------------------------ | 106 // MenuGtk::Delegate implementation ------------------------------------------ |
111 virtual bool IsCommandEnabled(int id) const { | 107 virtual bool IsCommandEnabled(int id) const { |
112 return IsItemCommandEnabled(id); | 108 return IsItemCommandEnabled(id); |
113 } | 109 } |
114 | 110 |
115 virtual bool IsItemChecked(int id) const { | 111 virtual bool IsItemChecked(int id) const { |
116 return ItemIsChecked(id); | 112 return ItemIsChecked(id); |
117 } | 113 } |
118 | 114 |
119 virtual void ExecuteCommand(int id) { | 115 virtual void ExecuteCommand(int id) { |
120 return ExecuteItemCommand(id); | 116 ExecuteItemCommand(id); |
121 } | 117 } |
122 | 118 |
123 virtual void StoppedShowing() { | 119 virtual void StoppedShowing() { |
124 download_item_->menu_showing_ = false; | 120 download_item_->menu_showing_ = false; |
125 gtk_widget_queue_draw(download_item_->menu_button_); | 121 gtk_widget_queue_draw(download_item_->menu_button_); |
126 } | 122 } |
127 | 123 |
128 private: | 124 private: |
129 // The menu we show on Popup(). We keep a pointer to it for a couple reasons: | 125 // The menu we show on Popup(). We keep a pointer to it for a couple reasons: |
130 // * we don't want to have to recreate the menu every time it's popped up. | 126 // * we don't want to have to recreate the menu every time it's popped up. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 arrow_(NULL), | 185 arrow_(NULL), |
190 menu_showing_(false), | 186 menu_showing_(false), |
191 theme_provider_(GtkThemeProvider::GetFrom( | 187 theme_provider_(GtkThemeProvider::GetFrom( |
192 parent_shelf->browser()->profile())), | 188 parent_shelf->browser()->profile())), |
193 progress_angle_(download_util::kStartAngleDegrees), | 189 progress_angle_(download_util::kStartAngleDegrees), |
194 download_model_(download_model), | 190 download_model_(download_model), |
195 bounding_widget_(parent_shelf->GetRightBoundingWidget()), | 191 bounding_widget_(parent_shelf->GetRightBoundingWidget()), |
196 dangerous_prompt_(NULL), | 192 dangerous_prompt_(NULL), |
197 dangerous_label_(NULL), | 193 dangerous_label_(NULL), |
198 icon_(NULL), | 194 icon_(NULL), |
199 creation_time_(base::Time::Now()), | 195 creation_time_(base::Time::Now()) { |
200 method_factory_(this) { | |
201 LoadIcon(); | 196 LoadIcon(); |
202 | 197 |
203 body_.Own(gtk_button_new()); | 198 body_.Own(gtk_button_new()); |
204 gtk_widget_set_app_paintable(body_.get(), TRUE); | 199 gtk_widget_set_app_paintable(body_.get(), TRUE); |
205 | 200 |
206 g_signal_connect(body_.get(), "expose-event", | 201 g_signal_connect(body_.get(), "expose-event", |
207 G_CALLBACK(OnExpose), this); | 202 G_CALLBACK(OnExpose), this); |
208 g_signal_connect(body_.get(), "clicked", | 203 g_signal_connect(body_.get(), "clicked", |
209 G_CALLBACK(OnClick), this); | 204 G_CALLBACK(OnClick), this); |
210 GTK_WIDGET_UNSET_FLAGS(body_.get(), GTK_CAN_FOCUS); | 205 GTK_WIDGET_UNSET_FLAGS(body_.get(), GTK_CAN_FOCUS); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 365 |
371 if (download->full_path() != icon_filepath_) { | 366 if (download->full_path() != icon_filepath_) { |
372 // Turns out the file path is "unconfirmed %d.download" for dangerous | 367 // Turns out the file path is "unconfirmed %d.download" for dangerous |
373 // downloads. When the download is confirmed, the file is renamed on | 368 // downloads. When the download is confirmed, the file is renamed on |
374 // another thread, so reload the icon if the download filename changes. | 369 // another thread, so reload the icon if the download filename changes. |
375 LoadIcon(); | 370 LoadIcon(); |
376 } | 371 } |
377 | 372 |
378 switch (download->state()) { | 373 switch (download->state()) { |
379 case DownloadItem::REMOVING: | 374 case DownloadItem::REMOVING: |
380 // Delete ourselves asychronously so that if we were deleted from the | 375 parent_shelf_->RemoveDownloadItem(this); // This will delete us! |
381 // context menu, its ref holders have a chance to let go. | |
382 MessageLoop::current()->PostTask(FROM_HERE, | |
383 method_factory_.NewRunnableMethod(&DownloadItemGtk::RemoveThis)); | |
384 return; | 376 return; |
385 case DownloadItem::CANCELLED: | 377 case DownloadItem::CANCELLED: |
386 StopDownloadProgress(); | 378 StopDownloadProgress(); |
387 gtk_widget_queue_draw(progress_area_.get()); | 379 gtk_widget_queue_draw(progress_area_.get()); |
388 break; | 380 break; |
389 case DownloadItem::COMPLETE: | 381 case DownloadItem::COMPLETE: |
390 StopDownloadProgress(); | 382 StopDownloadProgress(); |
391 complete_animation_.reset(new SlideAnimation(this)); | 383 complete_animation_.reset(new SlideAnimation(this)); |
392 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); | 384 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); |
393 complete_animation_->SetTweenType(SlideAnimation::NONE); | 385 complete_animation_->SetTweenType(SlideAnimation::NONE); |
(...skipping 18 matching lines...) Expand all Loading... |
412 // Remove the status text label. | 404 // Remove the status text label. |
413 if (status_text.empty()) { | 405 if (status_text.empty()) { |
414 gtk_widget_destroy(status_label_); | 406 gtk_widget_destroy(status_label_); |
415 status_label_ = NULL; | 407 status_label_ = NULL; |
416 return; | 408 return; |
417 } | 409 } |
418 | 410 |
419 UpdateStatusLabel(status_label_, status_text_); | 411 UpdateStatusLabel(status_label_, status_text_); |
420 } | 412 } |
421 | 413 |
422 void DownloadItemGtk::RemoveThis() { | |
423 parent_shelf_->RemoveDownloadItem(this); | |
424 } | |
425 | |
426 void DownloadItemGtk::AnimationProgressed(const Animation* animation) { | 414 void DownloadItemGtk::AnimationProgressed(const Animation* animation) { |
427 if (animation == complete_animation_.get()) { | 415 if (animation == complete_animation_.get()) { |
428 gtk_widget_queue_draw(progress_area_.get()); | 416 gtk_widget_queue_draw(progress_area_.get()); |
429 } else { | 417 } else { |
430 if (IsDangerous()) { | 418 if (IsDangerous()) { |
431 int progress = (dangerous_hbox_full_width_ - | 419 int progress = (dangerous_hbox_full_width_ - |
432 dangerous_hbox_start_width_) * | 420 dangerous_hbox_start_width_) * |
433 new_item_animation_->GetCurrentValue(); | 421 new_item_animation_->GetCurrentValue(); |
434 int showing_width = dangerous_hbox_start_width_ + progress; | 422 int showing_width = dangerous_hbox_start_width_ + progress; |
435 gtk_widget_set_size_request(dangerous_hbox_, showing_width, -1); | 423 gtk_widget_set_size_request(dangerous_hbox_, showing_width, -1); |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 | 868 |
881 // static | 869 // static |
882 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button, | 870 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button, |
883 DownloadItemGtk* item) { | 871 DownloadItemGtk* item) { |
884 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 872 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
885 base::Time::Now() - item->creation_time_); | 873 base::Time::Now() - item->creation_time_); |
886 if (item->get_download()->state() == DownloadItem::IN_PROGRESS) | 874 if (item->get_download()->state() == DownloadItem::IN_PROGRESS) |
887 item->get_download()->Cancel(true); | 875 item->get_download()->Cancel(true); |
888 item->get_download()->Remove(true); | 876 item->get_download()->Remove(true); |
889 } | 877 } |
OLD | NEW |