Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/banners/app_banner_debug_log.h" | 5 #include "chrome/browser/banners/app_banner_debug_log.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | |
| 7 #include "content/public/browser/render_frame_host.h" | 8 #include "content/public/browser/render_frame_host.h" |
| 8 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 9 | 10 |
| 10 namespace banners { | 11 namespace banners { |
| 11 | 12 |
| 12 const char kRendererRequestCancel[] = | 13 static const char kRendererRequestCancelMessage[] = |
| 13 "renderer has requested the banner prompt be cancelled"; | 14 "page has requested the banner prompt be cancelled"; |
| 14 const char kManifestEmpty[] = | 15 static const char kManifestEmptyMessage[] = |
| 15 "manifest could not be fetched, is empty, or could not be parsed"; | 16 "manifest could not be fetched, is empty, or could not be parsed"; |
| 16 const char kNoManifest[] = "site has no manifest <link> URL"; | 17 static const char kNoManifestMessage[] = |
| 17 // The required size is prepended. | 18 "site has no manifest <link> URL"; |
| 18 const char kNoIconMatchingRequirements[] = | 19 static const char kNoIconMatchingRequirementsMessage[] = |
| 19 "px square icon is required, but no supplied icon is at least this size"; | 20 "%spx square icon is required, but no supplied icon is at least this size"; |
| 20 const char kCannotDownloadIcon[] = "could not download the specified icon"; | 21 static const char kCannotDownloadIconMessage[] = |
| 21 const char kNoMatchingServiceWorker[] = | 22 "could not download the specified icon"; |
| 23 static const char kNoMatchingServiceWorkerMessage[] = | |
| 22 "no matching service worker detected. You may need to reload the page, or " | 24 "no matching service worker detected. You may need to reload the page, or " |
| 23 "check that the service worker for the current page also controls the " | 25 "check that the service worker for the current page also controls the " |
| 24 "start URL from the manifest"; | 26 "start URL from the manifest"; |
| 25 const char kNoIconAvailable[] = "no icon available to display"; | 27 static const char kNoIconAvailableMessage[] = |
| 26 const char kUserNavigatedBeforeBannerShown[] = | 28 "no icon available to display"; |
| 29 static const char kUserNavigatedBeforeBannerShownMessage[] = | |
| 27 "the user navigated before the banner could be shown"; | 30 "the user navigated before the banner could be shown"; |
| 28 const char kStartURLNotValid[] = "start URL in manifest is not valid"; | 31 static const char kStartURLNotValidMessage[] = |
| 29 const char kManifestMissingNameOrShortName[] = | 32 "start URL in manifest is not valid"; |
| 33 static const char kManifestMissingNameOrShortNameMessage[] = | |
| 30 "one of manifest name or short name must be specified"; | 34 "one of manifest name or short name must be specified"; |
| 31 const char kManifestMissingSuitableIcon[] = | 35 static const char kManifestMissingSuitableIconMessage[] = |
| 32 "manifest does not contain a suitable icon - PNG format of at least " | 36 "manifest does not contain a suitable icon - PNG format of at least " |
| 33 "144x144px is required, and the sizes attribute must be set"; | 37 "144x144px is required, and the sizes attribute must be set"; |
| 34 const char kNotLoadedInMainFrame[] = "page not loaded in the main frame"; | 38 static const char kNotLoadedInMainFrameMessage[] = |
| 35 const char kNotServedFromSecureOrigin[] = | 39 "page not loaded in the main frame"; |
| 40 static const char kNotServedFromSecureOriginMessage[] = | |
| 36 "page not served from a secure origin"; | 41 "page not served from a secure origin"; |
| 37 // The leading space is intentional as another string is prepended. | 42 // The leading space is intentional as another string is prepended. |
| 38 const char kIgnoredNotSupportedOnAndroid[] = | 43 static const char kIgnoredNotSupportedOnAndroidMessage[] = |
| 39 " application ignored: not supported on Android"; | 44 "%s application ignored: not supported on Android"; |
|
dominickn
2016/03/27 22:32:05
Nit: now that the prefix for all of the messages i
pfeldman
2016/03/28 18:39:31
Done.
| |
| 40 const char kIgnoredNoId[] = "play application ignored: no id provided"; | 45 static const char kIgnoredNoIdMessage[] = |
| 41 const char kIgnoredIdsDoNotMatch[] = | 46 "play application ignored: no id provided"; |
|
dominickn
2016/03/27 22:32:05
Nit: "no Play store ID provided"
pfeldman
2016/03/28 18:39:31
Done.
| |
| 47 static const char kIgnoredIdsDoNotMatchMessage[] = | |
| 42 "play application ignored: app URL and id fields were specified in the " | 48 "play application ignored: app URL and id fields were specified in the " |
|
dominickn
2016/03/27 22:32:05
Nit: "a Play app URL and Play store ID were specif
pfeldman
2016/03/28 18:39:31
Done.
| |
| 43 "manifest, but they do not match"; | 49 "manifest, but they do not match"; |
| 44 | 50 |
| 45 void OutputDeveloperNotShownMessage(content::WebContents* web_contents, | 51 void OutputDeveloperNotShownMessage(content::WebContents* web_contents, |
| 46 const std::string& message, | 52 OutputDeveloperMessageCode code, |
| 47 bool is_debug_mode) { | 53 bool is_debug_mode) { |
| 48 OutputDeveloperDebugMessage(web_contents, "not shown: " + message, | 54 OutputDeveloperNotShownMessage(web_contents, code, std::string(), |
| 49 is_debug_mode); | 55 is_debug_mode); |
| 50 } | 56 } |
| 51 | 57 |
| 52 void OutputDeveloperDebugMessage(content::WebContents* web_contents, | 58 void OutputDeveloperNotShownMessage(content::WebContents* web_contents, |
| 53 const std::string& message, | 59 OutputDeveloperMessageCode code, |
| 54 bool is_debug_mode) { | 60 const std::string& param, |
| 61 bool is_debug_mode) { | |
| 55 if (!is_debug_mode || !web_contents) | 62 if (!is_debug_mode || !web_contents) |
| 56 return; | 63 return; |
| 64 | |
| 65 const char* pattern; | |
| 66 content::ConsoleMessageLevel severity = content::CONSOLE_MESSAGE_LEVEL_ERROR; | |
| 67 switch (code) { | |
| 68 case kRendererRequestCancel: | |
| 69 pattern = kRendererRequestCancelMessage; | |
| 70 severity = content::CONSOLE_MESSAGE_LEVEL_LOG; | |
| 71 break; | |
| 72 case kManifestEmpty: | |
| 73 pattern = kManifestEmptyMessage; | |
| 74 break; | |
| 75 case kNoManifest: | |
| 76 pattern = kNoManifestMessage; | |
| 77 break; | |
| 78 case kNoIconMatchingRequirements: | |
| 79 pattern = kNoIconMatchingRequirementsMessage; | |
| 80 break; | |
| 81 case kCannotDownloadIcon: | |
| 82 pattern = kCannotDownloadIconMessage; | |
| 83 break; | |
| 84 case kNoMatchingServiceWorker: | |
| 85 pattern = kNoMatchingServiceWorkerMessage; | |
| 86 break; | |
| 87 case kNoIconAvailable: | |
| 88 pattern = kNoIconAvailableMessage; | |
| 89 break; | |
| 90 case kUserNavigatedBeforeBannerShown: | |
| 91 pattern = kUserNavigatedBeforeBannerShownMessage; | |
| 92 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; | |
| 93 break; | |
| 94 case kStartURLNotValid: | |
| 95 pattern = kStartURLNotValidMessage; | |
| 96 break; | |
| 97 case kManifestMissingNameOrShortName: | |
| 98 pattern = kManifestMissingNameOrShortNameMessage; | |
| 99 break; | |
| 100 case kManifestMissingSuitableIcon: | |
| 101 pattern = kManifestMissingSuitableIconMessage; | |
| 102 break; | |
| 103 case kNotLoadedInMainFrame: | |
| 104 pattern = kNotLoadedInMainFrameMessage; | |
| 105 break; | |
| 106 case kNotServedFromSecureOrigin: | |
| 107 pattern = kNotServedFromSecureOriginMessage; | |
| 108 break; | |
| 109 case kIgnoredNotSupportedOnAndroid: | |
| 110 pattern = kIgnoredNotSupportedOnAndroidMessage; | |
| 111 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; | |
| 112 break; | |
| 113 case kIgnoredNoId: | |
| 114 pattern = kIgnoredNoIdMessage; | |
| 115 break; | |
| 116 case kIgnoredIdsDoNotMatch: | |
| 117 pattern = kIgnoredIdsDoNotMatchMessage; | |
| 118 break; | |
| 119 } | |
| 120 std::string message = param.empty() ? | |
| 121 pattern : base::StringPrintf(pattern, param.c_str()); | |
| 57 web_contents->GetMainFrame()->AddMessageToConsole( | 122 web_contents->GetMainFrame()->AddMessageToConsole( |
| 58 content::CONSOLE_MESSAGE_LEVEL_DEBUG, "App banner " + message); | 123 severity, "App banner not shown: " + message); |
| 124 | |
| 59 } | 125 } |
| 60 | 126 |
| 61 } // namespace banners | 127 } // namespace banners |
| OLD | NEW |