| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/shell_integration.h" | 5 #include "chrome/browser/shell_integration.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | 19 using content::BrowserThread; |
| 20 | 20 |
| 21 bool ShellIntegration::CanSetAsDefaultProtocolClient() { | 21 ShellIntegration::DefaultWebClientSetPermission |
| 22 ShellIntegration::CanSetAsDefaultProtocolClient() { |
| 22 // Allowed as long as the browser can become the operating system default | 23 // Allowed as long as the browser can become the operating system default |
| 23 // browser. | 24 // browser. |
| 24 return CanSetAsDefaultBrowser(); | 25 return CanSetAsDefaultBrowser(); |
| 25 } | 26 } |
| 26 | 27 |
| 27 ShellIntegration::ShortcutInfo::ShortcutInfo() | 28 ShellIntegration::ShortcutInfo::ShortcutInfo() |
| 28 : is_platform_app(false), | 29 : is_platform_app(false), |
| 29 create_on_desktop(false), | 30 create_on_desktop(false), |
| 30 create_in_applications_menu(false), | 31 create_in_applications_menu(false), |
| 31 create_in_quick_launch_bar(false) { | 32 create_in_quick_launch_bar(false) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 86 } |
| 86 } else { | 87 } else { |
| 87 // Use '--app=url' instead of just 'url' to launch the browser with minimal | 88 // Use '--app=url' instead of just 'url' to launch the browser with minimal |
| 88 // chrome. | 89 // chrome. |
| 89 // Note: Do not change this flag! Old Gears shortcuts will break if you do! | 90 // Note: Do not change this flag! Old Gears shortcuts will break if you do! |
| 90 new_cmd_line.AppendSwitchASCII(switches::kApp, url.spec()); | 91 new_cmd_line.AppendSwitchASCII(switches::kApp, url.spec()); |
| 91 } | 92 } |
| 92 return new_cmd_line; | 93 return new_cmd_line; |
| 93 } | 94 } |
| 94 | 95 |
| 96 #if !defined(OS_WIN) |
| 97 // static |
| 98 bool ShellIntegration::SetAsDefaultBrowserInteractive() { |
| 99 return false; |
| 100 } |
| 101 #endif |
| 102 |
| 95 /////////////////////////////////////////////////////////////////////////////// | 103 /////////////////////////////////////////////////////////////////////////////// |
| 96 // ShellIntegration::DefaultWebClientWorker | 104 // ShellIntegration::DefaultWebClientWorker |
| 97 // | 105 // |
| 98 | 106 |
| 99 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker( | 107 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker( |
| 100 DefaultWebClientObserver* observer) | 108 DefaultWebClientObserver* observer) |
| 101 : observer_(observer) { | 109 : observer_(observer) { |
| 102 } | 110 } |
| 103 | 111 |
| 104 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() { | 112 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // The worker has finished everything it needs to do, so free the observer | 155 // The worker has finished everything it needs to do, so free the observer |
| 148 // if we own it. | 156 // if we own it. |
| 149 if (observer_ && observer_->IsOwnedByWorker()) { | 157 if (observer_ && observer_->IsOwnedByWorker()) { |
| 150 delete observer_; | 158 delete observer_; |
| 151 observer_ = NULL; | 159 observer_ = NULL; |
| 152 } | 160 } |
| 153 } | 161 } |
| 154 | 162 |
| 155 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault() { | 163 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault() { |
| 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 157 SetAsDefault(); | 165 SetAsDefault(observer_ && observer_->IsInteractiveSetDefaultPermitted()); |
| 158 BrowserThread::PostTask( | 166 BrowserThread::PostTask( |
| 159 BrowserThread::UI, FROM_HERE, | 167 BrowserThread::UI, FROM_HERE, |
| 160 base::Bind( | 168 base::Bind( |
| 161 &DefaultWebClientWorker::CompleteSetAsDefault, this)); | 169 &DefaultWebClientWorker::CompleteSetAsDefault, this)); |
| 162 } | 170 } |
| 163 | 171 |
| 164 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault() { | 172 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault() { |
| 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 166 // Set as default completed, check again to make sure it stuck... | 174 // Set as default completed, check again to make sure it stuck... |
| 167 StartCheckIsDefault(); | 175 StartCheckIsDefault(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 196 } | 204 } |
| 197 | 205 |
| 198 /////////////////////////////////////////////////////////////////////////////// | 206 /////////////////////////////////////////////////////////////////////////////// |
| 199 // DefaultBrowserWorker, private: | 207 // DefaultBrowserWorker, private: |
| 200 | 208 |
| 201 ShellIntegration::DefaultWebClientState | 209 ShellIntegration::DefaultWebClientState |
| 202 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { | 210 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { |
| 203 return ShellIntegration::IsDefaultBrowser(); | 211 return ShellIntegration::IsDefaultBrowser(); |
| 204 } | 212 } |
| 205 | 213 |
| 206 void ShellIntegration::DefaultBrowserWorker::SetAsDefault() { | 214 void ShellIntegration::DefaultBrowserWorker::SetAsDefault( |
| 207 ShellIntegration::SetAsDefaultBrowser(); | 215 bool interactive_permitted) { |
| 216 switch (ShellIntegration::CanSetAsDefaultBrowser()) { |
| 217 case ShellIntegration::SET_DEFAULT_UNATTENDED: |
| 218 ShellIntegration::SetAsDefaultBrowser(); |
| 219 break; |
| 220 case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
| 221 if (interactive_permitted) |
| 222 ShellIntegration::SetAsDefaultBrowserInteractive(); |
| 223 break; |
| 224 default: |
| 225 NOTREACHED(); |
| 226 } |
| 208 } | 227 } |
| 209 | 228 |
| 210 /////////////////////////////////////////////////////////////////////////////// | 229 /////////////////////////////////////////////////////////////////////////////// |
| 211 // ShellIntegration::DefaultProtocolClientWorker | 230 // ShellIntegration::DefaultProtocolClientWorker |
| 212 // | 231 // |
| 213 | 232 |
| 214 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( | 233 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( |
| 215 DefaultWebClientObserver* observer, const std::string& protocol) | 234 DefaultWebClientObserver* observer, const std::string& protocol) |
| 216 : DefaultWebClientWorker(observer), | 235 : DefaultWebClientWorker(observer), |
| 217 protocol_(protocol) { | 236 protocol_(protocol) { |
| 218 } | 237 } |
| 219 | 238 |
| 220 /////////////////////////////////////////////////////////////////////////////// | 239 /////////////////////////////////////////////////////////////////////////////// |
| 221 // DefaultProtocolClientWorker, private: | 240 // DefaultProtocolClientWorker, private: |
| 222 | 241 |
| 223 ShellIntegration::DefaultWebClientState | 242 ShellIntegration::DefaultWebClientState |
| 224 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { | 243 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { |
| 225 return ShellIntegration::IsDefaultProtocolClient(protocol_); | 244 return ShellIntegration::IsDefaultProtocolClient(protocol_); |
| 226 } | 245 } |
| 227 | 246 |
| 228 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault() { | 247 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( |
| 248 bool interactive_permitted) { |
| 229 ShellIntegration::SetAsDefaultProtocolClient(protocol_); | 249 ShellIntegration::SetAsDefaultProtocolClient(protocol_); |
| 230 } | 250 } |
| OLD | NEW |