| 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 #if !defined(__LP64__) | 5 #if !defined(__LP64__) |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include "content/plugin/plugin_interpose_util_mac.h" | 9 #include "content/plugin/plugin_interpose_util_mac.h" |
| 10 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
| 11 #include "webkit/plugins/npapi/carbon_plugin_window_tracker_mac.h" | |
| 12 | 11 |
| 13 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | 12 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 14 | 13 |
| 15 #if defined(MAC_OS_X_VERSION_10_7) && \ | 14 #if defined(MAC_OS_X_VERSION_10_7) && \ |
| 16 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 | 15 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 |
| 17 // QuickdrawAPI.h is no longer included in the 10.7 SDK, but the symbols are | 16 // QuickdrawAPI.h is no longer included in the 10.7 SDK, but the symbols are |
| 18 // still exported by QD.framework (a subframework of ApplicationServices). | 17 // still exported by QD.framework (a subframework of ApplicationServices). |
| 19 // http://developer.apple.com/legacy/mac/library/documentation/Carbon/reference/
QuickDraw_Ref/QuickDraw_Ref.pdf | 18 // http://developer.apple.com/legacy/mac/library/documentation/Carbon/reference/
QuickDraw_Ref/QuickDraw_Ref.pdf |
| 20 extern "C" { | 19 extern "C" { |
| 21 Boolean PtInRect(Point pt, const Rect* r); | |
| 22 void SetCursor(const Cursor* crsr); | 20 void SetCursor(const Cursor* crsr); |
| 23 } | 21 } |
| 24 #endif // 10.7+ SDK | 22 #endif // 10.7+ SDK |
| 25 | 23 |
| 26 // Returns true if the given window is modal. | 24 // Returns true if the given window is modal. |
| 27 static bool IsModalWindow(WindowRef window) { | 25 static bool IsModalWindow(WindowRef window) { |
| 28 WindowModality modality = kWindowModalityNone; | 26 WindowModality modality = kWindowModalityNone; |
| 29 WindowRef modal_target = NULL; | 27 WindowRef modal_target = NULL; |
| 30 OSStatus status = GetWindowModality(window, &modality, &modal_target); | 28 OSStatus status = GetWindowModality(window, &modality, &modal_target); |
| 31 return (status == noErr) && (modality != kWindowModalityNone); | 29 return (status == noErr) && (modality != kWindowModalityNone); |
| 32 } | 30 } |
| 33 | 31 |
| 34 static bool IsContainingWindowActive(const OpaquePluginRef delegate) { | |
| 35 return mac_plugin_interposing::GetPluginWindowHasFocus(delegate); | |
| 36 } | |
| 37 | |
| 38 static CGRect CGRectForWindow(WindowRef window) { | 32 static CGRect CGRectForWindow(WindowRef window) { |
| 39 CGRect bounds = { { 0, 0 }, { 0, 0 } }; | 33 CGRect bounds = { { 0, 0 }, { 0, 0 } }; |
| 40 HIWindowGetBounds(window, kWindowContentRgn, kHICoordSpace72DPIGlobal, | 34 HIWindowGetBounds(window, kWindowContentRgn, kHICoordSpace72DPIGlobal, |
| 41 &bounds); | 35 &bounds); |
| 42 return bounds; | 36 return bounds; |
| 43 } | 37 } |
| 44 | 38 |
| 45 struct WindowInfo { | 39 struct WindowInfo { |
| 46 uint32 window_id; | 40 uint32 window_id; |
| 47 CGRect bounds; | 41 CGRect bounds; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 63 } | 57 } |
| 64 | 58 |
| 65 static void OnPluginWindowSelected(WindowRef window) { | 59 static void OnPluginWindowSelected(WindowRef window) { |
| 66 mac_plugin_interposing::NotifyBrowserOfPluginSelectWindow( | 60 mac_plugin_interposing::NotifyBrowserOfPluginSelectWindow( |
| 67 HIWindowGetCGWindowID(window), CGRectForWindow(window), | 61 HIWindowGetCGWindowID(window), CGRectForWindow(window), |
| 68 IsModalWindow(window)); | 62 IsModalWindow(window)); |
| 69 } | 63 } |
| 70 | 64 |
| 71 #pragma mark - | 65 #pragma mark - |
| 72 | 66 |
| 73 static Boolean ChromePluginIsWindowActive(WindowRef window) { | |
| 74 const OpaquePluginRef delegate = | |
| 75 webkit::npapi::CarbonPluginWindowTracker::SharedInstance()-> | |
| 76 GetDelegateForDummyWindow(window); | |
| 77 return delegate ? IsContainingWindowActive(delegate) | |
| 78 : IsWindowActive(window); | |
| 79 } | |
| 80 | |
| 81 static Boolean ChromePluginIsWindowHilited(WindowRef window) { | |
| 82 const OpaquePluginRef delegate = | |
| 83 webkit::npapi::CarbonPluginWindowTracker::SharedInstance()-> | |
| 84 GetDelegateForDummyWindow(window); | |
| 85 return delegate ? IsContainingWindowActive(delegate) | |
| 86 : IsWindowHilited(window); | |
| 87 } | |
| 88 | |
| 89 static void ChromePluginSelectWindow(WindowRef window) { | 67 static void ChromePluginSelectWindow(WindowRef window) { |
| 90 mac_plugin_interposing::SwitchToPluginProcess(); | 68 mac_plugin_interposing::SwitchToPluginProcess(); |
| 91 SelectWindow(window); | 69 SelectWindow(window); |
| 92 OnPluginWindowSelected(window); | 70 OnPluginWindowSelected(window); |
| 93 } | 71 } |
| 94 | 72 |
| 95 static void ChromePluginShowWindow(WindowRef window) { | 73 static void ChromePluginShowWindow(WindowRef window) { |
| 96 mac_plugin_interposing::SwitchToPluginProcess(); | 74 mac_plugin_interposing::SwitchToPluginProcess(); |
| 97 ShowWindow(window); | 75 ShowWindow(window); |
| 98 OnPluginWindowShown(window); | 76 OnPluginWindowShown(window); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 128 OnPluginWindowClosed(window_info); | 106 OnPluginWindowClosed(window_info); |
| 129 } | 107 } |
| 130 | 108 |
| 131 static void ChromePluginDisposeDialog(DialogRef dialog) { | 109 static void ChromePluginDisposeDialog(DialogRef dialog) { |
| 132 WindowRef window = GetDialogWindow(dialog); | 110 WindowRef window = GetDialogWindow(dialog); |
| 133 WindowInfo window_info(window); | 111 WindowInfo window_info(window); |
| 134 DisposeDialog(dialog); | 112 DisposeDialog(dialog); |
| 135 OnPluginWindowClosed(window_info); | 113 OnPluginWindowClosed(window_info); |
| 136 } | 114 } |
| 137 | 115 |
| 138 static WindowPartCode ChromePluginFindWindow(Point point, WindowRef* window) { | |
| 139 OpaquePluginRef delegate = mac_plugin_interposing::GetActiveDelegate(); | |
| 140 webkit::npapi::CarbonPluginWindowTracker* tracker = | |
| 141 webkit::npapi::CarbonPluginWindowTracker::SharedInstance(); | |
| 142 WindowRef plugin_window = tracker->GetDummyWindowForDelegate(delegate); | |
| 143 if (plugin_window) { | |
| 144 // If plugin_window is non-NULL, then we are in the middle of routing an | |
| 145 // event to the plugin, so we know it's destined for this window already, | |
| 146 // so we don't have to worry that we'll be stealing an event meant for an | |
| 147 // overlapping window. | |
| 148 Rect window_bounds; | |
| 149 GetWindowBounds(plugin_window, kWindowContentRgn, &window_bounds); | |
| 150 if (PtInRect(point, &window_bounds)) { | |
| 151 if (window) | |
| 152 *window = plugin_window; | |
| 153 return inContent; | |
| 154 } | |
| 155 } | |
| 156 return FindWindow(point, window); | |
| 157 } | |
| 158 | |
| 159 static OSStatus ChromePluginSetThemeCursor(ThemeCursor cursor) { | 116 static OSStatus ChromePluginSetThemeCursor(ThemeCursor cursor) { |
| 160 OpaquePluginRef delegate = mac_plugin_interposing::GetActiveDelegate(); | 117 OpaquePluginRef delegate = mac_plugin_interposing::GetActiveDelegate(); |
| 161 if (delegate) { | 118 if (delegate) { |
| 162 mac_plugin_interposing::NotifyPluginOfSetThemeCursor(delegate, cursor); | 119 mac_plugin_interposing::NotifyPluginOfSetThemeCursor(delegate, cursor); |
| 163 return noErr; | 120 return noErr; |
| 164 } | 121 } |
| 165 return SetThemeCursor(cursor); | 122 return SetThemeCursor(cursor); |
| 166 } | 123 } |
| 167 | 124 |
| 168 static void ChromePluginSetCursor(const Cursor* cursor) { | 125 static void ChromePluginSetCursor(const Cursor* cursor) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 180 const void* replacement; | 137 const void* replacement; |
| 181 const void* original; | 138 const void* original; |
| 182 }; | 139 }; |
| 183 | 140 |
| 184 #define INTERPOSE_FUNCTION(function) \ | 141 #define INTERPOSE_FUNCTION(function) \ |
| 185 { reinterpret_cast<const void*>(ChromePlugin##function), \ | 142 { reinterpret_cast<const void*>(ChromePlugin##function), \ |
| 186 reinterpret_cast<const void*>(function) } | 143 reinterpret_cast<const void*>(function) } |
| 187 | 144 |
| 188 __attribute__((used)) static const interpose_substitution substitutions[] | 145 __attribute__((used)) static const interpose_substitution substitutions[] |
| 189 __attribute__((section("__DATA, __interpose"))) = { | 146 __attribute__((section("__DATA, __interpose"))) = { |
| 190 INTERPOSE_FUNCTION(IsWindowActive), | |
| 191 INTERPOSE_FUNCTION(IsWindowHilited), | |
| 192 INTERPOSE_FUNCTION(SelectWindow), | 147 INTERPOSE_FUNCTION(SelectWindow), |
| 193 INTERPOSE_FUNCTION(ShowWindow), | 148 INTERPOSE_FUNCTION(ShowWindow), |
| 194 INTERPOSE_FUNCTION(ShowHide), | 149 INTERPOSE_FUNCTION(ShowHide), |
| 195 INTERPOSE_FUNCTION(DisposeWindow), | 150 INTERPOSE_FUNCTION(DisposeWindow), |
| 196 INTERPOSE_FUNCTION(HideWindow), | 151 INTERPOSE_FUNCTION(HideWindow), |
| 197 INTERPOSE_FUNCTION(ReleaseWindow), | 152 INTERPOSE_FUNCTION(ReleaseWindow), |
| 198 INTERPOSE_FUNCTION(DisposeDialog), | 153 INTERPOSE_FUNCTION(DisposeDialog), |
| 199 INTERPOSE_FUNCTION(FindWindow), | |
| 200 INTERPOSE_FUNCTION(SetThemeCursor), | 154 INTERPOSE_FUNCTION(SetThemeCursor), |
| 201 INTERPOSE_FUNCTION(SetCursor), | 155 INTERPOSE_FUNCTION(SetCursor), |
| 202 }; | 156 }; |
| 203 | 157 |
| 204 #endif // !__LP64__ | 158 #endif // !__LP64__ |
| OLD | NEW |