| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/create_application_shortcut_view.h" | 5 #include "chrome/browser/ui/views/create_application_shortcut_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
| 14 #include "chrome/browser/extensions/tab_helper.h" | 14 #include "chrome/browser/extensions/tab_helper.h" |
| 15 #include "chrome/browser/favicon/favicon_util.h" | 15 #include "chrome/browser/favicon/favicon_util.h" |
| 16 #include "chrome/browser/history/select_favicon_frames.h" | 16 #include "chrome/browser/history/select_favicon_frames.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_commands.h" | 19 #include "chrome/browser/ui/browser_commands.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 21 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 22 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 22 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 23 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| 27 #include "content/public/browser/render_widget_host_view.h" | 27 #include "content/public/browser/render_widget_host_view.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 30 #include "grit/chromium_strings.h" |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "grit/locale_settings.h" | 32 #include "grit/locale_settings.h" |
| 32 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 33 #include "net/base/load_flags.h" | 34 #include "net/base/load_flags.h" |
| 34 #include "net/url_request/url_request.h" | 35 #include "net/url_request/url_request.h" |
| 35 #include "skia/ext/image_operations.h" | 36 #include "skia/ext/image_operations.h" |
| 36 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
| 37 #include "third_party/skia/include/core/SkPaint.h" | 38 #include "third_party/skia/include/core/SkPaint.h" |
| 38 #include "third_party/skia/include/core/SkRect.h" | 39 #include "third_party/skia/include/core/SkRect.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 371 } |
| 371 | 372 |
| 372 bool CreateApplicationShortcutView::Accept() { | 373 bool CreateApplicationShortcutView::Accept() { |
| 373 if (!IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)) | 374 if (!IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)) |
| 374 return false; | 375 return false; |
| 375 | 376 |
| 376 ShellIntegration::ShortcutLocations creation_locations; | 377 ShellIntegration::ShortcutLocations creation_locations; |
| 377 creation_locations.on_desktop = desktop_check_box_->checked(); | 378 creation_locations.on_desktop = desktop_check_box_->checked(); |
| 378 creation_locations.in_applications_menu = menu_check_box_ == NULL ? false : | 379 creation_locations.in_applications_menu = menu_check_box_ == NULL ? false : |
| 379 menu_check_box_->checked(); | 380 menu_check_box_->checked(); |
| 381 creation_locations.applications_menu_subdir = shortcut_menu_subdir_; |
| 380 | 382 |
| 381 #if defined(OS_WIN) | 383 #if defined(OS_WIN) |
| 382 creation_locations.in_quick_launch_bar = quick_launch_check_box_ == NULL ? | 384 creation_locations.in_quick_launch_bar = quick_launch_check_box_ == NULL ? |
| 383 NULL : quick_launch_check_box_->checked(); | 385 NULL : quick_launch_check_box_->checked(); |
| 384 #elif defined(OS_POSIX) | 386 #elif defined(OS_POSIX) |
| 385 // Create shortcut in Mac dock or as Linux (gnome/kde) application launcher | 387 // Create shortcut in Mac dock or as Linux (gnome/kde) application launcher |
| 386 // are not implemented yet. | 388 // are not implemented yet. |
| 387 creation_locations.in_quick_launch_bar = false; | 389 creation_locations.in_quick_launch_bar = false; |
| 388 #endif | 390 #endif |
| 389 | 391 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 pending_download_id_(-1) { | 426 pending_download_id_(-1) { |
| 425 | 427 |
| 426 web_app::GetShortcutInfoForTab(web_contents_, &shortcut_info_); | 428 web_app::GetShortcutInfoForTab(web_contents_, &shortcut_info_); |
| 427 const WebApplicationInfo& app_info = | 429 const WebApplicationInfo& app_info = |
| 428 extensions::TabHelper::FromWebContents(web_contents_)->web_app_info(); | 430 extensions::TabHelper::FromWebContents(web_contents_)->web_app_info(); |
| 429 if (!app_info.icons.empty()) { | 431 if (!app_info.icons.empty()) { |
| 430 web_app::GetIconsInfo(app_info, &unprocessed_icons_); | 432 web_app::GetIconsInfo(app_info, &unprocessed_icons_); |
| 431 FetchIcon(); | 433 FetchIcon(); |
| 432 } | 434 } |
| 433 | 435 |
| 436 // NOTE: Leave shortcut_menu_subdir_ blank to create URL app shortcuts in the |
| 437 // top-level menu. |
| 438 |
| 434 InitControls(); | 439 InitControls(); |
| 435 } | 440 } |
| 436 | 441 |
| 437 CreateUrlApplicationShortcutView::~CreateUrlApplicationShortcutView() { | 442 CreateUrlApplicationShortcutView::~CreateUrlApplicationShortcutView() { |
| 438 } | 443 } |
| 439 | 444 |
| 440 bool CreateUrlApplicationShortcutView::Accept() { | 445 bool CreateUrlApplicationShortcutView::Accept() { |
| 441 if (!CreateApplicationShortcutView::Accept()) | 446 if (!CreateApplicationShortcutView::Accept()) |
| 442 return false; | 447 return false; |
| 443 | 448 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( | 508 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( |
| 504 Profile* profile, | 509 Profile* profile, |
| 505 const extensions::Extension* app) : | 510 const extensions::Extension* app) : |
| 506 CreateApplicationShortcutView(profile), | 511 CreateApplicationShortcutView(profile), |
| 507 app_(app), | 512 app_(app), |
| 508 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 513 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 509 // Required by InitControls(). | 514 // Required by InitControls(). |
| 510 shortcut_info_.title = UTF8ToUTF16(app->name()); | 515 shortcut_info_.title = UTF8ToUTF16(app->name()); |
| 511 shortcut_info_.description = UTF8ToUTF16(app->description()); | 516 shortcut_info_.description = UTF8ToUTF16(app->description()); |
| 512 | 517 |
| 518 // Place Chrome app shortcuts in the "Chrome Apps" submenu. |
| 519 shortcut_menu_subdir_ = |
| 520 l10n_util::GetStringUTF16(IDS_APP_SHORTCUTS_SUBDIR_NAME); |
| 521 |
| 513 InitControls(); | 522 InitControls(); |
| 514 | 523 |
| 515 // Get shortcut information and icon now; they are needed for our UI. | 524 // Get shortcut information and icon now; they are needed for our UI. |
| 516 web_app::UpdateShortcutInfoAndIconForApp( | 525 web_app::UpdateShortcutInfoAndIconForApp( |
| 517 *app, profile, | 526 *app, profile, |
| 518 base::Bind(&CreateChromeApplicationShortcutView::OnShortcutInfoLoaded, | 527 base::Bind(&CreateChromeApplicationShortcutView::OnShortcutInfoLoaded, |
| 519 weak_ptr_factory_.GetWeakPtr())); | 528 weak_ptr_factory_.GetWeakPtr())); |
| 520 } | 529 } |
| 521 | 530 |
| 522 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} | 531 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} |
| 523 | 532 |
| 524 // Called when the app's ShortcutInfo (with icon) is loaded. | 533 // Called when the app's ShortcutInfo (with icon) is loaded. |
| 525 void CreateChromeApplicationShortcutView::OnShortcutInfoLoaded( | 534 void CreateChromeApplicationShortcutView::OnShortcutInfoLoaded( |
| 526 const ShellIntegration::ShortcutInfo& shortcut_info) { | 535 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 527 shortcut_info_ = shortcut_info; | 536 shortcut_info_ = shortcut_info; |
| 528 | 537 |
| 529 CHECK(app_info_); | 538 CHECK(app_info_); |
| 530 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | 539 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); |
| 531 } | 540 } |
| OLD | NEW |