| 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/browser/chrome_plugin_host.h" | 5 #include "chrome/browser/chrome_plugin_host.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 11 #include "base/gfx/png_encoder.h" | 12 #include "base/gfx/png_encoder.h" |
| 12 #include "base/histogram.h" | 13 #include "base/histogram.h" |
| 13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 15 #include "base/perftimer.h" | 16 #include "base/perftimer.h" |
| 16 #include "base/singleton.h" | 17 #include "base/singleton.h" |
| 17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 18 #include "chrome/browser/browser_list.h" | 19 #include "chrome/browser/browser_list.h" |
| 19 #include "chrome/browser/chrome_plugin_browsing_context.h" | 20 #include "chrome/browser/chrome_plugin_browsing_context.h" |
| 20 #include "chrome/browser/chrome_thread.h" | 21 #include "chrome/browser/chrome_thread.h" |
| 21 #include "chrome/browser/dom_ui/html_dialog_contents.h" | |
| 22 #include "chrome/browser/gears_integration.h" | 22 #include "chrome/browser/gears_integration.h" |
| 23 #include "chrome/browser/plugin_process_host.h" | 23 #include "chrome/browser/plugin_process_host.h" |
| 24 #include "chrome/browser/plugin_service.h" | 24 #include "chrome/browser/plugin_service.h" |
| 25 #include "chrome/browser/profile.h" | 25 #include "chrome/browser/profile.h" |
| 26 #include "chrome/browser/renderer_host/render_process_host.h" | 26 #include "chrome/browser/renderer_host/render_process_host.h" |
| 27 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/common/chrome_counters.h" | 28 #include "chrome/common/chrome_counters.h" |
| 29 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/chrome_plugin_lib.h" | 30 #include "chrome/common/chrome_plugin_lib.h" |
| 31 #include "chrome/common/chrome_plugin_util.h" | 31 #include "chrome/common/chrome_plugin_util.h" |
| 32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/gears_api.h" | 33 #include "chrome/common/gears_api.h" |
| 34 #include "chrome/common/notification_service.h" | 34 #include "chrome/common/notification_service.h" |
| 35 #include "chrome/common/net/url_request_intercept_job.h" | 35 #include "chrome/common/net/url_request_intercept_job.h" |
| 36 #include "chrome/common/plugin_messages.h" | |
| 37 #include "chrome/common/render_messages.h" | 36 #include "chrome/common/render_messages.h" |
| 38 #include "net/base/base64.h" | 37 #include "net/base/base64.h" |
| 39 #include "net/base/cookie_monster.h" | 38 #include "net/base/cookie_monster.h" |
| 40 #include "net/url_request/url_request_context.h" | 39 #include "net/url_request/url_request_context.h" |
| 41 #include "net/url_request/url_request_error_job.h" | 40 #include "net/url_request/url_request_error_job.h" |
| 42 #include "skia/include/SkBitmap.h" | 41 #include "skia/include/SkBitmap.h" |
| 43 | 42 |
| 43 // TODO(port): Port these files. |
| 44 #if defined(OS_WIN) |
| 45 #include "chrome/browser/dom_ui/html_dialog_contents.h" |
| 46 #include "chrome/common/plugin_messages.h" |
| 47 #else |
| 48 #include "chrome/common/temp_scaffolding_stubs.h" |
| 49 #endif |
| 50 |
| 44 using base::TimeDelta; | 51 using base::TimeDelta; |
| 45 | 52 |
| 46 // This class manages the interception of network requests. It queries the | 53 // This class manages the interception of network requests. It queries the |
| 47 // plugin on every request, and creates an intercept job if the plugin can | 54 // plugin on every request, and creates an intercept job if the plugin can |
| 48 // intercept the request. | 55 // intercept the request. |
| 49 // NOTE: All methods must be called on the IO thread. | 56 // NOTE: All methods must be called on the IO thread. |
| 50 class PluginRequestInterceptor | 57 class PluginRequestInterceptor |
| 51 : public PluginHelper, public URLRequest::Interceptor { | 58 : public PluginHelper, public URLRequest::Interceptor { |
| 52 public: | 59 public: |
| 53 static URLRequestJob* UninterceptedProtocolHandler( | 60 static URLRequestJob* UninterceptedProtocolHandler( |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // on demand on the plugin thread, and proxies calls to and from the UI thread | 283 // on demand on the plugin thread, and proxies calls to and from the UI thread |
| 277 // to display the UI. | 284 // to display the UI. |
| 278 class ModelessHtmlDialogDelegate : public HtmlDialogContentsDelegate { | 285 class ModelessHtmlDialogDelegate : public HtmlDialogContentsDelegate { |
| 279 public: | 286 public: |
| 280 ModelessHtmlDialogDelegate(const GURL& url, | 287 ModelessHtmlDialogDelegate(const GURL& url, |
| 281 int width, int height, | 288 int width, int height, |
| 282 const std::string& json_arguments, | 289 const std::string& json_arguments, |
| 283 void* plugin_context, | 290 void* plugin_context, |
| 284 ChromePluginLib* plugin, | 291 ChromePluginLib* plugin, |
| 285 MessageLoop* main_message_loop, | 292 MessageLoop* main_message_loop, |
| 286 HWND parent_hwnd) | 293 gfx::NativeWindow parent_wnd) |
| 287 : plugin_(plugin), | 294 : main_message_loop_(main_message_loop), |
| 295 io_message_loop_(MessageLoop::current()), |
| 296 plugin_(plugin), |
| 288 plugin_context_(plugin_context), | 297 plugin_context_(plugin_context), |
| 289 main_message_loop_(main_message_loop), | 298 parent_wnd_(parent_wnd) { |
| 290 io_message_loop_(MessageLoop::current()), | |
| 291 parent_hwnd_(parent_hwnd) { | |
| 292 DCHECK(ChromePluginLib::IsPluginThread()); | 299 DCHECK(ChromePluginLib::IsPluginThread()); |
| 293 params_.url = url; | 300 params_.url = url; |
| 294 params_.height = height; | 301 params_.height = height; |
| 295 params_.width = width; | 302 params_.width = width; |
| 296 params_.json_input = json_arguments; | 303 params_.json_input = json_arguments; |
| 297 | 304 |
| 298 main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 305 main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 299 this, &ModelessHtmlDialogDelegate::Show)); | 306 this, &ModelessHtmlDialogDelegate::Show)); |
| 300 } | 307 } |
| 301 ~ModelessHtmlDialogDelegate() { | 308 ~ModelessHtmlDialogDelegate() { |
| 302 DCHECK(ChromePluginLib::IsPluginThread()); | 309 DCHECK(ChromePluginLib::IsPluginThread()); |
| 303 } | 310 } |
| 304 | 311 |
| 305 // The following public methods are called from the UI thread. | 312 // The following public methods are called from the UI thread. |
| 306 | 313 |
| 307 // HtmlDialogContentsDelegate implementation: | 314 // HtmlDialogContentsDelegate implementation: |
| 308 virtual bool IsDialogModal() const { return false; } | 315 virtual bool IsDialogModal() const { return false; } |
| 309 virtual std::wstring GetDialogTitle() const { return L"Google Gears"; } | 316 virtual std::wstring GetDialogTitle() const { return L"Google Gears"; } |
| 310 virtual GURL GetDialogContentURL() const { return params_.url; } | 317 virtual GURL GetDialogContentURL() const { return params_.url; } |
| 311 virtual void GetDialogSize(CSize* size) const { | 318 virtual void GetDialogSize(gfx::Size* size) const { |
| 312 size->cx = params_.width; | 319 size->set_width(params_.width); |
| 313 size->cy = params_.height; | 320 size->set_height(params_.height); |
| 314 } | 321 } |
| 315 virtual std::string GetDialogArgs() const { return params_.json_input; } | 322 virtual std::string GetDialogArgs() const { return params_.json_input; } |
| 316 virtual void OnDialogClosed(const std::string& json_retval) { | 323 virtual void OnDialogClosed(const std::string& json_retval) { |
| 317 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 324 io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 318 this, &ModelessHtmlDialogDelegate::ReportResults, json_retval)); | 325 this, &ModelessHtmlDialogDelegate::ReportResults, json_retval)); |
| 319 } | 326 } |
| 320 | 327 |
| 321 private: | 328 private: |
| 322 // Actually shows the dialog on the UI thread. | 329 // Actually shows the dialog on the UI thread. |
| 323 void Show() { | 330 void Show() { |
| 324 DCHECK(MessageLoop::current() == main_message_loop_); | 331 DCHECK(MessageLoop::current() == main_message_loop_); |
| 325 Browser* browser = BrowserList::GetLastActive(); | 332 Browser* browser = BrowserList::GetLastActive(); |
| 326 browser->ShowHtmlDialog(this, parent_hwnd_); | 333 browser->ShowHtmlDialog(this, parent_wnd_); |
| 327 } | 334 } |
| 328 | 335 |
| 329 // Gives the JSON result string back to the plugin. | 336 // Gives the JSON result string back to the plugin. |
| 330 void ReportResults(const std::string& json_retval) { | 337 void ReportResults(const std::string& json_retval) { |
| 331 DCHECK(MessageLoop::current() == io_message_loop_); | 338 DCHECK(MessageLoop::current() == io_message_loop_); |
| 332 // The plugin may have unloaded before it was time to report the results. | 339 // The plugin may have unloaded before it was time to report the results. |
| 333 if (plugin_->is_loaded()) | 340 if (plugin_->is_loaded()) |
| 334 plugin_->functions().html_dialog_closed(plugin_context_, | 341 plugin_->functions().html_dialog_closed(plugin_context_, |
| 335 json_retval.c_str()); | 342 json_retval.c_str()); |
| 336 delete this; | 343 delete this; |
| 337 } | 344 } |
| 338 | 345 |
| 339 // The parameters needed to display a modal HTML dialog. | 346 // The parameters needed to display a modal HTML dialog. |
| 340 HtmlDialogContents::HtmlDialogParams params_; | 347 HtmlDialogContents::HtmlDialogParams params_; |
| 341 | 348 |
| 342 // Message loops for sending messages between UI and IO threads. | 349 // Message loops for sending messages between UI and IO threads. |
| 343 MessageLoop* main_message_loop_; | 350 MessageLoop* main_message_loop_; |
| 344 MessageLoop* io_message_loop_; | 351 MessageLoop* io_message_loop_; |
| 345 | 352 |
| 346 // The plugin object that requested the dialog. This can only be accessed on | 353 // The plugin object that requested the dialog. This can only be accessed on |
| 347 // the IO thread. | 354 // the IO thread. |
| 348 scoped_refptr<ChromePluginLib> plugin_; | 355 scoped_refptr<ChromePluginLib> plugin_; |
| 349 | 356 |
| 350 // The plugin's context argument to CPB_ShowHtmlDialog. | 357 // The plugin's context argument to CPB_ShowHtmlDialog. |
| 351 void* plugin_context_; | 358 void* plugin_context_; |
| 352 | 359 |
| 353 // The window this dialog box should be parented to, or NULL for the last | 360 // The window this dialog box should be parented to, or NULL for the last |
| 354 // active browser window. | 361 // active browser window. |
| 355 HWND parent_hwnd_; | 362 gfx::NativeWindow parent_wnd_; |
| 356 | 363 |
| 357 DISALLOW_EVIL_CONSTRUCTORS(ModelessHtmlDialogDelegate); | 364 DISALLOW_EVIL_CONSTRUCTORS(ModelessHtmlDialogDelegate); |
| 358 }; | 365 }; |
| 359 | 366 |
| 360 // Allows InvokeLater without adding refcounting. The object is only deleted | 367 // Allows InvokeLater without adding refcounting. The object is only deleted |
| 361 // when its last InvokeLater is run anyway. | 368 // when its last InvokeLater is run anyway. |
| 369 template<> |
| 362 void RunnableMethodTraits<ModelessHtmlDialogDelegate>::RetainCallee( | 370 void RunnableMethodTraits<ModelessHtmlDialogDelegate>::RetainCallee( |
| 363 ModelessHtmlDialogDelegate* remover) { | 371 ModelessHtmlDialogDelegate* remover) { |
| 364 } | 372 } |
| 373 template<> |
| 365 void RunnableMethodTraits<ModelessHtmlDialogDelegate>::ReleaseCallee( | 374 void RunnableMethodTraits<ModelessHtmlDialogDelegate>::ReleaseCallee( |
| 366 ModelessHtmlDialogDelegate* remover) { | 375 ModelessHtmlDialogDelegate* remover) { |
| 367 } | 376 } |
| 368 | 377 |
| 369 namespace { | 378 namespace { |
| 370 | 379 |
| 371 // | 380 // |
| 372 // Generic functions | 381 // Generic functions |
| 373 // | 382 // |
| 374 | 383 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 578 |
| 570 CPError STDCALL CPB_CreateRequest(CPID id, CPBrowsingContext context, | 579 CPError STDCALL CPB_CreateRequest(CPID id, CPBrowsingContext context, |
| 571 const char* method, const char* url, | 580 const char* method, const char* url, |
| 572 CPRequest** request) { | 581 CPRequest** request) { |
| 573 CHECK(ChromePluginLib::IsPluginThread()); | 582 CHECK(ChromePluginLib::IsPluginThread()); |
| 574 ChromePluginLib* plugin = ChromePluginLib::FromCPID(id); | 583 ChromePluginLib* plugin = ChromePluginLib::FromCPID(id); |
| 575 CHECK(plugin); | 584 CHECK(plugin); |
| 576 | 585 |
| 577 ScopableCPRequest* cprequest = new ScopableCPRequest(url, method, context); | 586 ScopableCPRequest* cprequest = new ScopableCPRequest(url, method, context); |
| 578 PluginRequestHandler* handler = new PluginRequestHandler(plugin, cprequest); | 587 PluginRequestHandler* handler = new PluginRequestHandler(plugin, cprequest); |
| 588 CHECK(handler); |
| 579 | 589 |
| 580 *request = cprequest; | 590 *request = cprequest; |
| 581 return CPERR_SUCCESS; | 591 return CPERR_SUCCESS; |
| 582 } | 592 } |
| 583 | 593 |
| 584 CPError STDCALL CPR_StartRequest(CPRequest* request) { | 594 CPError STDCALL CPR_StartRequest(CPRequest* request) { |
| 585 CHECK(ChromePluginLib::IsPluginThread()); | 595 CHECK(ChromePluginLib::IsPluginThread()); |
| 586 PluginRequestHandler* handler = PluginRequestHandler::FromCPRequest(request); | 596 PluginRequestHandler* handler = PluginRequestHandler::FromCPRequest(request); |
| 587 CHECK(handler); | 597 CHECK(handler); |
| 588 handler->request()->Start(); | 598 handler->request()->Start(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 PluginService* service = PluginService::GetInstance(); | 703 PluginService* service = PluginService::GetInstance(); |
| 694 if (!service) | 704 if (!service) |
| 695 return CPERR_FAILURE; | 705 return CPERR_FAILURE; |
| 696 PluginProcessHost *host = | 706 PluginProcessHost *host = |
| 697 service->FindOrStartPluginProcess(plugin->filename(), std::string()); | 707 service->FindOrStartPluginProcess(plugin->filename(), std::string()); |
| 698 if (!host) | 708 if (!host) |
| 699 return CPERR_FAILURE; | 709 return CPERR_FAILURE; |
| 700 | 710 |
| 701 const unsigned char* data_ptr = static_cast<const unsigned char*>(data); | 711 const unsigned char* data_ptr = static_cast<const unsigned char*>(data); |
| 702 std::vector<uint8> v(data_ptr, data_ptr + data_len); | 712 std::vector<uint8> v(data_ptr, data_ptr + data_len); |
| 713 #if defined(OS_WIN) |
| 703 if (!host->Send(new PluginProcessMsg_PluginMessage(v))) | 714 if (!host->Send(new PluginProcessMsg_PluginMessage(v))) |
| 704 return CPERR_FAILURE; | 715 return CPERR_FAILURE; |
| 716 #else |
| 717 // TODO(port): Implement PluginProcessMsg. |
| 718 NOTIMPLEMENTED(); |
| 719 #endif |
| 705 | 720 |
| 706 return CPERR_SUCCESS; | 721 return CPERR_SUCCESS; |
| 707 } | 722 } |
| 708 } | 723 } |
| 709 | 724 |
| 710 CPError STDCALL CPB_SendSyncMessage(CPID id, const void *data, uint32 data_len, | 725 CPError STDCALL CPB_SendSyncMessage(CPID id, const void *data, uint32 data_len, |
| 711 void **retval, uint32 *retval_len) { | 726 void **retval, uint32 *retval_len) { |
| 712 NOTREACHED() << "Sync messages should not be sent from the browser process."; | 727 NOTREACHED() << "Sync messages should not be sent from the browser process."; |
| 713 | 728 |
| 714 return CPERR_FAILURE; | 729 return CPERR_FAILURE; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 void CPHandleCommand(int command, CPCommandInterface* data, | 811 void CPHandleCommand(int command, CPCommandInterface* data, |
| 797 CPBrowsingContext context) { | 812 CPBrowsingContext context) { |
| 798 // Sadly if we try and pass context through, we seem to break cl's little | 813 // Sadly if we try and pass context through, we seem to break cl's little |
| 799 // brain trying to compile the Tuple3 ctor. This cast works. | 814 // brain trying to compile the Tuple3 ctor. This cast works. |
| 800 int32 context_as_int32 = static_cast<int32>(context); | 815 int32 context_as_int32 = static_cast<int32>(context); |
| 801 // Plugins can only be accessed on the IO thread. | 816 // Plugins can only be accessed on the IO thread. |
| 802 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 817 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 803 NewRunnableFunction(PluginCommandHandler::HandleCommand, | 818 NewRunnableFunction(PluginCommandHandler::HandleCommand, |
| 804 command, data, context_as_int32)); | 819 command, data, context_as_int32)); |
| 805 } | 820 } |
| OLD | NEW |