Index: chrome/browser/banners/app_banner_debug_log.cc |
diff --git a/chrome/browser/banners/app_banner_debug_log.cc b/chrome/browser/banners/app_banner_debug_log.cc |
index d58a2172479bcedce718009584502cabc20714dd..a26a28e3f8cdab072315b3236dc94bd417000216 100644 |
--- a/chrome/browser/banners/app_banner_debug_log.cc |
+++ b/chrome/browser/banners/app_banner_debug_log.cc |
@@ -4,58 +4,123 @@ |
#include "chrome/browser/banners/app_banner_debug_log.h" |
-#include "content/public/browser/render_frame_host.h" |
+#include "base/strings/stringprintf.h" |
#include "content/public/browser/web_contents.h" |
namespace banners { |
-const char kRendererRequestCancel[] = |
- "renderer has requested the banner prompt be cancelled"; |
-const char kManifestEmpty[] = |
+static const char kRendererRequestCancelMessage[] = |
+ "page has requested the banner prompt be cancelled"; |
+static const char kManifestEmptyMessage[] = |
"manifest could not be fetched, is empty, or could not be parsed"; |
-const char kNoManifest[] = "site has no manifest <link> URL"; |
-// The required size is prepended. |
-const char kNoIconMatchingRequirements[] = |
- "px square icon is required, but no supplied icon is at least this size"; |
-const char kCannotDownloadIcon[] = "could not download the specified icon"; |
-const char kNoMatchingServiceWorker[] = |
+static const char kNoManifestMessage[] = |
+ "site has no manifest <link> URL"; |
+static const char kNoIconMatchingRequirementsMessage[] = |
+ "%spx square icon is required, but no supplied icon is at least this size"; |
+static const char kCannotDownloadIconMessage[] = |
+ "could not download the specified icon"; |
+static const char kNoMatchingServiceWorkerMessage[] = |
"no matching service worker detected. You may need to reload the page, or " |
"check that the service worker for the current page also controls the " |
"start URL from the manifest"; |
-const char kNoIconAvailable[] = "no icon available to display"; |
-const char kUserNavigatedBeforeBannerShown[] = |
+static const char kNoIconAvailableMessage[] = |
+ "no icon available to display"; |
+static const char kUserNavigatedBeforeBannerShownMessage[] = |
"the user navigated before the banner could be shown"; |
-const char kStartURLNotValid[] = "start URL in manifest is not valid"; |
-const char kManifestMissingNameOrShortName[] = |
+static const char kStartURLNotValidMessage[] = |
+ "start URL in manifest is not valid"; |
+static const char kManifestMissingNameOrShortNameMessage[] = |
"one of manifest name or short name must be specified"; |
-const char kManifestMissingSuitableIcon[] = |
+static const char kManifestMissingSuitableIconMessage[] = |
"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[] = |
+static const char kNotLoadedInMainFrameMessage[] = |
+ "page not loaded in the main frame"; |
+static const char kNotServedFromSecureOriginMessage[] = |
"page not served from a secure origin"; |
// The leading space is intentional as another string is prepended. |
-const char kIgnoredNotSupportedOnAndroid[] = |
- " application ignored: not supported on Android"; |
-const char kIgnoredNoId[] = "play application ignored: no id provided"; |
-const char kIgnoredIdsDoNotMatch[] = |
+static const char kIgnoredNotSupportedOnAndroidMessage[] = |
+ "%s application ignored: not supported on Android"; |
+static const char kIgnoredNoIdMessage[] = |
+ "play application ignored: no id provided"; |
+static const char kIgnoredIdsDoNotMatchMessage[] = |
"play application ignored: app URL and id fields were specified in the " |
"manifest, but they do not match"; |
void OutputDeveloperNotShownMessage(content::WebContents* web_contents, |
- const std::string& message, |
+ OutputDeveloperMessageCode code, |
bool is_debug_mode) { |
- OutputDeveloperDebugMessage(web_contents, "not shown: " + message, |
- is_debug_mode); |
+ OutputDeveloperNotShownMessage(web_contents, code, std::string(), |
+ is_debug_mode); |
} |
-void OutputDeveloperDebugMessage(content::WebContents* web_contents, |
- const std::string& message, |
- bool is_debug_mode) { |
+void OutputDeveloperNotShownMessage(content::WebContents* web_contents, |
+ OutputDeveloperMessageCode code, |
+ const std::string& param, |
+ bool is_debug_mode) { |
if (!is_debug_mode || !web_contents) |
return; |
+ |
+ const char* pattern; |
+ content::ConsoleMessageLevel severity = content::CONSOLE_MESSAGE_LEVEL_ERROR; |
+ switch (code) { |
+ case kRendererRequestCancel: |
+ pattern = kRendererRequestCancelMessage; |
+ severity = content::CONSOLE_MESSAGE_LEVEL_LOG; |
+ break; |
+ case kManifestEmpty: |
+ pattern = kManifestEmptyMessage; |
+ break; |
+ case kNoManifest: |
+ pattern = kNoManifestMessage; |
+ break; |
+ case kNoIconMatchingRequirements: |
+ pattern = kNoIconMatchingRequirementsMessage; |
+ break; |
+ case kCannotDownloadIcon: |
+ pattern = kCannotDownloadIconMessage; |
+ break; |
+ case kNoMatchingServiceWorker: |
+ pattern = kNoMatchingServiceWorkerMessage; |
+ break; |
+ case kNoIconAvailable: |
+ pattern = kNoIconAvailableMessage; |
+ break; |
+ case kUserNavigatedBeforeBannerShown: |
+ pattern = kUserNavigatedBeforeBannerShownMessage; |
+ severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; |
+ break; |
+ case kStartURLNotValid: |
+ pattern = kStartURLNotValidMessage; |
+ break; |
+ case kManifestMissingNameOrShortName: |
+ pattern = kManifestMissingNameOrShortNameMessage; |
+ break; |
+ case kManifestMissingSuitableIcon: |
+ pattern = kManifestMissingSuitableIconMessage; |
+ break; |
+ case kNotLoadedInMainFrame: |
+ pattern = kNotLoadedInMainFrameMessage; |
+ break; |
+ case kNotServedFromSecureOrigin: |
+ pattern = kNotServedFromSecureOriginMessage; |
+ break; |
+ case kIgnoredNotSupportedOnAndroid: |
+ pattern = kIgnoredNotSupportedOnAndroidMessage; |
+ severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; |
+ break; |
+ case kIgnoredNoId: |
+ pattern = kIgnoredNoIdMessage; |
+ break; |
+ case kIgnoredIdsDoNotMatch: |
+ pattern = kIgnoredIdsDoNotMatchMessage; |
+ break; |
+ } |
+ std::string message = param.empty() ? |
+ pattern : base::StringPrintf(pattern, param.c_str()); |
web_contents->GetMainFrame()->AddMessageToConsole( |
- content::CONSOLE_MESSAGE_LEVEL_DEBUG, "App banner " + message); |
+ severity, "App banner not shown: " + message); |
+ |
} |
} // namespace banners |