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

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

Issue 256065: External protocol dialog support for the Mac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/external_protocol_handler.h" 5 #include "chrome/browser/external_protocol_handler.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 return BLOCK; 83 return BLOCK;
84 84
85 if (scheme.length() == 1) { 85 if (scheme.length() == 1) {
86 // We have a URL that looks something like: 86 // We have a URL that looks something like:
87 // C:/WINDOWS/system32/notepad.exe 87 // C:/WINDOWS/system32/notepad.exe
88 // ShellExecuting this URL will cause the specified program to be executed. 88 // ShellExecuting this URL will cause the specified program to be executed.
89 return BLOCK; 89 return BLOCK;
90 } 90 }
91 91
92 // Check the stored prefs. 92 // Check the stored prefs.
93 // TODO(pkasting): http://b/119651 This kind of thing should go in the 93 // TODO(pkasting): http://b/1119651 This kind of thing should go in the
94 // preferences on the profile, not in the local state. 94 // preferences on the profile, not in the local state.
95 PrefService* pref = g_browser_process->local_state(); 95 PrefService* pref = g_browser_process->local_state();
96 if (pref) { // May be NULL during testing. 96 if (pref) { // May be NULL during testing.
97 DictionaryValue* win_pref = 97 DictionaryValue* win_pref =
98 pref->GetMutableDictionary(prefs::kExcludedSchemes); 98 pref->GetMutableDictionary(prefs::kExcludedSchemes);
99 CHECK(win_pref); 99 CHECK(win_pref);
100 100
101 // Warm up the dictionary if needed. 101 // Warm up the dictionary if needed.
102 PrepopulateDictionary(win_pref); 102 PrepopulateDictionary(win_pref);
103 103
104 bool should_block; 104 bool should_block;
105 if (win_pref->GetBoolean(scheme, &should_block)) 105 if (win_pref->GetBoolean(scheme, &should_block))
106 return should_block ? BLOCK : DONT_BLOCK; 106 return should_block ? BLOCK : DONT_BLOCK;
107 } 107 }
108 108
109 return UNKNOWN; 109 return UNKNOWN;
110 } 110 }
111 111
112 // static 112 // static
113 void ExternalProtocolHandler::SetBlockState(const std::wstring& scheme,
114 BlockState state) {
115 // Set in the stored prefs.
116 // TODO(pkasting): http://b/1119651 This kind of thing should go in the
117 // preferences on the profile, not in the local state.
118 PrefService* pref = g_browser_process->local_state();
119 if (pref) { // May be NULL during testing.
120 DictionaryValue* win_pref =
121 pref->GetMutableDictionary(prefs::kExcludedSchemes);
122 CHECK(win_pref);
123
124 if (state == UNKNOWN)
125 win_pref->Remove(scheme, NULL);
126 else
127 win_pref->SetBoolean(scheme, state == BLOCK ? true : false);
128 }
129 }
130
131 // static
113 void ExternalProtocolHandler::LaunchUrl(const GURL& url, 132 void ExternalProtocolHandler::LaunchUrl(const GURL& url,
114 int render_process_host_id, 133 int render_process_host_id,
115 int tab_contents_id) { 134 int tab_contents_id) {
116 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 135 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type());
117 136
118 // Escape the input scheme to be sure that the command does not 137 // Escape the input scheme to be sure that the command does not
119 // have parameters unexpected by the external program. 138 // have parameters unexpected by the external program.
120 std::string escaped_url_string = EscapeExternalHandlerValue(url.spec()); 139 std::string escaped_url_string = EscapeExternalHandlerValue(url.spec());
121 GURL escaped_url(escaped_url_string); 140 GURL escaped_url(escaped_url_string);
122 BlockState block_state = GetBlockState(ASCIIToWide(escaped_url.scheme())); 141 BlockState block_state = GetBlockState(ASCIIToWide(escaped_url.scheme()));
123 if (block_state == BLOCK) 142 if (block_state == BLOCK)
124 return; 143 return;
125 144
126 if (block_state == UNKNOWN) { 145 if (block_state == UNKNOWN) {
127 #if defined(OS_WIN) || defined(TOOLKIT_GTK) 146 #if defined(OS_WIN) || defined(TOOLKIT_GTK) || defined(OS_MACOSX)
128 g_accept_requests = false; 147 g_accept_requests = false;
129 // Ask the user if they want to allow the protocol. This will call 148 // Ask the user if they want to allow the protocol. This will call
130 // LaunchUrlWithoutSecurityCheck if the user decides to accept the protocol. 149 // LaunchUrlWithoutSecurityCheck if the user decides to accept the protocol.
131 RunExternalProtocolDialog(escaped_url, 150 RunExternalProtocolDialog(escaped_url,
132 render_process_host_id, 151 render_process_host_id,
133 tab_contents_id); 152 tab_contents_id);
134 #endif 153 #endif
135 // For now, allow only whitelisted protocols to fire on Mac and Linux/Views. 154 // For now, allow only whitelisted protocols to fire on Linux/Views.
136 // See http://crbug.com/15546. 155 // See http://crbug.com/23853 .
137 return; 156 return;
138 } 157 }
139 158
140 LaunchUrlWithoutSecurityCheck(escaped_url); 159 LaunchUrlWithoutSecurityCheck(escaped_url);
141 } 160 }
142 161
143 // static 162 // static
144 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(const GURL& url) { 163 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(const GURL& url) {
145 #if defined(OS_MACOSX) 164 #if defined(OS_MACOSX)
146 // This must run on the UI thread on OS X. 165 // This must run on the UI thread on OS X.
(...skipping 14 matching lines...) Expand all
161 // static 180 // static
162 void ExternalProtocolHandler::RegisterPrefs(PrefService* prefs) { 181 void ExternalProtocolHandler::RegisterPrefs(PrefService* prefs) {
163 prefs->RegisterDictionaryPref(prefs::kExcludedSchemes); 182 prefs->RegisterDictionaryPref(prefs::kExcludedSchemes);
164 } 183 }
165 184
166 // static 185 // static
167 void ExternalProtocolHandler::OnUserGesture() { 186 void ExternalProtocolHandler::OnUserGesture() {
168 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 187 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type());
169 g_accept_requests = true; 188 g_accept_requests = true;
170 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698