OLD | NEW |
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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/plugin_service.h" | 7 #include "chrome/browser/plugin_service.h" |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 const FilePath& PluginService::GetChromePluginDataDir() { | 97 const FilePath& PluginService::GetChromePluginDataDir() { |
98 return chrome_plugin_data_dir_; | 98 return chrome_plugin_data_dir_; |
99 } | 99 } |
100 | 100 |
101 const std::wstring& PluginService::GetUILocale() { | 101 const std::wstring& PluginService::GetUILocale() { |
102 return ui_locale_; | 102 return ui_locale_; |
103 } | 103 } |
104 | 104 |
105 PluginProcessHost* PluginService::FindPluginProcess( | 105 PluginProcessHost* PluginService::FindPluginProcess( |
106 const FilePath& plugin_path) { | 106 const FilePath& plugin_path) { |
107 DCHECK(MessageLoop::current() == | 107 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
108 ChromeThread::GetMessageLoop(ChromeThread::IO)); | |
109 | 108 |
110 if (plugin_path.value().empty()) { | 109 if (plugin_path.value().empty()) { |
111 NOTREACHED() << "should only be called if we have a plugin to load"; | 110 NOTREACHED() << "should only be called if we have a plugin to load"; |
112 return NULL; | 111 return NULL; |
113 } | 112 } |
114 | 113 |
115 for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); | 114 for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
116 !iter.Done(); ++iter) { | 115 !iter.Done(); ++iter) { |
117 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); | 116 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
118 if (plugin->info().path == plugin_path) | 117 if (plugin->info().path == plugin_path) |
119 return plugin; | 118 return plugin; |
120 } | 119 } |
121 | 120 |
122 return NULL; | 121 return NULL; |
123 } | 122 } |
124 | 123 |
125 PluginProcessHost* PluginService::FindOrStartPluginProcess( | 124 PluginProcessHost* PluginService::FindOrStartPluginProcess( |
126 const FilePath& plugin_path) { | 125 const FilePath& plugin_path) { |
127 DCHECK(MessageLoop::current() == | 126 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
128 ChromeThread::GetMessageLoop(ChromeThread::IO)); | |
129 | 127 |
130 PluginProcessHost *plugin_host = FindPluginProcess(plugin_path); | 128 PluginProcessHost *plugin_host = FindPluginProcess(plugin_path); |
131 if (plugin_host) | 129 if (plugin_host) |
132 return plugin_host; | 130 return plugin_host; |
133 | 131 |
134 WebPluginInfo info; | 132 WebPluginInfo info; |
135 if (!NPAPI::PluginList::Singleton()->GetPluginInfoByPath( | 133 if (!NPAPI::PluginList::Singleton()->GetPluginInfoByPath( |
136 plugin_path, &info)) { | 134 plugin_path, &info)) { |
137 DCHECK(false); | 135 DCHECK(false); |
138 return NULL; | 136 return NULL; |
139 } | 137 } |
140 | 138 |
141 // This plugin isn't loaded by any plugin process, so create a new process. | 139 // This plugin isn't loaded by any plugin process, so create a new process. |
142 plugin_host = new PluginProcessHost(); | 140 plugin_host = new PluginProcessHost(); |
143 if (!plugin_host->Init(info, ui_locale_)) { | 141 if (!plugin_host->Init(info, ui_locale_)) { |
144 DCHECK(false); // Init is not expected to fail | 142 DCHECK(false); // Init is not expected to fail |
145 delete plugin_host; | 143 delete plugin_host; |
146 return NULL; | 144 return NULL; |
147 } | 145 } |
148 | 146 |
149 return plugin_host; | 147 return plugin_host; |
150 } | 148 } |
151 | 149 |
152 void PluginService::OpenChannelToPlugin( | 150 void PluginService::OpenChannelToPlugin( |
153 ResourceMessageFilter* renderer_msg_filter, | 151 ResourceMessageFilter* renderer_msg_filter, |
154 const GURL& url, | 152 const GURL& url, |
155 const std::string& mime_type, | 153 const std::string& mime_type, |
156 const std::wstring& locale, | 154 const std::wstring& locale, |
157 IPC::Message* reply_msg) { | 155 IPC::Message* reply_msg) { |
158 DCHECK(MessageLoop::current() == | 156 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
159 ChromeThread::GetMessageLoop(ChromeThread::IO)); | |
160 // We don't need a policy URL here because that was already checked by a | 157 // We don't need a policy URL here because that was already checked by a |
161 // previous call to GetPluginPath. | 158 // previous call to GetPluginPath. |
162 GURL policy_url; | 159 GURL policy_url; |
163 FilePath plugin_path = GetPluginPath(url, policy_url, mime_type, NULL); | 160 FilePath plugin_path = GetPluginPath(url, policy_url, mime_type, NULL); |
164 PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path); | 161 PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path); |
165 if (plugin_host) { | 162 if (plugin_host) { |
166 plugin_host->OpenChannelToPlugin(renderer_msg_filter, mime_type, reply_msg); | 163 plugin_host->OpenChannelToPlugin(renderer_msg_filter, mime_type, reply_msg); |
167 } else { | 164 } else { |
168 PluginProcessHost::ReplyToRenderer( | 165 PluginProcessHost::ReplyToRenderer( |
169 renderer_msg_filter, IPC::ChannelHandle(), WebPluginInfo(), reply_msg); | 166 renderer_msg_filter, IPC::ChannelHandle(), WebPluginInfo(), reply_msg); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path); | 256 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path); |
260 if (it == private_plugins_.end()) | 257 if (it == private_plugins_.end()) |
261 return true; // This plugin is not private, so it's allowed everywhere. | 258 return true; // This plugin is not private, so it's allowed everywhere. |
262 | 259 |
263 // We do a dumb compare of scheme and host, rather than using the domain | 260 // We do a dumb compare of scheme and host, rather than using the domain |
264 // service, since we only care about this for extensions. | 261 // service, since we only care about this for extensions. |
265 const GURL& required_url = it->second; | 262 const GURL& required_url = it->second; |
266 return (url.scheme() == required_url.scheme() && | 263 return (url.scheme() == required_url.scheme() && |
267 url.host() == required_url.host()); | 264 url.host() == required_url.host()); |
268 } | 265 } |
OLD | NEW |