| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/proxy/serialized_flash_menu.h" | 5 #include "ppapi/proxy/serialized_flash_menu.h" |
| 6 | 6 |
| 7 #include "ipc/ipc_message.h" | 7 #include "ipc/ipc_message.h" |
| 8 #include "ppapi/c/private/ppb_flash_menu.h" | 8 #include "ppapi/c/private/ppb_flash_menu.h" |
| 9 #include "ppapi/proxy/ppapi_param_traits.h" | 9 #include "ppapi/proxy/ppapi_param_traits.h" |
| 10 | 10 |
| 11 namespace ppapi { | 11 namespace ppapi { |
| 12 namespace proxy { | 12 namespace proxy { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are | 15 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are |
| 16 // allowed, but not sub-submenus). | 16 // allowed, but not sub-submenus). |
| 17 const int kMaxMenuDepth = 2; | 17 const int kMaxMenuDepth = 2; |
| 18 const uint32_t kMaxMenuEntries = 1000; | 18 const uint32_t kMaxMenuEntries = 1000; |
| 19 | 19 |
| 20 bool CheckMenu(int depth, const PP_Flash_Menu* menu); | 20 bool CheckMenu(int depth, const PP_Flash_Menu* menu); |
| 21 void FreeMenu(const PP_Flash_Menu* menu); | 21 void FreeMenu(const PP_Flash_Menu* menu); |
| 22 void WriteMenu(IPC::Message* m, const PP_Flash_Menu* menu); | 22 void WriteMenu(IPC::Message* m, const PP_Flash_Menu* menu); |
| 23 PP_Flash_Menu* ReadMenu(int depth, const IPC::Message* m, PickleIterator* iter); | 23 PP_Flash_Menu* ReadMenu(int depth, |
| 24 const IPC::Message* m, |
| 25 base::PickleIterator* iter); |
| 24 | 26 |
| 25 bool CheckMenuItem(int depth, const PP_Flash_MenuItem* item) { | 27 bool CheckMenuItem(int depth, const PP_Flash_MenuItem* item) { |
| 26 if (item->type == PP_FLASH_MENUITEM_TYPE_SUBMENU) | 28 if (item->type == PP_FLASH_MENUITEM_TYPE_SUBMENU) |
| 27 return CheckMenu(depth, item->submenu); | 29 return CheckMenu(depth, item->submenu); |
| 28 return true; | 30 return true; |
| 29 } | 31 } |
| 30 | 32 |
| 31 bool CheckMenu(int depth, const PP_Flash_Menu* menu) { | 33 bool CheckMenu(int depth, const PP_Flash_Menu* menu) { |
| 32 if (depth > kMaxMenuDepth || !menu) | 34 if (depth > kMaxMenuDepth || !menu) |
| 33 return false; | 35 return false; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 if (menu->items) { | 73 if (menu->items) { |
| 72 for (uint32_t i = 0; i < menu->count; ++i) | 74 for (uint32_t i = 0; i < menu->count; ++i) |
| 73 FreeMenuItem(menu->items + i); | 75 FreeMenuItem(menu->items + i); |
| 74 delete [] menu->items; | 76 delete [] menu->items; |
| 75 } | 77 } |
| 76 delete menu; | 78 delete menu; |
| 77 } | 79 } |
| 78 | 80 |
| 79 bool ReadMenuItem(int depth, | 81 bool ReadMenuItem(int depth, |
| 80 const IPC::Message* m, | 82 const IPC::Message* m, |
| 81 PickleIterator* iter, | 83 base::PickleIterator* iter, |
| 82 PP_Flash_MenuItem* menu_item) { | 84 PP_Flash_MenuItem* menu_item) { |
| 83 uint32_t type; | 85 uint32_t type; |
| 84 if (!iter->ReadUInt32(&type)) | 86 if (!iter->ReadUInt32(&type)) |
| 85 return false; | 87 return false; |
| 86 if (type > PP_FLASH_MENUITEM_TYPE_SUBMENU) | 88 if (type > PP_FLASH_MENUITEM_TYPE_SUBMENU) |
| 87 return false; | 89 return false; |
| 88 menu_item->type = static_cast<PP_Flash_MenuItem_Type>(type); | 90 menu_item->type = static_cast<PP_Flash_MenuItem_Type>(type); |
| 89 std::string name; | 91 std::string name; |
| 90 if (!iter->ReadString(&name)) | 92 if (!iter->ReadString(&name)) |
| 91 return false; | 93 return false; |
| 92 menu_item->name = new char[name.size() + 1]; | 94 menu_item->name = new char[name.size() + 1]; |
| 93 std::copy(name.begin(), name.end(), menu_item->name); | 95 std::copy(name.begin(), name.end(), menu_item->name); |
| 94 menu_item->name[name.size()] = 0; | 96 menu_item->name[name.size()] = 0; |
| 95 if (!iter->ReadInt(&menu_item->id)) | 97 if (!iter->ReadInt(&menu_item->id)) |
| 96 return false; | 98 return false; |
| 97 if (!IPC::ParamTraits<PP_Bool>::Read(m, iter, &menu_item->enabled)) | 99 if (!IPC::ParamTraits<PP_Bool>::Read(m, iter, &menu_item->enabled)) |
| 98 return false; | 100 return false; |
| 99 if (!IPC::ParamTraits<PP_Bool>::Read(m, iter, &menu_item->checked)) | 101 if (!IPC::ParamTraits<PP_Bool>::Read(m, iter, &menu_item->checked)) |
| 100 return false; | 102 return false; |
| 101 if (type == PP_FLASH_MENUITEM_TYPE_SUBMENU) { | 103 if (type == PP_FLASH_MENUITEM_TYPE_SUBMENU) { |
| 102 menu_item->submenu = ReadMenu(depth, m, iter); | 104 menu_item->submenu = ReadMenu(depth, m, iter); |
| 103 if (!menu_item->submenu) | 105 if (!menu_item->submenu) |
| 104 return false; | 106 return false; |
| 105 } | 107 } |
| 106 return true; | 108 return true; |
| 107 } | 109 } |
| 108 | 110 |
| 109 PP_Flash_Menu* ReadMenu(int depth, | 111 PP_Flash_Menu* ReadMenu(int depth, |
| 110 const IPC::Message* m, | 112 const IPC::Message* m, |
| 111 PickleIterator* iter) { | 113 base::PickleIterator* iter) { |
| 112 if (depth > kMaxMenuDepth) | 114 if (depth > kMaxMenuDepth) |
| 113 return NULL; | 115 return NULL; |
| 114 ++depth; | 116 ++depth; |
| 115 | 117 |
| 116 PP_Flash_Menu* menu = new PP_Flash_Menu; | 118 PP_Flash_Menu* menu = new PP_Flash_Menu; |
| 117 menu->items = NULL; | 119 menu->items = NULL; |
| 118 | 120 |
| 119 if (!iter->ReadUInt32(&menu->count)) { | 121 if (!iter->ReadUInt32(&menu->count)) { |
| 120 FreeMenu(menu); | 122 FreeMenu(menu); |
| 121 return NULL; | 123 return NULL; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 own_menu_ = false; | 162 own_menu_ = false; |
| 161 return true; | 163 return true; |
| 162 } | 164 } |
| 163 | 165 |
| 164 | 166 |
| 165 void SerializedFlashMenu::WriteToMessage(IPC::Message* m) const { | 167 void SerializedFlashMenu::WriteToMessage(IPC::Message* m) const { |
| 166 WriteMenu(m, pp_menu_); | 168 WriteMenu(m, pp_menu_); |
| 167 } | 169 } |
| 168 | 170 |
| 169 bool SerializedFlashMenu::ReadFromMessage(const IPC::Message* m, | 171 bool SerializedFlashMenu::ReadFromMessage(const IPC::Message* m, |
| 170 PickleIterator* iter) { | 172 base::PickleIterator* iter) { |
| 171 DCHECK(!pp_menu_); | 173 DCHECK(!pp_menu_); |
| 172 pp_menu_ = ReadMenu(0, m, iter); | 174 pp_menu_ = ReadMenu(0, m, iter); |
| 173 if (!pp_menu_) | 175 if (!pp_menu_) |
| 174 return false; | 176 return false; |
| 175 | 177 |
| 176 own_menu_ = true; | 178 own_menu_ = true; |
| 177 return true; | 179 return true; |
| 178 } | 180 } |
| 179 | 181 |
| 180 } // namespace proxy | 182 } // namespace proxy |
| 181 } // namespace ppapi | 183 } // namespace ppapi |
| OLD | NEW |