Add idl version of ppb_flash_menu.idl

See CR=11013017

Convert .h to .idl

[email protected]
BUG=None


Review URL: https://chromiumcodereview.appspot.com/11446066

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172932 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ppapi/api/private/finish_writing_these/ppb_flash_menu.idl b/ppapi/api/private/finish_writing_these/ppb_flash_menu.idl
deleted file mode 100644
index 85149ad..0000000
--- a/ppapi/api/private/finish_writing_these/ppb_flash_menu.idl
+++ /dev/null
@@ -1,52 +0,0 @@
-/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* PPB_Flash */
-
-/* Menu item type.
- *
- * TODO(viettrungluu): Radio items not supported yet. Will also probably want
- * special menu items tied to clipboard access.
- */
-enum PP_Flash_MenuItem_Type {
-  PP_FLASH_MENUITEM_TYPE_NORMAL    = 0,
-  PP_FLASH_MENUITEM_TYPE_CHECKBOX  = 1,
-  PP_FLASH_MENUITEM_TYPE_SEPARATOR = 2,
-  PP_FLASH_MENUITEM_TYPE_SUBMENU   = 3
-};
-
-struct PP_Flash_MenuItem {
-  PP_Flash_MenuItem_Type type;
-  str_t name;
-  int32_t id;
-  PP_Bool enabled;
-  PP_Bool checked;
-  PP_Flash_Menu submenu;
-};
-
-struct PP_Flash_Menu {
-  uint32_t count;
-  [size_is(count)] PP_Flash_MenuItem[] items;
-};
-
-interface PPB_Flash_Menu_0_1 {
-  PP_Resource Create(
-      [in] PP_Instance instance_id,
-      [in] PP_Flash_Menu menu_data);
-
-  PP_Bool IsFlashMenu(
-      [in] PP_Resource resource_id);
-
-  /* Display a context menu at the given location. If the user selects an item,
-   * |selected_id| will be set to its |id| and the callback called with |PP_OK|.
-   * If the user dismisses the menu without selecting an item,
-   * |PP_ERROR_USERCANCEL| will be indicated.
-   */
-  int32_t Show(
-      [in] PP_Resource menu_id,
-      [in] PP_Point location,
-      [out] int32_t selected_id,
-      [in] PP_CompletionCallback callback);
-};
diff --git a/ppapi/api/private/ppb_flash_menu.idl b/ppapi/api/private/ppb_flash_menu.idl
new file mode 100644
index 0000000..253d8bd
--- /dev/null
+++ b/ppapi/api/private/ppb_flash_menu.idl
@@ -0,0 +1,54 @@
+/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * This file defines the <code>PPB_Flash_Menu</code> interface.
+ */
+label Chrome {
+  M14 = 0.2
+};
+
+/* Menu item type.
+ *
+ * TODO(viettrungluu): Radio items not supported yet. Will also probably want
+ * special menu items tied to clipboard access.
+ */
+[assert_size(4)]
+enum PP_Flash_MenuItem_Type {
+  PP_FLASH_MENUITEM_TYPE_NORMAL = 0,
+  PP_FLASH_MENUITEM_TYPE_CHECKBOX = 1,
+  PP_FLASH_MENUITEM_TYPE_SEPARATOR = 2,
+  PP_FLASH_MENUITEM_TYPE_SUBMENU = 3
+};
+
+struct PP_Flash_MenuItem {
+  PP_Flash_MenuItem_Type type;
+  str_t name;
+  int32_t id;
+  PP_Bool enabled;
+  PP_Bool checked;
+  [ref] PP_Flash_Menu submenu;
+};
+
+struct PP_Flash_Menu {
+  uint32_t count;
+  [size_is(count)] PP_Flash_MenuItem[] items;
+};
+
+interface PPB_Flash_Menu {
+  PP_Resource Create([in] PP_Instance instance_id,
+                     [in] PP_Flash_Menu menu_data);
+  PP_Bool IsFlashMenu(PP_Resource resource_id);
+  /* Display a context menu at the given location. If the user selects an item,
+   * |selected_id| will be set to its |id| and the callback called with |PP_OK|.
+   * If the user dismisses the menu without selecting an item,
+   * |PP_ERROR_USERCANCEL| will be indicated.
+   */
+  int32_t Show([in] PP_Resource menu_id,
+               [in] PP_Point location,
+               [out] int32_t selected_id,
+               [in] PP_CompletionCallback callback);
+};
+
diff --git a/ppapi/c/private/ppb_flash_menu.h b/ppapi/c/private/ppb_flash_menu.h
index fbdaa123..0b32478 100644
--- a/ppapi/c/private/ppb_flash_menu.h
+++ b/ppapi/c/private/ppb_flash_menu.h
@@ -1,29 +1,57 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* From private/ppb_flash_menu.idl modified Tue Dec 11 13:47:09 2012. */
 
 #ifndef PPAPI_C_PRIVATE_PPB_FLASH_MENU_H_
 #define PPAPI_C_PRIVATE_PPB_FLASH_MENU_H_
 
 #include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_completion_callback.h"
 #include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_macros.h"
 #include "ppapi/c/pp_point.h"
 #include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_stdint.h"
+
+/* Struct prototypes */
+struct PP_Flash_Menu;
 
 #define PPB_FLASH_MENU_INTERFACE_0_2 "PPB_Flash_Menu;0.2"
 #define PPB_FLASH_MENU_INTERFACE PPB_FLASH_MENU_INTERFACE_0_2
 
-struct PP_CompletionCallback;
+/**
+ * @file
+ * This file defines the <code>PPB_Flash_Menu</code> interface.
+ */
 
+
+/**
+ * @addtogroup Enums
+ * @{
+ */
+/* Menu item type.
+ *
+ * TODO(viettrungluu): Radio items not supported yet. Will also probably want
+ * special menu items tied to clipboard access.
+ */
 typedef enum {
-  // TODO(viettrungluu): Radio items not supported yet. Will also probably want
-  // special menu items tied to clipboard access.
   PP_FLASH_MENUITEM_TYPE_NORMAL = 0,
-  PP_FLASH_MENUITEM_TYPE_CHECKBOX,
-  PP_FLASH_MENUITEM_TYPE_SEPARATOR,
-  PP_FLASH_MENUITEM_TYPE_SUBMENU
+  PP_FLASH_MENUITEM_TYPE_CHECKBOX = 1,
+  PP_FLASH_MENUITEM_TYPE_SEPARATOR = 2,
+  PP_FLASH_MENUITEM_TYPE_SUBMENU = 3
 } PP_Flash_MenuItem_Type;
+PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_Flash_MenuItem_Type, 4);
+/**
+ * @}
+ */
 
+/**
+ * @addtogroup Structs
+ * @{
+ */
 struct PP_Flash_MenuItem {
   PP_Flash_MenuItem_Type type;
   char* name;
@@ -35,18 +63,25 @@
 
 struct PP_Flash_Menu {
   uint32_t count;
-  struct PP_Flash_MenuItem* items;
+  struct PP_Flash_MenuItem *items;
 };
+/**
+ * @}
+ */
 
+/**
+ * @addtogroup Interfaces
+ * @{
+ */
 struct PPB_Flash_Menu_0_2 {
   PP_Resource (*Create)(PP_Instance instance_id,
                         const struct PP_Flash_Menu* menu_data);
   PP_Bool (*IsFlashMenu)(PP_Resource resource_id);
-
-  // Display a context menu at the given location. If the user selects an item,
-  // |selected_id| will be set to its |id| and the callback called with |PP_OK|.
-  // If the user dismisses the menu without selecting an item,
-  // |PP_ERROR_USERCANCEL| will be indicated.
+  /* Display a context menu at the given location. If the user selects an item,
+   * |selected_id| will be set to its |id| and the callback called with |PP_OK|.
+   * If the user dismisses the menu without selecting an item,
+   * |PP_ERROR_USERCANCEL| will be indicated.
+   */
   int32_t (*Show)(PP_Resource menu_id,
                   const struct PP_Point* location,
                   int32_t* selected_id,
@@ -54,5 +89,9 @@
 };
 
 typedef struct PPB_Flash_Menu_0_2 PPB_Flash_Menu;
+/**
+ * @}
+ */
 
-#endif  // PPAPI_C_PRIVATE_PPB_FLASH_MENU_H_
+#endif  /* PPAPI_C_PRIVATE_PPB_FLASH_MENU_H_ */
+
diff --git a/ppapi/generators/idl_c_header.py b/ppapi/generators/idl_c_header.py
index d4561d5..7311472 100755
--- a/ppapi/generators/idl_c_header.py
+++ b/ppapi/generators/idl_c_header.py
@@ -18,11 +18,43 @@
 from idl_parser import ParseFiles
 from idl_c_proto import CGen, GetNodeComments, CommentLines, Comment
 from idl_generator import Generator, GeneratorByFile
+from idl_visitor import IDLVisitor
 
 Option('dstroot', 'Base directory of output', default=os.path.join('..', 'c'))
 Option('guard', 'Include guard prefix', default=os.path.join('ppapi', 'c'))
 
 
+#
+# PrototypeResolver
+#
+# A specialized visitor which traverses the AST, building a mapping of
+# Release names to Versions numbers and calculating a min version.
+# The mapping is applied to the File nodes within the AST.
+#
+class ProtoResolver(IDLVisitor):
+  def __init__(self):
+    IDLVisitor.__init__(self)
+    self.struct_map = {}
+    self.interface_map = {}
+
+  def Arrive(self, node, ignore):
+    if node.IsA('Member') and node.GetProperty('ref'):
+      typeref = node.typelist.GetReleases()[0]
+      if typeref.IsA('Struct'):
+        nodelist = self.struct_map.get(typeref.GetName(), [])
+        nodelist.append(node)
+        self.struct_map[typeref.GetName()] = nodelist
+
+    if node.IsA('Param'):
+      typeref = node.typelist.GetReleases()[0]
+      if typeref.IsA('Interface'):
+        nodelist = self.struct_map.get(typeref.GetName(), [])
+        nodelist.append(node)
+        self.interface_map[typeref.GetName()] = nodelist
+
+    return None
+
+
 def GetPathFromNode(filenode, relpath=None, ext=None):
   path, name = os.path.split(filenode.GetProperty('NAME'))
   if ext: name = os.path.splitext(name)[0] + ext
@@ -128,6 +160,10 @@
 
   def GenerateHead(self, out, filenode, releases, options):
     __pychecker__ = 'unusednames=options'
+
+    proto = ProtoResolver()
+    proto.Visit(filenode, None)
+
     cgen = CGen()
     gpath = GetOption('guard')
     def_guard = GetHeaderFromNode(filenode, relpath=gpath)
@@ -176,6 +212,12 @@
       if include == cur_include: continue
       out.Write('#include "%s"\n' % include)
 
+    # Generate Prototypes
+    if proto.struct_map:
+      out.Write('\n/* Struct prototypes */\n')
+      for struct in proto.struct_map:
+        out.Write('struct %s;\n' % struct)
+
     # If we are generating a single release, then create a macro for the highest
     # available release number.
     if filenode.GetProperty('NAME').endswith('pp_macros.idl'):
diff --git a/ppapi/generators/idl_c_proto.py b/ppapi/generators/idl_c_proto.py
index b2b78d4..79656308 100755
--- a/ppapi/generators/idl_c_proto.py
+++ b/ppapi/generators/idl_c_proto.py
@@ -79,7 +79,8 @@
       'inout': '%s',
       'out': '%s*',
       'store': '%s',
-      'return': '%s'
+      'return': '%s',
+      'ref': '%s*'
     },
     'Callspec': {
       'in': '%s',
@@ -107,7 +108,8 @@
       'inout': '%s*',
       'out': '%s*',
       'return': ' %s*',
-      'store': '%s'
+      'store': '%s',
+      'ref': '%s*'
     },
     'blob_t': {
       'in': 'const %s',
@@ -396,9 +398,15 @@
 
 
   def Compose(self, rtype, name, arrayspec, callspec, prefix, func_as_ptr,
-              ptr_prefix, include_name):
+              ptr_prefix, include_name, unsized_as_ptr):
     self.LogEnter('Compose: %s %s' % (rtype, name))
     arrayspec = ''.join(arrayspec)
+
+    # Switch unsized array to a ptr. NOTE: Only last element can be unsized.
+    if unsized_as_ptr and arrayspec[-2:] == '[]':
+      prefix +=  '*'
+      arrayspec=arrayspec[:-2]
+
     if not include_name:
       name = prefix + arrayspec
     else:
@@ -409,7 +417,8 @@
       params = []
       for ptype, pname, parray, pspec in callspec:
         params.append(self.Compose(ptype, pname, parray, pspec, '', True,
-                                   ptr_prefix='', include_name=True))
+                                   ptr_prefix='', include_name=True,
+                                   unsized_as_ptr=unsized_as_ptr))
       if func_as_ptr:
         name = '(%s*%s)' % (ptr_prefix, name)
       if not params:
@@ -437,8 +446,13 @@
     rtype, name, arrayspec, callspec = self.GetComponents(node, release, mode)
     if include_version:
       name = self.GetStructName(node, release, True)
+
+    # If not a callspec (such as a struct) use a ptr instead of []
+    unsized_as_ptr = not callspec
+
     out = self.Compose(rtype, name, arrayspec, callspec, prefix,
-                       func_as_ptr, ptr_prefix, include_name)
+                       func_as_ptr, ptr_prefix, include_name, unsized_as_ptr)
+
     self.LogExit('Exit GetSignature: %s' % out)
     return out
 
@@ -492,7 +506,10 @@
     __pychecker__ = 'unusednames=prefix,comment'
     release = releases[0]
     self.LogEnter('DefineMember %s' % node)
-    out = '%s;' % self.GetSignature(node, release, 'store', '', True)
+    if node.GetProperty('ref'):
+      out = '%s;' % self.GetSignature(node, release, 'ref', '', True)
+    else:
+      out = '%s;' % self.GetSignature(node, release, 'store', '', True)
     self.LogExit('Exit DefineMember')
     return out
 
diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
index 1240569..c1a4bb9 100644
--- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
+++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
@@ -77,6 +77,7 @@
 #include "ppapi/c/private/ppb_flash_device_id.h"
 #include "ppapi/c/private/ppb_flash_font_file.h"
 #include "ppapi/c/private/ppb_flash_fullscreen.h"
+#include "ppapi/c/private/ppb_flash_menu.h"
 #include "ppapi/c/private/ppb_flash_message_loop.h"
 #include "ppapi/c/private/ppb_flash_print.h"
 #include "ppapi/c/private/ppb_gpu_blacklist_private.h"
@@ -227,6 +228,7 @@
 static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_FontFile_0_1;
 static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_FlashFullscreen_0_1;
 static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_FlashFullscreen_1_0;
+static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_Menu_0_2;
 static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_MessageLoop_0_1;
 static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_Print_1_0;
 static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_GpuBlacklist_Private_0_2;
@@ -2750,6 +2752,28 @@
 
 /* Not generating wrapper methods for PPB_FlashFullscreen_1_0 */
 
+/* Begin wrapper methods for PPB_Flash_Menu_0_2 */
+
+static __attribute__((pnaclcall))
+PP_Resource Pnacl_M14_PPB_Flash_Menu_Create(PP_Instance instance_id, const struct PP_Flash_Menu* menu_data) {
+  const struct PPB_Flash_Menu_0_2 *iface = Pnacl_WrapperInfo_PPB_Flash_Menu_0_2.real_iface;
+  return iface->Create(instance_id, menu_data);
+}
+
+static __attribute__((pnaclcall))
+PP_Bool Pnacl_M14_PPB_Flash_Menu_IsFlashMenu(PP_Resource resource_id) {
+  const struct PPB_Flash_Menu_0_2 *iface = Pnacl_WrapperInfo_PPB_Flash_Menu_0_2.real_iface;
+  return iface->IsFlashMenu(resource_id);
+}
+
+static __attribute__((pnaclcall))
+int32_t Pnacl_M14_PPB_Flash_Menu_Show(PP_Resource menu_id, const struct PP_Point* location, int32_t* selected_id, struct PP_CompletionCallback callback) {
+  const struct PPB_Flash_Menu_0_2 *iface = Pnacl_WrapperInfo_PPB_Flash_Menu_0_2.real_iface;
+  return iface->Show(menu_id, location, selected_id, callback);
+}
+
+/* End wrapper methods for PPB_Flash_Menu_0_2 */
+
 /* Not generating wrapper methods for PPB_Flash_MessageLoop_0_1 */
 
 /* Not generating wrapper methods for PPB_Flash_Print_1_0 */
@@ -4137,6 +4161,12 @@
 
 /* Not generating wrapper interface for PPB_FlashFullscreen_1_0 */
 
+struct PPB_Flash_Menu_0_2 Pnacl_Wrappers_PPB_Flash_Menu_0_2 = {
+    .Create = (PP_Resource (*)(PP_Instance instance_id, const struct PP_Flash_Menu* menu_data))&Pnacl_M14_PPB_Flash_Menu_Create,
+    .IsFlashMenu = (PP_Bool (*)(PP_Resource resource_id))&Pnacl_M14_PPB_Flash_Menu_IsFlashMenu,
+    .Show = (int32_t (*)(PP_Resource menu_id, const struct PP_Point* location, int32_t* selected_id, struct PP_CompletionCallback callback))&Pnacl_M14_PPB_Flash_Menu_Show
+};
+
 /* Not generating wrapper interface for PPB_Flash_MessageLoop_0_1 */
 
 /* Not generating wrapper interface for PPB_Flash_Print_1_0 */
@@ -4969,6 +4999,12 @@
   .real_iface = NULL
 };
 
+static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_Menu_0_2 = {
+  .iface_macro = PPB_FLASH_MENU_INTERFACE_0_2,
+  .wrapped_iface = (void *) &Pnacl_Wrappers_PPB_Flash_Menu_0_2,
+  .real_iface = NULL
+};
+
 static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_MessageLoop_0_1 = {
   .iface_macro = PPB_FLASH_MESSAGELOOP_INTERFACE_0_1,
   .wrapped_iface = NULL /* Still need slot for real_iface */,
@@ -5211,6 +5247,7 @@
   &Pnacl_WrapperInfo_PPB_Flash_FontFile_0_1,
   &Pnacl_WrapperInfo_PPB_FlashFullscreen_0_1,
   &Pnacl_WrapperInfo_PPB_FlashFullscreen_1_0,
+  &Pnacl_WrapperInfo_PPB_Flash_Menu_0_2,
   &Pnacl_WrapperInfo_PPB_Flash_MessageLoop_0_1,
   &Pnacl_WrapperInfo_PPB_Flash_Print_1_0,
   &Pnacl_WrapperInfo_PPB_GpuBlacklist_Private_0_2,
diff --git a/ppapi/thunk/ppb_flash_device_id_thunk.cc b/ppapi/thunk/ppb_flash_device_id_thunk.cc
index 38ee1a50..7c85fcd 100644
--- a/ppapi/thunk/ppb_flash_device_id_thunk.cc
+++ b/ppapi/thunk/ppb_flash_device_id_thunk.cc
@@ -2,8 +2,9 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// From private/ppb_flash_device_id.idl modified Mon Dec 10 16:03:11 2012.
+// From private/ppb_flash_device_id.idl modified Tue Dec 11 13:47:18 2012.
 
+#include "ppapi/c/pp_completion_callback.h"
 #include "ppapi/c/pp_errors.h"
 #include "ppapi/c/private/ppb_flash_device_id.h"
 #include "ppapi/shared_impl/tracked_callback.h"