| 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 #ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_ | 5 #ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| 6 #define CHROME_BROWSER_SHELL_INTEGRATION_H_ | 6 #define CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 // Returns true if Firefox is likely to be the default browser for the current | 102 // Returns true if Firefox is likely to be the default browser for the current |
| 103 // user. This method is very fast so it can be invoked in the UI thread. | 103 // user. This method is very fast so it can be invoked in the UI thread. |
| 104 bool IsFirefoxDefaultBrowser(); | 104 bool IsFirefoxDefaultBrowser(); |
| 105 | 105 |
| 106 // Attempt to determine if this instance of Chrome is the default client | 106 // Attempt to determine if this instance of Chrome is the default client |
| 107 // application for the given protocol and return the appropriate state. | 107 // application for the given protocol and return the appropriate state. |
| 108 DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol); | 108 DefaultWebClientState IsDefaultProtocolClient(const std::string& protocol); |
| 109 | 109 |
| 110 // Data that needs to be passed between the app launcher stub and Chrome. | 110 // Data that needs to be passed between the app launcher stub and Chrome. |
| 111 struct AppModeInfo {}; | 111 struct AppModeInfo { |
| 112 }; |
| 112 void SetAppModeInfo(const AppModeInfo* info); | 113 void SetAppModeInfo(const AppModeInfo* info); |
| 113 const AppModeInfo* AppModeInfo(); | 114 const AppModeInfo* AppModeInfo(); |
| 114 | 115 |
| 115 // Is the current instance of Chrome running in App mode. | 116 // Is the current instance of Chrome running in App mode. |
| 116 bool IsRunningInAppMode(); | 117 bool IsRunningInAppMode(); |
| 117 | 118 |
| 118 // Set up command line arguments for launching a URL or an app. | 119 // Set up command line arguments for launching a URL or an app. |
| 119 // The new command line reuses the current process's user data directory (and | 120 // The new command line reuses the current process's user data directory (and |
| 120 // login profile, for ChromeOS). | 121 // login profile, for ChromeOS). |
| 121 // If |extension_app_id| is non-empty, the arguments use kAppId=<id>. | 122 // If |extension_app_id| is non-empty, the arguments use kAppId=<id>. |
| 122 // Otherwise, kApp=<url> is used. | 123 // Otherwise, kApp=<url> is used. |
| 123 base::CommandLine CommandLineArgsForLauncher( | 124 base::CommandLine CommandLineArgsForLauncher( |
| 124 const GURL& url, | 125 const GURL& url, |
| 125 const std::string& extension_app_id, | 126 const std::string& extension_app_id, |
| 126 const base::FilePath& profile_path); | 127 const base::FilePath& profile_path); |
| 127 | 128 |
| 128 // Append command line arguments for launching a new chrome.exe process | 129 // Append command line arguments for launching a new chrome.exe process |
| 129 // based on the current process. | 130 // based on the current process. |
| 130 // The new command line reuses the current process's user data directory and | 131 // The new command line reuses the current process's user data directory and |
| 131 // profile. | 132 // profile. |
| 132 void AppendProfileArgs(const base::FilePath& profile_path, | 133 void AppendProfileArgs(const base::FilePath& profile_path, |
| 133 base::CommandLine* command_line); | 134 base::CommandLine* command_line); |
| 134 | 135 |
| 135 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
| 136 // Generates an application user model ID (AppUserModelId) for a given app | 137 // Generates an application user model ID (AppUserModelId) for a given app |
| 137 // name and profile path. The returned app id is in the format of | 138 // name and profile path. The returned app id is in the format of |
| 138 // "|app_name|[.<profile_id>]". "profile_id" is appended when user override | 139 // "|app_name|[.<profile_id>]". "profile_id" is appended when user override |
| 139 // the default value. | 140 // the default value. |
| 140 // Note: If the app has an installation specific suffix (e.g. on user-level | 141 // Note: If the app has an installation specific suffix (e.g. on user-level |
| 141 // Chrome installs), |app_name| should already be suffixed, this method will | 142 // Chrome installs), |app_name| should already be suffixed, this method will |
| 142 // then further suffix it with the profile id as described above. | 143 // then further suffix it with the profile id as described above. |
| 143 base::string16 GetAppModelIdForProfile(const base::string16& app_name, | 144 base::string16 GetAppModelIdForProfile(const base::string16& app_name, |
| 144 const base::FilePath& profile_path); | 145 const base::FilePath& profile_path); |
| 145 | 146 |
| 146 // Generates an application user model ID (AppUserModelId) for Chromium by | 147 // Generates an application user model ID (AppUserModelId) for Chromium by |
| 147 // calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name. | 148 // calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name. |
| 148 base::string16 GetChromiumModelIdForProfile(const base::FilePath& profile_path); | 149 base::string16 GetChromiumModelIdForProfile( |
| 150 const base::FilePath& profile_path); |
| 149 | 151 |
| 150 // Get the AppUserModelId for the App List, for the profile in |profile_path|. | 152 // Get the AppUserModelId for the App List, for the profile in |profile_path|. |
| 151 base::string16 GetAppListAppModelIdForProfile( | 153 base::string16 GetAppListAppModelIdForProfile( |
| 152 const base::FilePath& profile_path); | 154 const base::FilePath& profile_path); |
| 153 | 155 |
| 154 // Migrates existing chrome taskbar pins by tagging them with correct app id. | 156 // Migrates existing chrome taskbar pins by tagging them with correct app id. |
| 155 // see http://crbug.com/28104 | 157 // see http://crbug.com/28104 |
| 156 void MigrateTaskbarPins(); | 158 void MigrateTaskbarPins(); |
| 157 | 159 |
| 158 // Migrates all shortcuts in |path| which point to |chrome_exe| such that they | 160 // Migrates all shortcuts in |path| which point to |chrome_exe| such that they |
| 159 // have the appropriate AppUserModelId. Also clears the legacy dual_mode | 161 // have the appropriate AppUserModelId. Also clears the legacy dual_mode |
| 160 // property from shortcuts with the default chrome app id. | 162 // property from shortcuts with the default chrome app id. |
| 161 // Returns the number of shortcuts migrated. | 163 // Returns the number of shortcuts migrated. |
| 162 // This method should not be called prior to Windows 7. | 164 // This method should not be called prior to Windows 7. |
| 163 // This method is only public for the sake of tests and shouldn't be called | 165 // This method is only public for the sake of tests and shouldn't be called |
| 164 // externally otherwise. | 166 // externally otherwise. |
| 165 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, | 167 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, |
| 166 const base::FilePath& path); | 168 const base::FilePath& path); |
| 167 | 169 |
| 168 // Returns the path to the Start Menu shortcut for the given Chrome. | 170 // Returns the path to the Start Menu shortcut for the given Chrome. |
| 169 base::FilePath GetStartMenuShortcut(const base::FilePath& chrome_exe); | 171 base::FilePath GetStartMenuShortcut(const base::FilePath& chrome_exe); |
| 170 #endif // defined(OS_WIN) | 172 #endif // defined(OS_WIN) |
| 171 | 173 |
| 172 #if !defined(OS_WIN) | 174 #if !defined(OS_WIN) |
| 173 // TODO(calamity): replace with | 175 // TODO(calamity): replace with |
| 174 // BrowserDistribution::GetStartMenuShortcutSubfolder() once | 176 // BrowserDistribution::GetStartMenuShortcutSubfolder() once |
| 175 // BrowserDistribution is cross-platform. | 177 // BrowserDistribution is cross-platform. |
| 176 // Gets the name of the Chrome Apps menu folder in which to place app | 178 // Gets the name of the Chrome Apps menu folder in which to place app |
| (...skipping 13 matching lines...) Expand all Loading... |
| 190 }; | 192 }; |
| 191 | 193 |
| 192 class DefaultWebClientObserver { | 194 class DefaultWebClientObserver { |
| 193 public: | 195 public: |
| 194 virtual ~DefaultWebClientObserver() {} | 196 virtual ~DefaultWebClientObserver() {} |
| 195 // Updates the UI state to reflect the current default browser state. | 197 // Updates the UI state to reflect the current default browser state. |
| 196 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; | 198 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; |
| 197 // Called to notify the UI of the immediate result of invoking | 199 // Called to notify the UI of the immediate result of invoking |
| 198 // SetAsDefault. | 200 // SetAsDefault. |
| 199 virtual void OnSetAsDefaultConcluded(bool succeeded) {} | 201 virtual void OnSetAsDefaultConcluded(bool succeeded) {} |
| 200 // Observer classes that return true to OwnedByWorker are automatically | |
| 201 // freed by the worker when they are no longer needed. False by default. | |
| 202 virtual bool IsOwnedByWorker(); | |
| 203 // An observer can permit or decline set-as-default operation if it | |
| 204 // requires triggering user interaction. By default not allowed. | |
| 205 virtual bool IsInteractiveSetDefaultPermitted(); | |
| 206 }; | 202 }; |
| 207 | 203 |
| 208 // Helper objects that handle checking if Chrome is the default browser | 204 // Helper objects that handle checking if Chrome is the default browser |
| 209 // or application for a url protocol on Windows and Linux, and also setting | 205 // or application for a url protocol on Windows and Linux, and also setting |
| 210 // it as the default. These operations are performed asynchronously on the | 206 // it as the default. These operations are performed asynchronously on the |
| 211 // file thread since registry access (on Windows) or the preference database | 207 // file thread since registry access (on Windows) or the preference database |
| 212 // (on Linux) are involved and this can be slow. | 208 // (on Linux) are involved and this can be slow. |
| 209 // By default, the worker will present the user with an interactive flow if |
| 210 // required by the platform. This can be suppressed via |
| 211 // set_interactive_permitted(), in which case an attempt to set Chrome as |
| 212 // the default handler will silently fail on such platforms. |
| 213 class DefaultWebClientWorker | 213 class DefaultWebClientWorker |
| 214 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { | 214 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
| 215 public: | 215 public: |
| 216 explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); | 216 // Constructor. The worker will post updates to |observer|. If |
| 217 // |delete_observer| is true, the worker owns the observer and it will be |
| 218 // freed in the destructor. |
| 219 DefaultWebClientWorker(DefaultWebClientObserver* observer, |
| 220 bool delete_observer); |
| 221 |
| 222 // Controls whether the worker can use user interaction to set the default |
| 223 // web client. If false, the set-as-default operation will fail on OS where |
| 224 // it is required. |
| 225 void set_interactive_permitted(bool interactive_permitted) { |
| 226 interactive_permitted_ = interactive_permitted; |
| 227 } |
| 217 | 228 |
| 218 // Checks to see if Chrome is the default web client application. The result | 229 // Checks to see if Chrome is the default web client application. The result |
| 219 // will be passed back to the observer via the SetDefaultWebClientUIState | 230 // will be passed back to the observer via the SetDefaultWebClientUIState |
| 220 // function. If there is no observer, this function does not do anything. | 231 // function. If there is no observer, this function does not do anything. |
| 221 void StartCheckIsDefault(); | 232 void StartCheckIsDefault(); |
| 222 | 233 |
| 223 // Sets Chrome as the default web client application. If there is an | 234 // Sets Chrome as the default web client application. If there is an |
| 224 // observer, once the operation has completed the new default will be | 235 // observer, once the operation has completed the new default will be |
| 225 // queried and the current status reported via SetDefaultWebClientUIState. | 236 // queried and the current status reported via SetDefaultWebClientUIState. |
| 226 void StartSetAsDefault(); | 237 void StartSetAsDefault(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 // is default process. | 281 // is default process. |
| 271 // It is safe to call this multiple times. Only the first call is processed | 282 // It is safe to call this multiple times. Only the first call is processed |
| 272 // after StartSetAsDefault() is invoked. | 283 // after StartSetAsDefault() is invoked. |
| 273 void OnSetAsDefaultAttemptComplete(AttemptResult result); | 284 void OnSetAsDefaultAttemptComplete(AttemptResult result); |
| 274 | 285 |
| 275 // Returns true if FinalizeSetAsDefault() will be called. | 286 // Returns true if FinalizeSetAsDefault() will be called. |
| 276 bool set_as_default_initialized() const { | 287 bool set_as_default_initialized() const { |
| 277 return set_as_default_initialized_; | 288 return set_as_default_initialized_; |
| 278 } | 289 } |
| 279 | 290 |
| 291 // When false, the operation to set as default will fail for interactive |
| 292 // flows. |
| 293 bool interactive_permitted_ = true; |
| 294 |
| 280 // Flag that indicates if the set-as-default operation is in progess to | 295 // Flag that indicates if the set-as-default operation is in progess to |
| 281 // prevent multiple notifications to the observer. | 296 // prevent multiple notifications to the observer. |
| 282 bool set_as_default_in_progress_ = false; | 297 bool set_as_default_in_progress_ = false; |
| 283 | 298 |
| 284 private: | 299 private: |
| 285 // Checks whether Chrome is the default web client. Always called on the | 300 // Checks whether Chrome is the default web client. Always called on the |
| 286 // FILE thread. Subclasses are responsible for calling | 301 // FILE thread. Subclasses are responsible for calling |
| 287 // OnCheckIsDefaultComplete() on the UI thread. | 302 // OnCheckIsDefaultComplete() on the UI thread. |
| 288 virtual void CheckIsDefault() = 0; | 303 virtual void CheckIsDefault() = 0; |
| 289 | 304 |
| 290 // Sets Chrome as the default web client. Always called on the FILE thread. | 305 // Sets Chrome as the default web client. Always called on the FILE thread. |
| 291 // |interactive_permitted| will make SetAsDefault() fail if it requires | 306 // Subclasses are responsible for calling OnSetAsDefaultAttemptComplete() on |
| 292 // interaction with the user. Subclasses are responsible for calling | 307 // the UI thread. |
| 293 // OnSetAsDefaultAttemptComplete() on the UI thread. | 308 virtual void SetAsDefault() = 0; |
| 294 virtual void SetAsDefault(bool interactive_permitted) = 0; | |
| 295 | 309 |
| 296 // Returns the prefix used for metrics to differentiate UMA metrics for | 310 // Returns the prefix used for metrics to differentiate UMA metrics for |
| 297 // setting the default browser and setting the default protocol client. | 311 // setting the default browser and setting the default protocol client. |
| 298 virtual const char* GetHistogramPrefix() = 0; | 312 virtual const char* GetHistogramPrefix() = 0; |
| 299 | 313 |
| 300 // Invoked on the UI thread prior to starting a set-as-default operation. | 314 // Invoked on the UI thread prior to starting a set-as-default operation. |
| 301 // Returns true if the initialization succeeded and a subsequent call to | 315 // Returns true if the initialization succeeded and a subsequent call to |
| 302 // FinalizeSetAsDefault() is required. | 316 // FinalizeSetAsDefault() is required. |
| 303 virtual bool InitializeSetAsDefault(); | 317 virtual bool InitializeSetAsDefault(); |
| 304 | 318 |
| 305 // Invoked on the UI thread following a set-as-default operation. | 319 // Invoked on the UI thread following a set-as-default operation. |
| 306 virtual void FinalizeSetAsDefault(); | 320 virtual void FinalizeSetAsDefault(); |
| 307 | 321 |
| 308 // Reports the result and duration for one set-as-default attempt. | 322 // Reports the result and duration for one set-as-default attempt. |
| 309 void ReportAttemptResult(AttemptResult result); | 323 void ReportAttemptResult(AttemptResult result); |
| 310 | 324 |
| 311 // Updates the UI in our associated view with the current default web | 325 // Updates the UI in our associated view with the current default web |
| 312 // client state. | 326 // client state. |
| 313 void UpdateUI(DefaultWebClientState state); | 327 void UpdateUI(DefaultWebClientState state); |
| 314 | 328 |
| 315 // Returns true if the duration of an attempt to set the default web client | 329 // Returns true if the duration of an attempt to set the default web client |
| 316 // should be reported to UMA for |result|. | 330 // should be reported to UMA for |result|. |
| 317 static bool ShouldReportDurationForResult(AttemptResult result); | 331 static bool ShouldReportDurationForResult(AttemptResult result); |
| 318 | 332 |
| 319 // Returns a string based on |result|. This is used for UMA reports. | 333 // Returns a string based on |result|. This is used for UMA reports. |
| 320 static const char* AttemptResultToString(AttemptResult result); | 334 static const char* AttemptResultToString(AttemptResult result); |
| 321 | 335 |
| 322 DefaultWebClientObserver* observer_; | 336 DefaultWebClientObserver* observer_; |
| 323 | 337 |
| 338 // Indicates if the the observer will be automatically freed by the worker. |
| 339 bool delete_observer_; |
| 340 |
| 324 // Flag that indicates the return value of InitializeSetAsDefault(). If | 341 // Flag that indicates the return value of InitializeSetAsDefault(). If |
| 325 // true, FinalizeSetAsDefault() will be called to clear what was | 342 // true, FinalizeSetAsDefault() will be called to clear what was |
| 326 // initialized. | 343 // initialized. |
| 327 bool set_as_default_initialized_ = false; | 344 bool set_as_default_initialized_ = false; |
| 328 | 345 |
| 329 // Records the time it takes to set the default browser. | 346 // Records the time it takes to set the default browser. |
| 330 base::TimeTicks start_time_; | 347 base::TimeTicks start_time_; |
| 331 | 348 |
| 332 // Wait until Chrome has been confirmed as the default browser before | 349 // Wait until Chrome has been confirmed as the default browser before |
| 333 // reporting a successful attempt. | 350 // reporting a successful attempt. |
| 334 bool check_default_should_report_success_ = false; | 351 bool check_default_should_report_success_ = false; |
| 335 | 352 |
| 336 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); | 353 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
| 337 }; | 354 }; |
| 338 | 355 |
| 339 // Worker for checking and setting the default browser. | 356 // Worker for checking and setting the default browser. |
| 340 class DefaultBrowserWorker : public DefaultWebClientWorker { | 357 class DefaultBrowserWorker : public DefaultWebClientWorker { |
| 341 public: | 358 public: |
| 342 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 359 // Constructor. The worker will post updates to |observer|. If |
| 360 // |delete_observer| is true, the worker owns the observer and it will be |
| 361 // freed in the destructor. |
| 362 DefaultBrowserWorker(DefaultWebClientObserver* observer, |
| 363 bool delete_observer); |
| 343 | 364 |
| 344 private: | 365 private: |
| 345 ~DefaultBrowserWorker() override; | 366 ~DefaultBrowserWorker() override; |
| 346 | 367 |
| 347 // Check if Chrome is the default browser. | 368 // Check if Chrome is the default browser. |
| 348 void CheckIsDefault() override; | 369 void CheckIsDefault() override; |
| 349 | 370 |
| 350 // Set Chrome as the default browser. | 371 // Set Chrome as the default browser. |
| 351 void SetAsDefault(bool interactive_permitted) override; | 372 void SetAsDefault() override; |
| 352 | 373 |
| 353 // Returns the histogram prefix for DefaultBrowserWorker. | 374 // Returns the histogram prefix for DefaultBrowserWorker. |
| 354 const char* GetHistogramPrefix() override; | 375 const char* GetHistogramPrefix() override; |
| 355 | 376 |
| 356 #if defined(OS_WIN) | 377 #if defined(OS_WIN) |
| 357 // On Windows 10+, adds the default browser callback and starts the timer | 378 // On Windows 10+, adds the default browser callback and starts the timer |
| 358 // that determines if the operation was successful or not. | 379 // that determines if the operation was successful or not. |
| 359 bool InitializeSetAsDefault() override; | 380 bool InitializeSetAsDefault() override; |
| 360 | 381 |
| 361 // On Windows 10+, removes the default browser callback and stops the timer. | 382 // On Windows 10+, removes the default browser callback and stops the timer. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 372 | 393 |
| 373 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 394 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| 374 }; | 395 }; |
| 375 | 396 |
| 376 // Worker for checking and setting the default client application | 397 // Worker for checking and setting the default client application |
| 377 // for a given protocol. A different worker instance is needed for each | 398 // for a given protocol. A different worker instance is needed for each |
| 378 // protocol you are interested in, so to check or set the default for | 399 // protocol you are interested in, so to check or set the default for |
| 379 // multiple protocols you should use multiple worker objects. | 400 // multiple protocols you should use multiple worker objects. |
| 380 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 401 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
| 381 public: | 402 public: |
| 403 // Constructor. The worker will post updates to |observer|. If |
| 404 // |delete_observer| is true, the worker owns the observer and it will be |
| 405 // freed in the destructor. |
| 382 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 406 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
| 383 const std::string& protocol); | 407 const std::string& protocol, |
| 408 bool delete_observer); |
| 384 | 409 |
| 385 const std::string& protocol() const { return protocol_; } | 410 const std::string& protocol() const { return protocol_; } |
| 386 | 411 |
| 387 protected: | 412 protected: |
| 388 ~DefaultProtocolClientWorker() override; | 413 ~DefaultProtocolClientWorker() override; |
| 389 | 414 |
| 390 private: | 415 private: |
| 391 // Check is Chrome is the default handler for this protocol. | 416 // Check is Chrome is the default handler for this protocol. |
| 392 void CheckIsDefault() override; | 417 void CheckIsDefault() override; |
| 393 | 418 |
| 394 // Set Chrome as the default handler for this protocol. | 419 // Set Chrome as the default handler for this protocol. |
| 395 void SetAsDefault(bool interactive_permitted) override; | 420 void SetAsDefault() override; |
| 396 | 421 |
| 397 // Returns the histogram prefix for DefaultProtocolClientWorker. | 422 // Returns the histogram prefix for DefaultProtocolClientWorker. |
| 398 const char* GetHistogramPrefix() override; | 423 const char* GetHistogramPrefix() override; |
| 399 | 424 |
| 400 std::string protocol_; | 425 std::string protocol_; |
| 401 | 426 |
| 402 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 427 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
| 403 }; | 428 }; |
| 404 | 429 |
| 405 } // namespace shell_integration | 430 } // namespace shell_integration |
| 406 | 431 |
| 407 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 432 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| OLD | NEW |