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 "chrome/plugin/webplugin_delegate_stub.h" | 5 #include "chrome/plugin/webplugin_delegate_stub.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "chrome/common/child_process_logging.h" |
10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/plugin_messages.h" | 12 #include "chrome/common/plugin_messages.h" |
12 #include "chrome/plugin/npobject_stub.h" | 13 #include "chrome/plugin/npobject_stub.h" |
13 #include "chrome/plugin/plugin_channel.h" | 14 #include "chrome/plugin/plugin_channel.h" |
14 #include "chrome/plugin/plugin_thread.h" | 15 #include "chrome/plugin/plugin_thread.h" |
15 #include "chrome/plugin/webplugin_proxy.h" | 16 #include "chrome/plugin/webplugin_proxy.h" |
16 #include "printing/native_metafile.h" | 17 #include "printing/native_metafile.h" |
17 #include "third_party/npapi/bindings/npapi.h" | 18 #include "third_party/npapi/bindings/npapi.h" |
18 #include "third_party/npapi/bindings/npruntime.h" | 19 #include "third_party/npapi/bindings/npruntime.h" |
19 #include "skia/ext/platform_device.h" | 20 #include "skia/ext/platform_device.h" |
(...skipping 22 matching lines...) Expand all Loading... |
42 const std::string& mime_type, int instance_id, PluginChannel* channel) : | 43 const std::string& mime_type, int instance_id, PluginChannel* channel) : |
43 mime_type_(mime_type), | 44 mime_type_(mime_type), |
44 instance_id_(instance_id), | 45 instance_id_(instance_id), |
45 channel_(channel), | 46 channel_(channel), |
46 delegate_(NULL), | 47 delegate_(NULL), |
47 webplugin_(NULL) { | 48 webplugin_(NULL) { |
48 DCHECK(channel); | 49 DCHECK(channel); |
49 } | 50 } |
50 | 51 |
51 WebPluginDelegateStub::~WebPluginDelegateStub() { | 52 WebPluginDelegateStub::~WebPluginDelegateStub() { |
| 53 child_process_logging::ScopedActiveURLSetter url_setter(page_url_); |
| 54 |
52 if (channel_->in_send()) { | 55 if (channel_->in_send()) { |
53 // The delegate or an npobject is in the callstack, so don't delete it | 56 // The delegate or an npobject is in the callstack, so don't delete it |
54 // right away. | 57 // right away. |
55 MessageLoop::current()->PostNonNestableTask(FROM_HERE, | 58 MessageLoop::current()->PostNonNestableTask(FROM_HERE, |
56 new FinishDestructionTask(delegate_, webplugin_)); | 59 new FinishDestructionTask(delegate_, webplugin_)); |
57 } else { | 60 } else { |
58 // Safe to delete right away. | 61 // Safe to delete right away. |
59 if (delegate_) | 62 if (delegate_) |
60 delegate_->PluginDestroyed(); | 63 delegate_->PluginDestroyed(); |
61 | 64 |
62 delete webplugin_; | 65 delete webplugin_; |
63 } | 66 } |
64 } | 67 } |
65 | 68 |
66 void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { | 69 void WebPluginDelegateStub::OnMessageReceived(const IPC::Message& msg) { |
| 70 child_process_logging::ScopedActiveURLSetter url_setter(page_url_); |
| 71 |
67 // A plugin can execute a script to delete itself in any of its NPP methods. | 72 // A plugin can execute a script to delete itself in any of its NPP methods. |
68 // Hold an extra reference to ourself so that if this does occur and we're | 73 // Hold an extra reference to ourself so that if this does occur and we're |
69 // handling a sync message, we don't crash when attempting to send a reply. | 74 // handling a sync message, we don't crash when attempting to send a reply. |
70 AddRef(); | 75 AddRef(); |
71 | 76 |
72 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateStub, msg) | 77 IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateStub, msg) |
73 IPC_MESSAGE_HANDLER(PluginMsg_Init, OnInit) | 78 IPC_MESSAGE_HANDLER(PluginMsg_Init, OnInit) |
74 IPC_MESSAGE_HANDLER(PluginMsg_WillSendRequest, OnWillSendRequest) | 79 IPC_MESSAGE_HANDLER(PluginMsg_WillSendRequest, OnWillSendRequest) |
75 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveResponse, OnDidReceiveResponse) | 80 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveResponse, OnDidReceiveResponse) |
76 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveData, OnDidReceiveData) | 81 IPC_MESSAGE_HANDLER(PluginMsg_DidReceiveData, OnDidReceiveData) |
(...skipping 26 matching lines...) Expand all Loading... |
103 | 108 |
104 Release(); | 109 Release(); |
105 } | 110 } |
106 | 111 |
107 bool WebPluginDelegateStub::Send(IPC::Message* msg) { | 112 bool WebPluginDelegateStub::Send(IPC::Message* msg) { |
108 return channel_->Send(msg); | 113 return channel_->Send(msg); |
109 } | 114 } |
110 | 115 |
111 void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params, | 116 void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params, |
112 bool* result) { | 117 bool* result) { |
| 118 page_url_ = params.page_url; |
| 119 child_process_logging::ScopedActiveURLSetter url_setter(page_url_); |
| 120 |
113 *result = false; | 121 *result = false; |
114 int argc = static_cast<int>(params.arg_names.size()); | 122 int argc = static_cast<int>(params.arg_names.size()); |
115 if (argc != static_cast<int>(params.arg_values.size())) { | 123 if (argc != static_cast<int>(params.arg_values.size())) { |
116 NOTREACHED(); | 124 NOTREACHED(); |
117 return; | 125 return; |
118 } | 126 } |
119 | 127 |
120 char **argn = new char*[argc]; | 128 char **argn = new char*[argc]; |
121 char **argv = new char*[argc]; | 129 char **argv = new char*[argc]; |
122 for (int i = 0; i < argc; ++i) { | 130 for (int i = 0; i < argc; ++i) { |
123 argn[i] = const_cast<char*>(params.arg_names[i].c_str()); | 131 argn[i] = const_cast<char*>(params.arg_names[i].c_str()); |
124 argv[i] = const_cast<char*>(params.arg_values[i].c_str()); | 132 argv[i] = const_cast<char*>(params.arg_values[i].c_str()); |
125 } | 133 } |
126 | 134 |
127 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 135 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
128 FilePath path = FilePath::FromWStringHack( | 136 FilePath path = FilePath::FromWStringHack( |
129 command_line.GetSwitchValue(switches::kPluginPath)); | 137 command_line.GetSwitchValue(switches::kPluginPath)); |
130 | 138 |
131 | 139 |
132 gfx::PluginWindowHandle parent = NULL; | 140 gfx::PluginWindowHandle parent = NULL; |
133 #if defined(OS_WIN) | 141 #if defined(OS_WIN) |
134 parent = gfx::NativeViewFromId(params.containing_window); | 142 parent = gfx::NativeViewFromId(params.containing_window); |
135 #elif defined(OS_LINUX) | 143 #elif defined(OS_LINUX) |
136 PluginThread::current()->Send(new PluginProcessHostMsg_MapNativeViewId( | 144 PluginThread::current()->Send(new PluginProcessHostMsg_MapNativeViewId( |
137 params.containing_window, &parent)); | 145 params.containing_window, &parent)); |
138 #endif | 146 #endif |
139 delegate_ = WebPluginDelegate::Create(path, mime_type_, parent); | 147 delegate_ = WebPluginDelegate::Create(path, mime_type_, parent); |
140 | 148 |
141 if (delegate_) { | 149 if (delegate_) { |
142 webplugin_ = new WebPluginProxy(channel_, instance_id_, delegate_); | 150 webplugin_ = new WebPluginProxy( |
| 151 channel_, instance_id_, delegate_, page_url_); |
143 #if defined(OS_WIN) | 152 #if defined(OS_WIN) |
144 if (!webplugin_->SetModalDialogEvent(params.modal_dialog_event)) | 153 if (!webplugin_->SetModalDialogEvent(params.modal_dialog_event)) |
145 return; | 154 return; |
146 #endif | 155 #endif |
147 *result = delegate_->Initialize( | 156 *result = delegate_->Initialize( |
148 params.url, argn, argv, argc, webplugin_, params.load_manually); | 157 params.url, argn, argv, argc, webplugin_, params.load_manually); |
149 } | 158 } |
150 | 159 |
151 delete[] argn; | 160 delete[] argn; |
152 delete[] argv; | 161 delete[] argv; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 if (!object) { | 280 if (!object) { |
272 *route_id = MSG_ROUTING_NONE; | 281 *route_id = MSG_ROUTING_NONE; |
273 return; | 282 return; |
274 } | 283 } |
275 | 284 |
276 *route_id = channel_->GenerateRouteID(); | 285 *route_id = channel_->GenerateRouteID(); |
277 *npobject_ptr = reinterpret_cast<intptr_t>(object); | 286 *npobject_ptr = reinterpret_cast<intptr_t>(object); |
278 // The stub will delete itself when the proxy tells it that it's released, or | 287 // The stub will delete itself when the proxy tells it that it's released, or |
279 // otherwise when the channel is closed. | 288 // otherwise when the channel is closed. |
280 new NPObjectStub( | 289 new NPObjectStub( |
281 object, channel_.get(), *route_id, webplugin_->modal_dialog_event()); | 290 object, channel_.get(), *route_id, webplugin_->modal_dialog_event(), |
| 291 page_url_); |
282 | 292 |
283 // Release ref added by GetPluginScriptableObject (our stub holds its own). | 293 // Release ref added by GetPluginScriptableObject (our stub holds its own). |
284 NPN_ReleaseObject(object); | 294 NPN_ReleaseObject(object); |
285 } | 295 } |
286 | 296 |
287 void WebPluginDelegateStub::OnSendJavaScriptStream(const std::string& url, | 297 void WebPluginDelegateStub::OnSendJavaScriptStream(const std::string& url, |
288 const std::wstring& result, | 298 const std::wstring& result, |
289 bool success, | 299 bool success, |
290 bool notify_needed, | 300 bool notify_needed, |
291 intptr_t notify_data) { | 301 intptr_t notify_data) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 params.notify_data, | 368 params.notify_data, |
359 params.stream); | 369 params.stream); |
360 webplugin_->OnResourceCreated(params.resource_id, resource_client); | 370 webplugin_->OnResourceCreated(params.resource_id, resource_client); |
361 } | 371 } |
362 | 372 |
363 void WebPluginDelegateStub::OnURLRequestRouted(const std::string& url, | 373 void WebPluginDelegateStub::OnURLRequestRouted(const std::string& url, |
364 bool notify_needed, | 374 bool notify_needed, |
365 intptr_t notify_data) { | 375 intptr_t notify_data) { |
366 delegate_->URLRequestRouted(url, notify_needed, notify_data); | 376 delegate_->URLRequestRouted(url, notify_needed, notify_data); |
367 } | 377 } |
OLD | NEW |