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

Side by Side Diff: chrome/browser/interstitials/chrome_controller_client.cc

Issue 1481213003: Componentize the bad clock blocking page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change for pkasting Created 5 years 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/interstitials/chrome_controller_client.h" 5 #include "chrome/browser/interstitials/chrome_controller_client.h"
6 6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/files/file_util.h"
7 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/process/launch.h"
8 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/interstitial_page.h"
11 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
12 #include "content/public/common/referrer.h" 18 #include "content/public/common/referrer.h"
13 19
20 #if defined(OS_ANDROID)
21 #include "chrome/browser/android/intent_helper.h"
22 #endif
23
24 #if defined(OS_CHROMEOS)
25 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/ui/chrome_pages.h"
27 #include "chrome/common/url_constants.h"
28 #include "chrome/grit/generated_resources.h"
29 #include "ui/base/l10n/l10n_util.h"
30 #endif
31
32 #if defined(OS_WIN)
33 #include "base/base_paths_win.h"
34 #include "base/path_service.h"
35 #include "base/strings/string16.h"
36 #include "base/win/windows_version.h"
37 #endif
38
14 using content::Referrer; 39 using content::Referrer;
15 40
41 namespace {
42
43 void LaunchDateAndTimeSettingsOnFile() {
44 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
45 // The code for each OS is completely separate, in order to avoid bugs like
46 // https://crbug.com/430877 .
47 #if defined(OS_ANDROID)
48 chrome::android::OpenDateAndTimeSettings();
49
50 #elif defined(OS_CHROMEOS)
51 std::string sub_page =
52 std::string(chrome::kSearchSubPage) + "#" +
53 l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME);
54 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(),
55 sub_page);
56
57 #elif defined(OS_IOS)
58 // TODO(blundell): Remove this once iOS has its own version of this class.
59 // iOS does not have a way to launch the date and time settings.
60 NOTREACHED();
61
62 #elif defined(OS_LINUX)
63 struct ClockCommand {
64 const char* pathname;
65 const char* argument;
66 };
67 static const ClockCommand kClockCommands[] = {
68 // Unity
69 {"/usr/bin/unity-control-center", "datetime"},
70 // GNOME
71 //
72 // NOTE: On old Ubuntu, naming control panels doesn't work, so it
73 // opens the overview. This will have to be good enough.
74 {"/usr/bin/gnome-control-center", "datetime"},
75 {"/usr/local/bin/gnome-control-center", "datetime"},
76 {"/opt/bin/gnome-control-center", "datetime"},
77 // KDE
78 {"/usr/bin/kcmshell4", "clock"},
79 {"/usr/local/bin/kcmshell4", "clock"},
80 {"/opt/bin/kcmshell4", "clock"},
81 };
82
83 base::CommandLine command(base::FilePath(""));
84 for (const ClockCommand& cmd : kClockCommands) {
85 base::FilePath pathname(cmd.pathname);
86 if (base::PathExists(pathname)) {
87 command.SetProgram(pathname);
88 command.AppendArg(cmd.argument);
89 break;
90 }
91 }
92 if (command.GetProgram().empty()) {
93 // Alas, there is nothing we can do.
94 return;
95 }
96
97 base::LaunchOptions options;
98 options.wait = false;
99 options.allow_new_privs = true;
100 base::LaunchProcess(command, options);
101
102 #elif defined(OS_MACOSX)
103 base::CommandLine command(base::FilePath("/usr/bin/open"));
104 command.AppendArg("/System/Library/PreferencePanes/DateAndTime.prefPane");
105
106 base::LaunchOptions options;
107 options.wait = false;
108 base::LaunchProcess(command, options);
109
110 #elif defined(OS_WIN)
111 base::FilePath path;
112 PathService::Get(base::DIR_SYSTEM, &path);
113 static const base::char16 kControlPanelExe[] = L"control.exe";
114 path = path.Append(base::string16(kControlPanelExe));
115 base::CommandLine command(path);
116 command.AppendArg(std::string("/name"));
117 command.AppendArg(std::string("Microsoft.DateAndTime"));
118
119 base::LaunchOptions options;
120 options.wait = false;
121 base::LaunchProcess(command, options);
122
123 #else
124 NOTREACHED();
125
126 #endif
127 // Don't add code here! (See the comment at the beginning of the function.)
128 }
129
130 } // namespace
131
16 ChromeControllerClient::ChromeControllerClient( 132 ChromeControllerClient::ChromeControllerClient(
17 content::WebContents* web_contents) 133 content::WebContents* web_contents)
18 : web_contents_(web_contents) {} 134 : web_contents_(web_contents), interstitial_page_(nullptr) {}
19 135
20 ChromeControllerClient::~ChromeControllerClient() {} 136 ChromeControllerClient::~ChromeControllerClient() {}
21 137
138 void ChromeControllerClient::set_interstitial_page(
139 content::InterstitialPage* interstitial_page) {
140 interstitial_page_ = interstitial_page;
141 }
142
143 bool ChromeControllerClient::CanLaunchDateAndTimeSettings() {
144 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_LINUX) || \
145 defined(OS_MACOSX) || defined(OS_WIN)
146 return true;
147 #else
148 return false;
149 #endif
150 }
151
152 void ChromeControllerClient::LaunchDateAndTimeSettings() {
153 content::BrowserThread::PostTask(
154 content::BrowserThread::FILE, FROM_HERE,
155 base::Bind(&LaunchDateAndTimeSettingsOnFile));
156 }
157
158 void ChromeControllerClient::GoBack() {
159 DCHECK(interstitial_page_);
160 interstitial_page_->DontProceed();
161 }
162
22 void ChromeControllerClient::OpenUrlInCurrentTab(const GURL& url) { 163 void ChromeControllerClient::OpenUrlInCurrentTab(const GURL& url) {
23 content::OpenURLParams params(url, Referrer(), CURRENT_TAB, 164 content::OpenURLParams params(url, Referrer(), CURRENT_TAB,
24 ui::PAGE_TRANSITION_LINK, false); 165 ui::PAGE_TRANSITION_LINK, false);
25 web_contents_->OpenURL(params); 166 web_contents_->OpenURL(params);
26 } 167 }
27 168
28 const std::string& ChromeControllerClient::GetApplicationLocale() { 169 const std::string& ChromeControllerClient::GetApplicationLocale() {
29 return g_browser_process->GetApplicationLocale(); 170 return g_browser_process->GetApplicationLocale();
30 } 171 }
31 172
32 PrefService* ChromeControllerClient::GetPrefService() { 173 PrefService* ChromeControllerClient::GetPrefService() {
33 Profile* profile = 174 Profile* profile =
34 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 175 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
35 return profile->GetPrefs(); 176 return profile->GetPrefs();
36 } 177 }
37 178
38 const std::string ChromeControllerClient::GetExtendedReportingPrefName() { 179 const std::string ChromeControllerClient::GetExtendedReportingPrefName() {
39 return prefs::kSafeBrowsingExtendedReportingEnabled; 180 return prefs::kSafeBrowsingExtendedReportingEnabled;
40 } 181 }
OLDNEW
« no previous file with comments | « chrome/browser/interstitials/chrome_controller_client.h ('k') | chrome/browser/interstitials/security_interstitial_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698