| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/plugins/npapi/test/plugin_get_javascript_url_test.h" | 5 #include "webkit/plugins/npapi/test/plugin_get_javascript_url_test.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 // url for "self". | 10 // url for "self". |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 const int kNPNEvaluateTimerID = 100; | 21 const int kNPNEvaluateTimerID = 100; |
| 22 const int kNPNEvaluateTimerElapse = 50; | 22 const int kNPNEvaluateTimerElapse = 50; |
| 23 | 23 |
| 24 | 24 |
| 25 namespace NPAPIClient { | 25 namespace NPAPIClient { |
| 26 | 26 |
| 27 ExecuteGetJavascriptUrlTest::ExecuteGetJavascriptUrlTest( | 27 ExecuteGetJavascriptUrlTest::ExecuteGetJavascriptUrlTest( |
| 28 NPP id, NPNetscapeFuncs *host_functions) | 28 NPP id, NPNetscapeFuncs *host_functions) |
| 29 : PluginTest(id, host_functions), | 29 : PluginTest(id, host_functions), |
| 30 test_started_(false), | 30 test_started_(false), |
| 31 #ifdef OS_WIN | 31 #if defined(OS_WIN) |
| 32 window_(NULL), | 32 window_(NULL), |
| 33 #endif | 33 #endif |
| 34 npn_evaluate_context_(false) { | 34 npn_evaluate_context_(false) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 NPError ExecuteGetJavascriptUrlTest::SetWindow(NPWindow* pNPWindow) { | 37 NPError ExecuteGetJavascriptUrlTest::SetWindow(NPWindow* pNPWindow) { |
| 38 #if !defined(OS_MACOSX) | 38 #if !defined(OS_MACOSX) |
| 39 if (pNPWindow->window == NULL) | 39 if (pNPWindow->window == NULL) |
| 40 return NPERR_NO_ERROR; | 40 return NPERR_NO_ERROR; |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 if (!test_started_) { | 43 if (!test_started_) { |
| 44 std::string url = SELF_URL; | 44 std::string url = SELF_URL; |
| 45 HostFunctions()->geturlnotify(id(), url.c_str(), "_top", | 45 HostFunctions()->geturlnotify(id(), url.c_str(), "_top", |
| 46 reinterpret_cast<void*>(SELF_URL_STREAM_ID)); | 46 reinterpret_cast<void*>(SELF_URL_STREAM_ID)); |
| 47 test_started_ = true; | 47 test_started_ = true; |
| 48 | 48 |
| 49 #ifdef OS_WIN | 49 #if defined(OS_WIN) |
| 50 HWND window_handle = reinterpret_cast<HWND>(pNPWindow->window); | 50 HWND window_handle = reinterpret_cast<HWND>(pNPWindow->window); |
| 51 if (!::GetProp(window_handle, L"Plugin_Instance")) { | 51 if (!::GetProp(window_handle, L"Plugin_Instance")) { |
| 52 // TODO: this propery leaks. | 52 // TODO: this propery leaks. |
| 53 ::SetProp(window_handle, L"Plugin_Instance", this); | 53 ::SetProp(window_handle, L"Plugin_Instance", this); |
| 54 // We attempt to retreive the NPObject for the plugin instance identified | 54 // We attempt to retreive the NPObject for the plugin instance identified |
| 55 // by the NPObjectLifetimeTestInstance2 class as it may not have been | 55 // by the NPObjectLifetimeTestInstance2 class as it may not have been |
| 56 // instantiated yet. | 56 // instantiated yet. |
| 57 SetTimer(window_handle, kNPNEvaluateTimerID, kNPNEvaluateTimerElapse, | 57 SetTimer(window_handle, kNPNEvaluateTimerID, kNPNEvaluateTimerElapse, |
| 58 TimerProc); | 58 TimerProc); |
| 59 } | 59 } |
| 60 window_ = window_handle; | 60 window_ = window_handle; |
| 61 #endif | 61 #endif |
| 62 } | 62 } |
| 63 | 63 |
| 64 return NPERR_NO_ERROR; | 64 return NPERR_NO_ERROR; |
| 65 } | 65 } |
| 66 | 66 |
| 67 #ifdef OS_WIN | 67 #if defined(OS_WIN) |
| 68 void CALLBACK ExecuteGetJavascriptUrlTest::TimerProc( | 68 void CALLBACK ExecuteGetJavascriptUrlTest::TimerProc( |
| 69 HWND window, UINT message, UINT_PTR timer_id, DWORD elapsed_time) { | 69 HWND window, UINT message, UINT_PTR timer_id, DWORD elapsed_time) { |
| 70 ExecuteGetJavascriptUrlTest* this_instance = | 70 ExecuteGetJavascriptUrlTest* this_instance = |
| 71 reinterpret_cast<ExecuteGetJavascriptUrlTest*> | 71 reinterpret_cast<ExecuteGetJavascriptUrlTest*> |
| 72 (::GetProp(window, L"Plugin_Instance")); | 72 (::GetProp(window, L"Plugin_Instance")); |
| 73 CHECK(this_instance); | 73 CHECK(this_instance); |
| 74 | 74 |
| 75 ::RemoveProp(window, L"Plugin_Instance"); | 75 ::RemoveProp(window, L"Plugin_Instance"); |
| 76 | 76 |
| 77 NPObject *window_obj = NULL; | 77 NPObject *window_obj = NULL; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 |
| 167 NPError ExecuteGetJavascriptUrlTest::DestroyStream(NPStream *stream, | 167 NPError ExecuteGetJavascriptUrlTest::DestroyStream(NPStream *stream, |
| 168 NPError reason) { | 168 NPError reason) { |
| 169 if (stream == NULL) { | 169 if (stream == NULL) { |
| 170 SetError("NewStream got null stream"); | 170 SetError("NewStream got null stream"); |
| 171 return NPERR_INVALID_PARAM; | 171 return NPERR_INVALID_PARAM; |
| 172 } | 172 } |
| 173 | 173 |
| 174 #ifdef OS_WIN | 174 #if defined(OS_WIN) |
| 175 KillTimer(window_, kNPNEvaluateTimerID); | 175 KillTimer(window_, kNPNEvaluateTimerID); |
| 176 #endif | 176 #endif |
| 177 | 177 |
| 178 if (npn_evaluate_context_) { | 178 if (npn_evaluate_context_) { |
| 179 SetError("DestroyStream received in context of NPN_Evaluate"); | 179 SetError("DestroyStream received in context of NPN_Evaluate"); |
| 180 return NPERR_NO_ERROR; | 180 return NPERR_NO_ERROR; |
| 181 } | 181 } |
| 182 | 182 |
| 183 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), | 183 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 184 cast_validity_check); | 184 cast_validity_check); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 213 SetError("Failed to obtain window location."); | 213 SetError("Failed to obtain window location."); |
| 214 SignalTestCompleted(); | 214 SignalTestCompleted(); |
| 215 break; | 215 break; |
| 216 default: | 216 default: |
| 217 SetError("Unexpected NewStream callback"); | 217 SetError("Unexpected NewStream callback"); |
| 218 break; | 218 break; |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // namespace NPAPIClient | 222 } // namespace NPAPIClient |
| OLD | NEW |