Home | History | Annotate | Download | only in custom
      1 /*
      2  * Copyright (C) 2010 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 "V8DirectoryEntry.h"
     33 
     34 #if ENABLE(FILE_SYSTEM)
     35 
     36 #include "DirectoryEntry.h"
     37 #include "ExceptionCode.h"
     38 #include "V8Binding.h"
     39 #include "V8BindingMacros.h"
     40 #include "V8EntryCallback.h"
     41 #include "V8ErrorCallback.h"
     42 #include "V8WebKitFlags.h"
     43 #include "V8Proxy.h"
     44 #include <wtf/RefCounted.h>
     45 #include <wtf/RefPtr.h>
     46 
     47 namespace WebCore {
     48 
     49 v8::Handle<v8::Value> V8DirectoryEntry::getDirectoryCallback(const v8::Arguments& args)
     50 {
     51     INC_STATS("DOM.DirectoryEntry.getDirectory");
     52     DirectoryEntry* imp = V8DirectoryEntry::toNative(args.Holder());
     53     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<WithUndefinedOrNullCheck>, path, args[0]);
     54     if (args.Length() <= 1) {
     55         imp->getDirectory(path);
     56         return v8::Handle<v8::Value>();
     57     }
     58     RefPtr<WebKitFlags> flags;
     59     if (!isUndefinedOrNull(args[1]) && args[1]->IsObject() && !V8WebKitFlags::HasInstance(args[1])) {
     60         EXCEPTION_BLOCK(v8::Handle<v8::Object>, object, v8::Handle<v8::Object>::Cast(args[1]));
     61         flags = WebKitFlags::create();
     62         v8::Local<v8::Value> v8Create = object->Get(v8::String::New("create"));
     63         if (!v8Create.IsEmpty() && !isUndefinedOrNull(v8Create)) {
     64             EXCEPTION_BLOCK(bool, isCreate, v8Create->BooleanValue());
     65             flags->setCreate(isCreate);
     66         }
     67         v8::Local<v8::Value> v8Exclusive = object->Get(v8::String::New("exclusive"));
     68         if (!v8Exclusive.IsEmpty() && !isUndefinedOrNull(v8Exclusive)) {
     69             EXCEPTION_BLOCK(bool, isExclusive, v8Exclusive->BooleanValue());
     70             flags->setExclusive(isExclusive);
     71         }
     72     } else {
     73         EXCEPTION_BLOCK(WebKitFlags*, tmp_flags, V8WebKitFlags::HasInstance(args[1]) ? V8WebKitFlags::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0);
     74         flags = tmp_flags;
     75     }
     76     RefPtr<EntryCallback> successCallback;
     77     if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) {
     78         if (!args[2]->IsObject())
     79             return throwError(TYPE_MISMATCH_ERR);
     80         successCallback = V8EntryCallback::create(args[2], getScriptExecutionContext());
     81     }
     82     RefPtr<ErrorCallback> errorCallback;
     83     if (args.Length() > 3 && !args[3]->IsNull() && !args[3]->IsUndefined()) {
     84         if (!args[3]->IsObject())
     85             return throwError(TYPE_MISMATCH_ERR);
     86         errorCallback = V8ErrorCallback::create(args[3], getScriptExecutionContext());
     87     }
     88     imp->getDirectory(path, flags, successCallback, errorCallback);
     89     return v8::Handle<v8::Value>();
     90 }
     91 
     92 v8::Handle<v8::Value> V8DirectoryEntry::getFileCallback(const v8::Arguments& args)
     93 {
     94     INC_STATS("DOM.DirectoryEntry.getFile");
     95     DirectoryEntry* imp = V8DirectoryEntry::toNative(args.Holder());
     96     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<WithUndefinedOrNullCheck>, path, args[0]);
     97     if (args.Length() <= 1) {
     98         imp->getFile(path);
     99         return v8::Handle<v8::Value>();
    100     }
    101     RefPtr<WebKitFlags> flags;
    102     if (!isUndefinedOrNull(args[1]) && args[1]->IsObject() && !V8WebKitFlags::HasInstance(args[1])) {
    103         EXCEPTION_BLOCK(v8::Handle<v8::Object>, object, v8::Handle<v8::Object>::Cast(args[1]));
    104         flags = WebKitFlags::create();
    105         v8::Local<v8::Value> v8Create = object->Get(v8::String::New("create"));
    106         if (!v8Create.IsEmpty() && !isUndefinedOrNull(v8Create)) {
    107             EXCEPTION_BLOCK(bool, isCreate, v8Create->BooleanValue());
    108             flags->setCreate(isCreate);
    109         }
    110         v8::Local<v8::Value> v8Exclusive = object->Get(v8::String::New("exclusive"));
    111         if (!v8Exclusive.IsEmpty() && !isUndefinedOrNull(v8Exclusive)) {
    112             EXCEPTION_BLOCK(bool, isExclusive, v8Exclusive->BooleanValue());
    113             flags->setExclusive(isExclusive);
    114         }
    115     } else {
    116        EXCEPTION_BLOCK(WebKitFlags*, tmp_flags, V8WebKitFlags::HasInstance(args[1]) ? V8WebKitFlags::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0);
    117        flags = tmp_flags;
    118     }
    119     RefPtr<EntryCallback> successCallback;
    120     if (args.Length() > 2 && !args[2]->IsNull() && !args[2]->IsUndefined()) {
    121         if (!args[2]->IsObject())
    122             return throwError(TYPE_MISMATCH_ERR);
    123         successCallback = V8EntryCallback::create(args[2], getScriptExecutionContext());
    124     }
    125     RefPtr<ErrorCallback> errorCallback;
    126     if (args.Length() > 3 && !args[3]->IsNull() && !args[3]->IsUndefined()) {
    127         if (!args[3]->IsObject())
    128             return throwError(TYPE_MISMATCH_ERR);
    129         errorCallback = V8ErrorCallback::create(args[3], getScriptExecutionContext());
    130     }
    131     imp->getFile(path, flags, successCallback, errorCallback);
    132     return v8::Handle<v8::Value>();
    133 }
    134 
    135 
    136 
    137 } // namespace WebCore
    138 
    139 #endif // ENABLE(FILE_SYSTEM)
    140