OLD | NEW |
1 // Copyright 2016 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/installable/installable_logging.h" | 5 #include "chrome/browser/installable/installable_logging.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "content/public/browser/render_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 const std::string& GetMessagePrefix() { | 14 const std::string& GetMessagePrefix() { |
15 CR_DEFINE_STATIC_LOCAL(std::string, message_prefix, | 15 CR_DEFINE_STATIC_LOCAL(std::string, message_prefix, |
16 ("Site cannot be installed: ")); | 16 ("Site cannot be installed: ")); |
17 return message_prefix; | 17 return message_prefix; |
18 } | 18 } |
19 | 19 |
20 // Error message strings corresponding to the InstallableErrorCode enum. | 20 // Error message strings corresponding to the InstallableStatusCode enum. |
21 static const char kRendererExitingMessage[] = | 21 static const char kRendererExitingMessage[] = |
22 "the page is in the process of being closed"; | 22 "the page is in the process of being closed"; |
23 static const char kRendererCancelledMessage[] = | 23 static const char kRendererCancelledMessage[] = |
24 "the page has requested the banner prompt be cancelled"; | 24 "the page has requested the banner prompt be cancelled"; |
25 static const char kUserNavigatedMessage[] = | 25 static const char kUserNavigatedMessage[] = |
26 "the page was navigated before the banner could be shown"; | 26 "the page was navigated before the banner could be shown"; |
27 static const char kNotInMainFrameMessage[] = | 27 static const char kNotInMainFrameMessage[] = |
28 "the page is not loaded in the main frame"; | 28 "the page is not loaded in the main frame"; |
29 static const char kNotFromSecureOriginMessage[] = | 29 static const char kNotFromSecureOriginMessage[] = |
30 "the page is not served from a secure origin"; | 30 "the page is not served from a secure origin"; |
(...skipping 25 matching lines...) Expand all Loading... |
56 "the specified application platform is not supported on Android"; | 56 "the specified application platform is not supported on Android"; |
57 static const char kNoIdSpecifiedMessage[] = | 57 static const char kNoIdSpecifiedMessage[] = |
58 "no Play store ID provided"; | 58 "no Play store ID provided"; |
59 static const char kIdsDoNotMatchMessage[] = | 59 static const char kIdsDoNotMatchMessage[] = |
60 "a Play Store app URL and Play Store ID were specified in the manifest, " | 60 "a Play Store app URL and Play Store ID were specified in the manifest, " |
61 "but they do not match"; | 61 "but they do not match"; |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 void LogErrorToConsole(content::WebContents* web_contents, | 65 void LogErrorToConsole(content::WebContents* web_contents, |
66 InstallableErrorCode code, | 66 InstallableStatusCode code, |
67 const std::string& param) { | 67 const std::string& param) { |
68 if (!web_contents) | 68 if (!web_contents) |
69 return; | 69 return; |
70 | 70 |
71 content::ConsoleMessageLevel severity = content::CONSOLE_MESSAGE_LEVEL_ERROR; | 71 content::ConsoleMessageLevel severity = content::CONSOLE_MESSAGE_LEVEL_ERROR; |
72 const char* pattern = nullptr; | 72 const char* pattern = nullptr; |
73 switch (code) { | 73 switch (code) { |
74 case NO_ERROR_DETECTED: | 74 case NO_ERROR_DETECTED: |
| 75 // These codes are solely used for UMA reporting. |
| 76 case ALREADY_INSTALLED: |
| 77 case INSUFFICIENT_ENGAGEMENT: |
| 78 case PACKAGE_NAME_OR_START_URL_EMPTY: |
| 79 case PREVIOUSLY_BLOCKED: |
| 80 case PREVIOUSLY_IGNORED: |
| 81 case SHOWING_NATIVE_APP_BANNER: |
| 82 case SHOWING_WEB_APP_BANNER: |
| 83 case FAILED_TO_CREATE_BANNER: |
75 case MAX_ERROR_CODE: | 84 case MAX_ERROR_CODE: |
76 return; | 85 return; |
77 case RENDERER_EXITING: | 86 case RENDERER_EXITING: |
78 pattern = kRendererExitingMessage; | 87 pattern = kRendererExitingMessage; |
79 break; | 88 break; |
80 case RENDERER_CANCELLED: | 89 case RENDERER_CANCELLED: |
81 pattern = kRendererCancelledMessage; | 90 pattern = kRendererCancelledMessage; |
82 severity = content::CONSOLE_MESSAGE_LEVEL_LOG; | 91 severity = content::CONSOLE_MESSAGE_LEVEL_LOG; |
83 break; | 92 break; |
84 case USER_NAVIGATED: | 93 case USER_NAVIGATED: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 break; | 142 break; |
134 } | 143 } |
135 | 144 |
136 if (!pattern) | 145 if (!pattern) |
137 return; | 146 return; |
138 std::string message = param.empty() ? | 147 std::string message = param.empty() ? |
139 pattern : base::StringPrintf(pattern, param.c_str()); | 148 pattern : base::StringPrintf(pattern, param.c_str()); |
140 web_contents->GetMainFrame()->AddMessageToConsole( | 149 web_contents->GetMainFrame()->AddMessageToConsole( |
141 severity, GetMessagePrefix() + message); | 150 severity, GetMessagePrefix() + message); |
142 } | 151 } |
OLD | NEW |