OLD | NEW |
---|---|
(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() { | |
Lei Zhang
2016/08/03 06:49:51
no need for static inside an anonymous namespace.
dominickn
2016/08/03 07:01:43
Done.
| |
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 InstallableErrorCode 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 | |
Lei Zhang
2016/08/03 06:49:51
omit anonymous
dominickn
2016/08/03 07:01:43
Done.
| |
64 | |
65 void LogErrorToConsole(content::WebContents* web_contents, | |
Lei Zhang
2016/08/03 06:49:51
Nobody is calling this yet?
dominickn
2016/08/03 07:01:43
It's being called in the follow-up CL - crrev.com/
| |
66 InstallableErrorCode code, | |
67 const std::string& param) { | |
68 if (!web_contents) | |
69 return; | |
70 | |
71 content::ConsoleMessageLevel severity = content::CONSOLE_MESSAGE_LEVEL_ERROR; | |
72 const char* pattern = nullptr; | |
73 switch (code) { | |
74 case NO_ERROR_DETECTED: | |
75 case MAX_ERROR_CODE: | |
76 return; | |
77 case RENDERER_EXITING: | |
78 pattern = kRendererExitingMessage; | |
79 break; | |
80 case RENDERER_CANCELLED: | |
81 pattern = kRendererCancelledMessage; | |
82 severity = content::CONSOLE_MESSAGE_LEVEL_LOG; | |
83 break; | |
84 case USER_NAVIGATED: | |
85 pattern = kUserNavigatedMessage; | |
86 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; | |
87 break; | |
88 case NOT_IN_MAIN_FRAME: | |
89 pattern = kNotInMainFrameMessage; | |
90 break; | |
91 case NOT_FROM_SECURE_ORIGIN: | |
92 pattern = kNotFromSecureOriginMessage; | |
93 break; | |
94 case NO_MANIFEST: | |
95 pattern = kNoManifestMessage; | |
96 break; | |
97 case MANIFEST_EMPTY: | |
98 pattern = kManifestEmptyMessage; | |
99 break; | |
100 case START_URL_NOT_VALID: | |
101 pattern = kStartUrlNotValidMessage; | |
102 break; | |
103 case MANIFEST_MISSING_NAME_OR_SHORT_NAME: | |
104 pattern = kManifestMissingNameOrShortNameMessage; | |
105 break; | |
106 case MANIFEST_DISPLAY_NOT_SUPPORTED: | |
107 pattern = kManifestDisplayNotSupportedMessage; | |
108 break; | |
109 case MANIFEST_MISSING_SUITABLE_ICON: | |
110 pattern = kManifestMissingSuitableIconMessage; | |
111 break; | |
112 case NO_MATCHING_SERVICE_WORKER: | |
113 pattern = kNoMatchingServiceWorkerMessage; | |
114 break; | |
115 case NO_ACCEPTABLE_ICON: | |
116 pattern = kNoAcceptableIconMessage; | |
117 break; | |
118 case CANNOT_DOWNLOAD_ICON: | |
119 pattern = kCannotDownloadIconMessage; | |
120 break; | |
121 case NO_ICON_AVAILABLE: | |
122 pattern = kNoIconAvailableMessage; | |
123 break; | |
124 case PLATFORM_NOT_SUPPORTED_ON_ANDROID: | |
125 pattern = kPlatformNotSupportedOnAndroidMessage; | |
126 severity = content::CONSOLE_MESSAGE_LEVEL_WARNING; | |
127 break; | |
128 case NO_ID_SPECIFIED: | |
129 pattern = kNoIdSpecifiedMessage; | |
130 break; | |
131 case IDS_DO_NOT_MATCH: | |
132 pattern = kIdsDoNotMatchMessage; | |
133 break; | |
134 } | |
135 | |
136 if (!pattern) | |
137 return; | |
138 std::string message = param.empty() ? | |
139 pattern : base::StringPrintf(pattern, param.c_str()); | |
140 web_contents->GetMainFrame()->AddMessageToConsole( | |
141 severity, GetMessagePrefix() + message); | |
142 } | |
OLD | NEW |