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

Side by Side Diff: chrome/browser/shell_integration.cc

Issue 6961013: Allow chrome to become the os default handler for arbitrary protocols on mac/win. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More changes for comments; fix for a bug introduced with DefaultWebClientWorker refactoring Created 9 years, 7 months 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 | Annotate | Revision Log
OLDNEW
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/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } else { 54 } else {
55 // Use '--app=url' instead of just 'url' to launch the browser with minimal 55 // Use '--app=url' instead of just 'url' to launch the browser with minimal
56 // chrome. 56 // chrome.
57 // Note: Do not change this flag! Old Gears shortcuts will break if you do! 57 // Note: Do not change this flag! Old Gears shortcuts will break if you do!
58 new_cmd_line.AppendSwitchASCII(switches::kApp, url.spec()); 58 new_cmd_line.AppendSwitchASCII(switches::kApp, url.spec());
59 } 59 }
60 return new_cmd_line; 60 return new_cmd_line;
61 } 61 }
62 62
63 /////////////////////////////////////////////////////////////////////////////// 63 ///////////////////////////////////////////////////////////////////////////////
64 // ShellIntegration::DefaultWebClientWorker
65 //
66
67 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker(
68 DefaultWebClientObserver* observer)
69 : observer_(observer) {
70 }
71
72 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() {
73 if (observer_) {
74 observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
75 BrowserThread::PostTask(
76 BrowserThread::FILE, FROM_HERE,
77 NewRunnableMethod(
78 this, &DefaultWebClientWorker::ExecuteCheckIsDefault));
79 }
80 }
81
82 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() {
83 if (observer_) {
84 observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
85 }
86 BrowserThread::PostTask(
87 BrowserThread::FILE, FROM_HERE,
88 NewRunnableMethod(
89 this, &DefaultWebClientWorker::ExecuteSetAsDefault));
90 }
91
92 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() {
93 // Our associated view has gone away, so we shouldn't call back to it if
94 // our worker thread returns after the view is dead.
95 observer_ = NULL;
96 }
97
98 ///////////////////////////////////////////////////////////////////////////////
99 // DefaultWebClientWorker, private:
100
101 void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault() {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
103 DefaultWebClientState state = CheckIsDefault();
104 BrowserThread::PostTask(
105 BrowserThread::UI, FROM_HERE,
106 NewRunnableMethod(
107 this, &DefaultWebClientWorker::CompleteCheckIsDefault, state));
108 }
109
110 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault(
111 DefaultWebClientState state) {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
113 UpdateUI(state);
114 }
115
116 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault() {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
118 SetAsDefault();
119 BrowserThread::PostTask(
120 BrowserThread::UI, FROM_HERE,
121 NewRunnableMethod(
122 this, &DefaultWebClientWorker::CompleteSetAsDefault));
123 }
124
125 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault() {
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
127 // Set as default completed, check again to make sure it stuck...
128 StartCheckIsDefault();
129 }
130
131 void ShellIntegration::DefaultWebClientWorker::UpdateUI(
132 DefaultWebClientState state) {
133 if (observer_) {
134 switch (state) {
135 case NOT_DEFAULT_WEB_CLIENT:
136 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT);
137 break;
138 case IS_DEFAULT_WEB_CLIENT:
139 observer_->SetDefaultWebClientUIState(STATE_IS_DEFAULT);
140 break;
141 case UNKNOWN_DEFAULT_WEB_CLIENT:
142 observer_->SetDefaultWebClientUIState(STATE_UNKNOWN);
143 break;
144 default:
145 break;
146 }
147 }
148 }
149
150 ///////////////////////////////////////////////////////////////////////////////
64 // ShellIntegration::DefaultBrowserWorker 151 // ShellIntegration::DefaultBrowserWorker
65 // 152 //
66 153
67 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( 154 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker(
68 DefaultBrowserObserver* observer) 155 DefaultWebClientObserver* observer)
69 : observer_(observer) { 156 : DefaultWebClientWorker(observer) {
70 }
71
72 void ShellIntegration::DefaultBrowserWorker::StartCheckDefaultBrowser() {
73 observer_->SetDefaultBrowserUIState(STATE_PROCESSING);
74 BrowserThread::PostTask(
75 BrowserThread::FILE, FROM_HERE,
76 NewRunnableMethod(
77 this, &DefaultBrowserWorker::ExecuteCheckDefaultBrowser));
78 }
79
80 void ShellIntegration::DefaultBrowserWorker::StartSetAsDefaultBrowser() {
81 observer_->SetDefaultBrowserUIState(STATE_PROCESSING);
82 BrowserThread::PostTask(
83 BrowserThread::FILE, FROM_HERE,
84 NewRunnableMethod(
85 this, &DefaultBrowserWorker::ExecuteSetAsDefaultBrowser));
86 }
87
88 void ShellIntegration::DefaultBrowserWorker::ObserverDestroyed() {
89 // Our associated view has gone away, so we shouldn't call back to it if
90 // our worker thread returns after the view is dead.
91 observer_ = NULL;
92 } 157 }
93 158
94 /////////////////////////////////////////////////////////////////////////////// 159 ///////////////////////////////////////////////////////////////////////////////
95 // DefaultBrowserWorker, private: 160 // DefaultBrowserWorker, private:
96 161
97 void ShellIntegration::DefaultBrowserWorker::ExecuteCheckDefaultBrowser() { 162 ShellIntegration::DefaultWebClientState
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 163 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() {
99 DefaultBrowserState state = ShellIntegration::IsDefaultBrowser(); 164 return ShellIntegration::IsDefaultBrowser();
100 BrowserThread::PostTask(
101 BrowserThread::UI, FROM_HERE,
102 NewRunnableMethod(
103 this, &DefaultBrowserWorker::CompleteCheckDefaultBrowser, state));
104 } 165 }
105 166
106 void ShellIntegration::DefaultBrowserWorker::CompleteCheckDefaultBrowser( 167 void ShellIntegration::DefaultBrowserWorker::SetAsDefault() {
107 DefaultBrowserState state) { 168 ShellIntegration::SetAsDefaultBrowser();
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 UpdateUI(state);
110 } 169 }
111 170
112 void ShellIntegration::DefaultBrowserWorker::ExecuteSetAsDefaultBrowser() { 171 ///////////////////////////////////////////////////////////////////////////////
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 172 // ShellIntegration::DefaultProtocolClientWorker
114 ShellIntegration::SetAsDefaultBrowser(); 173 //
115 BrowserThread::PostTask( 174
116 BrowserThread::UI, FROM_HERE, 175 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker(
117 NewRunnableMethod( 176 DefaultWebClientObserver* observer, const std::string& protocol)
118 this, &DefaultBrowserWorker::CompleteSetAsDefaultBrowser)); 177 : DefaultWebClientWorker(observer),
178 protocol_(protocol) {
119 } 179 }
120 180
121 void ShellIntegration::DefaultBrowserWorker::CompleteSetAsDefaultBrowser() { 181 ///////////////////////////////////////////////////////////////////////////////
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 182 // DefaultProtocolClientWorker, private:
123 if (observer_) { 183
124 // Set as default completed, check again to make sure it stuck... 184 ShellIntegration::DefaultWebClientState
125 StartCheckDefaultBrowser(); 185 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() {
126 } 186 return ShellIntegration::IsDefaultProtocolClient(protocol_);
127 } 187 }
128 188
129 void ShellIntegration::DefaultBrowserWorker::UpdateUI( 189 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault() {
130 DefaultBrowserState state) { 190 ShellIntegration::SetAsDefaultProtocolClient(protocol_);
131 if (observer_) {
132 switch (state) {
133 case NOT_DEFAULT_BROWSER:
134 observer_->SetDefaultBrowserUIState(STATE_NOT_DEFAULT);
135 break;
136 case IS_DEFAULT_BROWSER:
137 observer_->SetDefaultBrowserUIState(STATE_IS_DEFAULT);
138 break;
139 case UNKNOWN_DEFAULT_BROWSER:
140 observer_->SetDefaultBrowserUIState(STATE_UNKNOWN);
141 break;
142 default:
143 break;
144 }
145 }
146 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698