OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/sync_promo/sync_promo_ui.h" | 5 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/first_run/first_run.h" | 10 #include "chrome/browser/first_run/first_run.h" |
11 #include "chrome/browser/google/google_util.h" | 11 #include "chrome/browser/google/google_util.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
16 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 16 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
17 #include "chrome/browser/ui/webui/options/core_options_handler.h" | 17 #include "chrome/browser/ui/webui/options/core_options_handler.h" |
18 #include "chrome/browser/ui/webui/sync_promo/sync_promo_handler.h" | 18 #include "chrome/browser/ui/webui/sync_promo/sync_promo_handler.h" |
19 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" | 19 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" |
20 #include "chrome/browser/ui/webui/theme_source.h" | 20 #include "chrome/browser/ui/webui/theme_source.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "content/browser/webui/web_ui.h" |
24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
25 #include "googleurl/src/url_util.h" | 26 #include "googleurl/src/url_util.h" |
26 #include "grit/browser_resources.h" | 27 #include "grit/browser_resources.h" |
27 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
28 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
30 | 31 |
31 using content::WebContents; | 32 using content::WebContents; |
32 | 33 |
33 namespace { | 34 namespace { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 *out_value = ""; | 99 *out_value = ""; |
99 return true; | 100 return true; |
100 } | 101 } |
101 } | 102 } |
102 } | 103 } |
103 return false; | 104 return false; |
104 } | 105 } |
105 | 106 |
106 } // namespace | 107 } // namespace |
107 | 108 |
108 SyncPromoUI::SyncPromoUI(WebContents* contents) : WebUI(contents, this) { | 109 SyncPromoUI::SyncPromoUI(WebUI* web_ui) : WebUIController(web_ui) { |
109 should_hide_url_ = true; | 110 web_ui->HideURL(); |
110 | 111 |
111 SyncPromoHandler* handler = new SyncPromoHandler( | 112 SyncPromoHandler* handler = new SyncPromoHandler( |
112 g_browser_process->profile_manager()); | 113 g_browser_process->profile_manager()); |
113 AddMessageHandler(handler); | 114 web_ui->AddMessageHandler(handler); |
114 | 115 |
115 // Set up the chrome://theme/ source. | 116 // Set up the chrome://theme/ source. |
| 117 WebContents* contents = web_ui->web_contents(); |
116 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 118 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
117 ThemeSource* theme = new ThemeSource(profile); | 119 ThemeSource* theme = new ThemeSource(profile); |
118 profile->GetChromeURLDataManager()->AddDataSource(theme); | 120 profile->GetChromeURLDataManager()->AddDataSource(theme); |
119 | 121 |
120 // Set up the sync promo source. | 122 // Set up the sync promo source. |
121 SyncPromoUIHTMLSource* html_source = new SyncPromoUIHTMLSource(this); | 123 SyncPromoUIHTMLSource* html_source = new SyncPromoUIHTMLSource(web_ui); |
122 html_source->set_json_path(kStringsJsFile); | 124 html_source->set_json_path(kStringsJsFile); |
123 html_source->add_resource_path(kSyncPromoJsFile, IDR_SYNC_PROMO_JS); | 125 html_source->add_resource_path(kSyncPromoJsFile, IDR_SYNC_PROMO_JS); |
124 html_source->set_default_resource(IDR_SYNC_PROMO_HTML); | 126 html_source->set_default_resource(IDR_SYNC_PROMO_HTML); |
125 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 127 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
126 | 128 |
127 if (sync_promo_trial::IsPartOfBrandTrialToEnable()) { | 129 if (sync_promo_trial::IsPartOfBrandTrialToEnable()) { |
128 bool is_start_up = GetIsLaunchPageForSyncPromoURL(contents->GetURL()); | 130 bool is_start_up = GetIsLaunchPageForSyncPromoURL(contents->GetURL()); |
129 sync_promo_trial::RecordUserShownPromoWithTrialBrand(is_start_up, profile); | 131 sync_promo_trial::RecordUserShownPromoWithTrialBrand(is_start_up, profile); |
130 } | 132 } |
131 } | 133 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 UTF16ToUTF8(output.data(), output.length(), &url); | 270 UTF16ToUTF8(output.data(), output.length(), &url); |
269 return GURL(url); | 271 return GURL(url); |
270 } | 272 } |
271 return GURL(); | 273 return GURL(); |
272 } | 274 } |
273 | 275 |
274 // static | 276 // static |
275 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { | 277 bool SyncPromoUI::UserHasSeenSyncPromoAtStartup(Profile* profile) { |
276 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; | 278 return profile->GetPrefs()->GetInteger(prefs::kSyncPromoStartupCount) > 0; |
277 } | 279 } |
OLD | NEW |