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

Side by Side Diff: chrome/browser/chromeos/hats/hats_dialog.cc

Issue 2325883002: Adds a 'Done' button at the end of hats survey (Closed)
Patch Set: Adds a 'Done' button at the end of hats survey Created 4 years, 3 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
« no previous file with comments | « chrome/app/chromeos_strings.grdp ('k') | chrome/browser/resources/chromeos/hats/hats.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/chromeos/hats/hats_dialog.h" 5 #include "chrome/browser/chromeos/hats/hats_dialog.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/browser_dialogs.h" 10 #include "chrome/browser/ui/browser_dialogs.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "chrome/grit/browser_resources.h" 12 #include "chrome/grit/browser_resources.h"
13 #include "chrome/grit/generated_resources.h"
13 #include "chromeos/system/version_loader.h" 14 #include "chromeos/system/version_loader.h"
14 #include "components/prefs/pref_service.h" 15 #include "components/prefs/pref_service.h"
15 #include "components/version_info/version_info.h" 16 #include "components/version_info/version_info.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/geometry/size.h" 20 #include "ui/gfx/geometry/size.h"
19 21
20 using content::WebContents; 22 using content::WebContents;
21 using content::WebUIMessageHandler; 23 using content::WebUIMessageHandler;
22 24
23 namespace chromeos { 25 namespace chromeos {
24 26
25 namespace { 27 namespace {
26 28
27 // Default width/height ratio of screen size. 29 // Default width/height ratio of screen size.
28 const int kDefaultWidth = 400; 30 const int kDefaultWidth = 400;
29 const int kDefaultHeight = 420; 31 const int kDefaultHeight = 420;
30 // Site ID for HaTS survey. 32 // Site ID for HaTS survey.
31 constexpr char kSiteID[] = "cs5lsagwwbho7l5cbbdniso22e"; 33 constexpr char kSiteID[] = "cs5lsagwwbho7l5cbbdniso22e";
32 constexpr char kGooglerSiteID[] = "z56p2hjy7pegxh3gmmur4qlwha"; 34 constexpr char kGooglerSiteID[] = "z56p2hjy7pegxh3gmmur4qlwha";
33 35
34 constexpr char kReplacementToken[] = "$SCRIPT_SRC"; 36 constexpr char kScriptSrcReplacementToken[] = "$SCRIPT_SRC";
37 constexpr char kDoneButtonLabelReplacementToken[] = "$DONE_BUTTON_LABEL";
35 // Base URL to fetch the google consumer survey script. 38 // Base URL to fetch the google consumer survey script.
36 constexpr char kBaseFormatUrl[] = 39 constexpr char kBaseFormatUrl[] =
37 "https://www.google.com/insights/consumersurveys/" 40 "https://www.google.com/insights/consumersurveys/"
38 "async_survey?site=%s&force_https=1&sc=%s"; 41 "async_survey?site=%s&force_https=1&sc=%s";
39 // Keyword used to join the separate device info elements into a single string 42 // Keyword used to join the separate device info elements into a single string
40 // to be used as site context. 43 // to be used as site context.
41 const char kDeviceInfoStopKeyword[] = "STOP"; 44 const char kDeviceInfoStopKeyword[] = "STOP";
42 const char kDefaultProfileLocale[] = "en-US"; 45 const char kDefaultProfileLocale[] = "en-US";
43 enum class DeviceInfoKey : unsigned int { 46 enum class DeviceInfoKey : unsigned int {
44 BROWSER = 0, 47 BROWSER = 0,
45 PLATFORM, 48 PLATFORM,
46 FIRMWARE, 49 FIRMWARE,
47 LOCALE, 50 LOCALE,
48 }; 51 };
49 52
50 // Returns the local HaTS HTML file as a string with the correct Hats script 53 // Returns the local HaTS HTML file as a string with the correct Hats script
51 // URL. 54 // URL.
52 std::string LoadLocalHtmlAsString(std::string site_id, 55 std::string LoadLocalHtmlAsString(std::string site_id,
53 std::string site_context) { 56 std::string site_context) {
54 std::string html_data; 57 std::string html_data;
55 ResourceBundle::GetSharedInstance() 58 ResourceBundle::GetSharedInstance()
56 .GetRawDataResource(IDR_HATS_HTML) 59 .GetRawDataResource(IDR_HATS_HTML)
57 .CopyToString(&html_data); 60 .CopyToString(&html_data);
58 size_t pos = html_data.find(kReplacementToken); 61
59 html_data.replace(pos, strlen(kReplacementToken), 62 size_t pos = html_data.find(kScriptSrcReplacementToken);
63 html_data.replace(pos, strlen(kScriptSrcReplacementToken),
60 base::StringPrintf(kBaseFormatUrl, site_id.c_str(), 64 base::StringPrintf(kBaseFormatUrl, site_id.c_str(),
61 site_context.c_str())); 65 site_context.c_str()));
66
67 pos = html_data.find(kDoneButtonLabelReplacementToken);
68 html_data.replace(pos, strlen(kDoneButtonLabelReplacementToken),
69 l10n_util::GetStringUTF8(IDS_HATS_DONE_BUTTON_LABEL));
62 return html_data; 70 return html_data;
63 } 71 }
64 72
65 // Maps the given DeviceInfoKey |key| enum to the corresponding string value 73 // Maps the given DeviceInfoKey |key| enum to the corresponding string value
66 // that can be used as a key when creating a URL parameter. 74 // that can be used as a key when creating a URL parameter.
67 const std::string KeyEnumToString(DeviceInfoKey key) { 75 const std::string KeyEnumToString(DeviceInfoKey key) {
68 switch (key) { 76 switch (key) {
69 case DeviceInfoKey::BROWSER: 77 case DeviceInfoKey::BROWSER:
70 return "browser"; 78 return "browser";
71 case DeviceInfoKey::PLATFORM: 79 case DeviceInfoKey::PLATFORM:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 bool HatsDialog::ShouldShowDialogTitle() const { 185 bool HatsDialog::ShouldShowDialogTitle() const {
178 return false; 186 return false;
179 } 187 }
180 188
181 bool HatsDialog::HandleContextMenu(const content::ContextMenuParams& params) { 189 bool HatsDialog::HandleContextMenu(const content::ContextMenuParams& params) {
182 // Disable context menu. 190 // Disable context menu.
183 return true; 191 return true;
184 } 192 }
185 193
186 } // namespace chromeos 194 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/app/chromeos_strings.grdp ('k') | chrome/browser/resources/chromeos/hats/hats.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698