diff options
Diffstat (limited to 'chrome/browser/banners')
12 files changed, 119 insertions, 65 deletions
diff --git a/chrome/browser/banners/app_banner_data_fetcher.cc b/chrome/browser/banners/app_banner_data_fetcher.cc index 321e8d3..d953485 100644 --- a/chrome/browser/banners/app_banner_data_fetcher.cc +++ b/chrome/browser/banners/app_banner_data_fetcher.cc @@ -71,11 +71,11 @@ void AppBannerDataFetcher::SetTimeDeltaForTesting(int days) { gTimeDeltaForTesting = base::TimeDelta::FromDays(days); } -AppBannerDataFetcher::AppBannerDataFetcher( - content::WebContents* web_contents, - base::WeakPtr<Delegate> delegate, - int ideal_icon_size_in_dp, - int minimum_icon_size_in_dp) +AppBannerDataFetcher::AppBannerDataFetcher(content::WebContents* web_contents, + base::WeakPtr<Delegate> delegate, + int ideal_icon_size_in_dp, + int minimum_icon_size_in_dp, + bool is_debug_mode) : WebContentsObserver(web_contents), weak_delegate_(delegate), ideal_icon_size_in_dp_(ideal_icon_size_in_dp), @@ -83,6 +83,9 @@ AppBannerDataFetcher::AppBannerDataFetcher( is_active_(false), was_canceled_by_page_(false), page_requested_prompt_(false), + is_debug_mode_(is_debug_mode || + base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kBypassAppBannerEngagementChecks)), event_request_id_(-1) { DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); } @@ -184,7 +187,8 @@ void AppBannerDataFetcher::OnBannerPromptReply( !page_requested_prompt_) { was_canceled_by_page_ = true; referrer_ = referrer; - OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel); + OutputDeveloperNotShownMessage(web_contents, kRendererRequestCancel, + is_debug_mode_); return; } @@ -250,7 +254,7 @@ void AppBannerDataFetcher::OnDidHasManifest(bool has_manifest) { if (!CheckFetcherIsStillAlive(web_contents) || !has_manifest) { if (!has_manifest) - OutputDeveloperNotShownMessage(web_contents, kNoManifest); + OutputDeveloperNotShownMessage(web_contents, kNoManifest, is_debug_mode_); Cancel(); return; @@ -268,7 +272,8 @@ void AppBannerDataFetcher::OnDidGetManifest( return; } if (manifest.IsEmpty()) { - OutputDeveloperNotShownMessage(web_contents, kManifestEmpty); + OutputDeveloperNotShownMessage(web_contents, kManifestEmpty, + is_debug_mode_); Cancel(); return; } @@ -278,12 +283,13 @@ void AppBannerDataFetcher::OnDidGetManifest( for (const auto& application : manifest.related_applications) { std::string platform = base::UTF16ToUTF8(application.platform.string()); std::string id = base::UTF16ToUTF8(application.id.string()); - if (weak_delegate_->HandleNonWebApp(platform, application.url, id)) + if (weak_delegate_->HandleNonWebApp(platform, application.url, id, + is_debug_mode_)) return; } } - if (!IsManifestValidForWebApp(manifest, web_contents)) { + if (!IsManifestValidForWebApp(manifest, web_contents, is_debug_mode_)) { Cancel(); return; } @@ -293,9 +299,9 @@ void AppBannerDataFetcher::OnDidGetManifest( if (IsWebAppInstalled(web_contents->GetBrowserContext(), manifest.start_url) && - !base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kBypassAppBannerEngagementChecks)) { - OutputDeveloperNotShownMessage(web_contents, kBannerAlreadyAdded); + !is_debug_mode_) { + OutputDeveloperNotShownMessage(web_contents, kBannerAlreadyAdded, + is_debug_mode_); Cancel(); return; } @@ -327,7 +333,8 @@ void AppBannerDataFetcher::OnDidCheckHasServiceWorker( if (!has_service_worker) { TrackDisplayEvent(DISPLAY_EVENT_LACKS_SERVICE_WORKER); - OutputDeveloperNotShownMessage(web_contents, kNoMatchingServiceWorker); + OutputDeveloperNotShownMessage(web_contents, kNoMatchingServiceWorker, + is_debug_mode_); Cancel(); return; } @@ -345,7 +352,8 @@ void AppBannerDataFetcher::OnHasServiceWorker( gfx::Screen::GetScreenFor(web_contents->GetNativeView())); if (!FetchAppIcon(web_contents, icon_url)) { - OutputDeveloperNotShownMessage(web_contents, kCannotDetermineBestIcon); + OutputDeveloperNotShownMessage(web_contents, kCannotDetermineBestIcon, + is_debug_mode_); Cancel(); } } @@ -370,16 +378,18 @@ void AppBannerDataFetcher::OnAppIconFetched(const SkBitmap& bitmap) { return; } if (bitmap.drawsNothing()) { - OutputDeveloperNotShownMessage(web_contents, kNoIconAvailable); + OutputDeveloperNotShownMessage(web_contents, kNoIconAvailable, + is_debug_mode_); Cancel(); return; } RecordCouldShowBanner(); - if (!CheckIfShouldShowBanner()) { + if (!is_debug_mode_ && !CheckIfShouldShowBanner()) { // At this point, the only possible case is that the banner has been added // to the homescreen, given all of the other checks that have been made. - OutputDeveloperNotShownMessage(web_contents, kBannerAlreadyAdded); + OutputDeveloperNotShownMessage(web_contents, kBannerAlreadyAdded, + is_debug_mode_); Cancel(); return; } @@ -419,8 +429,8 @@ bool AppBannerDataFetcher::CheckIfShouldShowBanner() { bool AppBannerDataFetcher::CheckFetcherIsStillAlive( content::WebContents* web_contents) { if (!is_active_) { - OutputDeveloperNotShownMessage(web_contents, - kUserNavigatedBeforeBannerShown); + OutputDeveloperNotShownMessage( + web_contents, kUserNavigatedBeforeBannerShown, is_debug_mode_); return false; } if (!web_contents) { @@ -432,22 +442,25 @@ bool AppBannerDataFetcher::CheckFetcherIsStillAlive( // static bool AppBannerDataFetcher::IsManifestValidForWebApp( const content::Manifest& manifest, - content::WebContents* web_contents) { + content::WebContents* web_contents, + bool is_debug_mode) { if (manifest.IsEmpty()) { - OutputDeveloperNotShownMessage(web_contents, kManifestEmpty); + OutputDeveloperNotShownMessage(web_contents, kManifestEmpty, is_debug_mode); return false; } if (!manifest.start_url.is_valid()) { - OutputDeveloperNotShownMessage(web_contents, kStartURLNotValid); + OutputDeveloperNotShownMessage(web_contents, kStartURLNotValid, + is_debug_mode); return false; } if (manifest.name.is_null() && manifest.short_name.is_null()) { - OutputDeveloperNotShownMessage(web_contents, - kManifestMissingNameOrShortName); + OutputDeveloperNotShownMessage( + web_contents, kManifestMissingNameOrShortName, is_debug_mode); return false; } if (!DoesManifestContainRequiredIcon(manifest)) { - OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon); + OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon, + is_debug_mode); return false; } return true; diff --git a/chrome/browser/banners/app_banner_data_fetcher.h b/chrome/browser/banners/app_banner_data_fetcher.h index fe943f2..194bf0b 100644 --- a/chrome/browser/banners/app_banner_data_fetcher.h +++ b/chrome/browser/banners/app_banner_data_fetcher.h @@ -49,7 +49,8 @@ class AppBannerDataFetcher : public base::RefCountedThreadSafe< // handled, and the fetcher needs to remain active and wait for a callback. virtual bool HandleNonWebApp(const std::string& platform, const GURL& url, - const std::string& id) = 0; + const std::string& id, + bool is_debug_mode) = 0; }; // Returns the current time. @@ -61,7 +62,8 @@ class AppBannerDataFetcher : public base::RefCountedThreadSafe< AppBannerDataFetcher(content::WebContents* web_contents, base::WeakPtr<Delegate> weak_delegate, int ideal_icon_size_in_dp, - int minimum_icon_size_in_dp); + int minimum_icon_size_in_dp, + bool is_debug_mode); // Begins creating a banner for the URL being displayed by the Delegate's // WebContents. @@ -89,6 +91,10 @@ class AppBannerDataFetcher : public base::RefCountedThreadSafe< // by calling prompt() on the beforeinstallprompt Javascript event. bool page_requested_prompt() { return page_requested_prompt_; } + // Returns true when it was created by the user action in DevTools or + // "bypass-app-banner-engagement-checks" flag is set. + bool is_debug_mode() const { return is_debug_mode_; } + // Returns the type of transition which triggered this fetch. ui::PageTransition transition_type() { return transition_type_; } @@ -172,7 +178,8 @@ class AppBannerDataFetcher : public base::RefCountedThreadSafe< // Returns whether the given Manifest is following the requirements to show // a web app banner. static bool IsManifestValidForWebApp(const content::Manifest& manifest, - content::WebContents* web_contents); + content::WebContents* web_contents, + bool is_debug_mode); const base::WeakPtr<Delegate> weak_delegate_; const int ideal_icon_size_in_dp_; @@ -181,6 +188,7 @@ class AppBannerDataFetcher : public base::RefCountedThreadSafe< bool is_active_; bool was_canceled_by_page_; bool page_requested_prompt_; + const bool is_debug_mode_; ui::PageTransition transition_type_; int event_request_id_; scoped_ptr<SkBitmap> app_icon_; diff --git a/chrome/browser/banners/app_banner_data_fetcher_browsertest.cc b/chrome/browser/banners/app_banner_data_fetcher_browsertest.cc index c868268..57d3883 100644 --- a/chrome/browser/banners/app_banner_data_fetcher_browsertest.cc +++ b/chrome/browser/banners/app_banner_data_fetcher_browsertest.cc @@ -73,7 +73,8 @@ class AppBannerDataFetcherBrowserTest : public InProcessBrowserTest, bool HandleNonWebApp(const std::string& platform, const GURL& url, - const std::string& id) override { + const std::string& id, + bool is_debug_mode) override { base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_); non_web_platform_ = platform; return false; @@ -95,9 +96,8 @@ class AppBannerDataFetcherBrowserTest : public InProcessBrowserTest, content::WebContents* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); scoped_refptr<AppBannerDataFetcherDesktop> fetcher( - new AppBannerDataFetcherDesktop(web_contents, - weak_factory_.GetWeakPtr(), - 128, 128)); + new AppBannerDataFetcherDesktop( + web_contents, weak_factory_.GetWeakPtr(), 128, 128, false)); base::HistogramTester histograms; base::RunLoop run_loop; diff --git a/chrome/browser/banners/app_banner_data_fetcher_desktop.cc b/chrome/browser/banners/app_banner_data_fetcher_desktop.cc index 5cc7fa8..ae69cff5 100644 --- a/chrome/browser/banners/app_banner_data_fetcher_desktop.cc +++ b/chrome/browser/banners/app_banner_data_fetcher_desktop.cc @@ -23,12 +23,13 @@ AppBannerDataFetcherDesktop::AppBannerDataFetcherDesktop( content::WebContents* web_contents, base::WeakPtr<Delegate> weak_delegate, int ideal_icon_size_in_dp, - int minimum_icon_size_in_dp) + int minimum_icon_size_in_dp, + bool is_debug_mode) : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size_in_dp, - minimum_icon_size_in_dp) { -} + minimum_icon_size_in_dp, + is_debug_mode) {} AppBannerDataFetcherDesktop::~AppBannerDataFetcherDesktop() { } diff --git a/chrome/browser/banners/app_banner_data_fetcher_desktop.h b/chrome/browser/banners/app_banner_data_fetcher_desktop.h index 1915e880..3bef84a 100644 --- a/chrome/browser/banners/app_banner_data_fetcher_desktop.h +++ b/chrome/browser/banners/app_banner_data_fetcher_desktop.h @@ -22,7 +22,8 @@ class AppBannerDataFetcherDesktop : public AppBannerDataFetcher { AppBannerDataFetcherDesktop(content::WebContents* web_contents, base::WeakPtr<Delegate> weak_delegate, int ideal_icon_size_in_dp, - int minimum_icon_size_in_dp); + int minimum_icon_size_in_dp, + bool is_debug_mode); // Callback for finishing bookmark app creation void FinishCreateBookmarkApp(const extensions::Extension* extension, diff --git a/chrome/browser/banners/app_banner_data_fetcher_unittest.cc b/chrome/browser/banners/app_banner_data_fetcher_unittest.cc index 3b68086..4be44fe 100644 --- a/chrome/browser/banners/app_banner_data_fetcher_unittest.cc +++ b/chrome/browser/banners/app_banner_data_fetcher_unittest.cc @@ -36,7 +36,10 @@ class AppBannerDataFetcherUnitTest : public testing::Test { // The second argument is the web_contents pointer, which is used for // developer debug logging to the console. The logging is skipped inside the // method if a null web_contents pointer is provided, so this is safe. - return AppBannerDataFetcher::IsManifestValidForWebApp(manifest, nullptr); + // The third argument is the is_debug_mode boolean value, which is true only + // when it is triggered by the developer's action in DevTools. + return AppBannerDataFetcher::IsManifestValidForWebApp(manifest, nullptr, + false); } }; diff --git a/chrome/browser/banners/app_banner_debug_log.cc b/chrome/browser/banners/app_banner_debug_log.cc index e1b06f9..99e26f7 100644 --- a/chrome/browser/banners/app_banner_debug_log.cc +++ b/chrome/browser/banners/app_banner_debug_log.cc @@ -4,8 +4,6 @@ #include "chrome/browser/banners/app_banner_debug_log.h" -#include "base/command_line.h" -#include "chrome/common/chrome_switches.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" @@ -33,6 +31,7 @@ const char kManifestMissingNameOrShortName[] = const char kManifestMissingSuitableIcon[] = "manifest does not contain a suitable icon - PNG format of at least " "144x144px is required, and the sizes attribute must be set"; +const char kNotLoadedInMainFrame[] = "page not loaded in the main frame"; const char kNotServedFromSecureOrigin[] = "page not served from a secure origin"; // The leading space is intentional as another string is prepended. @@ -44,19 +43,19 @@ const char kIgnoredIdsDoNotMatch[] = "manifest, but they do not match"; void OutputDeveloperNotShownMessage(content::WebContents* web_contents, - const std::string& message) { - OutputDeveloperDebugMessage(web_contents, "not shown: " + message); + const std::string& message, + bool is_debug_mode) { + OutputDeveloperDebugMessage(web_contents, "not shown: " + message, + is_debug_mode); } void OutputDeveloperDebugMessage(content::WebContents* web_contents, - const std::string& message) { - std::string log_message = "App banner " + message; - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kBypassAppBannerEngagementChecks) && - web_contents) { - web_contents->GetMainFrame()->AddMessageToConsole( - content::CONSOLE_MESSAGE_LEVEL_DEBUG, log_message); - } + const std::string& message, + bool is_debug_mode) { + if (!is_debug_mode || !web_contents) + return; + web_contents->GetMainFrame()->AddMessageToConsole( + content::CONSOLE_MESSAGE_LEVEL_DEBUG, "App banner " + message); } } // namespace banners diff --git a/chrome/browser/banners/app_banner_debug_log.h b/chrome/browser/banners/app_banner_debug_log.h index c5767c8..0d07908 100644 --- a/chrome/browser/banners/app_banner_debug_log.h +++ b/chrome/browser/banners/app_banner_debug_log.h @@ -25,6 +25,7 @@ extern const char kUserNavigatedBeforeBannerShown[]; extern const char kStartURLNotValid[]; extern const char kManifestMissingNameOrShortName[]; extern const char kManifestMissingSuitableIcon[]; +extern const char kNotLoadedInMainFrame[]; extern const char kNotServedFromSecureOrigin[]; extern const char kIgnoredNotSupportedOnAndroid[]; extern const char kIgnoredNoId[]; @@ -33,12 +34,14 @@ extern const char kIgnoredIdsDoNotMatch[]; // Logs a message to the main console if a banner could not be shown // and the engagement checks have been bypassed. void OutputDeveloperNotShownMessage(content::WebContents* web_contents, - const std::string& message); + const std::string& message, + bool is_debug_mode); // Logs a debugging message to the main console if the engagement checks have // been bypassed. void OutputDeveloperDebugMessage(content::WebContents* web_contents, - const std::string& message); + const std::string& message, + bool is_debug_mode); } // namespace banners diff --git a/chrome/browser/banners/app_banner_manager.cc b/chrome/browser/banners/app_banner_manager.cc index e984f2d..6fe5b9c 100644 --- a/chrome/browser/banners/app_banner_manager.cc +++ b/chrome/browser/banners/app_banner_manager.cc @@ -70,14 +70,19 @@ void AppBannerManager::DidNavigateMainFrame( last_transition_type_ = params.transition; } -void AppBannerManager::DidFinishLoad( +void AppBannerManager::RequestAppBanner( content::RenderFrameHost* render_frame_host, - const GURL& validated_url) { - if (render_frame_host->GetParent()) + const GURL& validated_url, + bool is_debug_mode) { + if (render_frame_host->GetParent()) { + OutputDeveloperNotShownMessage(web_contents(), kNotLoadedInMainFrame, + is_debug_mode); return; + } if (data_fetcher_.get() && data_fetcher_->is_active() && - URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url)) { + URLsAreForTheSamePage(data_fetcher_->validated_url(), validated_url) && + !is_debug_mode) { return; } @@ -85,18 +90,29 @@ void AppBannerManager::DidFinishLoad( // URL is invalid. if (!content::IsOriginSecure(validated_url) && !gDisableSecureCheckForTesting) { - OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin); + OutputDeveloperNotShownMessage(web_contents(), kNotServedFromSecureOrigin, + is_debug_mode); return; } // Kick off the data retrieval pipeline. - data_fetcher_ = CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr()); + data_fetcher_ = + CreateAppBannerDataFetcher(weak_factory_.GetWeakPtr(), is_debug_mode); data_fetcher_->Start(validated_url, last_transition_type_); } +void AppBannerManager::DidFinishLoad( + content::RenderFrameHost* render_frame_host, + const GURL& validated_url) { + // The third argument is the is_debug_mode boolean value, which is true only + // when it is triggered by the developer's action in DevTools. + RequestAppBanner(render_frame_host, validated_url, false /* is_debug_mode */); +} + bool AppBannerManager::HandleNonWebApp(const std::string& platform, const GURL& url, - const std::string& id) { + const std::string& id, + bool is_debug_mode) { return false; } diff --git a/chrome/browser/banners/app_banner_manager.h b/chrome/browser/banners/app_banner_manager.h index c11b4cb..efcf332 100644 --- a/chrome/browser/banners/app_banner_manager.h +++ b/chrome/browser/banners/app_banner_manager.h @@ -39,6 +39,12 @@ class AppBannerManager : public content::WebContentsObserver, // Returns whether or not the URLs match for everything except for the ref. static bool URLsAreForTheSamePage(const GURL& first, const GURL& second); + // Requests an app banner. Set |is_debug_mode| when it is triggered by the + // developer's action in DevTools. + void RequestAppBanner(content::RenderFrameHost* render_frame_host, + const GURL& validated_url, + bool is_debug_mode); + AppBannerManager(); ~AppBannerManager() override; @@ -49,7 +55,8 @@ class AppBannerManager : public content::WebContentsObserver, // Creates an AppBannerDataFetcher, which constructs an app banner. virtual AppBannerDataFetcher* CreateAppBannerDataFetcher( - base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate) = 0; + base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, + bool is_debug_mode) = 0; // Return whether the AppBannerDataFetcher is active. bool IsFetcherActive(); @@ -68,7 +75,8 @@ class AppBannerManager : public content::WebContentsObserver, // AppBannerDataFetcher::Delegate overrides. bool HandleNonWebApp(const std::string& platform, const GURL& url, - const std::string& id) override; + const std::string& id, + bool is_debug_mode) override; // Cancels an active DataFetcher, stopping its banners from appearing. void CancelActiveFetcher(); diff --git a/chrome/browser/banners/app_banner_manager_desktop.cc b/chrome/browser/banners/app_banner_manager_desktop.cc index d3aa3bf..01b8e80 100644 --- a/chrome/browser/banners/app_banner_manager_desktop.cc +++ b/chrome/browser/banners/app_banner_manager_desktop.cc @@ -31,10 +31,11 @@ bool AppBannerManagerDesktop::IsEnabled() { } AppBannerDataFetcher* AppBannerManagerDesktop::CreateAppBannerDataFetcher( - base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate) { + base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, + bool is_debug_mode) { return new AppBannerDataFetcherDesktop(web_contents(), weak_delegate, - kMinimumIconSize, - kMinimumIconSize); + kMinimumIconSize, kMinimumIconSize, + is_debug_mode); } AppBannerManagerDesktop::AppBannerManagerDesktop( diff --git a/chrome/browser/banners/app_banner_manager_desktop.h b/chrome/browser/banners/app_banner_manager_desktop.h index fc40997..c45a821 100644 --- a/chrome/browser/banners/app_banner_manager_desktop.h +++ b/chrome/browser/banners/app_banner_manager_desktop.h @@ -21,7 +21,8 @@ class AppBannerManagerDesktop protected: AppBannerDataFetcher* CreateAppBannerDataFetcher( - base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate) override; + base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, + bool is_debug_mode) override; private: explicit AppBannerManagerDesktop(content::WebContents* web_contents); |
