Home | History | Annotate | Download | only in custom
      1 /*
      2  * Copyright (C) 2007-2009 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "config.h"
     32 #include "V8InspectorFrontendHost.h"
     33 
     34 #include "InspectorController.h"
     35 #include "InspectorFrontendClient.h"
     36 #include "InspectorFrontendHost.h"
     37 #include "PlatformString.h"
     38 
     39 #include "V8Binding.h"
     40 #include "V8MouseEvent.h"
     41 #include "V8Proxy.h"
     42 
     43 namespace WebCore {
     44 
     45 v8::Handle<v8::Value> V8InspectorFrontendHost::platformCallback(const v8::Arguments&)
     46 {
     47 #if defined(OS_MACOSX)
     48     return v8String("mac");
     49 #elif defined(OS_LINUX)
     50     return v8String("linux");
     51 #elif defined(OS_FREEBSD)
     52     return v8String("freebsd");
     53 #elif defined(OS_WIN)
     54     return v8String("windows");
     55 #else
     56     return v8String("unknown");
     57 #endif
     58 }
     59 
     60 v8::Handle<v8::Value> V8InspectorFrontendHost::portCallback(const v8::Arguments&)
     61 {
     62     return v8::Undefined();
     63 }
     64 
     65 v8::Handle<v8::Value> V8InspectorFrontendHost::showContextMenuCallback(const v8::Arguments& args)
     66 {
     67     if (args.Length() < 2)
     68         return v8::Undefined();
     69 
     70     v8::Local<v8::Object> eventWrapper = v8::Local<v8::Object>::Cast(args[0]);
     71     if (!V8MouseEvent::info.equals(V8DOMWrapper::domWrapperType(eventWrapper)))
     72         return v8::Undefined();
     73 
     74     Event* event = V8Event::toNative(eventWrapper);
     75     if (!args[1]->IsArray())
     76         return v8::Undefined();
     77 
     78     v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[1]);
     79     Vector<ContextMenuItem*> items;
     80 
     81     for (size_t i = 0; i < array->Length(); ++i) {
     82         v8::Local<v8::Object> item = v8::Local<v8::Object>::Cast(array->Get(v8::Integer::New(i)));
     83         v8::Local<v8::Value> type = item->Get(v8::String::New("type"));
     84         v8::Local<v8::Value> id = item->Get(v8::String::New("id"));
     85         v8::Local<v8::Value> label = item->Get(v8::String::New("label"));
     86         v8::Local<v8::Value> enabled = item->Get(v8::String::New("enabled"));
     87         v8::Local<v8::Value> checked = item->Get(v8::String::New("checked"));
     88         if (!type->IsString())
     89             continue;
     90         String typeString = toWebCoreStringWithNullCheck(type);
     91         if (typeString == "separator") {
     92             items.append(new ContextMenuItem(SeparatorType,
     93                                              ContextMenuItemCustomTagNoAction,
     94                                              String()));
     95         } else {
     96             ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id->ToInt32()->Value());
     97             ContextMenuItem* menuItem = new ContextMenuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, toWebCoreStringWithNullCheck(label));
     98             if (checked->IsBoolean())
     99                 menuItem->setChecked(checked->ToBoolean()->Value());
    100             if (enabled->IsBoolean())
    101                 menuItem->setEnabled(enabled->ToBoolean()->Value());
    102             items.append(menuItem);
    103         }
    104     }
    105 
    106     InspectorFrontendHost* frontendHost = V8InspectorFrontendHost::toNative(args.Holder());
    107     frontendHost->showContextMenu(event, items);
    108 
    109     return v8::Undefined();
    110 }
    111 
    112 } // namespace WebCore
    113