OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/bookmark_app_helper.h" | 5 #include "chrome/browser/extensions/bookmark_app_helper.h" |
6 | 6 |
7 #include <cctype> | 7 #include <cctype> |
8 | 8 |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 callback_ = callback; | 484 callback_ = callback; |
485 | 485 |
486 if (contents_) { | 486 if (contents_) { |
487 contents_->GetManifest(base::Bind(&BookmarkAppHelper::OnDidGetManifest, | 487 contents_->GetManifest(base::Bind(&BookmarkAppHelper::OnDidGetManifest, |
488 base::Unretained(this))); | 488 base::Unretained(this))); |
489 } else { | 489 } else { |
490 OnIconsDownloaded(true, std::map<GURL, std::vector<SkBitmap> >()); | 490 OnIconsDownloaded(true, std::map<GURL, std::vector<SkBitmap> >()); |
491 } | 491 } |
492 } | 492 } |
493 | 493 |
494 void BookmarkAppHelper::CreateFromAppBanner( | |
495 const CreateBookmarkAppCallback& callback, | |
496 const content::Manifest& manifest) { | |
497 callback_ = callback; | |
498 OnDidGetManifest(manifest); | |
benwells
2015/06/02 05:53:36
We should have some dchecks to make sure the manif
dominickn (DO NOT USE)
2015/06/02 06:51:33
In progress.
| |
499 } | |
500 | |
494 void BookmarkAppHelper::OnDidGetManifest(const content::Manifest& manifest) { | 501 void BookmarkAppHelper::OnDidGetManifest(const content::Manifest& manifest) { |
495 if (contents_->IsBeingDestroyed()) | 502 if (contents_->IsBeingDestroyed()) |
496 return; | 503 return; |
497 | 504 |
498 UpdateWebAppInfoFromManifest(manifest, &web_app_info_); | 505 UpdateWebAppInfoFromManifest(manifest, &web_app_info_); |
499 | 506 |
500 // Add urls from the WebApplicationInfo. | 507 // Add urls from the WebApplicationInfo. |
501 std::vector<GURL> web_app_info_icon_urls; | 508 std::vector<GURL> web_app_info_icon_urls; |
502 for (std::vector<WebApplicationInfo::IconInfo>::const_iterator it = | 509 for (std::vector<WebApplicationInfo::IconInfo>::const_iterator it = |
503 web_app_info_.icons.begin(); | 510 web_app_info_.icons.begin(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 ResizeIconsAndGenerateMissing(downloaded_icons, SizesToGenerate(), | 564 ResizeIconsAndGenerateMissing(downloaded_icons, SizesToGenerate(), |
558 &web_app_info_); | 565 &web_app_info_); |
559 ReplaceWebAppIcons(size_to_icons, &web_app_info_); | 566 ReplaceWebAppIcons(size_to_icons, &web_app_info_); |
560 favicon_downloader_.reset(); | 567 favicon_downloader_.reset(); |
561 | 568 |
562 if (!contents_) { | 569 if (!contents_) { |
563 // The web contents can be null in tests. | 570 // The web contents can be null in tests. |
564 OnBubbleCompleted(true, web_app_info_); | 571 OnBubbleCompleted(true, web_app_info_); |
565 return; | 572 return; |
566 } | 573 } |
574 ShowBookmarkAppBubble(); | |
575 } | |
567 | 576 |
577 void BookmarkAppHelper::ShowBookmarkAppBubble() { | |
benwells
2015/06/02 05:53:36
Is there a reason to split this out, or was it jus
dominickn (DO NOT USE)
2015/06/02 06:51:33
It was initially necessary, but is now just for cl
| |
568 Browser* browser = chrome::FindBrowserWithWebContents(contents_); | 578 Browser* browser = chrome::FindBrowserWithWebContents(contents_); |
569 if (!browser) { | 579 if (!browser) { |
570 // The browser can be null in tests. | 580 // The browser can be null in tests. |
571 OnBubbleCompleted(true, web_app_info_); | 581 OnBubbleCompleted(true, web_app_info_); |
572 return; | 582 return; |
573 } | 583 } |
584 | |
574 browser->window()->ShowBookmarkAppBubble( | 585 browser->window()->ShowBookmarkAppBubble( |
575 web_app_info_, base::Bind(&BookmarkAppHelper::OnBubbleCompleted, | 586 web_app_info_, base::Bind(&BookmarkAppHelper::OnBubbleCompleted, |
576 base::Unretained(this))); | 587 base::Unretained(this))); |
577 } | 588 } |
578 | 589 |
579 void BookmarkAppHelper::OnBubbleCompleted( | 590 void BookmarkAppHelper::OnBubbleCompleted( |
580 bool user_accepted, | 591 bool user_accepted, |
581 const WebApplicationInfo& web_app_info) { | 592 const WebApplicationInfo& web_app_info) { |
582 if (user_accepted) { | 593 if (user_accepted) { |
583 web_app_info_ = web_app_info; | 594 web_app_info_ = web_app_info; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); | 731 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); |
721 } | 732 } |
722 | 733 |
723 bool IsValidBookmarkAppUrl(const GURL& url) { | 734 bool IsValidBookmarkAppUrl(const GURL& url) { |
724 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes); | 735 URLPattern origin_only_pattern(Extension::kValidWebExtentSchemes); |
725 origin_only_pattern.SetMatchAllURLs(true); | 736 origin_only_pattern.SetMatchAllURLs(true); |
726 return url.is_valid() && origin_only_pattern.MatchesURL(url); | 737 return url.is_valid() && origin_only_pattern.MatchesURL(url); |
727 } | 738 } |
728 | 739 |
729 } // namespace extensions | 740 } // namespace extensions |
OLD | NEW |