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 #include "chrome/browser/download/notification/download_notification_item.h" | 5 #include "chrome/browser/download/notification/download_notification_item.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/download/download_crx_util.h" | 9 #include "chrome/browser/download/download_crx_util.h" |
| 10 #include "chrome/browser/download/download_item_model.h" | 10 #include "chrome/browser/download/download_item_model.h" |
| 11 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
| 12 #include "chrome/browser/notifications/notification_ui_manager.h" | 12 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 13 #include "chrome/browser/notifications/profile_notification.h" | 13 #include "chrome/browser/notifications/profile_notification.h" |
| 14 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | |
| 15 #include "chrome/common/url_constants.h" | |
| 14 #include "chrome/grit/chromium_strings.h" | 16 #include "chrome/grit/chromium_strings.h" |
| 15 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 16 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/download_interrupt_reasons.h" | 20 #include "content/public/browser/download_interrupt_reasons.h" |
| 19 #include "content/public/browser/download_item.h" | 21 #include "content/public/browser/download_item.h" |
| 22 #include "content/public/browser/page_navigator.h" | |
| 20 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 21 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "ui/message_center/message_center.h" | 27 #include "ui/message_center/message_center.h" |
| 25 | 28 |
| 26 namespace { | 29 namespace { |
| 27 | 30 |
| 28 const char kDownloadNotificationNotifierId[] = | 31 const char kDownloadNotificationNotifierId[] = |
| 29 "chrome://downloads/notification/id-notifier"; | 32 "chrome://downloads/notification/id-notifier"; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 UpdateNotificationData(ADD_NEW); | 109 UpdateNotificationData(ADD_NEW); |
| 107 } | 110 } |
| 108 | 111 |
| 109 DownloadNotificationItem::~DownloadNotificationItem() { | 112 DownloadNotificationItem::~DownloadNotificationItem() { |
| 110 if (item_) | 113 if (item_) |
| 111 item_->RemoveObserver(this); | 114 item_->RemoveObserver(this); |
| 112 } | 115 } |
| 113 | 116 |
| 114 void DownloadNotificationItem::OnNotificationClick() { | 117 void DownloadNotificationItem::OnNotificationClick() { |
| 115 if (openable_) { | 118 if (openable_) { |
| 116 if (item_->IsDone()) | 119 if (item_->IsDone()) { |
| 117 item_->OpenDownload(); | 120 item_->OpenDownload(); |
| 118 else | 121 CloseNotificationByUser(); |
| 122 } else { | |
| 119 item_->SetOpenWhenComplete(!item_->GetOpenWhenComplete()); // Toggle | 123 item_->SetOpenWhenComplete(!item_->GetOpenWhenComplete()); // Toggle |
| 124 } | |
| 125 } else if (item_->GetState() == content::DownloadItem::INTERRUPTED || | |
| 126 item_->GetState() == content::DownloadItem::CANCELLED) { | |
| 127 GetBrowser()->OpenURL(content::OpenURLParams( | |
| 128 GURL(chrome::kChromeUIDownloadsURL), content::Referrer(), | |
| 129 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | |
| 130 false /* is_renderer_initiated */)); | |
| 131 CloseNotificationByUser(); | |
| 132 } else if (item_->IsDone()) { | |
| 133 CloseNotificationByUser(); | |
| 120 } | 134 } |
| 121 | |
| 122 if (item_->IsDone()) | |
| 123 CloseNotificationByUser(); | |
| 124 } | 135 } |
| 125 | 136 |
| 126 void DownloadNotificationItem::OnNotificationButtonClick(int button_index) { | 137 void DownloadNotificationItem::OnNotificationButtonClick(int button_index) { |
| 127 if (button_index < 0 || | 138 if (button_index < 0 || |
| 128 static_cast<size_t>(button_index) >= button_actions_->size()) { | 139 static_cast<size_t>(button_index) >= button_actions_->size()) { |
| 129 // Out of boundary. | 140 // Out of boundary. |
| 130 NOTREACHED(); | 141 NOTREACHED(); |
| 131 return; | 142 return; |
| 132 } | 143 } |
| 133 | 144 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 case content::DownloadItem::IN_PROGRESS: | 334 case content::DownloadItem::IN_PROGRESS: |
| 324 actions->push_back(DownloadCommands::OPEN_WHEN_COMPLETE); | 335 actions->push_back(DownloadCommands::OPEN_WHEN_COMPLETE); |
| 325 if (!item_->IsPaused()) | 336 if (!item_->IsPaused()) |
| 326 actions->push_back(DownloadCommands::PAUSE); | 337 actions->push_back(DownloadCommands::PAUSE); |
| 327 else | 338 else |
| 328 actions->push_back(DownloadCommands::RESUME); | 339 actions->push_back(DownloadCommands::RESUME); |
| 329 actions->push_back(DownloadCommands::CANCEL); | 340 actions->push_back(DownloadCommands::CANCEL); |
| 330 break; | 341 break; |
| 331 case content::DownloadItem::CANCELLED: | 342 case content::DownloadItem::CANCELLED: |
| 332 case content::DownloadItem::INTERRUPTED: | 343 case content::DownloadItem::INTERRUPTED: |
| 333 actions->push_back(DownloadCommands::RETRY); | 344 if (item_->CanResume()) |
| 345 actions->push_back(DownloadCommands::RETRY); | |
| 334 break; | 346 break; |
| 335 case content::DownloadItem::COMPLETE: | 347 case content::DownloadItem::COMPLETE: |
| 336 actions->push_back(DownloadCommands::OPEN_WHEN_COMPLETE); | 348 actions->push_back(DownloadCommands::OPEN_WHEN_COMPLETE); |
| 337 actions->push_back(DownloadCommands::SHOW_IN_FOLDER); | 349 actions->push_back(DownloadCommands::SHOW_IN_FOLDER); |
| 338 break; | 350 break; |
| 339 case content::DownloadItem::MAX_DOWNLOAD_STATE: | 351 case content::DownloadItem::MAX_DOWNLOAD_STATE: |
| 340 NOTREACHED(); | 352 NOTREACHED(); |
| 341 } | 353 } |
| 342 return actions.Pass(); | 354 return actions.Pass(); |
| 343 } | 355 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 break; | 396 break; |
| 385 case DownloadCommands::RESUME: | 397 case DownloadCommands::RESUME: |
| 386 // Only for non menu. | 398 // Only for non menu. |
| 387 id = IDS_DOWNLOAD_LINK_RESUME; | 399 id = IDS_DOWNLOAD_LINK_RESUME; |
| 388 break; | 400 break; |
| 389 case DownloadCommands::SHOW_IN_FOLDER: | 401 case DownloadCommands::SHOW_IN_FOLDER: |
| 390 id = IDS_DOWNLOAD_LINK_SHOW; | 402 id = IDS_DOWNLOAD_LINK_SHOW; |
| 391 break; | 403 break; |
| 392 case DownloadCommands::RETRY: | 404 case DownloadCommands::RETRY: |
| 393 // Only for non menu. | 405 // Only for non menu. |
| 394 id = IDS_DOWNLOAD_LINK_RETRY; | 406 id = IDS_DOWNLOAD_LINK_RETRY; |
|
yoshiki
2015/05/14 01:21:45
Note that this string is still used by other place
| |
| 395 break; | 407 break; |
| 396 case DownloadCommands::DISCARD: | 408 case DownloadCommands::DISCARD: |
| 397 id = IDS_DISCARD_DOWNLOAD; | 409 id = IDS_DISCARD_DOWNLOAD; |
| 398 break; | 410 break; |
| 399 case DownloadCommands::KEEP: | 411 case DownloadCommands::KEEP: |
| 400 id = IDS_CONFIRM_DOWNLOAD; | 412 id = IDS_CONFIRM_DOWNLOAD; |
| 401 break; | 413 break; |
| 402 case DownloadCommands::CANCEL: | 414 case DownloadCommands::CANCEL: |
| 403 id = IDS_DOWNLOAD_LINK_CANCEL; | 415 id = IDS_DOWNLOAD_LINK_CANCEL; |
| 404 break; | 416 break; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: | 460 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: |
| 449 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: | 461 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: |
| 450 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: | 462 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: |
| 451 case content::DOWNLOAD_DANGER_TYPE_MAX: { | 463 case content::DOWNLOAD_DANGER_TYPE_MAX: { |
| 452 break; | 464 break; |
| 453 } | 465 } |
| 454 } | 466 } |
| 455 NOTREACHED(); | 467 NOTREACHED(); |
| 456 return base::string16(); | 468 return base::string16(); |
| 457 } | 469 } |
| 470 | |
| 471 Browser* DownloadNotificationItem::GetBrowser() { | |
| 472 chrome::ScopedTabbedBrowserDisplayer browser_displayer( | |
| 473 profile_, chrome::GetActiveDesktop()); | |
| 474 DCHECK(browser_displayer.browser()); | |
| 475 return browser_displayer.browser(); | |
| 476 } | |
| OLD | NEW |