| 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/gtk/download/download_item_gtk.h" | 5 #include "chrome/browser/ui/gtk/download/download_item_gtk.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/download/download_item.h" | 14 #include "chrome/browser/download/download_item.h" |
| 15 #include "chrome/browser/download/download_item_model.h" | 15 #include "chrome/browser/download/download_item_model.h" |
| 16 #include "chrome/browser/download/download_manager.h" | 16 #include "chrome/browser/download/download_manager.h" |
| 17 #include "chrome/browser/download/download_util.h" | 17 #include "chrome/browser/download/download_util.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/gtk/custom_drag.h" | 19 #include "chrome/browser/ui/gtk/custom_drag.h" |
| 20 #include "chrome/browser/ui/gtk/download/download_shelf_context_menu_gtk.h" | 20 #include "chrome/browser/ui/gtk/download/download_shelf_context_menu_gtk.h" |
| 21 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" | 21 #include "chrome/browser/ui/gtk/download/download_shelf_gtk.h" |
| 22 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 22 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 23 #include "chrome/browser/ui/gtk/gtk_util.h" | 23 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 24 #include "chrome/browser/ui/gtk/nine_box.h" | 24 #include "chrome/browser/ui/gtk/nine_box.h" |
| 25 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "content/common/notification_service.h" | 26 #include "content/common/notification_service.h" |
| 26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 27 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 28 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
| 29 #include "ui/base/animation/slide_animation.h" | 30 #include "ui/base/animation/slide_animation.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "ui/base/text/text_elider.h" | 33 #include "ui/base/text/text_elider.h" |
| 33 #include "ui/gfx/canvas_skia_paint.h" | 34 #include "ui/gfx/canvas_skia_paint.h" |
| 34 #include "ui/gfx/color_utils.h" | 35 #include "ui/gfx/color_utils.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 gtk_container_add(GTK_CONTAINER(dangerous_prompt_), dangerous_hbox_.get()); | 236 gtk_container_add(GTK_CONTAINER(dangerous_prompt_), dangerous_hbox_.get()); |
| 236 gtk_box_pack_start(GTK_BOX(hbox_.get()), dangerous_prompt_, FALSE, FALSE, | 237 gtk_box_pack_start(GTK_BOX(hbox_.get()), dangerous_prompt_, FALSE, FALSE, |
| 237 0); | 238 0); |
| 238 gtk_widget_set_app_paintable(dangerous_prompt_, TRUE); | 239 gtk_widget_set_app_paintable(dangerous_prompt_, TRUE); |
| 239 gtk_widget_set_redraw_on_allocate(dangerous_prompt_, TRUE); | 240 gtk_widget_set_redraw_on_allocate(dangerous_prompt_, TRUE); |
| 240 g_signal_connect(dangerous_prompt_, "expose-event", | 241 g_signal_connect(dangerous_prompt_, "expose-event", |
| 241 G_CALLBACK(OnDangerousPromptExposeThunk), this); | 242 G_CALLBACK(OnDangerousPromptExposeThunk), this); |
| 242 gtk_widget_show_all(dangerous_prompt_); | 243 gtk_widget_show_all(dangerous_prompt_); |
| 243 } | 244 } |
| 244 | 245 |
| 245 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 246 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 246 Source<ThemeService>(theme_service_)); | 247 Source<ThemeService>(theme_service_)); |
| 247 theme_service_->InitThemesFor(this); | 248 theme_service_->InitThemesFor(this); |
| 248 | 249 |
| 249 // Set the initial width of the widget to be animated. | 250 // Set the initial width of the widget to be animated. |
| 250 if (IsDangerous()) { | 251 if (IsDangerous()) { |
| 251 gtk_widget_set_size_request(dangerous_hbox_.get(), | 252 gtk_widget_set_size_request(dangerous_hbox_.get(), |
| 252 dangerous_hbox_start_width_, -1); | 253 dangerous_hbox_start_width_, -1); |
| 253 } else { | 254 } else { |
| 254 gtk_widget_set_size_request(body_.get(), kMinDownloadItemWidth, -1); | 255 gtk_widget_set_size_request(body_.get(), kMinDownloadItemWidth, -1); |
| 255 } | 256 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 int showing_width = dangerous_hbox_start_width_ + progress; | 361 int showing_width = dangerous_hbox_start_width_ + progress; |
| 361 gtk_widget_set_size_request(dangerous_hbox_.get(), showing_width, -1); | 362 gtk_widget_set_size_request(dangerous_hbox_.get(), showing_width, -1); |
| 362 } else { | 363 } else { |
| 363 int showing_width = std::max(kMinDownloadItemWidth, | 364 int showing_width = std::max(kMinDownloadItemWidth, |
| 364 static_cast<int>(kBodyWidth * animation->GetCurrentValue())); | 365 static_cast<int>(kBodyWidth * animation->GetCurrentValue())); |
| 365 gtk_widget_set_size_request(body_.get(), showing_width, -1); | 366 gtk_widget_set_size_request(body_.get(), showing_width, -1); |
| 366 } | 367 } |
| 367 } | 368 } |
| 368 } | 369 } |
| 369 | 370 |
| 370 void DownloadItemGtk::Observe(NotificationType type, | 371 void DownloadItemGtk::Observe(int type, |
| 371 const NotificationSource& source, | 372 const NotificationSource& source, |
| 372 const NotificationDetails& details) { | 373 const NotificationDetails& details) { |
| 373 if (type == NotificationType::BROWSER_THEME_CHANGED) { | 374 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { |
| 374 // Our GtkArrow is only visible in gtk mode. Otherwise, we let the custom | 375 // Our GtkArrow is only visible in gtk mode. Otherwise, we let the custom |
| 375 // rendering code do whatever it wants. | 376 // rendering code do whatever it wants. |
| 376 if (theme_service_->UsingNativeTheme()) { | 377 if (theme_service_->UsingNativeTheme()) { |
| 377 if (!arrow_) { | 378 if (!arrow_) { |
| 378 arrow_ = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE); | 379 arrow_ = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE); |
| 379 gtk_widget_set_size_request(arrow_, | 380 gtk_widget_set_size_request(arrow_, |
| 380 static_cast<int>(kTextSize), | 381 static_cast<int>(kTextSize), |
| 381 static_cast<int>(kTextSize)); | 382 static_cast<int>(kTextSize)); |
| 382 gtk_container_add(GTK_CONTAINER(menu_button_), arrow_); | 383 gtk_container_add(GTK_CONTAINER(menu_button_), arrow_); |
| 383 } | 384 } |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 get_download()->DangerousDownloadValidated(); | 864 get_download()->DangerousDownloadValidated(); |
| 864 } | 865 } |
| 865 | 866 |
| 866 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { | 867 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button) { |
| 867 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 868 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
| 868 base::Time::Now() - creation_time_); | 869 base::Time::Now() - creation_time_); |
| 869 if (get_download()->IsPartialDownload()) | 870 if (get_download()->IsPartialDownload()) |
| 870 get_download()->Cancel(true); | 871 get_download()->Cancel(true); |
| 871 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 872 get_download()->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 872 } | 873 } |
| OLD | NEW |