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

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: Responded to comments 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 }
76 BrowserThread::PostTask(
77 BrowserThread::FILE, FROM_HERE,
78 NewRunnableMethod(
79 this, &DefaultWebClientWorker::ExecuteCheckIsDefault));
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
xiyuan 2011/05/24 17:55:20 nit: nuke one empty line.
benwells 2011/05/25 08:07:19 Done.
102 void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault() {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
104 DefaultWebClientState state = CheckIsDefault();
105 BrowserThread::PostTask(
106 BrowserThread::UI, FROM_HERE,
107 NewRunnableMethod(
108 this, &DefaultWebClientWorker::CompleteCheckIsDefault,
109 state));
Mark Mentovai 2011/05/24 16:28:53 This would fit on the previous line.
benwells 2011/05/25 08:07:19 Done.
110 }
111
112 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault(
113 DefaultWebClientState state) {
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
115 UpdateUI(state);
116 }
117
118 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault() {
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
120 SetAsDefault();
121 ShellIntegration::SetAsDefaultBrowser();
122 BrowserThread::PostTask(
123 BrowserThread::UI, FROM_HERE,
124 NewRunnableMethod(
125 this, &DefaultWebClientWorker::CompleteSetAsDefault));
126 }
127
128 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault() {
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
130 if (observer_) {
Mark Mentovai 2011/05/24 16:28:53 It doesn’t seem like you need this |observer_| che
benwells 2011/05/25 08:07:19 Interesting and valid point. Instead of checking h
131 // Set as default completed, check again to make sure it stuck...
132 StartCheckIsDefault();
133 }
134 }
135
136 void ShellIntegration::DefaultWebClientWorker::UpdateUI(
137 DefaultWebClientState state) {
138 if (observer_) {
139 switch (state) {
140 case NOT_DEFAULT_WEB_CLIENT:
141 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT);
142 break;
143 case IS_DEFAULT_WEB_CLIENT:
144 observer_->SetDefaultWebClientUIState(STATE_IS_DEFAULT);
145 break;
146 case UNKNOWN_DEFAULT_WEB_CLIENT:
147 observer_->SetDefaultWebClientUIState(STATE_UNKNOWN);
148 break;
149 default:
150 break;
151 }
152 }
153 }
154
155 ///////////////////////////////////////////////////////////////////////////////
64 // ShellIntegration::DefaultBrowserWorker 156 // ShellIntegration::DefaultBrowserWorker
65 // 157 //
66 158
67 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( 159 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker(
68 DefaultBrowserObserver* observer) 160 DefaultWebClientObserver* observer)
69 : observer_(observer) { 161 : 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 } 162 }
93 163
94 /////////////////////////////////////////////////////////////////////////////// 164 ///////////////////////////////////////////////////////////////////////////////
95 // DefaultBrowserWorker, private: 165 // DefaultBrowserWorker, private:
96 166
97 void ShellIntegration::DefaultBrowserWorker::ExecuteCheckDefaultBrowser() { 167 ShellIntegration::DefaultWebClientState
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 168 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() {
99 DefaultBrowserState state = ShellIntegration::IsDefaultBrowser(); 169 return ShellIntegration::IsDefaultBrowser();
100 BrowserThread::PostTask(
101 BrowserThread::UI, FROM_HERE,
102 NewRunnableMethod(
103 this, &DefaultBrowserWorker::CompleteCheckDefaultBrowser, state));
104 } 170 }
105 171
106 void ShellIntegration::DefaultBrowserWorker::CompleteCheckDefaultBrowser( 172 void ShellIntegration::DefaultBrowserWorker::SetAsDefault() {
107 DefaultBrowserState state) { 173 ShellIntegration::SetAsDefaultBrowser();
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 UpdateUI(state);
110 } 174 }
111 175
112 void ShellIntegration::DefaultBrowserWorker::ExecuteSetAsDefaultBrowser() { 176 ///////////////////////////////////////////////////////////////////////////////
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 177 // ShellIntegration::DefaultProtocolClientWorker
114 ShellIntegration::SetAsDefaultBrowser(); 178 //
115 BrowserThread::PostTask( 179
116 BrowserThread::UI, FROM_HERE, 180 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker(
117 NewRunnableMethod( 181 DefaultWebClientObserver* observer, const std::string& protocol)
118 this, &DefaultBrowserWorker::CompleteSetAsDefaultBrowser)); 182 : DefaultWebClientWorker(observer),
183 protocol_(protocol) {
119 } 184 }
120 185
121 void ShellIntegration::DefaultBrowserWorker::CompleteSetAsDefaultBrowser() { 186 ///////////////////////////////////////////////////////////////////////////////
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 187 // DefaultProtocolClientWorker, private:
123 if (observer_) { 188
124 // Set as default completed, check again to make sure it stuck... 189 ShellIntegration::DefaultWebClientState
125 StartCheckDefaultBrowser(); 190 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() {
126 } 191 return ShellIntegration::IsDefaultProtocolClient(protocol_);
127 } 192 }
128 193
129 void ShellIntegration::DefaultBrowserWorker::UpdateUI( 194 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault() {
130 DefaultBrowserState state) { 195 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 } 196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698