Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 v8SetReturnValue(info, v8AtomicString(info.GetIsolate(), "mac")); | 51 v8SetReturnValue(info, v8AtomicString(info.GetIsolate(), "mac")); |
| 52 #elif OS(WIN) | 52 #elif OS(WIN) |
| 53 v8SetReturnValue(info, v8AtomicString(info.GetIsolate(), "windows")); | 53 v8SetReturnValue(info, v8AtomicString(info.GetIsolate(), "windows")); |
| 54 #else // Unix-like systems | 54 #else // Unix-like systems |
| 55 v8SetReturnValue(info, v8AtomicString(info.GetIsolate(), "linux")); | 55 v8SetReturnValue(info, v8AtomicString(info.GetIsolate(), "linux")); |
| 56 #endif | 56 #endif |
| 57 } | 57 } |
| 58 | 58 |
| 59 static bool populateContextMenuItems(const v8::Local<v8::Array>& itemArray, Cont extMenu& menu, v8::Isolate* isolate) | 59 static bool populateContextMenuItems(const v8::Local<v8::Array>& itemArray, Cont extMenu& menu, v8::Isolate* isolate) |
| 60 { | 60 { |
| 61 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
| 61 for (size_t i = 0; i < itemArray->Length(); ++i) { | 62 for (size_t i = 0; i < itemArray->Length(); ++i) { |
| 62 v8::Local<v8::Object> item = v8::Local<v8::Object>::Cast(itemArray->Get( i)); | 63 v8::Local<v8::Object> item = v8::Local<v8::Object>::Cast(itemArray->Get( context, i).ToLocalChecked()); |
|
Yuki
2015/04/08 04:55:59
Why don't you use As()? Why Cast()?
bashi
2015/04/08 07:40:01
Since I just added |context| and ToLocalChecked()
| |
| 63 v8::Local<v8::Value> type = item->Get(v8AtomicString(isolate, "type")); | 64 v8::Local<v8::Value> type; |
| 64 v8::Local<v8::Value> id = item->Get(v8AtomicString(isolate, "id")); | 65 v8::Local<v8::Value> id; |
| 65 v8::Local<v8::Value> label = item->Get(v8AtomicString(isolate, "label")) ; | 66 v8::Local<v8::Value> label; |
| 66 v8::Local<v8::Value> enabled = item->Get(v8AtomicString(isolate, "enable d")); | 67 v8::Local<v8::Value> enabled; |
| 67 v8::Local<v8::Value> checked = item->Get(v8AtomicString(isolate, "checke d")); | 68 v8::Local<v8::Value> checked; |
| 68 v8::Local<v8::Value> subItems = item->Get(v8AtomicString(isolate, "subIt ems")); | 69 v8::Local<v8::Value> subItems; |
| 70 if (!item->Get(context, v8AtomicString(isolate, "type")).ToLocal(&type) | |
| 71 || !item->Get(context, v8AtomicString(isolate, "id")).ToLocal(&id) | |
| 72 || !item->Get(context, v8AtomicString(isolate, "label")).ToLocal(&la bel) | |
| 73 || !item->Get(context, v8AtomicString(isolate, "enabled")).ToLocal(& enabled) | |
| 74 || !item->Get(context, v8AtomicString(isolate, "checked")).ToLocal(& checked) | |
| 75 || !item->Get(context, v8AtomicString(isolate, "subItems")).ToLocal( &subItems)) | |
| 76 return false; | |
| 69 if (!type->IsString()) | 77 if (!type->IsString()) |
| 70 continue; | 78 continue; |
| 71 String typeString = toCoreStringWithNullCheck(type.As<v8::String>()); | 79 String typeString = toCoreStringWithNullCheck(type.As<v8::String>()); |
| 72 if (typeString == "separator") { | 80 if (typeString == "separator") { |
| 73 ContextMenuItem item(ContextMenuItem(SeparatorType, | 81 ContextMenuItem item(ContextMenuItem(SeparatorType, |
| 74 ContextMenuItemCustomTagNoAction, | 82 ContextMenuItemCustomTagNoAction, |
| 75 String(), | 83 String(), |
| 76 String())); | 84 String())); |
| 77 menu.appendItem(item); | 85 menu.appendItem(item); |
| 78 } else if (typeString == "subMenu" && subItems->IsArray()) { | 86 } else if (typeString == "subMenu" && subItems->IsArray()) { |
| 79 ContextMenu subMenu; | 87 ContextMenu subMenu; |
| 80 v8::Local<v8::Array> subItemsArray = v8::Local<v8::Array>::Cast(subI tems); | 88 v8::Local<v8::Array> subItemsArray = v8::Local<v8::Array>::Cast(subI tems); |
| 81 if (!populateContextMenuItems(subItemsArray, subMenu, isolate)) | 89 if (!populateContextMenuItems(subItemsArray, subMenu, isolate)) |
| 82 return false; | 90 return false; |
| 83 TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelStrin g, label, false); | 91 TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelStrin g, label, false); |
| 84 ContextMenuItem item(SubmenuType, | 92 ContextMenuItem item(SubmenuType, |
| 85 ContextMenuItemCustomTagNoAction, | 93 ContextMenuItemCustomTagNoAction, |
| 86 labelString, | 94 labelString, |
| 87 String(), | 95 String(), |
| 88 &subMenu); | 96 &subMenu); |
| 89 menu.appendItem(item); | 97 menu.appendItem(item); |
| 90 } else { | 98 } else { |
| 91 ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMe nuItemBaseCustomTag + id->ToInt32(isolate)->Value()); | 99 int32_t int32Id; |
| 100 if (!v8Call(id->Int32Value(context), int32Id)) | |
| 101 return false; | |
| 102 ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMe nuItemBaseCustomTag + int32Id); | |
| 92 TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelStrin g, label, false); | 103 TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelStrin g, label, false); |
| 93 ContextMenuItem menuItem((typeString == "checkbox" ? CheckableAction Type : ActionType), typedId, labelString, String()); | 104 ContextMenuItem menuItem((typeString == "checkbox" ? CheckableAction Type : ActionType), typedId, labelString, String()); |
| 94 if (checked->IsBoolean()) | 105 if (checked->IsBoolean()) |
| 95 menuItem.setChecked(checked.As<v8::Boolean>()->Value()); | 106 menuItem.setChecked(checked.As<v8::Boolean>()->Value()); |
| 96 if (enabled->IsBoolean()) | 107 if (enabled->IsBoolean()) |
| 97 menuItem.setEnabled(enabled.As<v8::Boolean>()->Value()); | 108 menuItem.setEnabled(enabled.As<v8::Boolean>()->Value()); |
| 98 menu.appendItem(menuItem); | 109 menu.appendItem(menuItem); |
| 99 } | 110 } |
| 100 } | 111 } |
| 101 return true; | 112 return true; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 if (!document || !document->frame()) | 169 if (!document || !document->frame()) |
| 159 return; | 170 return; |
| 160 | 171 |
| 161 DevToolsHost* devtoolsHost = V8DevToolsHost::toImpl(info.Holder()); | 172 DevToolsHost* devtoolsHost = V8DevToolsHost::toImpl(info.Holder()); |
| 162 Vector<ContextMenuItem> items = menu.items(); | 173 Vector<ContextMenuItem> items = menu.items(); |
| 163 devtoolsHost->showContextMenu(document->frame(), x, y, items); | 174 devtoolsHost->showContextMenu(document->frame(), x, y, items); |
| 164 } | 175 } |
| 165 | 176 |
| 166 } // namespace blink | 177 } // namespace blink |
| 167 | 178 |
| OLD | NEW |