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 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 } | 245 } |
246 | 246 |
247 } // namespace chrome | 247 } // namespace chrome |
248 | 248 |
249 CreateApplicationShortcutView::CreateApplicationShortcutView(Profile* profile) | 249 CreateApplicationShortcutView::CreateApplicationShortcutView(Profile* profile) |
250 : profile_(profile), | 250 : profile_(profile), |
251 app_info_(NULL), | 251 app_info_(NULL), |
252 create_shortcuts_label_(NULL), | 252 create_shortcuts_label_(NULL), |
253 desktop_check_box_(NULL), | 253 desktop_check_box_(NULL), |
254 menu_check_box_(NULL), | 254 menu_check_box_(NULL), |
255 quick_launch_check_box_(NULL) {} | 255 quick_launch_check_box_(NULL), |
256 shortcut_info_(new web_app::ShortcutInfo) { | |
257 } | |
256 | 258 |
257 CreateApplicationShortcutView::~CreateApplicationShortcutView() {} | 259 CreateApplicationShortcutView::~CreateApplicationShortcutView() {} |
258 | 260 |
259 void CreateApplicationShortcutView::InitControls(DialogLayout dialog_layout) { | 261 void CreateApplicationShortcutView::InitControls(DialogLayout dialog_layout) { |
260 if (dialog_layout == DIALOG_LAYOUT_URL_SHORTCUT) { | 262 if (dialog_layout == DIALOG_LAYOUT_URL_SHORTCUT) { |
261 app_info_ = new AppInfoView(shortcut_info_.title, | 263 app_info_ = new AppInfoView(shortcut_info_->title, |
262 shortcut_info_.description, | 264 shortcut_info_->description, |
263 shortcut_info_.favicon); | 265 shortcut_info_->favicon); |
264 } | 266 } |
265 create_shortcuts_label_ = new views::Label( | 267 create_shortcuts_label_ = new views::Label( |
266 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_LABEL)); | 268 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_LABEL)); |
267 create_shortcuts_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 269 create_shortcuts_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
268 | 270 |
269 desktop_check_box_ = AddCheckbox( | 271 desktop_check_box_ = AddCheckbox( |
270 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_DESKTOP_CHKBOX), | 272 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_DESKTOP_CHKBOX), |
271 profile_->GetPrefs()->GetBoolean(prefs::kWebAppCreateOnDesktop)); | 273 profile_->GetPrefs()->GetBoolean(prefs::kWebAppCreateOnDesktop)); |
272 | 274 |
273 menu_check_box_ = NULL; | 275 menu_check_box_ = NULL; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 creation_locations.in_quick_launch_bar = quick_launch_check_box_ == NULL ? | 388 creation_locations.in_quick_launch_bar = quick_launch_check_box_ == NULL ? |
387 NULL : quick_launch_check_box_->checked(); | 389 NULL : quick_launch_check_box_->checked(); |
388 #elif defined(OS_POSIX) | 390 #elif defined(OS_POSIX) |
389 // Create shortcut in Mac dock or as Linux (gnome/kde) application launcher | 391 // Create shortcut in Mac dock or as Linux (gnome/kde) application launcher |
390 // are not implemented yet. | 392 // are not implemented yet. |
391 creation_locations.in_quick_launch_bar = false; | 393 creation_locations.in_quick_launch_bar = false; |
392 #endif | 394 #endif |
393 | 395 |
394 web_app::CreateShortcutsWithInfo(web_app::SHORTCUT_CREATION_BY_USER, | 396 web_app::CreateShortcutsWithInfo(web_app::SHORTCUT_CREATION_BY_USER, |
395 creation_locations, | 397 creation_locations, |
396 shortcut_info_, | 398 shortcut_info_.Pass(), |
397 file_handlers_info_); | 399 file_handlers_info_); |
400 // CreateShortcutsWithInfo stole ownership of |shortcut_info_|, so create a | |
401 // new blank one (to satisfy the non-null constraint). | |
402 shortcut_info_.reset(new web_app::ShortcutInfo); | |
benwells
2015/03/26 05:28:51
Why do this? Put another way, why is there a const
Matt Giuca
2015/03/27 08:14:46
Partly laziness :)
It would mean having to introd
| |
398 return true; | 403 return true; |
399 } | 404 } |
400 | 405 |
401 views::Checkbox* CreateApplicationShortcutView::AddCheckbox( | 406 views::Checkbox* CreateApplicationShortcutView::AddCheckbox( |
402 const base::string16& text, bool checked) { | 407 const base::string16& text, bool checked) { |
403 views::Checkbox* checkbox = new views::Checkbox(text); | 408 views::Checkbox* checkbox = new views::Checkbox(text); |
404 checkbox->SetChecked(checked); | 409 checkbox->SetChecked(checked); |
405 checkbox->set_listener(this); | 410 checkbox->set_listener(this); |
406 return checkbox; | 411 return checkbox; |
407 } | 412 } |
(...skipping 15 matching lines...) Expand all Loading... | |
423 GetDialogClientView()->UpdateDialogButtons(); | 428 GetDialogClientView()->UpdateDialogButtons(); |
424 } | 429 } |
425 | 430 |
426 CreateUrlApplicationShortcutView::CreateUrlApplicationShortcutView( | 431 CreateUrlApplicationShortcutView::CreateUrlApplicationShortcutView( |
427 content::WebContents* web_contents) | 432 content::WebContents* web_contents) |
428 : CreateApplicationShortcutView( | 433 : CreateApplicationShortcutView( |
429 Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 434 Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
430 web_contents_(web_contents), | 435 web_contents_(web_contents), |
431 pending_download_id_(-1), | 436 pending_download_id_(-1), |
432 weak_ptr_factory_(this) { | 437 weak_ptr_factory_(this) { |
433 web_app::GetShortcutInfoForTab(web_contents_, &shortcut_info_); | 438 web_app::GetShortcutInfoForTab(web_contents_, shortcut_info_.get()); |
434 const WebApplicationInfo& app_info = | 439 const WebApplicationInfo& app_info = |
435 extensions::TabHelper::FromWebContents(web_contents_)->web_app_info(); | 440 extensions::TabHelper::FromWebContents(web_contents_)->web_app_info(); |
436 if (!app_info.icons.empty()) { | 441 if (!app_info.icons.empty()) { |
437 web_app::GetIconsInfo(app_info, &unprocessed_icons_); | 442 web_app::GetIconsInfo(app_info, &unprocessed_icons_); |
438 FetchIcon(); | 443 FetchIcon(); |
439 } | 444 } |
440 | 445 |
441 // Create URL app shortcuts in the top-level menu. | 446 // Create URL app shortcuts in the top-level menu. |
442 create_in_chrome_apps_subdir_ = false; | 447 create_in_chrome_apps_subdir_ = false; |
443 | 448 |
444 InitControls(DIALOG_LAYOUT_URL_SHORTCUT); | 449 InitControls(DIALOG_LAYOUT_URL_SHORTCUT); |
445 } | 450 } |
446 | 451 |
447 CreateUrlApplicationShortcutView::~CreateUrlApplicationShortcutView() { | 452 CreateUrlApplicationShortcutView::~CreateUrlApplicationShortcutView() { |
448 } | 453 } |
449 | 454 |
450 bool CreateUrlApplicationShortcutView::Accept() { | 455 bool CreateUrlApplicationShortcutView::Accept() { |
451 if (!CreateApplicationShortcutView::Accept()) | 456 if (!CreateApplicationShortcutView::Accept()) |
452 return false; | 457 return false; |
453 | 458 |
454 // Get the smallest icon in the icon family (should have only 1). | 459 // Get the smallest icon in the icon family (should have only 1). |
455 const gfx::Image* icon = shortcut_info_.favicon.GetBest(0, 0); | 460 const gfx::Image* icon = shortcut_info_->favicon.GetBest(0, 0); |
456 SkBitmap bitmap = icon ? icon->AsBitmap() : SkBitmap(); | 461 SkBitmap bitmap = icon ? icon->AsBitmap() : SkBitmap(); |
457 extensions::TabHelper::FromWebContents(web_contents_)->SetAppIcon(bitmap); | 462 extensions::TabHelper::FromWebContents(web_contents_)->SetAppIcon(bitmap); |
458 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 463 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
459 if (browser) | 464 if (browser) |
460 chrome::ConvertTabToAppWindow(browser, web_contents_); | 465 chrome::ConvertTabToAppWindow(browser, web_contents_); |
461 return true; | 466 return true; |
462 } | 467 } |
463 | 468 |
464 void CreateUrlApplicationShortcutView::FetchIcon() { | 469 void CreateUrlApplicationShortcutView::FetchIcon() { |
465 // There should only be fetch job at a time. | 470 // There should only be fetch job at a time. |
(...skipping 25 matching lines...) Expand all Loading... | |
491 if (id != pending_download_id_) | 496 if (id != pending_download_id_) |
492 return; | 497 return; |
493 pending_download_id_ = -1; | 498 pending_download_id_ = -1; |
494 | 499 |
495 gfx::ImageSkia image_skia = CreateFaviconImageSkia( | 500 gfx::ImageSkia image_skia = CreateFaviconImageSkia( |
496 bitmaps, | 501 bitmaps, |
497 original_bitmap_sizes, | 502 original_bitmap_sizes, |
498 requested_size, | 503 requested_size, |
499 NULL); | 504 NULL); |
500 if (!image_skia.isNull()) { | 505 if (!image_skia.isNull()) { |
501 shortcut_info_.favicon.Add(image_skia); | 506 shortcut_info_->favicon.Add(image_skia); |
502 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | 507 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_->favicon); |
503 } else { | 508 } else { |
504 FetchIcon(); | 509 FetchIcon(); |
505 } | 510 } |
506 } | 511 } |
507 | 512 |
508 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( | 513 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( |
509 Profile* profile, | 514 Profile* profile, |
510 const extensions::Extension* app, | 515 const extensions::Extension* app, |
511 const base::Callback<void(bool)>& close_callback) | 516 const base::Callback<void(bool)>& close_callback) |
512 : CreateApplicationShortcutView(profile), | 517 : CreateApplicationShortcutView(profile), |
(...skipping 21 matching lines...) Expand all Loading... | |
534 return CreateApplicationShortcutView::Accept(); | 539 return CreateApplicationShortcutView::Accept(); |
535 } | 540 } |
536 | 541 |
537 bool CreateChromeApplicationShortcutView::Cancel() { | 542 bool CreateChromeApplicationShortcutView::Cancel() { |
538 if (!close_callback_.is_null()) | 543 if (!close_callback_.is_null()) |
539 close_callback_.Run(false); | 544 close_callback_.Run(false); |
540 return CreateApplicationShortcutView::Cancel(); | 545 return CreateApplicationShortcutView::Cancel(); |
541 } | 546 } |
542 | 547 |
543 void CreateChromeApplicationShortcutView::OnAppInfoLoaded( | 548 void CreateChromeApplicationShortcutView::OnAppInfoLoaded( |
544 const web_app::ShortcutInfo& shortcut_info, | 549 scoped_ptr<web_app::ShortcutInfo> shortcut_info, |
545 const extensions::FileHandlersInfo& file_handlers_info) { | 550 const extensions::FileHandlersInfo& file_handlers_info) { |
546 shortcut_info_ = shortcut_info; | 551 shortcut_info_ = shortcut_info.Pass(); |
547 file_handlers_info_ = file_handlers_info; | 552 file_handlers_info_ = file_handlers_info; |
548 } | 553 } |
OLD | NEW |