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