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

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: Addressing reviewer comments 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/installable/installable_logging.h"
6
7 #include "base/macros.h"
8 #include "base/strings/stringprintf.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/web_contents.h"
11
12 namespace {
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";
23 static const char kRendererCancelledMessage[] =
24 "the page has requested the banner prompt be cancelled";
25 static const char kUserNavigatedMessage[] =
26 "the page was navigated before the banner could be shown";
27 static const char kNotInMainFrameMessage[] =
28 "the page is not loaded in the main frame";
29 static const char kNotFromSecureOriginMessage[] =
30 "the page is not served from a secure origin";
31 static const char kNoManifestMessage[] =
32 "the page has no manifest <link> URL";
33 static const char kManifestEmptyMessage[] =
34 "the manifest could not be fetched, is empty, or could not be parsed";
35 static const char kStartUrlNotValidMessage[] =
36 "the start URL in manifest is not valid";
37 static const char kManifestMissingNameOrShortNameMessage[] =
38 "one of manifest name or short name must be specified";
39 static const char kManifestDisplayNotSupportedMessage[] =
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";
44 static const char kNoMatchingServiceWorkerMessage[] =
45 "no matching service worker detected. You may need to reload the page, or "
46 "check that the service worker for the current page also controls the "
47 "start URL from the manifest";
48 static const char kNoAcceptableIconMessage[] =
49 "a %spx square icon is required, but no supplied icon meets this "
50 "requirement";
51 static const char kCannotDownloadIconMessage[] =
52 "could not download the specified icon";
53 static const char kNoIconAvailableMessage[] =
54 "no icon available to display";
55 static const char kPlatformNotSupportedOnAndroidMessage[] =
56 "the specified application platform is not supported on Android";
57 static const char kNoIdSpecifiedMessage[] =
58 "no Play store ID provided";
59 static const char kIdsDoNotMatchMessage[] =
60 "a Play Store app URL and Play Store ID were specified in the manifest, "
61 "but they do not match";
62
63 } // anonymous namespace
64
65 namespace installable {
66
67 void LogErrorToConsole(content::WebContents* web_contents,
68 ErrorCode code,
69 const std::string& param) {
70 if (!web_contents)
71 return;
72
73 content::ConsoleMessageLevel severity = content::CONSOLE_MESSAGE_LEVEL_ERROR;
74 const char* pattern = nullptr;
75 switch (code) {
76 case NO_ERROR:
77 case MAX_ERROR_CODE:
78 return;
79 case RENDERER_EXITING:
80 pattern = kRendererExitingMessage;
81 break;
82 case RENDERER_CANCELLED:
83 pattern = kRendererCancelledMessage;
84 severity = content::CONSOLE_MESSAGE_LEVEL_LOG;
85 break;
86 case USER_NAVIGATED:
87 pattern = kUserNavigatedMessage;
88 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING;
89 break;
90 case NOT_IN_MAIN_FRAME:
91 pattern = kNotInMainFrameMessage;
92 break;
93 case NOT_FROM_SECURE_ORIGIN:
94 pattern = kNotFromSecureOriginMessage;
95 break;
96 case NO_MANIFEST:
97 pattern = kNoManifestMessage;
98 break;
99 case MANIFEST_EMPTY:
100 pattern = kManifestEmptyMessage;
101 break;
102 case START_URL_NOT_VALID:
103 pattern = kStartUrlNotValidMessage;
104 break;
105 case MANIFEST_MISSING_NAME_OR_SHORT_NAME:
106 pattern = kManifestMissingNameOrShortNameMessage;
107 break;
108 case MANIFEST_DISPLAY_NOT_SUPPORTED:
109 pattern = kManifestDisplayNotSupportedMessage;
110 break;
111 case MANIFEST_MISSING_SUITABLE_ICON:
112 pattern = kManifestMissingSuitableIconMessage;
113 break;
114 case NO_MATCHING_SERVICE_WORKER:
115 pattern = kNoMatchingServiceWorkerMessage;
116 break;
117 case NO_ACCEPTABLE_ICON:
118 pattern = kNoAcceptableIconMessage;
119 break;
120 case CANNOT_DOWNLOAD_ICON:
121 pattern = kCannotDownloadIconMessage;
122 break;
123 case NO_ICON_AVAILABLE:
124 pattern = kNoIconAvailableMessage;
125 break;
126 case PLATFORM_NOT_SUPPORTED_ON_ANDROID:
127 pattern = kPlatformNotSupportedOnAndroidMessage;
128 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING;
129 break;
130 case NO_ID_SPECIFIED:
131 pattern = kNoIdSpecifiedMessage;
132 break;
133 case IDS_DO_NOT_MATCH:
134 pattern = kIdsDoNotMatchMessage;
135 break;
136 }
137
138 if (!pattern)
139 return;
140 std::string message = param.empty() ?
141 pattern : base::StringPrintf(pattern, param.c_str());
142 web_contents->GetMainFrame()->AddMessageToConsole(
143 severity, GetMessagePrefix() + message);
144 }
145
146 } // namespace installable
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698