| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "PluginTest.h" | 5 #include "PluginTest.h" |
| 6 | 6 |
| 7 using namespace std; | 7 using namespace std; |
| 8 | 8 |
| 9 class LeakWindowScriptableObject : public PluginTest { | 9 class LeakWindowScriptableObject : public PluginTest { |
| 10 public: | 10 public: |
| 11 LeakWindowScriptableObject(NPP npp, const string& identifier) | 11 LeakWindowScriptableObject(NPP npp, const string& identifier) |
| 12 : PluginTest(npp, identifier) | 12 : PluginTest(npp, identifier) |
| 13 { | 13 { |
| 14 } | 14 } |
| 15 | 15 |
| 16 private: | 16 private: |
| 17 virtual NPError NPP_New(NPMIMEType pluginType, | 17 virtual NPError NPP_New(NPMIMEType pluginType, |
| 18 uint16_t mode, | 18 uint16_t mode, |
| 19 int16_t argc, | 19 int16_t argc, |
| 20 char* argn[], | 20 char* argn[], |
| 21 char* argv[], | 21 char* argv[], |
| 22 NPSavedData* saved) OVERRIDE { | 22 NPSavedData* saved) override { |
| 23 // Get a new reference to the window script object. | 23 // Get a new reference to the window script object. |
| 24 NPObject* window; | 24 NPObject* window; |
| 25 if (NPN_GetValue(NPNVWindowNPObject, &window) != NPERR_NO_ERROR) { | 25 if (NPN_GetValue(NPNVWindowNPObject, &window) != NPERR_NO_ERROR) { |
| 26 log("Fail: Cannot fetch window script object"); | 26 log("Fail: Cannot fetch window script object"); |
| 27 return NPERR_NO_ERROR; | 27 return NPERR_NO_ERROR; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // Get another reference to the same object via window.self. | 30 // Get another reference to the same object via window.self. |
| 31 NPIdentifier self_name = NPN_GetStringIdentifier("self"); | 31 NPIdentifier self_name = NPN_GetStringIdentifier("self"); |
| 32 NPVariant window_self_variant; | 32 NPVariant window_self_variant; |
| 33 if (!NPN_GetProperty(window, self_name, &window_self_variant)) { | 33 if (!NPN_GetProperty(window, self_name, &window_self_variant)) { |
| 34 log("Fail: Cannot query window.self"); | 34 log("Fail: Cannot query window.self"); |
| 35 return NPERR_NO_ERROR; | 35 return NPERR_NO_ERROR; |
| 36 } | 36 } |
| 37 if (!NPVARIANT_IS_OBJECT(window_self_variant)) { | 37 if (!NPVARIANT_IS_OBJECT(window_self_variant)) { |
| 38 log("Fail: window.self is not an object"); | 38 log("Fail: window.self is not an object"); |
| 39 return NPERR_NO_ERROR; | 39 return NPERR_NO_ERROR; |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Leak both references to the window script object. | 42 // Leak both references to the window script object. |
| 43 return NPERR_NO_ERROR; | 43 return NPERR_NO_ERROR; |
| 44 } | 44 } |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 static PluginTest::Register<LeakWindowScriptableObject> leakWindowScriptableObje
ct("leak-window-scriptable-object"); | 47 static PluginTest::Register<LeakWindowScriptableObject> leakWindowScriptableObje
ct("leak-window-scriptable-object"); |
| OLD | NEW |