OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 #include "webkit/glue/plugins/fake_plugin_window_tracker_mac.h" |
| 7 |
| 8 FakePluginWindowTracker::FakePluginWindowTracker() |
| 9 : window_to_delegate_map_(CFDictionaryCreateMutable(kCFAllocatorDefault, |
| 10 0, NULL, NULL)) { |
| 11 } |
| 12 |
| 13 FakePluginWindowTracker* FakePluginWindowTracker::SharedInstance() { |
| 14 static FakePluginWindowTracker* tracker = new FakePluginWindowTracker(); |
| 15 return tracker; |
| 16 } |
| 17 |
| 18 WindowRef FakePluginWindowTracker::GenerateFakeWindowForDelegate( |
| 19 WebPluginDelegateImpl* delegate) { |
| 20 // TODO(stuartmorgan): Eventually we will be interposing enough that we don't |
| 21 // even need a window, and can just use made-up identifiers, but for now we |
| 22 // create one so that things that we don't interpose won't crash trying to use |
| 23 // a bad WindowRef. |
| 24 |
| 25 // The real size will be set by the plugin instance, once that size is known. |
| 26 Rect window_bounds = { 0, 0, 100, 100 }; |
| 27 WindowRef new_ref = NULL; |
| 28 if (CreateNewWindow(kDocumentWindowClass, |
| 29 kWindowStandardDocumentAttributes, |
| 30 &window_bounds, |
| 31 &new_ref) == noErr) { |
| 32 CFDictionaryAddValue(window_to_delegate_map_, new_ref, delegate); |
| 33 } |
| 34 return new_ref; |
| 35 } |
| 36 |
| 37 const WebPluginDelegateImpl* FakePluginWindowTracker::GetDelegateForFakeWindow( |
| 38 WindowRef window) const { |
| 39 return static_cast<const WebPluginDelegateImpl*>( |
| 40 CFDictionaryGetValue(window_to_delegate_map_, window)); |
| 41 } |
| 42 |
| 43 void FakePluginWindowTracker::RemoveFakeWindowForDelegate( |
| 44 WebPluginDelegateImpl* delegate, WindowRef window) { |
| 45 DCHECK(GetDelegateForFakeWindow(window) == delegate); |
| 46 CFDictionaryRemoveValue(window_to_delegate_map_, delegate); |
| 47 if (window) // Check just in case the initial window creation failed. |
| 48 DisposeWindow(window); |
| 49 } |
OLD | NEW |