1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/plugin_process_host.h"
#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_POSIX)
#include <utility> // for pair<>
#endif
#include <vector>
#include "app/app_switches.h"
#include "app/gfx/native_widget_types.h"
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_util.h"
#include "chrome/browser/child_process_security_policy.h"
#include "chrome/browser/chrome_plugin_browsing_context.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_request_context_getter.h"
#include "chrome/browser/net/url_request_tracking.h"
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/common/chrome_descriptors.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_plugin_lib.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/plugin_messages.h"
#include "chrome/common/render_messages.h"
#include "ipc/ipc_descriptors.h"
#include "ipc/ipc_switches.h"
#include "net/base/file_stream.h"
#include "net/base/io_buffer.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#if defined(OS_WIN)
#include "app/win_util.h"
#include "chrome/browser/sandbox_policy.h"
#include "sandbox/src/sandbox.h"
#include "webkit/glue/plugins/plugin_constants_win.h"
#endif
#if defined(OS_POSIX)
#include "base/global_descriptors_posix.h"
#include "ipc/ipc_channel_posix.h"
#endif
#if defined(OS_LINUX)
#include "app/gfx/gtk_native_view_id_manager.h"
#include "chrome/browser/crash_handler_host_linux.h"
#endif
#if defined(OS_MACOSX)
#include "base/mac_util.h"
#include "chrome/common/plugin_carbon_interpose_constants_mac.h"
#endif
static const char kDefaultPluginFinderURL[] =
"https://dl-ssl.google.com/edgedl/chrome/plugins/plugins2.xml";
#if defined(OS_WIN)
// The PluginDownloadUrlHelper is used to handle one download URL request
// from the plugin. Each download request is handled by a new instance
// of this class.
class PluginDownloadUrlHelper : public URLRequest::Delegate {
static const int kDownloadFileBufferSize = 32768;
public:
PluginDownloadUrlHelper(const std::string& download_url,
int source_pid, gfx::NativeWindow caller_window);
~PluginDownloadUrlHelper();
void InitiateDownload();
// URLRequest::Delegate
virtual void OnAuthRequired(URLRequest* request,
net::AuthChallengeInfo* auth_info);
virtual void OnSSLCertificateError(URLRequest* request,
int cert_error,
net::X509Certificate* cert);
virtual void OnResponseStarted(URLRequest* request);
virtual void OnReadCompleted(URLRequest* request, int bytes_read);
void OnDownloadCompleted(URLRequest* request);
protected:
void DownloadCompletedHelper(bool success);
// The download file request initiated by the plugin.
URLRequest* download_file_request_;
// Handle to the downloaded file.
scoped_ptr<net::FileStream> download_file_;
// The full path of the downloaded file.
FilePath download_file_path_;
// The buffer passed off to URLRequest::Read.
scoped_refptr<net::IOBuffer> download_file_buffer_;
// TODO(port): this comment doesn't describe the situation on Posix.
// The window handle for sending the WM_COPYDATA notification,
// indicating that the download completed.
gfx::NativeWindow download_file_caller_window_;
std::string download_url_;
int download_source_child_unique_id_;
DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper);
};
PluginDownloadUrlHelper::PluginDownloadUrlHelper(
const std::string& download_url,
int source_child_unique_id,
gfx::NativeWindow caller_window)
: download_file_request_(NULL),
download_file_buffer_(new net::IOBuffer(kDownloadFileBufferSize)),
download_file_caller_window_(caller_window),
download_url_(download_url),
download_source_child_unique_id_(source_child_unique_id) {
DCHECK(::IsWindow(caller_window));
memset(download_file_buffer_->data(), 0, kDownloadFileBufferSize);
download_file_.reset(new net::FileStream());
}
PluginDownloadUrlHelper::~PluginDownloadUrlHelper() {
if (download_file_request_) {
delete download_file_request_;
download_file_request_ = NULL;
}
}
void PluginDownloadUrlHelper::InitiateDownload() {
download_file_request_ = new URLRequest(GURL(download_url_), this);
chrome_browser_net::SetOriginProcessUniqueIDForRequest(
download_source_child_unique_id_, download_file_request_);
download_file_request_->set_context(
Profile::GetDefaultRequestContext()->GetURLRequestContext());
download_file_request_->Start();
}
void PluginDownloadUrlHelper::OnAuthRequired(
URLRequest* request,
net::AuthChallengeInfo* auth_info) {
URLRequest::Delegate::OnAuthRequired(request, auth_info);
DownloadCompletedHelper(false);
}
void PluginDownloadUrlHelper::OnSSLCertificateError(
URLRequest* request,
int cert_error,
net::X509Certificate* cert) {
URLRequest::Delegate::OnSSLCertificateError(request, cert_error, cert);
DownloadCompletedHelper(false);
}
void PluginDownloadUrlHelper::OnResponseStarted(URLRequest* request) {
if (!download_file_->IsOpen()) {
file_util::GetTempDir(&download_file_path_);
GURL request_url = request->url();
download_file_path_ = download_file_path_.Append(
UTF8ToWide(request_url.ExtractFileName()));
download_file_->Open(download_file_path_,
base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE);
if (!download_file_->IsOpen()) {
NOTREACHED();
OnDownloadCompleted(request);
return;
}
}
if (!request->status().is_success()) {
OnDownloadCompleted(request);
} else {
// Initiate a read.
int bytes_read = 0;
if (!request->Read(download_file_buffer_, kDownloadFileBufferSize,
&bytes_read)) {
// If the error is not an IO pending, then we're done
// reading.
if (!request->status().is_io_pending()) {
OnDownloadCompleted(request);
}
} else if (bytes_read == 0) {
OnDownloadCompleted(request);
} else {
OnReadCompleted(request, bytes_read);
}
}
}
void PluginDownloadUrlHelper::OnReadCompleted(URLRequest* request,
int bytes_read) {
DCHECK(download_file_->IsOpen());
if (bytes_read == 0) {
OnDownloadCompleted(request);
return;
}
int request_bytes_read = bytes_read;
while (request->status().is_success()) {
int bytes_written = download_file_->Write(download_file_buffer_->data(),
request_bytes_read, NULL);
DCHECK((bytes_written < 0) || (bytes_written == request_bytes_read));
if ((bytes_written < 0) || (bytes_written != request_bytes_read)) {
DownloadCompletedHelper(false);
break;
}
// Start reading
request_bytes_read = 0;
if (!request->Read(download_file_buffer_, kDownloadFileBufferSize,
&request_bytes_read)) {
if (!request->status().is_io_pending()) {
// If the error is not an IO pending, then we're done
// reading.
OnDownloadCompleted(request);
}
break;
} else if (request_bytes_read == 0) {
OnDownloadCompleted(request);
break;
}
}
}
void PluginDownloadUrlHelper::OnDownloadCompleted(URLRequest* request) {
bool success = true;
if (!request->status().is_success()) {
success = false;
} else if (!download_file_->IsOpen()) {
success = false;
}
DownloadCompletedHelper(success);
}
void PluginDownloadUrlHelper::DownloadCompletedHelper(bool success) {
if (download_file_->IsOpen()) {
download_file_.reset();
}
std::wstring path = download_file_path_.value();
COPYDATASTRUCT download_file_data = {0};
download_file_data.cbData =
static_cast<unsigned long>((path.length() + 1) * sizeof(wchar_t));
download_file_data.lpData = const_cast<wchar_t *>(path.c_str());
download_file_data.dwData = success;
if (::IsWindow(download_file_caller_window_)) {
::SendMessage(download_file_caller_window_, WM_COPYDATA, NULL,
reinterpret_cast<LPARAM>(&download_file_data));
}
// Don't access any members after this.
delete this;
}
void PluginProcessHost::OnPluginWindowDestroyed(HWND window, HWND parent) {
// The window is destroyed at this point, we just care about its parent, which
// is the intermediate window we created.
std::set<HWND>::iterator window_index =
plugin_parent_windows_set_.find(parent);
if (window_index == plugin_parent_windows_set_.end())
return;
plugin_parent_windows_set_.erase(window_index);
PostMessage(parent, WM_CLOSE, 0, 0);
}
void PluginProcessHost::OnDownloadUrl(const std::string& url,
int source_pid,
gfx::NativeWindow caller_window) {
PluginDownloadUrlHelper* download_url_helper =
new PluginDownloadUrlHelper(url, source_pid, caller_window);
download_url_helper->InitiateDownload();
}
void PluginProcessHost::AddWindow(HWND window) {
plugin_parent_windows_set_.insert(window);
}
#endif // defined(OS_WIN)
#if defined(OS_LINUX)
void PluginProcessHost::OnMapNativeViewId(gfx::NativeViewId id,
gfx::PluginWindowHandle* output) {
*output = 0;
Singleton<GtkNativeViewManager>()->GetXIDForId(output, id);
}
#endif // defined(OS_LINUX)
PluginProcessHost::PluginProcessHost()
: ChildProcessHost(
PLUGIN_PROCESS,
PluginService::GetInstance()->resource_dispatcher_host()),
ALLOW_THIS_IN_INITIALIZER_LIST(resolve_proxy_msg_helper_(this, NULL)) {
}
PluginProcessHost::~PluginProcessHost() {
#if defined(OS_WIN)
// We erase HWNDs from the plugin_parent_windows_set_ when we receive a
// notification that the window is being destroyed. If we don't receive this
// notification and the PluginProcessHost instance is being destroyed, it
// means that the plugin process crashed. We paint a sad face in this case in
// the renderer process. To ensure that the sad face shows up, and we don't
// leak HWNDs, we should destroy existing plugin parent windows.
std::set<HWND>::iterator window_index;
for (window_index = plugin_parent_windows_set_.begin();
window_index != plugin_parent_windows_set_.end();
window_index++) {
PostMessage(*window_index, WM_CLOSE, 0, 0);
}
#elif defined(OS_MACOSX)
// If the plugin process crashed but had fullscreen windows open at the time,
// make sure that the menu bar is visible.
std::set<uint32>::iterator window_index;
for (window_index = plugin_fullscreen_windows_set_.begin();
window_index != plugin_fullscreen_windows_set_.end();
window_index++) {
if (ChromeThread::CurrentlyOn(ChromeThread::UI)) {
mac_util::ReleaseFullScreen();
} else {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableFunction(mac_util::ReleaseFullScreen));
}
}
#endif
}
bool PluginProcessHost::Init(const WebPluginInfo& info,
const std::wstring& locale) {
info_ = info;
set_name(info_.name);
if (!CreateChannel())
return false;
// Build command line for plugin, we have to quote the plugin's path to deal
// with spaces.
FilePath exe_path = GetChildPath();
if (exe_path.empty())
return false;
CommandLine cmd_line(exe_path);
// Put the process type and plugin path first so they're easier to see
// in process listings using native process management tools.
cmd_line.AppendSwitchWithValue(switches::kProcessType,
switches::kPluginProcess);
cmd_line.AppendSwitchWithValue(switches::kPluginPath,
info.path.ToWStringHack());
if (logging::DialogsAreSuppressed())
cmd_line.AppendSwitch(switches::kNoErrorDialogs);
// Propagate the following switches to the plugin command line (along with
// any associated values) if present in the browser command line
static const char* const switch_names[] = {
switches::kPluginStartupDialog,
switches::kNoSandbox,
switches::kSafePlugins,
switches::kTestSandbox,
switches::kUserAgent,
switches::kDisableBreakpad,
switches::kFullMemoryCrashReport,
switches::kEnableLogging,
switches::kDisableLogging,
switches::kLoggingLevel,
switches::kLogPluginMessages,
switches::kUserDataDir,
switches::kEnableDCHECK,
switches::kSilentDumpOnDCHECK,
switches::kMemoryProfiling,
switches::kUseLowFragHeapCrt,
switches::kEnableStatsTable,
};
const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
for (size_t i = 0; i < arraysize(switch_names); ++i) {
if (browser_command_line.HasSwitch(switch_names[i])) {
cmd_line.AppendSwitchWithValue(
switch_names[i],
browser_command_line.GetSwitchValueASCII(switch_names[i]));
}
}
// If specified, prepend a launcher program to the command line.
std::wstring plugin_launcher =
browser_command_line.GetSwitchValue(switches::kPluginLauncher);
if (!plugin_launcher.empty())
cmd_line.PrependWrapper(plugin_launcher);
if (!locale.empty()) {
// Pass on the locale so the null plugin will use the right language in the
// prompt to install the desired plugin.
cmd_line.AppendSwitchWithValue(switches::kLang, locale);
}
// Gears requires the data dir to be available on startup.
std::wstring data_dir =
PluginService::GetInstance()->GetChromePluginDataDir().ToWStringHack();
DCHECK(!data_dir.empty());
cmd_line.AppendSwitchWithValue(switches::kPluginDataDir, data_dir);
cmd_line.AppendSwitchWithValue(switches::kProcessChannelID,
ASCIIToWide(channel_id()));
SetCrashReporterCommandLine(&cmd_line);
base::ProcessHandle process = 0;
#if defined(OS_WIN)
process = sandbox::StartProcess(&cmd_line);
#else
process = InitHelperPosix(cmd_line);
#endif // OS_WIN
if (!process)
return false;
SetHandle(process);
FilePath gears_path;
if (PathService::Get(chrome::FILE_GEARS_PLUGIN, &gears_path)) {
FilePath::StringType gears_path_lc = StringToLowerASCII(gears_path.value());
FilePath::StringType plugin_path_lc =
StringToLowerASCII(info.path.value());
if (plugin_path_lc == gears_path_lc) {
// Give Gears plugins "background" priority. See
// http://b/issue?id=1280317.
SetProcessBackgrounded();
}
}
return true;
}
#if defined(OS_POSIX)
base::ProcessHandle PluginProcessHost::InitHelperPosix(
const CommandLine& cmd_line) {
base::ProcessHandle process = 0;
// This code is duplicated with browser_render_process_host.cc, but
// there's not a good place to de-duplicate it.
base::file_handle_mapping_vector fds_to_map;
const int ipcfd = channel().GetClientFileDescriptor();
if (ipcfd > -1)
fds_to_map.push_back(std::pair<int, int>(
ipcfd, kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor));
base::environment_vector env;
#if defined(OS_MACOSX)
// Add our interposing library for Carbon. This is stripped back out in
// plugin_main.cc, so changes here should be reflected there.
std::string interpose_list(plugin_interpose_strings::kInterposeLibraryPath);
const char* existing_list =
getenv(plugin_interpose_strings::kDYLDInsertLibrariesKey);
if (existing_list) {
interpose_list.insert(0, ":");
interpose_list.insert(0, existing_list);
}
env.push_back(std::pair<const char*, const char*>(
plugin_interpose_strings::kDYLDInsertLibrariesKey,
interpose_list.c_str()));
#elif defined(OS_LINUX)
const int crash_signal_fd =
Singleton<PluginCrashHandlerHostLinux>()->GetDeathSignalSocket();
if (crash_signal_fd >= 0) {
fds_to_map.push_back(std::pair<int, uint32_t>(crash_signal_fd,
kCrashDumpSignal + 3));
}
#endif // OS_MACOSX
if (!base::LaunchApp(cmd_line.argv(), env, fds_to_map, false, &process))
process = 0;
return process;
}
#endif // OS_POSIX
void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetPluginFinderUrl,
OnGetPluginFinderUrl)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginMessage, OnPluginMessage)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetCookies, OnGetCookies)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_AccessFiles, OnAccessFiles)
IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_ResolveProxy,
OnResolveProxy)
#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginWindowDestroyed,
OnPluginWindowDestroyed)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_DownloadUrl, OnDownloadUrl)
#endif
#if defined(OS_LINUX)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_MapNativeViewId,
OnMapNativeViewId)
#endif
#if defined(OS_MACOSX)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginSelectWindow,
OnPluginSelectWindow)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginShowWindow,
OnPluginShowWindow)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginHideWindow,
OnPluginHideWindow)
IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginDisposeWindow,
OnPluginDisposeWindow)
#endif
IPC_MESSAGE_UNHANDLED_ERROR()
IPC_END_MESSAGE_MAP()
}
void PluginProcessHost::OnChannelConnected(int32 peer_pid) {
for (size_t i = 0; i < pending_requests_.size(); ++i) {
RequestPluginChannel(pending_requests_[i].renderer_message_filter_.get(),
pending_requests_[i].mime_type,
pending_requests_[i].reply_msg);
}
pending_requests_.clear();
}
void PluginProcessHost::OnChannelError() {
for (size_t i = 0; i < pending_requests_.size(); ++i) {
ReplyToRenderer(pending_requests_[i].renderer_message_filter_.get(),
IPC::ChannelHandle(),
info_,
pending_requests_[i].reply_msg);
}
pending_requests_.clear();
while (!sent_requests_.empty()) {
ReplyToRenderer(sent_requests_.front().renderer_message_filter_.get(),
IPC::ChannelHandle(),
info_,
sent_requests_.front().reply_msg);
sent_requests_.pop();
}
}
void PluginProcessHost::OpenChannelToPlugin(
ResourceMessageFilter* renderer_message_filter,
const std::string& mime_type,
IPC::Message* reply_msg) {
InstanceCreated();
if (opening_channel()) {
// The channel is already in the process of being opened. Put
// this "open channel" request into a queue of requests that will
// be run once the channel is open.
pending_requests_.push_back(
ChannelRequest(renderer_message_filter, mime_type, reply_msg));
return;
}
// We already have an open channel, send a request right away to plugin.
RequestPluginChannel(renderer_message_filter, mime_type, reply_msg);
}
void PluginProcessHost::OnGetCookies(uint32 request_context,
const GURL& url,
std::string* cookies) {
URLRequestContext* context = CPBrowsingContextManager::Instance()->
ToURLRequestContext(request_context);
// TODO(mpcomplete): remove fallback case when Gears support is prevalent.
if (!context)
context = Profile::GetDefaultRequestContext()->GetURLRequestContext();
// Note: We don't have a first_party_for_cookies check because plugins bypass
// third-party cookie blocking.
if (context && context->cookie_store()) {
*cookies = context->cookie_store()->GetCookies(url);
} else {
DLOG(ERROR) << "Could not serve plugin cookies request.";
*cookies = EmptyString();
}
}
void PluginProcessHost::OnAccessFiles(int renderer_id,
const std::vector<std::string>& files,
bool* allowed) {
ChildProcessSecurityPolicy* policy =
ChildProcessSecurityPolicy::GetInstance();
for (size_t i = 0; i < files.size(); ++i) {
const FilePath path = FilePath::FromWStringHack(UTF8ToWide(files[i]));
if (!policy->CanUploadFile(renderer_id, path)) {
LOG(INFO) << "Denied unauthorized request for file " << files[i];
*allowed = false;
return;
}
}
*allowed = true;
}
void PluginProcessHost::OnResolveProxy(const GURL& url,
IPC::Message* reply_msg) {
resolve_proxy_msg_helper_.Start(url, reply_msg);
}
void PluginProcessHost::OnResolveProxyCompleted(IPC::Message* reply_msg,
int result,
const std::string& proxy_list) {
PluginProcessHostMsg_ResolveProxy::WriteReplyParams(
reply_msg, result, proxy_list);
Send(reply_msg);
}
void PluginProcessHost::ReplyToRenderer(
ResourceMessageFilter* renderer_message_filter,
const IPC::ChannelHandle& channel,
const WebPluginInfo& info,
IPC::Message* reply_msg) {
ViewHostMsg_OpenChannelToPlugin::WriteReplyParams(reply_msg, channel, info);
renderer_message_filter->Send(reply_msg);
}
URLRequestContext* PluginProcessHost::GetRequestContext(
uint32 request_id,
const ViewHostMsg_Resource_Request& request_data) {
return CPBrowsingContextManager::Instance()->ToURLRequestContext(request_id);
}
void PluginProcessHost::RequestPluginChannel(
ResourceMessageFilter* renderer_message_filter,
const std::string& mime_type, IPC::Message* reply_msg) {
// We can't send any sync messages from the browser because it might lead to
// a hang. However this async messages must be answered right away by the
// plugin process (i.e. unblocks a Send() call like a sync message) otherwise
// a deadlock can occur if the plugin creation request from the renderer is
// a result of a sync message by the plugin process.
PluginProcessMsg_CreateChannel* msg = new PluginProcessMsg_CreateChannel(
renderer_message_filter->id(),
renderer_message_filter->off_the_record());
msg->set_unblock(true);
if (Send(msg)) {
sent_requests_.push(ChannelRequest(
renderer_message_filter, mime_type, reply_msg));
} else {
ReplyToRenderer(renderer_message_filter,
IPC::ChannelHandle(),
info_,
reply_msg);
}
}
void PluginProcessHost::OnChannelCreated(
const IPC::ChannelHandle& channel_handle) {
const ChannelRequest& request = sent_requests_.front();
ReplyToRenderer(request.renderer_message_filter_.get(),
channel_handle,
info_,
request.reply_msg);
sent_requests_.pop();
}
void PluginProcessHost::OnGetPluginFinderUrl(std::string* plugin_finder_url) {
if (!plugin_finder_url) {
NOTREACHED();
return;
}
// TODO(iyengar) Add the plumbing to retrieve the default
// plugin finder URL.
*plugin_finder_url = kDefaultPluginFinderURL;
}
void PluginProcessHost::OnPluginMessage(
const std::vector<uint8>& data) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
ChromePluginLib *chrome_plugin = ChromePluginLib::Find(info_.path);
if (chrome_plugin) {
void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0]));
uint32 data_len = static_cast<uint32>(data.size());
chrome_plugin->functions().on_message(data_ptr, data_len);
}
}
|