Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: chrome/browser/gtk/download_item_gtk.cc

Issue 113920: Dangerous download dialog for linux.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: mac uses DownloadManager? Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/download_item_gtk.h ('k') | chrome/browser/gtk/download_shelf_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gfx/canvas.h" 8 #include "app/gfx/canvas.h"
8 #include "app/gfx/font.h" 9 #include "app/gfx/font.h"
9 #include "app/gfx/text_elider.h" 10 #include "app/gfx/text_elider.h"
11 #include "app/resource_bundle.h"
10 #include "app/slide_animation.h" 12 #include "app/slide_animation.h"
11 #include "base/basictypes.h" 13 #include "base/basictypes.h"
12 #include "base/string_util.h" 14 #include "base/string_util.h"
13 #include "base/time.h" 15 #include "base/time.h"
14 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/download/download_item_model.h" 17 #include "chrome/browser/download/download_item_model.h"
16 #include "chrome/browser/download/download_manager.h" 18 #include "chrome/browser/download/download_manager.h"
17 #include "chrome/browser/download/download_shelf.h" 19 #include "chrome/browser/download/download_shelf.h"
18 #include "chrome/browser/download/download_util.h" 20 #include "chrome/browser/download/download_util.h"
19 #include "chrome/browser/gtk/download_shelf_gtk.h" 21 #include "chrome/browser/gtk/download_shelf_gtk.h"
20 #include "chrome/browser/gtk/menu_gtk.h" 22 #include "chrome/browser/gtk/menu_gtk.h"
21 #include "chrome/browser/gtk/nine_box.h" 23 #include "chrome/browser/gtk/nine_box.h"
22 #include "chrome/common/gtk_util.h" 24 #include "chrome/common/gtk_util.h"
23 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
24 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 27 #include "third_party/skia/include/core/SkBitmap.h"
26 28
27 namespace { 29 namespace {
28 30
29 // The width of the |menu_button_| widget. It has to be at least as wide as the 31 // The width of the |menu_button_| widget. It has to be at least as wide as the
30 // bitmap that we use to draw it, i.e. 16, but can be more. 32 // bitmap that we use to draw it, i.e. 16, but can be more.
31 const int kMenuButtonWidth = 16; 33 const int kMenuButtonWidth = 16;
32 34
35 // Padding on left and right of items in dangerous download prompt.
36 const int kDangerousElementPadding = 3;
37
33 // Amount of space we allot to showing the filename. If the filename is too wide 38 // Amount of space we allot to showing the filename. If the filename is too wide
34 // it will be elided. 39 // it will be elided.
35 const int kTextWidth = 140; 40 const int kTextWidth = 140;
36 41
37 // The minimum width we will ever draw the download item. Used as a lower bound 42 // The minimum width we will ever draw the download item. Used as a lower bound
38 // during animation. This number comes from the width of the images used to 43 // during animation. This number comes from the width of the images used to
39 // make the download item. 44 // make the download item.
40 const int kMinDownloadItemWidth = 13 + download_util::kSmallProgressIconSize; 45 const int kMinDownloadItemWidth = 13 + download_util::kSmallProgressIconSize;
41 46
47 // As above, but for the dangerous download prompt.
48 const int kMinDangerousDownloadWidth = 16;
49
42 const char* kLabelColorMarkup = "<span color='#%s'>%s</span>"; 50 const char* kLabelColorMarkup = "<span color='#%s'>%s</span>";
43 const char* kFilenameColor = "576C95"; // 87, 108, 149 51 const char* kFilenameColor = "576C95"; // 87, 108, 149
44 const char* kStatusColor = "7B8DAE"; // 123, 141, 174 52 const char* kStatusColor = "7B8DAE"; // 123, 141, 174
45 53
46 // New download item animation speed in milliseconds. 54 // New download item animation speed in milliseconds.
47 const int kNewItemAnimationDurationMs = 800; 55 const int kNewItemAnimationDurationMs = 800;
48 56
49 // How long the 'download complete' animation should last for. 57 // How long the 'download complete' animation should last for.
50 const int kCompleteAnimationDurationMs = 2500; 58 const int kCompleteAnimationDurationMs = 2500;
51 59
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // DownloadItemGtk ------------------------------------------------------------- 156 // DownloadItemGtk -------------------------------------------------------------
149 157
150 NineBox* DownloadItemGtk::body_nine_box_normal_ = NULL; 158 NineBox* DownloadItemGtk::body_nine_box_normal_ = NULL;
151 NineBox* DownloadItemGtk::body_nine_box_prelight_ = NULL; 159 NineBox* DownloadItemGtk::body_nine_box_prelight_ = NULL;
152 NineBox* DownloadItemGtk::body_nine_box_active_ = NULL; 160 NineBox* DownloadItemGtk::body_nine_box_active_ = NULL;
153 161
154 NineBox* DownloadItemGtk::menu_nine_box_normal_ = NULL; 162 NineBox* DownloadItemGtk::menu_nine_box_normal_ = NULL;
155 NineBox* DownloadItemGtk::menu_nine_box_prelight_ = NULL; 163 NineBox* DownloadItemGtk::menu_nine_box_prelight_ = NULL;
156 NineBox* DownloadItemGtk::menu_nine_box_active_ = NULL; 164 NineBox* DownloadItemGtk::menu_nine_box_active_ = NULL;
157 165
166 NineBox* DownloadItemGtk::dangerous_nine_box_ = NULL;
167
158 DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, 168 DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf,
159 BaseDownloadItemModel* download_model) 169 BaseDownloadItemModel* download_model)
160 : parent_shelf_(parent_shelf), 170 : parent_shelf_(parent_shelf),
161 menu_showing_(false), 171 menu_showing_(false),
162 progress_angle_(download_util::kStartAngleDegrees), 172 progress_angle_(download_util::kStartAngleDegrees),
163 download_model_(download_model), 173 download_model_(download_model),
164 bounding_widget_(parent_shelf->GetRightBoundingWidget()), 174 bounding_widget_(parent_shelf->GetRightBoundingWidget()),
175 dangerous_prompt_(NULL),
165 icon_(NULL) { 176 icon_(NULL) {
166 InitNineBoxes(); 177 InitNineBoxes();
167 LoadIcon(); 178 LoadIcon();
168 179
169 body_ = gtk_button_new(); 180 body_ = gtk_button_new();
170 gtk_widget_set_app_paintable(body_, TRUE); 181 gtk_widget_set_app_paintable(body_, TRUE);
171 g_signal_connect(body_, "expose-event", 182 g_signal_connect(body_, "expose-event",
172 G_CALLBACK(OnExpose), this); 183 G_CALLBACK(OnExpose), this);
173 GTK_WIDGET_UNSET_FLAGS(body_, GTK_CAN_FOCUS); 184 GTK_WIDGET_UNSET_FLAGS(body_, GTK_CAN_FOCUS);
174 // Remove internal padding on the button. 185 // Remove internal padding on the button.
175 GtkRcStyle* no_padding_style = gtk_rc_style_new(); 186 GtkRcStyle* no_padding_style = gtk_rc_style_new();
176 no_padding_style->xthickness = 0; 187 no_padding_style->xthickness = 0;
177 no_padding_style->ythickness = 0; 188 no_padding_style->ythickness = 0;
178 gtk_widget_modify_style(body_, no_padding_style); 189 gtk_widget_modify_style(body_, no_padding_style);
179 g_object_unref(no_padding_style); 190 g_object_unref(no_padding_style);
180 191
181 name_label_ = gtk_label_new(NULL); 192 name_label_ = gtk_label_new(NULL);
182 193
183 // TODO(estade): This is at best an educated guess, since we don't actually 194 // TODO(estade): This is at best an educated guess, since we don't actually
184 // use gfx::Font() to draw the text. This is why we need to add so 195 // use gfx::Font() to draw the text. This is why we need to add so
185 // much padding when we set the size request. We need to either use gfx::Font 196 // much padding when we set the size request. We need to either use gfx::Font
186 // or somehow extend TextElider. 197 // or somehow extend TextElider.
187 std::wstring elided_filename = gfx::ElideFilename( 198 std::wstring elided_filename = gfx::ElideFilename(
188 download_model_->download()->GetFileName(), 199 get_download()->GetFileName(),
189 gfx::Font(), kTextWidth); 200 gfx::Font(), kTextWidth);
190 gchar* label_markup = 201 gchar* label_markup =
191 g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor, 202 g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor,
192 WideToUTF8(elided_filename).c_str()); 203 WideToUTF8(elided_filename).c_str());
193 gtk_label_set_markup(GTK_LABEL(name_label_), label_markup); 204 gtk_label_set_markup(GTK_LABEL(name_label_), label_markup);
194 g_free(label_markup); 205 g_free(label_markup);
195 206
196 status_label_ = gtk_label_new(NULL); 207 status_label_ = gtk_label_new(NULL);
197 // Left align and vertically center the labels. 208 // Left align and vertically center the labels.
198 gtk_misc_set_alignment(GTK_MISC(name_label_), 0, 0.5); 209 gtk_misc_set_alignment(GTK_MISC(name_label_), 0, 0.5);
199 gtk_misc_set_alignment(GTK_MISC(status_label_), 0, 0.5); 210 gtk_misc_set_alignment(GTK_MISC(status_label_), 0, 0.5);
200 // Until we switch to vector graphics, force the font size. 211 // Until we switch to vector graphics, force the font size.
201 gtk_util::ForceFontSizePixels(name_label_, 13.4); // 13.4px == 10pt @ 96dpi 212 gtk_util::ForceFontSizePixels(name_label_, 13.4); // 13.4px == 10pt @ 96dpi
202 gtk_util::ForceFontSizePixels(status_label_, 13.4); // 13.4px == 10pt @ 96dpi 213 gtk_util::ForceFontSizePixels(status_label_, 13.4); // 13.4px == 10pt @ 96dpi
203 214
204 // Stack the labels on top of one another. 215 // Stack the labels on top of one another.
205 GtkWidget* text_stack = gtk_vbox_new(FALSE, 0); 216 GtkWidget* text_stack = gtk_vbox_new(FALSE, 0);
206 gtk_box_pack_start(GTK_BOX(text_stack), name_label_, TRUE, TRUE, 0); 217 gtk_box_pack_start(GTK_BOX(text_stack), name_label_, TRUE, TRUE, 0);
207 gtk_box_pack_start(GTK_BOX(text_stack), status_label_, FALSE, FALSE, 0); 218 gtk_box_pack_start(GTK_BOX(text_stack), status_label_, FALSE, FALSE, 0);
208 219
209 // We use a GtkFixed because we don't want it to have its own window. 220 // We use a GtkFixed because we don't want it to have its own window.
210 // This choice of widget is not critically important though. 221 // This choice of widget is not critically important though.
211 progress_area_ = gtk_fixed_new(); 222 progress_area_ = gtk_fixed_new();
212 gtk_widget_set_size_request(progress_area_, 223 gtk_widget_set_size_request(progress_area_,
(...skipping 24 matching lines...) Expand all
237 hbox_ = gtk_hbox_new(FALSE, 0); 248 hbox_ = gtk_hbox_new(FALSE, 0);
238 gtk_box_pack_start(GTK_BOX(hbox_), body_, FALSE, FALSE, 0); 249 gtk_box_pack_start(GTK_BOX(hbox_), body_, FALSE, FALSE, 0);
239 gtk_box_pack_start(GTK_BOX(hbox_), menu_button_, FALSE, FALSE, 0); 250 gtk_box_pack_start(GTK_BOX(hbox_), menu_button_, FALSE, FALSE, 0);
240 gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_, FALSE, FALSE, 0); 251 gtk_box_pack_start(GTK_BOX(shelf_hbox), hbox_, FALSE, FALSE, 0);
241 // Insert as the leftmost item. 252 // Insert as the leftmost item.
242 gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_, 1); 253 gtk_box_reorder_child(GTK_BOX(shelf_hbox), hbox_, 1);
243 254
244 resize_handler_id_ = g_signal_connect(G_OBJECT(shelf_hbox), "size-allocate", 255 resize_handler_id_ = g_signal_connect(G_OBJECT(shelf_hbox), "size-allocate",
245 G_CALLBACK(OnShelfResized), this); 256 G_CALLBACK(OnShelfResized), this);
246 257
247 download_model_->download()->AddObserver(this); 258 get_download()->AddObserver(this);
248 259
249 new_item_animation_.reset(new SlideAnimation(this)); 260 new_item_animation_.reset(new SlideAnimation(this));
250 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); 261 new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs);
251 gtk_widget_show_all(hbox_); 262 gtk_widget_show_all(hbox_);
263
264 if (IsDangerous()) {
265 // Hide the download item components for now.
266 gtk_widget_hide(body_);
267 gtk_widget_hide(menu_button_);
268
269 // Create an hbox to hold it all.
270 dangerous_hbox_ = gtk_hbox_new(FALSE, kDangerousElementPadding);
271
272 // Add padding at the beginning and end. The hbox will add padding between
273 // the empty labels and the other elements.
274 GtkWidget* empty_label_a = gtk_label_new(NULL);
275 GtkWidget* empty_label_b = gtk_label_new(NULL);
276 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), empty_label_a,
277 FALSE, FALSE, 0);
278 gtk_box_pack_end(GTK_BOX(dangerous_hbox_), empty_label_b,
279 FALSE, FALSE, 0);
280
281 // Create the warning icon.
282 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
283 GdkPixbuf* download_pixbuf = rb.GetPixbufNamed(IDR_WARNING);
284 GtkWidget* dangerous_image = gtk_image_new_from_pixbuf(download_pixbuf);
285 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_image,
286 FALSE, FALSE, 0);
287
288 // Create the warning text.
289 // TODO(estade): the encoding might not be UTF8.
290 std::string dangerous_warning =
291 l10n_util::GetStringFUTF8(IDS_PROMPT_DANGEROUS_DOWNLOAD,
292 UTF8ToUTF16(get_download()->original_name().value()));
293 gchar* label_markup =
294 g_markup_printf_escaped(kLabelColorMarkup, kFilenameColor,
295 dangerous_warning.c_str());
296 GtkWidget* dangerous_label = gtk_label_new(NULL);
297 // Until we switch to vector graphics, force the font size.
298 // 13.4px == 10pt @ 96dpi
299 gtk_util::ForceFontSizePixels(dangerous_label, 13.4);
300 gtk_label_set_markup(GTK_LABEL(dangerous_label), label_markup);
301 gtk_label_set_line_wrap(GTK_LABEL(dangerous_label), TRUE);
302 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_label,
303 FALSE, FALSE, 0);
304 g_free(label_markup);
305
306 // Create the ok button.
307 GtkWidget* dangerous_accept = gtk_button_new_with_label(
308 l10n_util::GetStringUTF8(IDS_SAVE_DOWNLOAD).c_str());
309 g_signal_connect(dangerous_accept, "clicked",
310 G_CALLBACK(OnDangerousAccept), this);
311 GtkWidget* dangerous_accept_vbox = gtk_vbox_new(FALSE, 0);
312 gtk_box_pack_start(GTK_BOX(dangerous_accept_vbox), dangerous_accept,
313 TRUE, FALSE, 0);
314 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_accept_vbox,
315 FALSE, FALSE, 0);
316
317 // Create the nevermind button.
318 GtkWidget* dangerous_decline = gtk_button_new_with_label(
319 l10n_util::GetStringUTF8(IDS_DISCARD_DOWNLOAD).c_str());
320 g_signal_connect(dangerous_decline, "clicked",
321 G_CALLBACK(OnDangerousDecline), this);
322 GtkWidget* dangerous_decline_vbox = gtk_vbox_new(FALSE, 0);
323 gtk_box_pack_start(GTK_BOX(dangerous_decline_vbox), dangerous_decline,
324 TRUE, FALSE, 0);
325 gtk_box_pack_start(GTK_BOX(dangerous_hbox_), dangerous_decline_vbox,
326 FALSE, FALSE, 0);
327
328 // Put it in an alignment so that padding will be added on the left and
329 // right, and an event box so that drawing will be clipped correctly.
330 dangerous_prompt_ = gtk_util::CreateGtkBorderBin(dangerous_hbox_, NULL,
331 0, 0, kDangerousElementPadding, kDangerousElementPadding);
332 gtk_box_pack_start(GTK_BOX(hbox_), dangerous_prompt_, FALSE, FALSE, 0);
333 gtk_widget_set_app_paintable(dangerous_prompt_, TRUE);
334 g_signal_connect(dangerous_prompt_, "expose-event",
335 G_CALLBACK(OnDangerousPromptExpose), this);
336 gtk_widget_show_all(dangerous_prompt_);
337
338 // The full width will depend on the text.
339 GtkRequisition req;
340 gtk_widget_size_request(dangerous_hbox_, &req);
341 dangerous_hbox_full_width_ = req.width;
342 }
343
252 new_item_animation_->Show(); 344 new_item_animation_->Show();
253 } 345 }
254 346
255 DownloadItemGtk::~DownloadItemGtk() { 347 DownloadItemGtk::~DownloadItemGtk() {
256 StopDownloadProgress(); 348 StopDownloadProgress();
257 g_signal_handler_disconnect(parent_shelf_->GetHBox(), resize_handler_id_); 349 g_signal_handler_disconnect(parent_shelf_->GetHBox(), resize_handler_id_);
258 gtk_widget_destroy(hbox_); 350 gtk_widget_destroy(hbox_);
259 download_model_->download()->RemoveObserver(this); 351 get_download()->RemoveObserver(this);
260 } 352 }
261 353
262 void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) { 354 void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) {
263 DCHECK_EQ(download, download_model_->download()); 355 DCHECK_EQ(download, get_download());
356
357 if (dangerous_prompt_ != NULL &&
358 download->safety_state() == DownloadItem::DANGEROUS_BUT_VALIDATED) {
359 // We have been approved.
360 gtk_widget_show_all(hbox_);
361 gtk_widget_destroy(dangerous_prompt_);
362 dangerous_prompt_ = NULL;
363 }
264 364
265 switch (download->state()) { 365 switch (download->state()) {
266 case DownloadItem::REMOVING: 366 case DownloadItem::REMOVING:
267 parent_shelf_->RemoveDownloadItem(this); // This will delete us! 367 parent_shelf_->RemoveDownloadItem(this); // This will delete us!
268 return; 368 return;
269 case DownloadItem::CANCELLED: 369 case DownloadItem::CANCELLED:
270 StopDownloadProgress(); 370 StopDownloadProgress();
271 break; 371 break;
272 case DownloadItem::COMPLETE: 372 case DownloadItem::COMPLETE:
273 StopDownloadProgress(); 373 StopDownloadProgress();
274 complete_animation_.reset(new SlideAnimation(this)); 374 complete_animation_.reset(new SlideAnimation(this));
275 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); 375 complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs);
276 complete_animation_->SetTweenType(SlideAnimation::NONE); 376 complete_animation_->SetTweenType(SlideAnimation::NONE);
277 complete_animation_->Show(); 377 complete_animation_->Show();
278 break; 378 break;
279 case DownloadItem::IN_PROGRESS: 379 case DownloadItem::IN_PROGRESS:
280 download_model_->download()->is_paused() ? 380 get_download()->is_paused() ?
281 StopDownloadProgress() : StartDownloadProgress(); 381 StopDownloadProgress() : StartDownloadProgress();
282 break; 382 break;
283 default: 383 default:
284 NOTREACHED(); 384 NOTREACHED();
285 } 385 }
286 386
287 // Now update the status label. We may have already removed it; if so, we 387 // Now update the status label. We may have already removed it; if so, we
288 // do nothing. 388 // do nothing.
289 if (!status_label_) { 389 if (!status_label_) {
290 return; 390 return;
(...skipping 11 matching lines...) Expand all
302 g_markup_printf_escaped(kLabelColorMarkup, kStatusColor, 402 g_markup_printf_escaped(kLabelColorMarkup, kStatusColor,
303 WideToUTF8(status_text).c_str()); 403 WideToUTF8(status_text).c_str());
304 gtk_label_set_markup(GTK_LABEL(status_label_), label_markup); 404 gtk_label_set_markup(GTK_LABEL(status_label_), label_markup);
305 g_free(label_markup); 405 g_free(label_markup);
306 } 406 }
307 407
308 void DownloadItemGtk::AnimationProgressed(const Animation* animation) { 408 void DownloadItemGtk::AnimationProgressed(const Animation* animation) {
309 if (animation == complete_animation_.get()) { 409 if (animation == complete_animation_.get()) {
310 gtk_widget_queue_draw(progress_area_); 410 gtk_widget_queue_draw(progress_area_);
311 } else { 411 } else {
312 DCHECK(animation == new_item_animation_.get()); 412 if (IsDangerous()) {
313 // See above TODO for explanation of the extra 50. 413 int showing_width = std::max(kMinDangerousDownloadWidth,
314 int showing_width = std::max(kMinDownloadItemWidth, 414 static_cast<int>(dangerous_hbox_full_width_ *
315 static_cast<int>((kTextWidth + 50 + 415 new_item_animation_->GetCurrentValue()));
316 download_util::kSmallProgressIconSize) * 416 gtk_widget_set_size_request(dangerous_hbox_, showing_width, -1);
317 new_item_animation_->GetCurrentValue())); 417 } else {
318 showing_width = std::max(showing_width, kMinDownloadItemWidth); 418 DCHECK(animation == new_item_animation_.get());
319 gtk_widget_set_size_request(body_, showing_width, -1); 419 // See above TODO for explanation of the extra 50.
420 int showing_width = std::max(kMinDownloadItemWidth,
421 static_cast<int>((kTextWidth + 50 +
422 download_util::kSmallProgressIconSize) *
423 new_item_animation_->GetCurrentValue()));
424 showing_width = std::max(showing_width, kMinDownloadItemWidth);
425 gtk_widget_set_size_request(body_, showing_width, -1);
426 }
320 } 427 }
321 } 428 }
322 429
430 DownloadItem* DownloadItemGtk::get_download() {
431 return download_model_->download();
432 }
433
434 bool DownloadItemGtk::IsDangerous() {
435 return get_download()->safety_state() == DownloadItem::DANGEROUS;
436 }
437
323 // Download progress animation functions. 438 // Download progress animation functions.
324 439
325 void DownloadItemGtk::UpdateDownloadProgress() { 440 void DownloadItemGtk::UpdateDownloadProgress() {
326 progress_angle_ = (progress_angle_ + 441 progress_angle_ = (progress_angle_ +
327 download_util::kUnknownIncrementDegrees) % 442 download_util::kUnknownIncrementDegrees) %
328 download_util::kMaxDegrees; 443 download_util::kMaxDegrees;
329 gtk_widget_queue_draw(progress_area_); 444 gtk_widget_queue_draw(progress_area_);
330 } 445 }
331 446
332 void DownloadItemGtk::StartDownloadProgress() { 447 void DownloadItemGtk::StartDownloadProgress() {
(...skipping 11 matching lines...) Expand all
344 // Icon loading functions. 459 // Icon loading functions.
345 460
346 void DownloadItemGtk::OnLoadIconComplete(IconManager::Handle handle, 461 void DownloadItemGtk::OnLoadIconComplete(IconManager::Handle handle,
347 SkBitmap* icon_bitmap) { 462 SkBitmap* icon_bitmap) {
348 icon_ = icon_bitmap; 463 icon_ = icon_bitmap;
349 gtk_widget_queue_draw(progress_area_); 464 gtk_widget_queue_draw(progress_area_);
350 } 465 }
351 466
352 void DownloadItemGtk::LoadIcon() { 467 void DownloadItemGtk::LoadIcon() {
353 IconManager* im = g_browser_process->icon_manager(); 468 IconManager* im = g_browser_process->icon_manager();
354 im->LoadIcon(download_model_->download()->full_path(), 469 im->LoadIcon(get_download()->full_path(),
355 IconLoader::SMALL, &icon_consumer_, 470 IconLoader::SMALL, &icon_consumer_,
356 NewCallback(this, &DownloadItemGtk::OnLoadIconComplete)); 471 NewCallback(this, &DownloadItemGtk::OnLoadIconComplete));
357 } 472 }
358 473
359 // static 474 // static
360 void DownloadItemGtk::InitNineBoxes() { 475 void DownloadItemGtk::InitNineBoxes() {
361 if (body_nine_box_normal_) 476 if (body_nine_box_normal_)
362 return; 477 return;
363 478
364 body_nine_box_normal_ = new NineBox( 479 body_nine_box_normal_ = new NineBox(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 516
402 menu_nine_box_prelight_ = new NineBox( 517 menu_nine_box_prelight_ = new NineBox(
403 IDR_DOWNLOAD_BUTTON_MENU_TOP_H, 0, 0, 518 IDR_DOWNLOAD_BUTTON_MENU_TOP_H, 0, 0,
404 IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_H, 0, 0, 519 IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_H, 0, 0,
405 IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_H, 0, 0); 520 IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_H, 0, 0);
406 521
407 menu_nine_box_active_ = new NineBox( 522 menu_nine_box_active_ = new NineBox(
408 IDR_DOWNLOAD_BUTTON_MENU_TOP_P, 0, 0, 523 IDR_DOWNLOAD_BUTTON_MENU_TOP_P, 0, 0,
409 IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_P, 0, 0, 524 IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_P, 0, 0,
410 IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_P, 0, 0); 525 IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_P, 0, 0);
526
527 dangerous_nine_box_ = new NineBox(
528 IDR_DOWNLOAD_BUTTON_LEFT_TOP,
529 IDR_DOWNLOAD_BUTTON_CENTER_TOP,
530 IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD,
531 IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE,
532 IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE,
533 IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD,
534 IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM,
535 IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM,
536 IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD);
411 } 537 }
412 538
413 // static 539 // static
414 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e, 540 gboolean DownloadItemGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e,
415 DownloadItemGtk* download_item) { 541 DownloadItemGtk* download_item) {
416 NineBox* nine_box = NULL; 542 NineBox* nine_box = NULL;
417 // If true, this widget is |body_|, otherwise it is |menu_button_|. 543 // If true, this widget is |body_|, otherwise it is |menu_button_|.
418 bool is_body = widget == download_item->body_; 544 bool is_body = widget == download_item->body_;
419 if (GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT) 545 if (GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT)
420 nine_box = is_body ? body_nine_box_prelight_ : menu_nine_box_prelight_; 546 nine_box = is_body ? body_nine_box_prelight_ : menu_nine_box_prelight_;
(...skipping 26 matching lines...) Expand all
447 if (download_item->complete_animation_->IsAnimating()) { 573 if (download_item->complete_animation_->IsAnimating()) {
448 download_util::PaintDownloadComplete(&canvas, 574 download_util::PaintDownloadComplete(&canvas,
449 widget->allocation.x, widget->allocation.y, 575 widget->allocation.x, widget->allocation.y,
450 download_item->complete_animation_->GetCurrentValue(), 576 download_item->complete_animation_->GetCurrentValue(),
451 download_util::SMALL); 577 download_util::SMALL);
452 } 578 }
453 } else { 579 } else {
454 download_util::PaintDownloadProgress(&canvas, 580 download_util::PaintDownloadProgress(&canvas,
455 widget->allocation.x, widget->allocation.y, 581 widget->allocation.x, widget->allocation.y,
456 download_item->progress_angle_, 582 download_item->progress_angle_,
457 download_item->download_model_->download()->PercentComplete(), 583 download_item->get_download()->PercentComplete(),
458 download_util::SMALL); 584 download_util::SMALL);
459 } 585 }
460 586
461 // TODO(estade): draw a default icon if |icon_| is null. 587 // TODO(estade): draw a default icon if |icon_| is null.
462 if (download_item->icon_) { 588 if (download_item->icon_) {
463 canvas.DrawBitmapInt(*download_item->icon_, 589 canvas.DrawBitmapInt(*download_item->icon_,
464 widget->allocation.x + download_util::kSmallProgressIconOffset, 590 widget->allocation.x + download_util::kSmallProgressIconOffset,
465 widget->allocation.y + download_util::kSmallProgressIconOffset); 591 widget->allocation.y + download_util::kSmallProgressIconOffset);
466 } 592 }
467 593
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // static 627 // static
502 void DownloadItemGtk::OnShelfResized(GtkWidget *widget, 628 void DownloadItemGtk::OnShelfResized(GtkWidget *widget,
503 GtkAllocation *allocation, 629 GtkAllocation *allocation,
504 DownloadItemGtk* item) { 630 DownloadItemGtk* item) {
505 if (item->hbox_->allocation.x + item->hbox_->allocation.width > 631 if (item->hbox_->allocation.x + item->hbox_->allocation.width >
506 item->bounding_widget_->allocation.x) 632 item->bounding_widget_->allocation.x)
507 gtk_widget_hide(item->hbox_); 633 gtk_widget_hide(item->hbox_);
508 else 634 else
509 gtk_widget_show(item->hbox_); 635 gtk_widget_show(item->hbox_);
510 } 636 }
637
638 // static
639 gboolean DownloadItemGtk::OnDangerousPromptExpose(GtkWidget* widget,
640 GdkEventExpose* event, DownloadItemGtk* item) {
641 dangerous_nine_box_->RenderToWidget(widget);
642 return FALSE; // Continue propagation.
643 }
644
645 // static
646 // TODO(estade): here and below, add clickjacking histogram code.
647 void DownloadItemGtk::OnDangerousAccept(GtkWidget* button,
648 DownloadItemGtk* item) {
649 item->get_download()->manager()->DangerousDownloadValidated(
650 item->get_download());
651 }
652
653 // static
654 void DownloadItemGtk::OnDangerousDecline(GtkWidget* button,
655 DownloadItemGtk* item) {
656 if (item->get_download()->state() == DownloadItem::IN_PROGRESS)
657 item->get_download()->Cancel(true);
658 item->get_download()->Remove(true);
659 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/download_item_gtk.h ('k') | chrome/browser/gtk/download_shelf_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698