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