OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/child/npapi/webplugin_delegate_impl.h" | 5 #include "content/child/npapi/webplugin_delegate_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 LAZY_INSTANCE_INITIALIZER; | 81 LAZY_INSTANCE_INITIALIZER; |
82 | 82 |
83 // Helper object for patching the RegEnumKeyExW API. | 83 // Helper object for patching the RegEnumKeyExW API. |
84 base::LazyInstance<base::win::IATPatchFunction> g_iat_patch_reg_enum_key_ex_w = | 84 base::LazyInstance<base::win::IATPatchFunction> g_iat_patch_reg_enum_key_ex_w = |
85 LAZY_INSTANCE_INITIALIZER; | 85 LAZY_INSTANCE_INITIALIZER; |
86 | 86 |
87 // Helper object for patching the GetProcAddress API. | 87 // Helper object for patching the GetProcAddress API. |
88 base::LazyInstance<base::win::IATPatchFunction> g_iat_patch_get_proc_address = | 88 base::LazyInstance<base::win::IATPatchFunction> g_iat_patch_get_proc_address = |
89 LAZY_INSTANCE_INITIALIZER; | 89 LAZY_INSTANCE_INITIALIZER; |
90 | 90 |
91 #if defined(USE_AURA) | |
92 base::LazyInstance<base::win::IATPatchFunction> g_iat_patch_window_from_point = | 91 base::LazyInstance<base::win::IATPatchFunction> g_iat_patch_window_from_point = |
93 LAZY_INSTANCE_INITIALIZER; | 92 LAZY_INSTANCE_INITIALIZER; |
94 #endif | |
95 | 93 |
96 // http://crbug.com/16114 | 94 // http://crbug.com/16114 |
97 // Enforces providing a valid device context in NPWindow, so that NPP_SetWindow | 95 // Enforces providing a valid device context in NPWindow, so that NPP_SetWindow |
98 // is never called with NPNWindoTypeDrawable and NPWindow set to NULL. | 96 // is never called with NPNWindoTypeDrawable and NPWindow set to NULL. |
99 // Doing so allows removing NPP_SetWindow call during painting a windowless | 97 // Doing so allows removing NPP_SetWindow call during painting a windowless |
100 // plugin, which otherwise could trigger layout change while painting by | 98 // plugin, which otherwise could trigger layout change while painting by |
101 // invoking NPN_Evaluate. Which would cause bad, bad crashes. Bad crashes. | 99 // invoking NPN_Evaluate. Which would cause bad, bad crashes. Bad crashes. |
102 // TODO(dglazkov): If this approach doesn't produce regressions, move class to | 100 // TODO(dglazkov): If this approach doesn't produce regressions, move class to |
103 // webplugin_delegate_impl.h and implement for other platforms. | 101 // webplugin_delegate_impl.h and implement for other platforms. |
104 class DrawableContextEnforcer { | 102 class DrawableContextEnforcer { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 if (instance_->mime_type() == kFlashPluginSwfMimeType || | 257 if (instance_->mime_type() == kFlashPluginSwfMimeType || |
260 filename == kFlashPlugin) { | 258 filename == kFlashPlugin) { |
261 // Flash only requests windowless plugins if we return a Mozilla user | 259 // Flash only requests windowless plugins if we return a Mozilla user |
262 // agent. | 260 // agent. |
263 instance_->set_use_mozilla_user_agent(); | 261 instance_->set_use_mozilla_user_agent(); |
264 quirks_ |= PLUGIN_QUIRK_THROTTLE_WM_USER_PLUS_ONE; | 262 quirks_ |= PLUGIN_QUIRK_THROTTLE_WM_USER_PLUS_ONE; |
265 quirks_ |= PLUGIN_QUIRK_PATCH_SETCURSOR; | 263 quirks_ |= PLUGIN_QUIRK_PATCH_SETCURSOR; |
266 quirks_ |= PLUGIN_QUIRK_ALWAYS_NOTIFY_SUCCESS; | 264 quirks_ |= PLUGIN_QUIRK_ALWAYS_NOTIFY_SUCCESS; |
267 quirks_ |= PLUGIN_QUIRK_HANDLE_MOUSE_CAPTURE; | 265 quirks_ |= PLUGIN_QUIRK_HANDLE_MOUSE_CAPTURE; |
268 quirks_ |= PLUGIN_QUIRK_EMULATE_IME; | 266 quirks_ |= PLUGIN_QUIRK_EMULATE_IME; |
269 #if defined(USE_AURA) | |
270 quirks_ |= PLUGIN_QUIRK_FAKE_WINDOW_FROM_POINT; | 267 quirks_ |= PLUGIN_QUIRK_FAKE_WINDOW_FROM_POINT; |
271 #endif | |
272 } else if (filename == kAcrobatReaderPlugin) { | 268 } else if (filename == kAcrobatReaderPlugin) { |
273 // Check for the version number above or equal 9. | 269 // Check for the version number above or equal 9. |
274 int major_version = GetPluginMajorVersion(plugin_info); | 270 int major_version = GetPluginMajorVersion(plugin_info); |
275 if (major_version >= 9) { | 271 if (major_version >= 9) { |
276 quirks_ |= PLUGIN_QUIRK_DIE_AFTER_UNLOAD; | 272 quirks_ |= PLUGIN_QUIRK_DIE_AFTER_UNLOAD; |
277 // 9.2 needs this. | 273 // 9.2 needs this. |
278 quirks_ |= PLUGIN_QUIRK_SETWINDOW_TWICE; | 274 quirks_ |= PLUGIN_QUIRK_SETWINDOW_TWICE; |
279 } | 275 } |
280 quirks_ |= PLUGIN_QUIRK_BLOCK_NONSTANDARD_GETURL_REQUESTS; | 276 quirks_ |= PLUGIN_QUIRK_BLOCK_NONSTANDARD_GETURL_REQUESTS; |
281 } else if (plugin_info.name.find(L"Windows Media Player") != | 277 } else if (plugin_info.name.find(L"Windows Media Player") != |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 // and use them to retrieve IME data. We add a patch to this function so we | 411 // and use them to retrieve IME data. We add a patch to this function so we |
416 // can dispatch these IMM32 calls to the WebPluginIMEWin class, which emulates | 412 // can dispatch these IMM32 calls to the WebPluginIMEWin class, which emulates |
417 // IMM32 functions for Flash. | 413 // IMM32 functions for Flash. |
418 if (!g_iat_patch_get_proc_address.Pointer()->is_patched() && | 414 if (!g_iat_patch_get_proc_address.Pointer()->is_patched() && |
419 (quirks_ & PLUGIN_QUIRK_EMULATE_IME)) { | 415 (quirks_ & PLUGIN_QUIRK_EMULATE_IME)) { |
420 g_iat_patch_get_proc_address.Pointer()->Patch( | 416 g_iat_patch_get_proc_address.Pointer()->Patch( |
421 GetPluginPath().value().c_str(), "kernel32.dll", "GetProcAddress", | 417 GetPluginPath().value().c_str(), "kernel32.dll", "GetProcAddress", |
422 GetProcAddressPatch); | 418 GetProcAddressPatch); |
423 } | 419 } |
424 | 420 |
425 #if defined(USE_AURA) | |
426 if (windowless_ && !g_iat_patch_window_from_point.Pointer()->is_patched() && | 421 if (windowless_ && !g_iat_patch_window_from_point.Pointer()->is_patched() && |
427 (quirks_ & PLUGIN_QUIRK_FAKE_WINDOW_FROM_POINT)) { | 422 (quirks_ & PLUGIN_QUIRK_FAKE_WINDOW_FROM_POINT)) { |
428 g_iat_patch_window_from_point.Pointer()->Patch( | 423 g_iat_patch_window_from_point.Pointer()->Patch( |
429 GetPluginPath().value().c_str(), "user32.dll", "WindowFromPoint", | 424 GetPluginPath().value().c_str(), "user32.dll", "WindowFromPoint", |
430 WebPluginDelegateImpl::WindowFromPointPatch); | 425 WebPluginDelegateImpl::WindowFromPointPatch); |
431 } | 426 } |
432 #endif | 427 |
433 return true; | 428 return true; |
434 } | 429 } |
435 | 430 |
436 void WebPluginDelegateImpl::PlatformDestroyInstance() { | 431 void WebPluginDelegateImpl::PlatformDestroyInstance() { |
437 if (!instance_->plugin_lib()) | 432 if (!instance_->plugin_lib()) |
438 return; | 433 return; |
439 | 434 |
440 // Unpatch if this is the last plugin instance. | 435 // Unpatch if this is the last plugin instance. |
441 if (instance_->plugin_lib()->instance_count() != 1) | 436 if (instance_->plugin_lib()->instance_count() != 1) |
442 return; | 437 return; |
443 | 438 |
444 if (g_iat_patch_set_cursor.Pointer()->is_patched()) | 439 if (g_iat_patch_set_cursor.Pointer()->is_patched()) |
445 g_iat_patch_set_cursor.Pointer()->Unpatch(); | 440 g_iat_patch_set_cursor.Pointer()->Unpatch(); |
446 | 441 |
447 if (g_iat_patch_track_popup_menu.Pointer()->is_patched()) | 442 if (g_iat_patch_track_popup_menu.Pointer()->is_patched()) |
448 g_iat_patch_track_popup_menu.Pointer()->Unpatch(); | 443 g_iat_patch_track_popup_menu.Pointer()->Unpatch(); |
449 | 444 |
450 if (g_iat_patch_reg_enum_key_ex_w.Pointer()->is_patched()) | 445 if (g_iat_patch_reg_enum_key_ex_w.Pointer()->is_patched()) |
451 g_iat_patch_reg_enum_key_ex_w.Pointer()->Unpatch(); | 446 g_iat_patch_reg_enum_key_ex_w.Pointer()->Unpatch(); |
452 | 447 |
453 #if defined(USE_AURA) | |
454 if (g_iat_patch_window_from_point.Pointer()->is_patched()) | 448 if (g_iat_patch_window_from_point.Pointer()->is_patched()) |
455 g_iat_patch_window_from_point.Pointer()->Unpatch(); | 449 g_iat_patch_window_from_point.Pointer()->Unpatch(); |
456 #endif | |
457 | 450 |
458 if (mouse_hook_) { | 451 if (mouse_hook_) { |
459 UnhookWindowsHookEx(mouse_hook_); | 452 UnhookWindowsHookEx(mouse_hook_); |
460 mouse_hook_ = NULL; | 453 mouse_hook_ = NULL; |
461 } | 454 } |
462 } | 455 } |
463 | 456 |
464 void WebPluginDelegateImpl::Paint(SkCanvas* canvas, const gfx::Rect& rect) { | 457 void WebPluginDelegateImpl::Paint(SkCanvas* canvas, const gfx::Rect& rect) { |
465 if (windowless_ && skia::SupportsPlatformPaint(canvas)) { | 458 if (windowless_ && skia::SupportsPlatformPaint(canvas)) { |
466 skia::ScopedPlatformPaint scoped_platform_paint(canvas); | 459 skia::ScopedPlatformPaint scoped_platform_paint(canvas); |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 | 1480 |
1488 // static | 1481 // static |
1489 FARPROC WINAPI WebPluginDelegateImpl::GetProcAddressPatch(HMODULE module, | 1482 FARPROC WINAPI WebPluginDelegateImpl::GetProcAddressPatch(HMODULE module, |
1490 LPCSTR name) { | 1483 LPCSTR name) { |
1491 FARPROC imm_function = WebPluginIMEWin::GetProcAddress(name); | 1484 FARPROC imm_function = WebPluginIMEWin::GetProcAddress(name); |
1492 if (imm_function) | 1485 if (imm_function) |
1493 return imm_function; | 1486 return imm_function; |
1494 return ::GetProcAddress(module, name); | 1487 return ::GetProcAddress(module, name); |
1495 } | 1488 } |
1496 | 1489 |
1497 #if defined(USE_AURA) | |
1498 HWND WINAPI WebPluginDelegateImpl::WindowFromPointPatch(POINT point) { | 1490 HWND WINAPI WebPluginDelegateImpl::WindowFromPointPatch(POINT point) { |
1499 HWND window = WindowFromPoint(point); | 1491 HWND window = WindowFromPoint(point); |
1500 if (::ScreenToClient(window, &point)) { | 1492 if (::ScreenToClient(window, &point)) { |
1501 HWND child = ChildWindowFromPoint(window, point); | 1493 HWND child = ChildWindowFromPoint(window, point); |
1502 if (::IsWindow(child) && | 1494 if (::IsWindow(child) && |
1503 ::GetProp(child, content::kPluginDummyParentProperty)) | 1495 ::GetProp(child, content::kPluginDummyParentProperty)) |
1504 return child; | 1496 return child; |
1505 } | 1497 } |
1506 return window; | 1498 return window; |
1507 } | 1499 } |
1508 #endif | |
1509 | 1500 |
1510 void WebPluginDelegateImpl::HandleCaptureForMessage(HWND window, | 1501 void WebPluginDelegateImpl::HandleCaptureForMessage(HWND window, |
1511 UINT message) { | 1502 UINT message) { |
1512 if (gfx::GetClassName(window) != base::string16(kNativeWindowClassName)) | 1503 if (gfx::GetClassName(window) != base::string16(kNativeWindowClassName)) |
1513 return; | 1504 return; |
1514 | 1505 |
1515 switch (message) { | 1506 switch (message) { |
1516 case WM_LBUTTONDOWN: | 1507 case WM_LBUTTONDOWN: |
1517 case WM_MBUTTONDOWN: | 1508 case WM_MBUTTONDOWN: |
1518 case WM_RBUTTONDOWN: | 1509 case WM_RBUTTONDOWN: |
(...skipping 11 matching lines...) Expand all Loading... |
1530 case WM_RBUTTONUP: | 1521 case WM_RBUTTONUP: |
1531 ::ReleaseCapture(); | 1522 ::ReleaseCapture(); |
1532 break; | 1523 break; |
1533 | 1524 |
1534 default: | 1525 default: |
1535 break; | 1526 break; |
1536 } | 1527 } |
1537 } | 1528 } |
1538 | 1529 |
1539 } // namespace content | 1530 } // namespace content |
OLD | NEW |