2013-04-01 19:57:28 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#include "cefclient/browser/window_test.h"
|
2013-04-01 19:57:28 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
2014-01-28 00:31:03 +01:00
|
|
|
#include <sstream>
|
2013-04-01 19:57:28 +02:00
|
|
|
#include <string>
|
2014-01-28 00:31:03 +01:00
|
|
|
#include <vector>
|
2013-04-01 19:57:28 +02:00
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
#include "include/base/cef_bind.h"
|
2013-04-01 19:57:28 +02:00
|
|
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "cefclient/browser/main_context.h"
|
|
|
|
#include "cefclient/browser/window_test_runner.h"
|
|
|
|
|
|
|
|
#if defined(OS_WIN) || defined(OS_LINUX)
|
|
|
|
#include "cefclient/browser/window_test_runner_views.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "cefclient/browser/window_test_runner_win.h"
|
|
|
|
#elif defined(OS_LINUX)
|
|
|
|
#include "cefclient/browser/window_test_runner_gtk.h"
|
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
#include "cefclient/browser/window_test_runner_mac.h"
|
|
|
|
#endif
|
2013-04-01 19:57:28 +02:00
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
namespace client {
|
2013-04-01 19:57:28 +02:00
|
|
|
namespace window_test {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
const char kTestUrl[] = "http://tests/window";
|
|
|
|
const char kMessagePositionName[] = "WindowTest.Position";
|
|
|
|
const char kMessageMinimizeName[] = "WindowTest.Minimize";
|
|
|
|
const char kMessageMaximizeName[] = "WindowTest.Maximize";
|
|
|
|
const char kMessageRestoreName[] = "WindowTest.Restore";
|
2013-04-01 19:57:28 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Create the appropriate platform test runner object.
|
|
|
|
scoped_ptr<WindowTestRunner> CreateWindowTestRunner() {
|
|
|
|
#if defined(OS_WIN) || defined(OS_LINUX)
|
|
|
|
if (MainContext::Get()->UseViews())
|
|
|
|
return scoped_ptr<WindowTestRunner>(new WindowTestRunnerViews());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
return scoped_ptr<WindowTestRunner>(new WindowTestRunnerWin());
|
|
|
|
#elif defined(OS_LINUX)
|
|
|
|
return scoped_ptr<WindowTestRunner>(new WindowTestRunnerGtk());
|
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
return scoped_ptr<WindowTestRunner>(new WindowTestRunnerMac());
|
|
|
|
#else
|
|
|
|
#error "No implementation available for your platform."
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-04-01 19:57:28 +02:00
|
|
|
// Handle messages in the browser process.
|
2014-01-28 00:31:03 +01:00
|
|
|
class Handler : public CefMessageRouterBrowserSide::Handler {
|
2013-04-01 19:57:28 +02:00
|
|
|
public:
|
2016-01-19 21:09:01 +01:00
|
|
|
Handler()
|
|
|
|
: runner_(CreateWindowTestRunner()) {
|
|
|
|
}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// Called due to cefBroadcast execution in window.html.
|
|
|
|
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int64 query_id,
|
|
|
|
const CefString& request,
|
|
|
|
bool persistent,
|
|
|
|
CefRefPtr<Callback> callback) OVERRIDE {
|
|
|
|
// Only handle messages from the test URL.
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
if (url.find(kTestUrl) != 0)
|
|
|
|
return false;
|
2013-04-01 19:57:28 +02:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
const std::string& message_name = request;
|
|
|
|
if (message_name.find(kMessagePositionName) == 0) {
|
|
|
|
// Parse the comma-delimited list of integer values.
|
|
|
|
std::vector<int> vec;
|
|
|
|
const std::string& vals =
|
|
|
|
message_name.substr(sizeof(kMessagePositionName));
|
|
|
|
std::stringstream ss(vals);
|
|
|
|
int i;
|
|
|
|
while (ss >> i) {
|
|
|
|
vec.push_back(i);
|
|
|
|
if (ss.peek() == ',')
|
|
|
|
ss.ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vec.size() == 4) {
|
2015-01-22 21:21:21 +01:00
|
|
|
// Execute SetPos() on the main thread.
|
2016-01-19 21:09:01 +01:00
|
|
|
runner_->SetPos(browser, vec[0], vec[1], vec[2], vec[3]);
|
2013-04-01 19:57:28 +02:00
|
|
|
}
|
|
|
|
} else if (message_name == kMessageMinimizeName) {
|
2015-01-22 21:21:21 +01:00
|
|
|
// Execute Minimize() on the main thread.
|
2016-01-19 21:09:01 +01:00
|
|
|
runner_->Minimize(browser);
|
2013-04-01 19:57:28 +02:00
|
|
|
} else if (message_name == kMessageMaximizeName) {
|
2015-01-22 21:21:21 +01:00
|
|
|
// Execute Maximize() on the main thread.
|
2016-01-19 21:09:01 +01:00
|
|
|
runner_->Maximize(browser);
|
2013-04-01 19:57:28 +02:00
|
|
|
} else if (message_name == kMessageRestoreName) {
|
2015-01-22 21:21:21 +01:00
|
|
|
// Execute Restore() on the main thread.
|
2016-01-19 21:09:01 +01:00
|
|
|
runner_->Restore(browser);
|
2014-01-28 00:31:03 +01:00
|
|
|
} else {
|
2014-07-11 22:10:05 +02:00
|
|
|
NOTREACHED();
|
2013-04-01 19:57:28 +02:00
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
callback->Success("");
|
|
|
|
return true;
|
2013-04-01 19:57:28 +02:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
scoped_ptr<WindowTestRunner> runner_;
|
2013-04-01 19:57:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers) {
|
|
|
|
handlers.insert(new Handler());
|
|
|
|
}
|
|
|
|
|
2013-04-01 19:57:28 +02:00
|
|
|
} // namespace window_test
|
2015-01-22 21:21:21 +01:00
|
|
|
} // namespace client
|