| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "build/build_config.h" | |
| 6 | |
| 7 #include "webkit/glue/plugins/plugin_instance.h" | |
| 8 | |
| 9 #include "base/file_util.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "base/string_number_conversions.h" | |
| 12 #include "base/utf_string_conversions.h" | |
| 13 #include "webkit/glue/webkit_glue.h" | |
| 14 #include "webkit/glue/plugins/plugin_host.h" | |
| 15 #include "webkit/glue/plugins/plugin_lib.h" | |
| 16 #include "webkit/glue/plugins/plugin_stream_url.h" | |
| 17 #include "webkit/glue/plugins/plugin_string_stream.h" | |
| 18 #include "webkit/glue/plugins/webplugin.h" | |
| 19 #include "webkit/glue/plugins/webplugin_delegate.h" | |
| 20 #include "net/base/escape.h" | |
| 21 | |
| 22 #if defined(OS_MACOSX) | |
| 23 #include <ApplicationServices/ApplicationServices.h> | |
| 24 #endif | |
| 25 | |
| 26 namespace NPAPI { | |
| 27 | |
| 28 PluginInstance::PluginInstance(PluginLib *plugin, const std::string &mime_type) | |
| 29 : plugin_(plugin), | |
| 30 npp_(0), | |
| 31 host_(PluginHost::Singleton()), | |
| 32 npp_functions_(plugin->functions()), | |
| 33 window_handle_(0), | |
| 34 windowless_(false), | |
| 35 transparent_(true), | |
| 36 webplugin_(0), | |
| 37 mime_type_(mime_type), | |
| 38 use_mozilla_user_agent_(false), | |
| 39 #if defined (OS_MACOSX) | |
| 40 #ifdef NP_NO_QUICKDRAW | |
| 41 drawing_model_(NPDrawingModelCoreGraphics), | |
| 42 #else | |
| 43 drawing_model_(NPDrawingModelQuickDraw), | |
| 44 #endif | |
| 45 #ifdef NP_NO_CARBON | |
| 46 event_model_(NPEventModelCocoa), | |
| 47 #else | |
| 48 event_model_(NPEventModelCarbon), | |
| 49 #endif | |
| 50 currently_handled_event_(NULL), | |
| 51 #endif | |
| 52 message_loop_(MessageLoop::current()), | |
| 53 load_manually_(false), | |
| 54 in_close_streams_(false), | |
| 55 next_timer_id_(1), | |
| 56 next_notify_id_(0), | |
| 57 next_range_request_id_(0), | |
| 58 handles_url_redirects_(false) { | |
| 59 npp_ = new NPP_t(); | |
| 60 npp_->ndata = 0; | |
| 61 npp_->pdata = 0; | |
| 62 | |
| 63 memset(&zero_padding_, 0, sizeof(zero_padding_)); | |
| 64 DCHECK(message_loop_); | |
| 65 } | |
| 66 | |
| 67 PluginInstance::~PluginInstance() { | |
| 68 CloseStreams(); | |
| 69 | |
| 70 if (npp_ != 0) { | |
| 71 delete npp_; | |
| 72 npp_ = 0; | |
| 73 } | |
| 74 | |
| 75 if (plugin_) | |
| 76 plugin_->CloseInstance(); | |
| 77 } | |
| 78 | |
| 79 PluginStreamUrl* PluginInstance::CreateStream(unsigned long resource_id, | |
| 80 const GURL& url, | |
| 81 const std::string& mime_type, | |
| 82 int notify_id) { | |
| 83 | |
| 84 bool notify; | |
| 85 void* notify_data; | |
| 86 GetNotifyData(notify_id, ¬ify, ¬ify_data); | |
| 87 PluginStreamUrl* stream = new PluginStreamUrl( | |
| 88 resource_id, url, this, notify, notify_data); | |
| 89 | |
| 90 AddStream(stream); | |
| 91 return stream; | |
| 92 } | |
| 93 | |
| 94 void PluginInstance::AddStream(PluginStream* stream) { | |
| 95 open_streams_.push_back(make_scoped_refptr(stream)); | |
| 96 } | |
| 97 | |
| 98 void PluginInstance::RemoveStream(PluginStream* stream) { | |
| 99 if (in_close_streams_) | |
| 100 return; | |
| 101 | |
| 102 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | |
| 103 for (stream_index = open_streams_.begin(); | |
| 104 stream_index != open_streams_.end(); ++stream_index) { | |
| 105 if (*stream_index == stream) { | |
| 106 open_streams_.erase(stream_index); | |
| 107 break; | |
| 108 } | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 bool PluginInstance::IsValidStream(const NPStream* stream) { | |
| 113 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | |
| 114 for (stream_index = open_streams_.begin(); | |
| 115 stream_index != open_streams_.end(); ++stream_index) { | |
| 116 if ((*stream_index)->stream() == stream) | |
| 117 return true; | |
| 118 } | |
| 119 | |
| 120 return false; | |
| 121 } | |
| 122 | |
| 123 void PluginInstance::CloseStreams() { | |
| 124 in_close_streams_ = true; | |
| 125 for (unsigned int index = 0; index < open_streams_.size(); ++index) { | |
| 126 // Close all streams on the way down. | |
| 127 open_streams_[index]->Close(NPRES_USER_BREAK); | |
| 128 } | |
| 129 open_streams_.clear(); | |
| 130 in_close_streams_ = false; | |
| 131 } | |
| 132 | |
| 133 webkit_glue::WebPluginResourceClient* PluginInstance::GetRangeRequest( | |
| 134 int id) { | |
| 135 PendingRangeRequestMap::iterator iter = pending_range_requests_.find(id); | |
| 136 if (iter == pending_range_requests_.end()) { | |
| 137 NOTREACHED(); | |
| 138 return NULL; | |
| 139 } | |
| 140 | |
| 141 webkit_glue::WebPluginResourceClient* rv = iter->second->AsResourceClient(); | |
| 142 pending_range_requests_.erase(iter); | |
| 143 return rv; | |
| 144 } | |
| 145 | |
| 146 bool PluginInstance::Start(const GURL& url, | |
| 147 char** const param_names, | |
| 148 char** const param_values, | |
| 149 int param_count, | |
| 150 bool load_manually) { | |
| 151 load_manually_ = load_manually; | |
| 152 unsigned short mode = load_manually_ ? NP_FULL : NP_EMBED; | |
| 153 npp_->ndata = this; | |
| 154 | |
| 155 NPError err = NPP_New(mode, param_count, | |
| 156 const_cast<char **>(param_names), const_cast<char **>(param_values)); | |
| 157 | |
| 158 if (err == NPERR_NO_ERROR) { | |
| 159 handles_url_redirects_ = | |
| 160 ((npp_functions_->version >= NPVERS_HAS_URL_REDIRECT_HANDLING) && | |
| 161 (npp_functions_->urlredirectnotify)); | |
| 162 } | |
| 163 return err == NPERR_NO_ERROR; | |
| 164 } | |
| 165 | |
| 166 NPObject *PluginInstance::GetPluginScriptableObject() { | |
| 167 NPObject *value = NULL; | |
| 168 NPError error = NPP_GetValue(NPPVpluginScriptableNPObject, &value); | |
| 169 if (error != NPERR_NO_ERROR || value == NULL) | |
| 170 return NULL; | |
| 171 return value; | |
| 172 } | |
| 173 | |
| 174 // WebPluginLoadDelegate methods | |
| 175 void PluginInstance::DidFinishLoadWithReason( | |
| 176 const GURL& url, NPReason reason, int notify_id) { | |
| 177 bool notify; | |
| 178 void* notify_data; | |
| 179 GetNotifyData(notify_id, ¬ify, ¬ify_data); | |
| 180 if (!notify) { | |
| 181 NOTREACHED(); | |
| 182 return; | |
| 183 } | |
| 184 | |
| 185 NPP_URLNotify(url.spec().c_str(), reason, notify_data); | |
| 186 } | |
| 187 | |
| 188 unsigned PluginInstance::GetBackingTextureId() { | |
| 189 // By default the plugin instance is not backed by an OpenGL texture. | |
| 190 return 0; | |
| 191 } | |
| 192 | |
| 193 // NPAPI methods | |
| 194 NPError PluginInstance::NPP_New(unsigned short mode, | |
| 195 short argc, | |
| 196 char *argn[], | |
| 197 char *argv[]) { | |
| 198 DCHECK(npp_functions_ != 0); | |
| 199 DCHECK(npp_functions_->newp != 0); | |
| 200 DCHECK(argc >= 0); | |
| 201 | |
| 202 if (npp_functions_->newp != 0) { | |
| 203 return npp_functions_->newp( | |
| 204 (NPMIMEType)mime_type_.c_str(), npp_, mode, argc, argn, argv, NULL); | |
| 205 } | |
| 206 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 207 } | |
| 208 | |
| 209 void PluginInstance::NPP_Destroy() { | |
| 210 DCHECK(npp_functions_ != 0); | |
| 211 DCHECK(npp_functions_->destroy != 0); | |
| 212 | |
| 213 if (npp_functions_->destroy != 0) { | |
| 214 NPSavedData *savedData = 0; | |
| 215 npp_functions_->destroy(npp_, &savedData); | |
| 216 | |
| 217 // TODO: Support savedData. Technically, these need to be | |
| 218 // saved on a per-URL basis, and then only passed | |
| 219 // to new instances of the plugin at the same URL. | |
| 220 // Sounds like a huge security risk. When we do support | |
| 221 // these, we should pass them back to the PluginLib | |
| 222 // to be stored there. | |
| 223 DCHECK(savedData == 0); | |
| 224 } | |
| 225 | |
| 226 for (unsigned int file_index = 0; file_index < files_created_.size(); | |
| 227 file_index++) { | |
| 228 file_util::Delete(files_created_[file_index], false); | |
| 229 } | |
| 230 | |
| 231 // Ensure that no timer callbacks are invoked after NPP_Destroy. | |
| 232 timers_.clear(); | |
| 233 } | |
| 234 | |
| 235 NPError PluginInstance::NPP_SetWindow(NPWindow *window) { | |
| 236 DCHECK(npp_functions_ != 0); | |
| 237 DCHECK(npp_functions_->setwindow != 0); | |
| 238 | |
| 239 if (npp_functions_->setwindow != 0) { | |
| 240 return npp_functions_->setwindow(npp_, window); | |
| 241 } | |
| 242 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 243 } | |
| 244 | |
| 245 NPError PluginInstance::NPP_NewStream(NPMIMEType type, | |
| 246 NPStream *stream, | |
| 247 NPBool seekable, | |
| 248 unsigned short *stype) { | |
| 249 DCHECK(npp_functions_ != 0); | |
| 250 DCHECK(npp_functions_->newstream != 0); | |
| 251 if (npp_functions_->newstream != 0) { | |
| 252 return npp_functions_->newstream(npp_, type, stream, seekable, stype); | |
| 253 } | |
| 254 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 255 } | |
| 256 | |
| 257 NPError PluginInstance::NPP_DestroyStream(NPStream *stream, NPReason reason) { | |
| 258 DCHECK(npp_functions_ != 0); | |
| 259 DCHECK(npp_functions_->destroystream != 0); | |
| 260 | |
| 261 if (stream == NULL || !IsValidStream(stream) || (stream->ndata == NULL)) | |
| 262 return NPERR_INVALID_INSTANCE_ERROR; | |
| 263 | |
| 264 if (npp_functions_->destroystream != 0) { | |
| 265 NPError result = npp_functions_->destroystream(npp_, stream, reason); | |
| 266 stream->ndata = NULL; | |
| 267 return result; | |
| 268 } | |
| 269 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 270 } | |
| 271 | |
| 272 int PluginInstance::NPP_WriteReady(NPStream *stream) { | |
| 273 DCHECK(npp_functions_ != 0); | |
| 274 DCHECK(npp_functions_->writeready != 0); | |
| 275 if (npp_functions_->writeready != 0) { | |
| 276 return npp_functions_->writeready(npp_, stream); | |
| 277 } | |
| 278 return 0; | |
| 279 } | |
| 280 | |
| 281 int PluginInstance::NPP_Write(NPStream *stream, | |
| 282 int offset, | |
| 283 int len, | |
| 284 void *buffer) { | |
| 285 DCHECK(npp_functions_ != 0); | |
| 286 DCHECK(npp_functions_->write != 0); | |
| 287 if (npp_functions_->write != 0) { | |
| 288 return npp_functions_->write(npp_, stream, offset, len, buffer); | |
| 289 } | |
| 290 return 0; | |
| 291 } | |
| 292 | |
| 293 void PluginInstance::NPP_StreamAsFile(NPStream *stream, const char *fname) { | |
| 294 DCHECK(npp_functions_ != 0); | |
| 295 DCHECK(npp_functions_->asfile != 0); | |
| 296 if (npp_functions_->asfile != 0) { | |
| 297 npp_functions_->asfile(npp_, stream, fname); | |
| 298 } | |
| 299 | |
| 300 // Creating a temporary FilePath instance on the stack as the explicit | |
| 301 // FilePath constructor with StringType as an argument causes a compiler | |
| 302 // error when invoked via vector push back. | |
| 303 FilePath file_name = FilePath::FromWStringHack(UTF8ToWide(fname)); | |
| 304 files_created_.push_back(file_name); | |
| 305 } | |
| 306 | |
| 307 void PluginInstance::NPP_URLNotify(const char *url, | |
| 308 NPReason reason, | |
| 309 void *notifyData) { | |
| 310 DCHECK(npp_functions_ != 0); | |
| 311 DCHECK(npp_functions_->urlnotify != 0); | |
| 312 if (npp_functions_->urlnotify != 0) { | |
| 313 npp_functions_->urlnotify(npp_, url, reason, notifyData); | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 NPError PluginInstance::NPP_GetValue(NPPVariable variable, void *value) { | |
| 318 DCHECK(npp_functions_ != 0); | |
| 319 // getvalue is NULL for Shockwave | |
| 320 if (npp_functions_->getvalue != 0) { | |
| 321 return npp_functions_->getvalue(npp_, variable, value); | |
| 322 } | |
| 323 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 324 } | |
| 325 | |
| 326 NPError PluginInstance::NPP_SetValue(NPNVariable variable, void *value) { | |
| 327 DCHECK(npp_functions_ != 0); | |
| 328 if (npp_functions_->setvalue != 0) { | |
| 329 return npp_functions_->setvalue(npp_, variable, value); | |
| 330 } | |
| 331 return NPERR_INVALID_FUNCTABLE_ERROR; | |
| 332 } | |
| 333 | |
| 334 short PluginInstance::NPP_HandleEvent(void* event) { | |
| 335 DCHECK(npp_functions_ != 0); | |
| 336 DCHECK(npp_functions_->event != 0); | |
| 337 if (npp_functions_->event != 0) { | |
| 338 return npp_functions_->event(npp_, (void*)event); | |
| 339 } | |
| 340 return false; | |
| 341 } | |
| 342 | |
| 343 bool PluginInstance::NPP_Print(NPPrint* platform_print) { | |
| 344 DCHECK(npp_functions_ != 0); | |
| 345 if (npp_functions_->print != 0) { | |
| 346 npp_functions_->print(npp_, platform_print); | |
| 347 return true; | |
| 348 } | |
| 349 return false; | |
| 350 } | |
| 351 | |
| 352 NPError PluginInstance::NPP_ClearSiteData(uint64 flags, | |
| 353 const char* domain, | |
| 354 uint64 max_age) { | |
| 355 DCHECK(npp_functions_ != 0); | |
| 356 // TODO(bauerb): Call NPAPI function when it is defined in the header. | |
| 357 return NPERR_NO_ERROR; | |
| 358 } | |
| 359 | |
| 360 void PluginInstance::NPP_URLRedirectNotify(const char* url, int32_t status, | |
| 361 void* notify_data) { | |
| 362 DCHECK(npp_functions_ != 0); | |
| 363 if (npp_functions_->urlredirectnotify != 0) { | |
| 364 npp_functions_->urlredirectnotify(npp_, url, status, notify_data); | |
| 365 } | |
| 366 } | |
| 367 | |
| 368 void PluginInstance::SendJavaScriptStream(const GURL& url, | |
| 369 const std::string& result, | |
| 370 bool success, | |
| 371 int notify_id) { | |
| 372 bool notify; | |
| 373 void* notify_data; | |
| 374 GetNotifyData(notify_id, ¬ify, ¬ify_data); | |
| 375 | |
| 376 if (success) { | |
| 377 PluginStringStream *stream = | |
| 378 new PluginStringStream(this, url, notify, notify_data); | |
| 379 AddStream(stream); | |
| 380 stream->SendToPlugin(result, "text/html"); | |
| 381 } else { | |
| 382 // NOTE: Sending an empty stream here will crash MacroMedia | |
| 383 // Flash 9. Just send the URL Notify. | |
| 384 if (notify) | |
| 385 NPP_URLNotify(url.spec().c_str(), NPRES_DONE, notify_data); | |
| 386 } | |
| 387 } | |
| 388 | |
| 389 void PluginInstance::DidReceiveManualResponse(const GURL& url, | |
| 390 const std::string& mime_type, | |
| 391 const std::string& headers, | |
| 392 uint32 expected_length, | |
| 393 uint32 last_modified) { | |
| 394 DCHECK(load_manually_); | |
| 395 | |
| 396 plugin_data_stream_ = CreateStream(-1, url, mime_type, 0); | |
| 397 plugin_data_stream_->DidReceiveResponse(mime_type, headers, expected_length, | |
| 398 last_modified, true); | |
| 399 } | |
| 400 | |
| 401 void PluginInstance::DidReceiveManualData(const char* buffer, int length) { | |
| 402 DCHECK(load_manually_); | |
| 403 if (plugin_data_stream_.get() != NULL) { | |
| 404 plugin_data_stream_->DidReceiveData(buffer, length, 0); | |
| 405 } | |
| 406 } | |
| 407 | |
| 408 void PluginInstance::DidFinishManualLoading() { | |
| 409 DCHECK(load_manually_); | |
| 410 if (plugin_data_stream_.get() != NULL) { | |
| 411 plugin_data_stream_->DidFinishLoading(); | |
| 412 plugin_data_stream_->Close(NPRES_DONE); | |
| 413 plugin_data_stream_ = NULL; | |
| 414 } | |
| 415 } | |
| 416 | |
| 417 void PluginInstance::DidManualLoadFail() { | |
| 418 DCHECK(load_manually_); | |
| 419 if (plugin_data_stream_.get() != NULL) { | |
| 420 plugin_data_stream_->DidFail(); | |
| 421 plugin_data_stream_ = NULL; | |
| 422 } | |
| 423 } | |
| 424 | |
| 425 void PluginInstance::PluginThreadAsyncCall(void (*func)(void *), | |
| 426 void *user_data) { | |
| 427 message_loop_->PostTask( | |
| 428 FROM_HERE, NewRunnableMethod( | |
| 429 this, &PluginInstance::OnPluginThreadAsyncCall, func, user_data)); | |
| 430 } | |
| 431 | |
| 432 void PluginInstance::OnPluginThreadAsyncCall(void (*func)(void *), | |
| 433 void *user_data) { | |
| 434 // Do not invoke the callback if NPP_Destroy has already been invoked. | |
| 435 if (webplugin_) | |
| 436 func(user_data); | |
| 437 } | |
| 438 | |
| 439 uint32 PluginInstance::ScheduleTimer(uint32 interval, | |
| 440 NPBool repeat, | |
| 441 void (*func)(NPP id, uint32 timer_id)) { | |
| 442 // Use next timer id. | |
| 443 uint32 timer_id; | |
| 444 timer_id = next_timer_id_; | |
| 445 ++next_timer_id_; | |
| 446 DCHECK(next_timer_id_ != 0); | |
| 447 | |
| 448 // Record timer interval and repeat. | |
| 449 TimerInfo info; | |
| 450 info.interval = interval; | |
| 451 info.repeat = repeat ? true : false; | |
| 452 timers_[timer_id] = info; | |
| 453 | |
| 454 // Schedule the callback. | |
| 455 MessageLoop::current()->PostDelayedTask( | |
| 456 FROM_HERE, | |
| 457 NewRunnableMethod( | |
| 458 this, &PluginInstance::OnTimerCall, func, npp_, timer_id), | |
| 459 interval); | |
| 460 return timer_id; | |
| 461 } | |
| 462 | |
| 463 void PluginInstance::UnscheduleTimer(uint32 timer_id) { | |
| 464 // Remove info about the timer. | |
| 465 TimerMap::iterator it = timers_.find(timer_id); | |
| 466 if (it != timers_.end()) | |
| 467 timers_.erase(it); | |
| 468 } | |
| 469 | |
| 470 #if !defined(OS_MACOSX) | |
| 471 NPError PluginInstance::PopUpContextMenu(NPMenu* menu) { | |
| 472 NOTIMPLEMENTED(); | |
| 473 return NPERR_GENERIC_ERROR; | |
| 474 } | |
| 475 #endif | |
| 476 | |
| 477 void PluginInstance::OnTimerCall(void (*func)(NPP id, uint32 timer_id), | |
| 478 NPP id, | |
| 479 uint32 timer_id) { | |
| 480 // Do not invoke callback if the timer has been unscheduled. | |
| 481 TimerMap::iterator it = timers_.find(timer_id); | |
| 482 if (it == timers_.end()) | |
| 483 return; | |
| 484 | |
| 485 // Get all information about the timer before invoking the callback. The | |
| 486 // callback might unschedule the timer. | |
| 487 TimerInfo info = it->second; | |
| 488 | |
| 489 func(id, timer_id); | |
| 490 | |
| 491 // If the timer was unscheduled by the callback, just free up the timer id. | |
| 492 if (timers_.find(timer_id) == timers_.end()) | |
| 493 return; | |
| 494 | |
| 495 // Reschedule repeating timers after invoking the callback so callback is not | |
| 496 // re-entered if it pumps the messager loop. | |
| 497 if (info.repeat) { | |
| 498 MessageLoop::current()->PostDelayedTask( | |
| 499 FROM_HERE, | |
| 500 NewRunnableMethod( | |
| 501 this, &PluginInstance::OnTimerCall, func, npp_, timer_id), | |
| 502 info.interval); | |
| 503 } else { | |
| 504 timers_.erase(it); | |
| 505 } | |
| 506 } | |
| 507 | |
| 508 void PluginInstance::PushPopupsEnabledState(bool enabled) { | |
| 509 popups_enabled_stack_.push(enabled); | |
| 510 } | |
| 511 | |
| 512 void PluginInstance::PopPopupsEnabledState() { | |
| 513 popups_enabled_stack_.pop(); | |
| 514 } | |
| 515 | |
| 516 void PluginInstance::RequestRead(NPStream* stream, NPByteRange* range_list) { | |
| 517 std::string range_info = "bytes="; | |
| 518 | |
| 519 while (range_list) { | |
| 520 range_info += base::IntToString(range_list->offset); | |
| 521 range_info.push_back('-'); | |
| 522 range_info += | |
| 523 base::IntToString(range_list->offset + range_list->length - 1); | |
| 524 range_list = range_list->next; | |
| 525 if (range_list) | |
| 526 range_info.push_back(','); | |
| 527 } | |
| 528 | |
| 529 if (plugin_data_stream_) { | |
| 530 if (plugin_data_stream_->stream() == stream) { | |
| 531 webplugin_->CancelDocumentLoad(); | |
| 532 plugin_data_stream_ = NULL; | |
| 533 } | |
| 534 } | |
| 535 | |
| 536 // The lifetime of a NPStream instance depends on the PluginStream instance | |
| 537 // which owns it. When a plugin invokes NPN_RequestRead on a seekable stream, | |
| 538 // we don't want to create a new stream when the corresponding response is | |
| 539 // received. We send over a cookie which represents the PluginStream | |
| 540 // instance which is sent back from the renderer when the response is | |
| 541 // received. | |
| 542 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | |
| 543 for (stream_index = open_streams_.begin(); | |
| 544 stream_index != open_streams_.end(); ++stream_index) { | |
| 545 PluginStream* plugin_stream = *stream_index; | |
| 546 if (plugin_stream->stream() == stream) { | |
| 547 // A stream becomes seekable the first time NPN_RequestRead | |
| 548 // is called on it. | |
| 549 plugin_stream->set_seekable(true); | |
| 550 | |
| 551 pending_range_requests_[++next_range_request_id_] = plugin_stream; | |
| 552 webplugin_->InitiateHTTPRangeRequest( | |
| 553 stream->url, range_info.c_str(), next_range_request_id_); | |
| 554 return; | |
| 555 } | |
| 556 } | |
| 557 NOTREACHED(); | |
| 558 } | |
| 559 | |
| 560 void PluginInstance::RequestURL(const char* url, | |
| 561 const char* method, | |
| 562 const char* target, | |
| 563 const char* buf, | |
| 564 unsigned int len, | |
| 565 bool notify, | |
| 566 void* notify_data) { | |
| 567 int notify_id = 0; | |
| 568 if (notify) { | |
| 569 notify_id = ++next_notify_id_; | |
| 570 pending_requests_[notify_id] = notify_data; | |
| 571 } | |
| 572 | |
| 573 webplugin_->HandleURLRequest( | |
| 574 url, method, target, buf, len, notify_id, popups_allowed(), | |
| 575 notify ? handles_url_redirects_ : false); | |
| 576 } | |
| 577 | |
| 578 bool PluginInstance::ConvertPoint(double source_x, double source_y, | |
| 579 NPCoordinateSpace source_space, | |
| 580 double* dest_x, double* dest_y, | |
| 581 NPCoordinateSpace dest_space) { | |
| 582 #if defined(OS_MACOSX) | |
| 583 CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID()); | |
| 584 | |
| 585 double flipped_screen_x = source_x; | |
| 586 double flipped_screen_y = source_y; | |
| 587 switch(source_space) { | |
| 588 case NPCoordinateSpacePlugin: | |
| 589 flipped_screen_x += plugin_origin_.x(); | |
| 590 flipped_screen_y += plugin_origin_.y(); | |
| 591 break; | |
| 592 case NPCoordinateSpaceWindow: | |
| 593 flipped_screen_x += containing_window_frame_.x(); | |
| 594 flipped_screen_y = containing_window_frame_.height() - source_y + | |
| 595 containing_window_frame_.y(); | |
| 596 break; | |
| 597 case NPCoordinateSpaceFlippedWindow: | |
| 598 flipped_screen_x += containing_window_frame_.x(); | |
| 599 flipped_screen_y += containing_window_frame_.y(); | |
| 600 break; | |
| 601 case NPCoordinateSpaceScreen: | |
| 602 flipped_screen_y = main_display_bounds.size.height - flipped_screen_y; | |
| 603 break; | |
| 604 case NPCoordinateSpaceFlippedScreen: | |
| 605 break; | |
| 606 default: | |
| 607 NOTREACHED(); | |
| 608 return false; | |
| 609 } | |
| 610 | |
| 611 double target_x = flipped_screen_x; | |
| 612 double target_y = flipped_screen_y; | |
| 613 switch(dest_space) { | |
| 614 case NPCoordinateSpacePlugin: | |
| 615 target_x -= plugin_origin_.x(); | |
| 616 target_y -= plugin_origin_.y(); | |
| 617 break; | |
| 618 case NPCoordinateSpaceWindow: | |
| 619 target_x -= containing_window_frame_.x(); | |
| 620 target_y -= containing_window_frame_.y(); | |
| 621 target_y = containing_window_frame_.height() - target_y; | |
| 622 break; | |
| 623 case NPCoordinateSpaceFlippedWindow: | |
| 624 target_x -= containing_window_frame_.x(); | |
| 625 target_y -= containing_window_frame_.y(); | |
| 626 break; | |
| 627 case NPCoordinateSpaceScreen: | |
| 628 target_y = main_display_bounds.size.height - flipped_screen_y; | |
| 629 break; | |
| 630 case NPCoordinateSpaceFlippedScreen: | |
| 631 break; | |
| 632 default: | |
| 633 NOTREACHED(); | |
| 634 return false; | |
| 635 } | |
| 636 | |
| 637 if (dest_x) | |
| 638 *dest_x = target_x; | |
| 639 if (dest_y) | |
| 640 *dest_y = target_y; | |
| 641 return true; | |
| 642 #else | |
| 643 NOTIMPLEMENTED(); | |
| 644 return false; | |
| 645 #endif | |
| 646 } | |
| 647 | |
| 648 void PluginInstance::GetNotifyData( | |
| 649 int notify_id, bool* notify, void** notify_data) { | |
| 650 PendingRequestMap::iterator iter = pending_requests_.find(notify_id); | |
| 651 if (iter != pending_requests_.end()) { | |
| 652 *notify = true; | |
| 653 *notify_data = iter->second; | |
| 654 pending_requests_.erase(iter); | |
| 655 } else { | |
| 656 *notify = false; | |
| 657 *notify_data = NULL; | |
| 658 } | |
| 659 } | |
| 660 | |
| 661 void PluginInstance::URLRedirectResponse(bool allow, void* notify_data) { | |
| 662 // The notify_data passed in allows us to identify the matching stream. | |
| 663 std::vector<scoped_refptr<PluginStream> >::iterator stream_index; | |
| 664 for (stream_index = open_streams_.begin(); | |
| 665 stream_index != open_streams_.end(); ++stream_index) { | |
| 666 PluginStream* plugin_stream = *stream_index; | |
| 667 if (plugin_stream->notify_data() == notify_data) { | |
| 668 webkit_glue::WebPluginResourceClient* resource_client = | |
| 669 plugin_stream->AsResourceClient(); | |
| 670 webplugin_->URLRedirectResponse(allow, resource_client->ResourceId()); | |
| 671 if (allow) { | |
| 672 plugin_stream->UpdateUrl( | |
| 673 plugin_stream->pending_redirect_url().c_str()); | |
| 674 } | |
| 675 break; | |
| 676 } | |
| 677 } | |
| 678 } | |
| 679 | |
| 680 } // namespace NPAPI | |
| OLD | NEW |