예제 #1
0
// synchronously send a string from Node to browser, then return string result from browser to Node
Handle<Value> Window::SendSync(const Arguments& args) {
  HandleScope scope;

  NativeWindow *window = ObjectWrap::Unwrap<NativeWindow> (args.This());

  if (window->GetBrowser()) {
    // find browser's v8 context
    CefRefPtr<CefV8Context> context = window->GetBrowser()->GetMainFrame()->GetV8Context();

    // ensure it's usable and enter
    if (context.get() && context->Enter()) {
      // try to get "appjs.onmessage" function
      CefRefPtr<CefV8Value> appjsObject = context->GetGlobal()->GetValue("appjs");
      CefRefPtr<CefV8Value> callback = appjsObject->GetValue("onmessage");
      if (callback.get()) {

        // convert Node V8 string to Cef V8 string
        CefV8ValueList argsOut;
        argsOut.push_back(CefV8Value::CreateString(V8StringToChar(args[0]->ToString())));

        // execute window.appjs fuction, passing in the string,
        // then convert the return value from a CefValue to a Node V8 string
        Handle<String> ret = CefStringToV8(callback->ExecuteFunction(appjsObject, argsOut)->GetStringValue());

        // exit browser v8 context, return string result to Node caller
        context->Exit();
        return scope.Close(ret);
      }
    }
  }
  // likely error condition
  return scope.Close(Undefined());
}
예제 #2
0
// Processes messages for the main window.
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
  NativeWindow* window = NativeWindow::GetWindow(hwnd);
  CefRefPtr<CefBrowser> browser;
  if (window) {
    browser = window->GetBrowser();
  }

  switch (message) {
    case WM_CREATE: {
      RECT rect;
      GetClientRect(hwnd, &rect);
      Cef::AddWebView(hwnd, rect, url_, browserSettings);
      return 0;
    }
    case WM_PAINT: {
      PAINTSTRUCT ps;
      HDC hdc;
      hdc = BeginPaint(hwnd, &ps);
      EndPaint(hwnd, &ps);
      return 0;
    }
    case WM_SETFOCUS:
      if (browser.get()) {
        PostMessage(browser->GetWindowHandle(), WM_SETFOCUS, wParam, NULL);
        return 0;
      }
    case WM_SIZE: {
      window->UpdatePosition();
      if (browser.get()) {
        RECT rect;
        GetClientRect(hwnd, &rect);
        HDWP hdwp = BeginDeferWindowPos(1);
        hdwp = DeferWindowPos(hdwp, browser->GetWindowHandle(), NULL,
                              rect.left, rect.top, rect.right - rect.left,
                              rect.bottom - rect.top, SWP_NOZORDER);
        EndDeferWindowPos(hdwp);
        if (emitFullscreen) {
          emitFullscreen = false;
          window->Emit("fullscreen");
        } else {
          window->Emit("resize", (int)LOWORD(lParam), (int)HIWORD(lParam));
        }
      }
      break;
    }
    case WM_WINDOWPOSCHANGING: {
      WINDOWPOS *position;
      position = (WINDOWPOS*)lParam;
      if (position->flags & SWP_STATECHANGED) {
        if (IsIconic(window->handle_)) {
          window->Emit("minimize");
        } else if (IsZoomed(window->handle_)) {
          window->Emit("maximize");
        } else {
          window->Emit("restore");
        }
      }
      break;
    }
    case WM_MOVE:
      window->UpdatePosition();
      if (browser.get()) {
        window->Emit("move", (int)LOWORD(lParam), (int)HIWORD(lParam));
      }
      break;
    case WM_NCHITTEST: {
      LRESULT result;
      if (DwmDefWindowProc != NULL) {
        if (DwmDefWindowProc(hwnd, message, wParam, lParam, &result)) {
          return result;
        }
      }
      break;
    }
    case WM_ERASEBKGND:
      if (browser.get()) {
        return 0;
      }
      break;
    case WM_CLOSE:
      if (browser.get()) {
        browser->ParentWindowWillClose();
      }
      break;
    //case WM_DESTROY:
    //  PostQuitMessage(0);

  }

  return DefWindowProc(hwnd, message, wParam, lParam);
}
예제 #3
0
// Processes messages for the main window.
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

  // Callback for the main window
  switch (message) {
    case WM_CREATE: {
      NativeWindow* window = ClientHandler::GetWindow(hwnd);
      RECT rect;
      GetClientRect(hwnd, &rect);
      Cef::AddWebView(hwnd, rect, url_, browserSettings);
      return 0;
    }
    case WM_PAINT: {
      PAINTSTRUCT ps;
      HDC hdc;
      hdc = BeginPaint(hwnd, &ps);
      EndPaint(hwnd, &ps);
      return 0;
    }
    /*case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowserHwnd()) {
        // Pass focus to the browser window
        PostMessage(g_handler->GetBrowserHwnd(), WM_SETFOCUS, wParam, NULL);
      }
      return 0;*/

    case WM_SIZE: {
      NativeWindow* window = ClientHandler::GetWindow(hwnd);
      if (window->GetBrowser()) {
        RECT r;
        GetClientRect(hwnd, &r);
        HDWP hdwp = BeginDeferWindowPos(1);
        hdwp = DeferWindowPos(hdwp, window->GetBrowser()->GetWindowHandle(), NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER);
        EndDeferWindowPos(hdwp);
      }
      window->UpdatePosition();
      break;
    }
    case WM_MOVE:
      ClientHandler::GetWindow(hwnd)->UpdatePosition();
      break;
    case WM_ERASEBKGND:
      return 1;
    // case WM_ERASEBKGND: {
    //   NativeWindow* window = ClientHandler::GetWindow(hwnd);
    //   if (window->GetBrowser()) {
    //     // Dont erase the background if the browser window has been loaded
    //     // (this avoids flashing)
    //     return 0;
    //   }
    case WM_CLOSE: {
      NativeWindow* window = ClientHandler::GetWindow(hwnd);
      if (window->GetBrowser()) {
        window->GetBrowser()->ParentWindowWillClose();
      }
    }
    break;
    //case WM_DESTROY:
    //  PostQuitMessage(0);

  }

  return DefWindowProc(hwnd, message, wParam, lParam);
}