Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: plugin/cross/o3d_glue.cc

Issue 149130: In preparation for becoming an internal plugin in chrome I did these things:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2009, Google Inc. 2 * Copyright 2009, Google Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 #ifdef OS_LINUX 160 #ifdef OS_LINUX
161 memset(got_double_click_, 0, sizeof(got_double_click_)); 161 memset(got_double_click_, 0, sizeof(got_double_click_));
162 #endif 162 #endif
163 163
164 // create an O3D object 164 // create an O3D object
165 client_ = new Client(&service_locator_); 165 client_ = new Client(&service_locator_);
166 166
167 globals_npobject_ = glue::CreateStaticNPObject(npp); 167 globals_npobject_ = glue::CreateStaticNPObject(npp);
168 client_npobject_ = 168 client_npobject_ =
169 glue::namespace_o3d::class_Client::GetNPObject(npp, client_); 169 glue::namespace_o3d::class_Client::GetNPObject(npp, client_);
170 user_agent_ = GetUserAgent(npp); 170 user_agent_ = o3d::GetUserAgent(npp);
171 } 171 }
172 172
173 PluginObject::~PluginObject() { 173 PluginObject::~PluginObject() {
174 } 174 }
175 175
176 void PluginObject::Init(int argc, char* argn[], char* argv[]) { 176 void PluginObject::Init(int argc, char* argn[], char* argv[]) {
177 DCHECK(argc == 0 || (argn != NULL && argv != NULL)); 177 DCHECK(argc == 0 || (argn != NULL && argv != NULL));
178 features_ = new Features(&service_locator_); 178 features_ = new Features(&service_locator_);
179 179
180 std::string o3d_name("o3d_features"); 180 std::string o3d_name("o3d_features");
(...skipping 17 matching lines...) Expand all
198 o3d::NPObjectPtr<NPObject> np_plugin_ptr(this); 198 o3d::NPObjectPtr<NPObject> np_plugin_ptr(this);
199 np_v8_bridge_.SetGlobalProperty(o3d::String("plugin"), 199 np_v8_bridge_.SetGlobalProperty(o3d::String("plugin"),
200 np_plugin_ptr); 200 np_plugin_ptr);
201 } 201 }
202 202
203 void PluginObject::TearDown() { 203 void PluginObject::TearDown() {
204 #ifdef OS_WIN 204 #ifdef OS_WIN
205 ClearPluginProperty(hWnd_); 205 ClearPluginProperty(hWnd_);
206 #endif // OS_WIN 206 #endif // OS_WIN
207 #ifdef OS_MACOSX 207 #ifdef OS_MACOSX
208 ReleaseSafariBrowserWindow(mac_cocoa_window_); 208 o3d::ReleaseSafariBrowserWindow(mac_cocoa_window_);
209 #endif 209 #endif
210 UnmapAll(); 210 UnmapAll();
211 211
212 // Delete the StreamManager to cleanup any streams that are in midflight. 212 // Delete the StreamManager to cleanup any streams that are in midflight.
213 // This needs to happen here, before the client is deleted as the streams 213 // This needs to happen here, before the client is deleted as the streams
214 // could be holding references to FileRequest objects. 214 // could be holding references to FileRequest objects.
215 stream_manager_.reset(NULL); 215 stream_manager_.reset(NULL);
216 216
217 delete client_; 217 delete client_;
218 client_ = NULL; 218 client_ = NULL;
219 219
220 // Release the graphics context before deletion. 220 // Release the graphics context before deletion.
221 DeleteRenderer(); 221 DeleteRenderer();
222 222
223 delete features_; 223 delete features_;
224 features_ = NULL; 224 features_ = NULL;
225 225
226 // There is a reference cycle between the V8 bridge and the plugin. 226 // There is a reference cycle between the V8 bridge and the plugin.
227 // Explicitly remove all V8 references during tear-down, so that the cycle is 227 // Explicitly remove all V8 references during tear-down, so that the cycle is
228 // broken, and the reference counting system will successfully delete the 228 // broken, and the reference counting system will successfully delete the
229 // plugin. 229 // plugin.
230 np_v8_bridge_.ReleaseNPObjects(); 230 np_v8_bridge_.ReleaseNPObjects();
231 } 231 }
232 232
233 void PluginObject::CreateRenderer(const o3d::DisplayWindow& display_window) { 233 void PluginObject::CreateRenderer(const o3d::DisplayWindow& display_window) {
234 if (!CheckConfig(npp_)) { 234 if (!o3d::CheckConfig(npp_)) {
235 renderer_init_status_ = o3d::Renderer::GPU_NOT_UP_TO_SPEC; 235 renderer_init_status_ = o3d::Renderer::GPU_NOT_UP_TO_SPEC;
236 } else { 236 } else {
237 renderer_ = o3d::Renderer::CreateDefaultRenderer(&service_locator_); 237 renderer_ = o3d::Renderer::CreateDefaultRenderer(&service_locator_);
238 DCHECK(renderer_); 238 DCHECK(renderer_);
239 239
240 // Attempt to initialize renderer. 240 // Attempt to initialize renderer.
241 renderer_init_status_ = renderer_->Init(display_window, false); 241 renderer_init_status_ = renderer_->Init(display_window, false);
242 if (renderer_init_status_ != o3d::Renderer::SUCCESS) { 242 if (renderer_init_status_ != o3d::Renderer::SUCCESS) {
243 DeleteRenderer(); 243 DeleteRenderer();
244 } 244 }
(...skipping 27 matching lines...) Expand all
272 // from Safari (on other browsers this tab value should always be NULL). 272 // from Safari (on other browsers this tab value should always be NULL).
273 // Written so that last_mac_event_time_ is always valid or NULL. 273 // Written so that last_mac_event_time_ is always valid or NULL.
274 void PluginObject::MacEventReceived() { 274 void PluginObject::MacEventReceived() {
275 CFDateRef now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()); 275 CFDateRef now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
276 CFDateRef previousTime = last_mac_event_time_; 276 CFDateRef previousTime = last_mac_event_time_;
277 last_mac_event_time_ = now; 277 last_mac_event_time_ = now;
278 if (previousTime != NULL) { 278 if (previousTime != NULL) {
279 CFRelease(previousTime); 279 CFRelease(previousTime);
280 } 280 }
281 if (!mac_cocoa_window_) { 281 if (!mac_cocoa_window_) {
282 mac_cocoa_window_ = SafariBrowserWindowForWindowRef(mac_window_); 282 mac_cocoa_window_ = o3d::SafariBrowserWindowForWindowRef(mac_window_);
283 } 283 }
284 mac_window_selected_tab_ = 284 mac_window_selected_tab_ =
285 SelectedTabForSafariBrowserWindow(mac_cocoa_window_); 285 o3d::SelectedTabForSafariBrowserWindow(mac_cocoa_window_);
286 } 286 }
287 287
288 // Returns the time elapsed since the MacEventReceived function was last called. 288 // Returns the time elapsed since the MacEventReceived function was last called.
289 CFTimeInterval PluginObject::TimeSinceLastMacEvent() { 289 CFTimeInterval PluginObject::TimeSinceLastMacEvent() {
290 CFTimeInterval elapsed = 0.0; 290 CFTimeInterval elapsed = 0.0;
291 if (last_mac_event_time_ != NULL) { 291 if (last_mac_event_time_ != NULL) {
292 CFDateRef now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()); 292 CFDateRef now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
293 elapsed = CFDateGetTimeIntervalSinceDate(now, last_mac_event_time_); 293 elapsed = CFDateGetTimeIntervalSinceDate(now, last_mac_event_time_);
294 CFRelease(now); 294 CFRelease(now);
295 } 295 }
296 return elapsed; 296 return elapsed;
297 } 297 }
298 298
299 // Detects if Safari has hidden our tab. 299 // Detects if Safari has hidden our tab.
300 // The heuristic is that we have not received any Mac events for a certain time 300 // The heuristic is that we have not received any Mac events for a certain time
301 // and also the value for selected tab is different from the value it had the 301 // and also the value for selected tab is different from the value it had the
302 // last time we did get a Mac event. 302 // last time we did get a Mac event.
303 bool PluginObject::DetectTabHiding() { 303 bool PluginObject::DetectTabHiding() {
304 const CFTimeInterval kMacTimeOut = 0.2; // a fifth of a second 304 const CFTimeInterval kMacTimeOut = 0.2; // a fifth of a second
305 if (TimeSinceLastMacEvent() < kMacTimeOut) 305 if (TimeSinceLastMacEvent() < kMacTimeOut)
306 return false; 306 return false;
307 307
308 if (!mac_cocoa_window_) { 308 if (!mac_cocoa_window_) {
309 mac_cocoa_window_ = SafariBrowserWindowForWindowRef(mac_window_); 309 mac_cocoa_window_ = o3d::SafariBrowserWindowForWindowRef(mac_window_);
310 } 310 }
311 311
312 return SelectedTabForSafariBrowserWindow(mac_cocoa_window_) != 312 return o3d::SelectedTabForSafariBrowserWindow(mac_cocoa_window_) !=
313 mac_window_selected_tab_; 313 mac_window_selected_tab_;
314 } 314 }
315 315
316 316
317 // Pick a constant way out of Apple's 0-22 range for our "no theme cursor" 317 // Pick a constant way out of Apple's 0-22 range for our "no theme cursor"
318 // constant. 318 // constant.
319 const ThemeCursor kNoThemeCursorForThat = 1000; 319 const ThemeCursor kNoThemeCursorForThat = 1000;
320 320
321 // Map o3d cursors to Mac theme cursors if possible, otherwise return 321 // Map o3d cursors to Mac theme cursors if possible, otherwise return
322 // kNoThemeCursorForThat. 322 // kNoThemeCursorForThat.
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 543 }
544 544
545 static bool PluginGetProperty(NPObject *header, NPIdentifier name, 545 static bool PluginGetProperty(NPObject *header, NPIdentifier name,
546 NPVariant *variant) { 546 NPVariant *variant) {
547 DebugScopedId id(name); 547 DebugScopedId id(name);
548 PluginObject *plugin_object = static_cast<PluginObject *>(header); 548 PluginObject *plugin_object = static_cast<PluginObject *>(header);
549 NPP npp = plugin_object->npp(); 549 NPP npp = plugin_object->npp();
550 if (name == property_ids[PROP_GPU_CONFIG]) { 550 if (name == property_ids[PROP_GPU_CONFIG]) {
551 // Gets the GPU config (VendorID, DeviceID, name) as a string. 551 // Gets the GPU config (VendorID, DeviceID, name) as a string.
552 // NOTE: this should probably be removed before we ship. 552 // NOTE: this should probably be removed before we ship.
553 GPUDevice device; 553 o3d::GPUDevice device;
554 bool result = GetGPUDevice(npp, &device); 554 bool result = o3d::GetGPUDevice(npp, &device);
555 if (!result) return false; 555 if (!result) return false;
556 std::string return_value = std::string("VendorID = 0x"); 556 std::string return_value = std::string("VendorID = 0x");
557 char id_text[9]; 557 char id_text[9];
558 base::snprintf(id_text, sizeof(id_text), "%04x", device.vendor_id); 558 base::snprintf(id_text, sizeof(id_text), "%04x", device.vendor_id);
559 return_value += id_text; 559 return_value += id_text;
560 return_value += ", DeviceID = 0x"; 560 return_value += ", DeviceID = 0x";
561 base::snprintf(id_text, sizeof(id_text), "%04x", device.device_id); 561 base::snprintf(id_text, sizeof(id_text), "%04x", device.device_id);
562 return_value += id_text; 562 return_value += id_text;
563 return_value += ", DeviceName = '"; 563 return_value += ", DeviceName = '";
564 return_value += device.name + "'"; 564 return_value += device.name + "'";
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 PluginObject *plugin_object = static_cast<PluginObject *>(npp->pdata); 878 PluginObject *plugin_object = static_cast<PluginObject *>(npp->pdata);
879 if (plugin_object) { // May not be initialized yet. 879 if (plugin_object) { // May not be initialized yet.
880 return plugin_object->client()->ProfileToString(); 880 return plugin_object->client()->ProfileToString();
881 } else { 881 } else {
882 return ""; 882 return "";
883 } 883 }
884 } 884 }
885 885
886 } // namespace globals 886 } // namespace globals
887 } // namespace glue 887 } // namespace glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698