Index: chrome/browser/installable/installable_logging.cc |
diff --git a/chrome/browser/banners/app_banner_debug_log.cc b/chrome/browser/installable/installable_logging.cc |
similarity index 51% |
copy from chrome/browser/banners/app_banner_debug_log.cc |
copy to chrome/browser/installable/installable_logging.cc |
index dac19e0351a7961a054f98eb967872259871de1e..4f8a4075bf410ccda1af41c78f8d446d8581ea68 100644 |
--- a/chrome/browser/banners/app_banner_debug_log.cc |
+++ b/chrome/browser/installable/installable_logging.cc |
@@ -1,135 +1,146 @@ |
-// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/banners/app_banner_debug_log.h" |
+#include "chrome/browser/installable/installable_logging.h" |
+#include "base/macros.h" |
#include "base/strings/stringprintf.h" |
#include "content/public/browser/render_frame_host.h" |
#include "content/public/browser/web_contents.h" |
-namespace banners { |
+namespace { |
+static const std::string& GetMessagePrefix() { |
+ CR_DEFINE_STATIC_LOCAL(std::string, message_prefix, |
+ ("Site cannot be installed: ")); |
+ return message_prefix; |
+} |
+ |
+// Error message strings corresponding to the values in the ErrorCode enum. |
+static const char kRendererExitingMessage[] = |
+ "the page is in the process of being closed"; |
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"; |
+ "the page has requested the banner prompt be cancelled"; |
+static const char kUserNavigatedBeforeBannerShownMessage[] = |
+ "the page was navigated before the banner could be shown"; |
+static const char kNotLoadedInMainFrameMessage[] = |
+ "the page is not loaded in the main frame"; |
+static const char kNotServedFromSecureOriginMessage[] = |
+ "the page is not served from a secure origin"; |
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"; |
+ "the page has no manifest <link> URL"; |
+static const char kManifestEmptyMessage[] = |
+ "the manifest could not be fetched, is empty, or could not be parsed"; |
+static const char kStartUrlNotValidMessage[] = |
+ "the start URL in manifest is not valid"; |
+static const char kManifestMissingNameOrShortNameMessage[] = |
+ "one of manifest name or short name must be specified"; |
+static const char kManifestDisplayIsNotStandaloneOrFullscreenMessage[] = |
+ "the manifest display property must be set to 'standalone' or 'fullscreen'"; |
+static const char kManifestMissingSuitableIconMessage[] = |
+ "the manifest does not contain a suitable icon - PNG format of at least " |
+ "%spx is required, and the sizes attribute must be set"; |
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"; |
+static const char kNoIconMatchingRequirementsMessage[] = |
+ "a %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 kNoIconAvailableMessage[] = |
"no icon available to display"; |
-static const char kUserNavigatedBeforeBannerShownMessage[] = |
- "the user navigated before the banner could be shown"; |
-static const char kStartURLNotValidMessage[] = |
- "start URL in manifest is not valid"; |
-static const char kManifestDisplayStandaloneFullscreenMessage[] = |
- "manifest display property must be set to 'standalone' or 'fullscreen'"; |
-static const char kManifestMissingNameOrShortNameMessage[] = |
- "one of manifest name or short name must be specified"; |
-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"; |
-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. |
static const char kIgnoredNotSupportedOnAndroidMessage[] = |
- "%s application is not supported on Android"; |
+ "the specified application platform is not supported on Android"; |
static const char kIgnoredNoIdMessage[] = |
"no Play store ID provided"; |
static const char kIgnoredIdsDoNotMatchMessage[] = |
- "a Play app URL and Play store ID were specified in the manifest, but they" |
- " do not match"; |
+ "a Play Store app URL and Play Store ID were specified in the manifest, " |
+ "but they do not match"; |
-void OutputDeveloperNotShownMessage(content::WebContents* web_contents, |
- OutputDeveloperMessageCode code, |
- bool is_debug_mode) { |
- OutputDeveloperNotShownMessage(web_contents, code, std::string(), |
- is_debug_mode); |
-} |
+} // anonymous namespace |
+ |
+namespace installable { |
-void OutputDeveloperNotShownMessage(content::WebContents* web_contents, |
- OutputDeveloperMessageCode code, |
- const std::string& param, |
- bool is_debug_mode) { |
- if (!is_debug_mode || !web_contents) |
+void LogErrorToConsole(content::WebContents* web_contents, |
+ ErrorCode code, |
+ const std::string& param) { |
+ if (!web_contents) |
return; |
- const char* pattern; |
content::ConsoleMessageLevel severity = content::CONSOLE_MESSAGE_LEVEL_ERROR; |
+ const char* pattern = nullptr; |
switch (code) { |
- case kRendererRequestCancel: |
+ case NoErrorDetected: |
+ case MaxErrorCode: |
+ return; |
+ case RendererExiting: |
+ pattern = kRendererExitingMessage; |
+ break; |
+ case RendererRequestCancel: |
pattern = kRendererRequestCancelMessage; |
severity = content::CONSOLE_MESSAGE_LEVEL_LOG; |
break; |
- case kManifestEmpty: |
- pattern = kManifestEmptyMessage; |
+ case UserNavigatedBeforeBannerShown: |
+ pattern = kUserNavigatedBeforeBannerShownMessage; |
+ severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; |
break; |
- case kNoManifest: |
- pattern = kNoManifestMessage; |
+ case NotLoadedInMainFrame: |
+ pattern = kNotLoadedInMainFrameMessage; |
break; |
- case kNoIconMatchingRequirements: |
- pattern = kNoIconMatchingRequirementsMessage; |
+ case NotServedFromSecureOrigin: |
+ pattern = kNotServedFromSecureOriginMessage; |
break; |
- case kCannotDownloadIcon: |
- pattern = kCannotDownloadIconMessage; |
+ case NoManifest: |
+ pattern = kNoManifestMessage; |
break; |
- case kNoMatchingServiceWorker: |
- pattern = kNoMatchingServiceWorkerMessage; |
+ case ManifestEmpty: |
+ pattern = kManifestEmptyMessage; |
break; |
- case kNoIconAvailable: |
- pattern = kNoIconAvailableMessage; |
+ case StartUrlNotValid: |
+ pattern = kStartUrlNotValidMessage; |
break; |
- case kUserNavigatedBeforeBannerShown: |
- pattern = kUserNavigatedBeforeBannerShownMessage; |
- severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; |
+ case ManifestMissingNameOrShortName: |
+ pattern = kManifestMissingNameOrShortNameMessage; |
break; |
- case kStartURLNotValid: |
- pattern = kStartURLNotValidMessage; |
+ case ManifestDisplayIsNotStandaloneOrFullscreen: |
+ pattern = kManifestDisplayIsNotStandaloneOrFullscreenMessage; |
break; |
- case kManifestDisplayStandaloneFullscreen: |
- pattern = kManifestDisplayStandaloneFullscreenMessage; |
+ case ManifestMissingSuitableIcon: |
+ pattern = kManifestMissingSuitableIconMessage; |
break; |
- case kManifestMissingNameOrShortName: |
- pattern = kManifestMissingNameOrShortNameMessage; |
+ case NoMatchingServiceWorker: |
+ pattern = kNoMatchingServiceWorkerMessage; |
break; |
- case kManifestMissingSuitableIcon: |
- pattern = kManifestMissingSuitableIconMessage; |
+ case NoIconMatchingRequirements: |
+ pattern = kNoIconMatchingRequirementsMessage; |
break; |
- case kNotLoadedInMainFrame: |
- pattern = kNotLoadedInMainFrameMessage; |
+ case CannotDownloadIcon: |
+ pattern = kCannotDownloadIconMessage; |
break; |
- case kNotServedFromSecureOrigin: |
- pattern = kNotServedFromSecureOriginMessage; |
+ case NoIconAvailable: |
+ pattern = kNoIconAvailableMessage; |
break; |
- case kIgnoredNotSupportedOnAndroid: |
+ case IgnoredNotSupportedOnAndroid: |
pattern = kIgnoredNotSupportedOnAndroidMessage; |
severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; |
break; |
- case kIgnoredNoId: |
+ case IgnoredNoId: |
pattern = kIgnoredNoIdMessage; |
break; |
- case kIgnoredIdsDoNotMatch: |
+ case IgnoredIdsDoNotMatch: |
pattern = kIgnoredIdsDoNotMatchMessage; |
break; |
- default: |
- NOTREACHED(); |
- return; |
} |
+ |
+ if (!pattern) |
+ return; |
std::string message = param.empty() ? |
pattern : base::StringPrintf(pattern, param.c_str()); |
web_contents->GetMainFrame()->AddMessageToConsole( |
- severity, "App banner not shown: " + message); |
- |
+ severity, GetMessagePrefix() + message); |
} |
-} // namespace banners |
+} // namespace installable |