Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: chrome/browser/installable/installable_logging.cc

Issue 2160513002: Extract AppBannerDataFetcher into an InstallableManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use pending_tasks_ vector and invoke callbacks directly Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/installable/installable_logging.h"
6 6
7 #include "base/macros.h"
7 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
8 #include "content/public/browser/render_frame_host.h" 9 #include "content/public/browser/render_frame_host.h"
9 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
10 11
11 namespace banners { 12 namespace {
12 13
14 static const std::string& GetMessagePrefix() {
15 CR_DEFINE_STATIC_LOCAL(std::string, message_prefix,
16 ("Site cannot be installed: "));
17 return message_prefix;
18 }
19
20 // Error message strings corresponding to the values in the ErrorCode enum.
21 static const char kRendererExitingMessage[] =
22 "the page is in the process of being closed";
13 static const char kRendererRequestCancelMessage[] = 23 static const char kRendererRequestCancelMessage[] =
14 "page has requested the banner prompt be cancelled"; 24 "the page has requested the banner prompt be cancelled";
25 static const char kUserNavigatedBeforeBannerShownMessage[] =
26 "the page was navigated before the banner could be shown";
27 static const char kNotLoadedInMainFrameMessage[] =
28 "the page is not loaded in the main frame";
29 static const char kNotServedFromSecureOriginMessage[] =
30 "the page is not served from a secure origin";
31 static const char kNoManifestMessage[] =
32 "the page has no manifest <link> URL";
15 static const char kManifestEmptyMessage[] = 33 static const char kManifestEmptyMessage[] =
16 "manifest could not be fetched, is empty, or could not be parsed"; 34 "the manifest could not be fetched, is empty, or could not be parsed";
17 static const char kNoManifestMessage[] = 35 static const char kStartUrlNotValidMessage[] =
18 "site has no manifest <link> URL"; 36 "the start URL in manifest is not valid";
19 static const char kNoIconMatchingRequirementsMessage[] = 37 static const char kManifestMissingNameOrShortNameMessage[] =
20 "%spx square icon is required, but no supplied icon is at least this size"; 38 "one of manifest name or short name must be specified";
21 static const char kCannotDownloadIconMessage[] = 39 static const char kManifestDisplayIsNotStandaloneOrFullscreenMessage[] =
22 "could not download the specified icon"; 40 "the manifest display property must be set to 'standalone' or 'fullscreen'";
41 static const char kManifestMissingSuitableIconMessage[] =
42 "the manifest does not contain a suitable icon - PNG format of at least "
43 "%spx is required, and the sizes attribute must be set";
23 static const char kNoMatchingServiceWorkerMessage[] = 44 static const char kNoMatchingServiceWorkerMessage[] =
24 "no matching service worker detected. You may need to reload the page, or " 45 "no matching service worker detected. You may need to reload the page, or "
25 "check that the service worker for the current page also controls the " 46 "check that the service worker for the current page also controls the "
26 "start URL from the manifest"; 47 "start URL from the manifest";
48 static const char kNoIconMatchingRequirementsMessage[] =
49 "a %spx square icon is required, but no supplied icon is at least this "
50 "size";
51 static const char kCannotDownloadIconMessage[] =
52 "could not download the specified icon";
27 static const char kNoIconAvailableMessage[] = 53 static const char kNoIconAvailableMessage[] =
28 "no icon available to display"; 54 "no icon available to display";
29 static const char kUserNavigatedBeforeBannerShownMessage[] =
30 "the user navigated before the banner could be shown";
31 static const char kStartURLNotValidMessage[] =
32 "start URL in manifest is not valid";
33 static const char kManifestDisplayStandaloneFullscreenMessage[] =
34 "manifest display property must be set to 'standalone' or 'fullscreen'";
35 static const char kManifestMissingNameOrShortNameMessage[] =
36 "one of manifest name or short name must be specified";
37 static const char kManifestMissingSuitableIconMessage[] =
38 "manifest does not contain a suitable icon - PNG format of at least "
39 "144x144px is required, and the sizes attribute must be set";
40 static const char kNotLoadedInMainFrameMessage[] =
41 "page not loaded in the main frame";
42 static const char kNotServedFromSecureOriginMessage[] =
43 "page not served from a secure origin";
44 // The leading space is intentional as another string is prepended.
45 static const char kIgnoredNotSupportedOnAndroidMessage[] = 55 static const char kIgnoredNotSupportedOnAndroidMessage[] =
46 "%s application is not supported on Android"; 56 "the specified application platform is not supported on Android";
47 static const char kIgnoredNoIdMessage[] = 57 static const char kIgnoredNoIdMessage[] =
48 "no Play store ID provided"; 58 "no Play store ID provided";
49 static const char kIgnoredIdsDoNotMatchMessage[] = 59 static const char kIgnoredIdsDoNotMatchMessage[] =
50 "a Play app URL and Play store ID were specified in the manifest, but they" 60 "a Play Store app URL and Play Store ID were specified in the manifest, "
51 " do not match"; 61 "but they do not match";
52 62
53 void OutputDeveloperNotShownMessage(content::WebContents* web_contents, 63 } // anonymous namespace
54 OutputDeveloperMessageCode code,
55 bool is_debug_mode) {
56 OutputDeveloperNotShownMessage(web_contents, code, std::string(),
57 is_debug_mode);
58 }
59 64
60 void OutputDeveloperNotShownMessage(content::WebContents* web_contents, 65 namespace installable {
61 OutputDeveloperMessageCode code, 66
62 const std::string& param, 67 void LogErrorToConsole(content::WebContents* web_contents,
63 bool is_debug_mode) { 68 ErrorCode code,
64 if (!is_debug_mode || !web_contents) 69 const std::string& param) {
70 if (!web_contents)
65 return; 71 return;
66 72
67 const char* pattern;
68 content::ConsoleMessageLevel severity = content::CONSOLE_MESSAGE_LEVEL_ERROR; 73 content::ConsoleMessageLevel severity = content::CONSOLE_MESSAGE_LEVEL_ERROR;
74 const char* pattern = nullptr;
69 switch (code) { 75 switch (code) {
70 case kRendererRequestCancel: 76 case NoErrorDetected:
77 case MaxErrorCode:
78 return;
79 case RendererExiting:
80 pattern = kRendererExitingMessage;
81 break;
82 case RendererRequestCancel:
71 pattern = kRendererRequestCancelMessage; 83 pattern = kRendererRequestCancelMessage;
72 severity = content::CONSOLE_MESSAGE_LEVEL_LOG; 84 severity = content::CONSOLE_MESSAGE_LEVEL_LOG;
73 break; 85 break;
74 case kManifestEmpty: 86 case UserNavigatedBeforeBannerShown:
75 pattern = kManifestEmptyMessage;
76 break;
77 case kNoManifest:
78 pattern = kNoManifestMessage;
79 break;
80 case kNoIconMatchingRequirements:
81 pattern = kNoIconMatchingRequirementsMessage;
82 break;
83 case kCannotDownloadIcon:
84 pattern = kCannotDownloadIconMessage;
85 break;
86 case kNoMatchingServiceWorker:
87 pattern = kNoMatchingServiceWorkerMessage;
88 break;
89 case kNoIconAvailable:
90 pattern = kNoIconAvailableMessage;
91 break;
92 case kUserNavigatedBeforeBannerShown:
93 pattern = kUserNavigatedBeforeBannerShownMessage; 87 pattern = kUserNavigatedBeforeBannerShownMessage;
94 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; 88 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING;
95 break; 89 break;
96 case kStartURLNotValid: 90 case NotLoadedInMainFrame:
97 pattern = kStartURLNotValidMessage; 91 pattern = kNotLoadedInMainFrameMessage;
98 break; 92 break;
99 case kManifestDisplayStandaloneFullscreen: 93 case NotServedFromSecureOrigin:
100 pattern = kManifestDisplayStandaloneFullscreenMessage; 94 pattern = kNotServedFromSecureOriginMessage;
101 break; 95 break;
102 case kManifestMissingNameOrShortName: 96 case NoManifest:
97 pattern = kNoManifestMessage;
98 break;
99 case ManifestEmpty:
100 pattern = kManifestEmptyMessage;
101 break;
102 case StartUrlNotValid:
103 pattern = kStartUrlNotValidMessage;
104 break;
105 case ManifestMissingNameOrShortName:
103 pattern = kManifestMissingNameOrShortNameMessage; 106 pattern = kManifestMissingNameOrShortNameMessage;
104 break; 107 break;
105 case kManifestMissingSuitableIcon: 108 case ManifestDisplayIsNotStandaloneOrFullscreen:
109 pattern = kManifestDisplayIsNotStandaloneOrFullscreenMessage;
110 break;
111 case ManifestMissingSuitableIcon:
106 pattern = kManifestMissingSuitableIconMessage; 112 pattern = kManifestMissingSuitableIconMessage;
107 break; 113 break;
108 case kNotLoadedInMainFrame: 114 case NoMatchingServiceWorker:
109 pattern = kNotLoadedInMainFrameMessage; 115 pattern = kNoMatchingServiceWorkerMessage;
110 break; 116 break;
111 case kNotServedFromSecureOrigin: 117 case NoIconMatchingRequirements:
112 pattern = kNotServedFromSecureOriginMessage; 118 pattern = kNoIconMatchingRequirementsMessage;
113 break; 119 break;
114 case kIgnoredNotSupportedOnAndroid: 120 case CannotDownloadIcon:
121 pattern = kCannotDownloadIconMessage;
122 break;
123 case NoIconAvailable:
124 pattern = kNoIconAvailableMessage;
125 break;
126 case IgnoredNotSupportedOnAndroid:
115 pattern = kIgnoredNotSupportedOnAndroidMessage; 127 pattern = kIgnoredNotSupportedOnAndroidMessage;
116 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; 128 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING;
117 break; 129 break;
118 case kIgnoredNoId: 130 case IgnoredNoId:
119 pattern = kIgnoredNoIdMessage; 131 pattern = kIgnoredNoIdMessage;
120 break; 132 break;
121 case kIgnoredIdsDoNotMatch: 133 case IgnoredIdsDoNotMatch:
122 pattern = kIgnoredIdsDoNotMatchMessage; 134 pattern = kIgnoredIdsDoNotMatchMessage;
123 break; 135 break;
124 default:
125 NOTREACHED();
126 return;
127 } 136 }
137
138 if (!pattern)
139 return;
128 std::string message = param.empty() ? 140 std::string message = param.empty() ?
129 pattern : base::StringPrintf(pattern, param.c_str()); 141 pattern : base::StringPrintf(pattern, param.c_str());
130 web_contents->GetMainFrame()->AddMessageToConsole( 142 web_contents->GetMainFrame()->AddMessageToConsole(
131 severity, "App banner not shown: " + message); 143 severity, GetMessagePrefix() + message);
132
133 } 144 }
134 145
135 } // namespace banners 146 } // namespace installable
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698