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

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

Powered by Google App Engine
This is Rietveld 408576698