| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <Carbon/Carbon.h> | 5 #include <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #include "base/gfx/rect.h" |
| 7 #include "webkit/glue/plugins/fake_plugin_window_tracker_mac.h" | 8 #include "webkit/glue/plugins/fake_plugin_window_tracker_mac.h" |
| 8 | 9 |
| 10 namespace webkit_glue { |
| 11 |
| 12 void NotifyBrowserOfPluginSelectWindow(uint32 window_id, CGRect bounds); |
| 13 void NotifyBrowserOfPluginShowWindow(uint32 window_id, CGRect bounds); |
| 14 void NotifyBrowserOfPluginHideWindow(uint32 window_id, CGRect bounds); |
| 15 void NotifyBrowserOfPluginDisposeWindow(uint32 window_id, CGRect bounds); |
| 16 |
| 17 } |
| 18 |
| 9 // The process that was frontmost when a plugin created a new window; generally | 19 // The process that was frontmost when a plugin created a new window; generally |
| 10 // we expect this to be the browser UI process. | 20 // we expect this to be the browser UI process. |
| 11 static ProcessSerialNumber g_saved_front_process = { 0, 0 }; | 21 static ProcessSerialNumber g_saved_front_process = { 0, 0 }; |
| 12 | 22 |
| 13 // Bring the plugin process to the front so that the user can see it. | 23 // Bring the plugin process to the front so that the user can see it. |
| 14 // TODO: Make this an IPC to order the plugin process above the browser | 24 // TODO: Make this an IPC to order the plugin process above the browser |
| 15 // process but not necessarily the frontmost. | 25 // process but not necessarily the frontmost. |
| 16 static void SwitchToPluginProcess() { | 26 static void SwitchToPluginProcess() { |
| 17 ProcessSerialNumber this_process, front_process; | 27 ProcessSerialNumber this_process, front_process; |
| 18 if (GetCurrentProcess(&this_process) != noErr) | 28 if (GetCurrentProcess(&this_process) != noErr) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // which would be false) means that clicking works, but it's not correct | 67 // which would be false) means that clicking works, but it's not correct |
| 58 // either. Ideally we need a way to find out if the delegate corresponds | 68 // either. Ideally we need a way to find out if the delegate corresponds |
| 59 // to a browser window that is active. | 69 // to a browser window that is active. |
| 60 const WebPluginDelegateImpl* delegate = | 70 const WebPluginDelegateImpl* delegate = |
| 61 FakePluginWindowTracker::SharedInstance()->GetDelegateForFakeWindow( | 71 FakePluginWindowTracker::SharedInstance()->GetDelegateForFakeWindow( |
| 62 window); | 72 window); |
| 63 Boolean isHilited = delegate ? true : IsWindowHilited(window); | 73 Boolean isHilited = delegate ? true : IsWindowHilited(window); |
| 64 return isHilited; | 74 return isHilited; |
| 65 } | 75 } |
| 66 | 76 |
| 77 static CGRect CGRectForWindow(WindowRef window) { |
| 78 CGRect bounds = { { 0, 0 }, { 0, 0 } }; |
| 79 HIWindowGetBounds(window, kWindowContentRgn, kHICoordSpace72DPIGlobal, |
| 80 &bounds); |
| 81 return bounds; |
| 82 } |
| 83 |
| 67 static void ChromePluginSelectWindow(WindowRef window) { | 84 static void ChromePluginSelectWindow(WindowRef window) { |
| 68 SwitchToPluginProcess(); | 85 SwitchToPluginProcess(); |
| 69 SelectWindow(window); | 86 SelectWindow(window); |
| 87 webkit_glue::NotifyBrowserOfPluginSelectWindow(HIWindowGetCGWindowID(window), |
| 88 CGRectForWindow(window)); |
| 70 } | 89 } |
| 71 | 90 |
| 72 static void ChromePluginShowWindow(WindowRef window) { | 91 static void ChromePluginShowWindow(WindowRef window) { |
| 73 SwitchToPluginProcess(); | 92 SwitchToPluginProcess(); |
| 74 ShowWindow(window); | 93 ShowWindow(window); |
| 94 webkit_glue::NotifyBrowserOfPluginShowWindow(HIWindowGetCGWindowID(window), |
| 95 CGRectForWindow(window)); |
| 75 } | 96 } |
| 76 | 97 |
| 77 static void ChromePluginDisposeWindow(WindowRef window) { | 98 static void ChromePluginDisposeWindow(WindowRef window) { |
| 78 SwitchToSavedProcess(); | 99 SwitchToSavedProcess(); |
| 100 webkit_glue::NotifyBrowserOfPluginDisposeWindow(HIWindowGetCGWindowID(window), |
| 101 CGRectForWindow(window)); |
| 79 DisposeWindow(window); | 102 DisposeWindow(window); |
| 80 } | 103 } |
| 81 | 104 |
| 82 static void ChromePluginHideWindow(WindowRef window) { | 105 static void ChromePluginHideWindow(WindowRef window) { |
| 83 SwitchToSavedProcess(); | 106 SwitchToSavedProcess(); |
| 107 webkit_glue::NotifyBrowserOfPluginHideWindow(HIWindowGetCGWindowID(window), |
| 108 CGRectForWindow(window)); |
| 84 HideWindow(window); | 109 HideWindow(window); |
| 85 } | 110 } |
| 86 | 111 |
| 87 #pragma mark - | 112 #pragma mark - |
| 88 | 113 |
| 89 struct interpose_substitution { | 114 struct interpose_substitution { |
| 90 const void* replacement; | 115 const void* replacement; |
| 91 const void* original; | 116 const void* original; |
| 92 }; | 117 }; |
| 93 | 118 |
| 94 #define INTERPOSE_FUNCTION(function) \ | 119 #define INTERPOSE_FUNCTION(function) \ |
| 95 { reinterpret_cast<const void*>(ChromePlugin##function), \ | 120 { reinterpret_cast<const void*>(ChromePlugin##function), \ |
| 96 reinterpret_cast<const void*>(function) } | 121 reinterpret_cast<const void*>(function) } |
| 97 | 122 |
| 98 __attribute__((used)) static const interpose_substitution substitutions[] | 123 __attribute__((used)) static const interpose_substitution substitutions[] |
| 99 __attribute__((section("__DATA, __interpose"))) = { | 124 __attribute__((section("__DATA, __interpose"))) = { |
| 100 INTERPOSE_FUNCTION(IsWindowHilited), | 125 INTERPOSE_FUNCTION(IsWindowHilited), |
| 101 INTERPOSE_FUNCTION(SelectWindow), | 126 INTERPOSE_FUNCTION(SelectWindow), |
| 102 INTERPOSE_FUNCTION(ShowWindow), | 127 INTERPOSE_FUNCTION(ShowWindow), |
| 103 INTERPOSE_FUNCTION(DisposeWindow), | 128 INTERPOSE_FUNCTION(DisposeWindow), |
| 104 INTERPOSE_FUNCTION(HideWindow), | 129 INTERPOSE_FUNCTION(HideWindow), |
| 105 }; | 130 }; |
| OLD | NEW |