| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 { | 49 { |
| 50 #if OS(MACOSX) | 50 #if OS(MACOSX) |
| 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(v8::Isolate* isolate, const v8::Local<v8::A
rray>& itemArray, ContextMenu& menu) |
| 60 { | 60 { |
| 61 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 61 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 62 for (size_t i = 0; i < itemArray->Length(); ++i) { | 62 for (size_t i = 0; i < itemArray->Length(); ++i) { |
| 63 v8::Local<v8::Object> item = itemArray->Get(context, i).ToLocalChecked()
.As<v8::Object>(); | 63 v8::Local<v8::Object> item = itemArray->Get(context, i).ToLocalChecked()
.As<v8::Object>(); |
| 64 v8::Local<v8::Value> type; | 64 v8::Local<v8::Value> type; |
| 65 v8::Local<v8::Value> id; | 65 v8::Local<v8::Value> id; |
| 66 v8::Local<v8::Value> label; | 66 v8::Local<v8::Value> label; |
| 67 v8::Local<v8::Value> enabled; | 67 v8::Local<v8::Value> enabled; |
| 68 v8::Local<v8::Value> checked; | 68 v8::Local<v8::Value> checked; |
| 69 v8::Local<v8::Value> subItems; | 69 v8::Local<v8::Value> subItems; |
| 70 if (!item->Get(context, v8AtomicString(isolate, "type")).ToLocal(&type) | 70 if (!item->Get(context, v8AtomicString(isolate, "type")).ToLocal(&type) |
| 71 || !item->Get(context, v8AtomicString(isolate, "id")).ToLocal(&id) | 71 || !item->Get(context, v8AtomicString(isolate, "id")).ToLocal(&id) |
| 72 || !item->Get(context, v8AtomicString(isolate, "label")).ToLocal(&la
bel) | 72 || !item->Get(context, v8AtomicString(isolate, "label")).ToLocal(&la
bel) |
| 73 || !item->Get(context, v8AtomicString(isolate, "enabled")).ToLocal(&
enabled) | 73 || !item->Get(context, v8AtomicString(isolate, "enabled")).ToLocal(&
enabled) |
| 74 || !item->Get(context, v8AtomicString(isolate, "checked")).ToLocal(&
checked) | 74 || !item->Get(context, v8AtomicString(isolate, "checked")).ToLocal(&
checked) |
| 75 || !item->Get(context, v8AtomicString(isolate, "subItems")).ToLocal(
&subItems)) | 75 || !item->Get(context, v8AtomicString(isolate, "subItems")).ToLocal(
&subItems)) |
| 76 return false; | 76 return false; |
| 77 if (!type->IsString()) | 77 if (!type->IsString()) |
| 78 continue; | 78 continue; |
| 79 String typeString = toCoreStringWithNullCheck(type.As<v8::String>()); | 79 String typeString = toCoreStringWithNullCheck(type.As<v8::String>()); |
| 80 if (typeString == "separator") { | 80 if (typeString == "separator") { |
| 81 ContextMenuItem item(ContextMenuItem(SeparatorType, | 81 ContextMenuItem item(ContextMenuItem(SeparatorType, |
| 82 ContextMenuItemCustomTagNoAction, | 82 ContextMenuItemCustomTagNoAction, |
| 83 String(), | 83 String(), |
| 84 String())); | 84 String())); |
| 85 menu.appendItem(item); | 85 menu.appendItem(item); |
| 86 } else if (typeString == "subMenu" && subItems->IsArray()) { | 86 } else if (typeString == "subMenu" && subItems->IsArray()) { |
| 87 ContextMenu subMenu; | 87 ContextMenu subMenu; |
| 88 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); |
| 89 if (!populateContextMenuItems(subItemsArray, subMenu, isolate)) | 89 if (!populateContextMenuItems(isolate, subItemsArray, subMenu)) |
| 90 return false; | 90 return false; |
| 91 TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelStrin
g, label, false); | 91 TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelStrin
g, label, false); |
| 92 ContextMenuItem item(SubmenuType, | 92 ContextMenuItem item(SubmenuType, |
| 93 ContextMenuItemCustomTagNoAction, | 93 ContextMenuItemCustomTagNoAction, |
| 94 labelString, | 94 labelString, |
| 95 String(), | 95 String(), |
| 96 &subMenu); | 96 &subMenu); |
| 97 menu.appendItem(item); | 97 menu.appendItem(item); |
| 98 } else { | 98 } else { |
| 99 int32_t int32Id; | 99 int32_t int32Id; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 120 v8::Local<v8::Object> eventWrapper = v8::Local<v8::Object>::Cast(info[0]); | 120 v8::Local<v8::Object> eventWrapper = v8::Local<v8::Object>::Cast(info[0]); |
| 121 if (!V8MouseEvent::wrapperTypeInfo.equals(toWrapperTypeInfo(eventWrapper))) | 121 if (!V8MouseEvent::wrapperTypeInfo.equals(toWrapperTypeInfo(eventWrapper))) |
| 122 return; | 122 return; |
| 123 | 123 |
| 124 Event* event = V8Event::toImpl(eventWrapper); | 124 Event* event = V8Event::toImpl(eventWrapper); |
| 125 if (!info[1]->IsArray()) | 125 if (!info[1]->IsArray()) |
| 126 return; | 126 return; |
| 127 | 127 |
| 128 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(info[1]); | 128 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(info[1]); |
| 129 ContextMenu menu; | 129 ContextMenu menu; |
| 130 if (!populateContextMenuItems(array, menu, info.GetIsolate())) | 130 if (!populateContextMenuItems(info.GetIsolate(), array, menu)) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 DevToolsHost* devtoolsHost = V8DevToolsHost::toImpl(info.Holder()); | 133 DevToolsHost* devtoolsHost = V8DevToolsHost::toImpl(info.Holder()); |
| 134 Vector<ContextMenuItem> items = menu.items(); | 134 Vector<ContextMenuItem> items = menu.items(); |
| 135 devtoolsHost->showContextMenu(event, items); | 135 devtoolsHost->showContextMenu(event, items); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void V8DevToolsHost::showContextMenuAtPointMethodCustom(const v8::FunctionCallba
ckInfo<v8::Value>& info) | 138 void V8DevToolsHost::showContextMenuAtPointMethodCustom(const v8::FunctionCallba
ckInfo<v8::Value>& info) |
| 139 { | 139 { |
| 140 if (info.Length() < 3) | 140 if (info.Length() < 3) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 ExceptionState exceptionState(ExceptionState::ExecutionContext, "showContext
MenuAtPoint", "DevToolsHost", info.Holder(), info.GetIsolate()); | 143 ExceptionState exceptionState(ExceptionState::ExecutionContext, "showContext
MenuAtPoint", "DevToolsHost", info.Holder(), info.GetIsolate()); |
| 144 | 144 |
| 145 TONATIVE_VOID_EXCEPTIONSTATE(float, x, toRestrictedFloat(info.GetIsolate(),
info[0], exceptionState), exceptionState); | 145 TONATIVE_VOID_EXCEPTIONSTATE(float, x, toRestrictedFloat(info.GetIsolate(),
info[0], exceptionState), exceptionState); |
| 146 TONATIVE_VOID_EXCEPTIONSTATE(float, y, toRestrictedFloat(info.GetIsolate(),
info[1], exceptionState), exceptionState); | 146 TONATIVE_VOID_EXCEPTIONSTATE(float, y, toRestrictedFloat(info.GetIsolate(),
info[1], exceptionState), exceptionState); |
| 147 | 147 |
| 148 v8::Local<v8::Value> array = v8::Local<v8::Value>::Cast(info[2]); | 148 v8::Local<v8::Value> array = v8::Local<v8::Value>::Cast(info[2]); |
| 149 if (!array->IsArray()) | 149 if (!array->IsArray()) |
| 150 return; | 150 return; |
| 151 ContextMenu menu; | 151 ContextMenu menu; |
| 152 if (!populateContextMenuItems(v8::Local<v8::Array>::Cast(array), menu, info.
GetIsolate())) | 152 if (!populateContextMenuItems(info.GetIsolate(), v8::Local<v8::Array>::Cast(
array), menu)) |
| 153 return; | 153 return; |
| 154 | 154 |
| 155 Document* document = nullptr; | 155 Document* document = nullptr; |
| 156 if (info.Length() >= 4 && v8::Local<v8::Value>::Cast(info[3])->IsObject()) { | 156 if (info.Length() >= 4 && v8::Local<v8::Value>::Cast(info[3])->IsObject()) { |
| 157 v8::Local<v8::Object> documentWrapper = v8::Local<v8::Object>::Cast(info
[3]); | 157 v8::Local<v8::Object> documentWrapper = v8::Local<v8::Object>::Cast(info
[3]); |
| 158 if (!V8HTMLDocument::wrapperTypeInfo.equals(toWrapperTypeInfo(documentWr
apper))) | 158 if (!V8HTMLDocument::wrapperTypeInfo.equals(toWrapperTypeInfo(documentWr
apper))) |
| 159 return; | 159 return; |
| 160 document = V8HTMLDocument::toImpl(documentWrapper); | 160 document = V8HTMLDocument::toImpl(documentWrapper); |
| 161 } else { | 161 } else { |
| 162 v8::Isolate* isolate = info.GetIsolate(); | 162 v8::Isolate* isolate = info.GetIsolate(); |
| 163 v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeC
hain(isolate->GetEnteredContext()->Global(), isolate); | 163 v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeC
hain(isolate->GetEnteredContext()->Global(), isolate); |
| 164 if (windowWrapper.IsEmpty()) | 164 if (windowWrapper.IsEmpty()) |
| 165 return; | 165 return; |
| 166 DOMWindow* window = V8Window::toImpl(windowWrapper); | 166 DOMWindow* window = V8Window::toImpl(windowWrapper); |
| 167 document = window ? toLocalDOMWindow(window)->document() : nullptr; | 167 document = window ? toLocalDOMWindow(window)->document() : nullptr; |
| 168 } | 168 } |
| 169 if (!document || !document->frame()) | 169 if (!document || !document->frame()) |
| 170 return; | 170 return; |
| 171 | 171 |
| 172 DevToolsHost* devtoolsHost = V8DevToolsHost::toImpl(info.Holder()); | 172 DevToolsHost* devtoolsHost = V8DevToolsHost::toImpl(info.Holder()); |
| 173 Vector<ContextMenuItem> items = menu.items(); | 173 Vector<ContextMenuItem> items = menu.items(); |
| 174 devtoolsHost->showContextMenu(document->frame(), x, y, items); | 174 devtoolsHost->showContextMenu(document->frame(), x, y, items); |
| 175 } | 175 } |
| 176 | 176 |
| 177 } // namespace blink | 177 } // namespace blink |
| 178 | 178 |
| OLD | NEW |