mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Create 2062 release branch for CEF3.
git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/2062@1783 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
98
tests/cefclient/dialog_test.cpp
Normal file
98
tests/cefclient/dialog_test.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
#include "cefclient/dialog_test.h"
|
||||
#include "include/cef_browser.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace dialog_test {
|
||||
|
||||
namespace {
|
||||
|
||||
const char kTestUrl[] = "http://tests/dialogs";
|
||||
const char kFileOpenMessageName[] = "DialogTest.FileOpen";
|
||||
const char kFileOpenMultipleMessageName[] = "DialogTest.FileOpenMultiple";
|
||||
const char kFileSaveMessageName[] = "DialogTest.FileSave";
|
||||
|
||||
// Callback executed when the file dialog is dismissed.
|
||||
class DialogCallback : public CefRunFileDialogCallback {
|
||||
public:
|
||||
explicit DialogCallback(
|
||||
CefRefPtr<CefMessageRouterBrowserSide::Callback> router_callback)
|
||||
: router_callback_(router_callback) {
|
||||
}
|
||||
|
||||
virtual void OnFileDialogDismissed(
|
||||
CefRefPtr<CefBrowserHost> browser_host,
|
||||
const std::vector<CefString>& file_paths) OVERRIDE {
|
||||
// Send a message back to the render process with the list of file paths.
|
||||
std::string response;
|
||||
for (int i = 0; i < static_cast<int>(file_paths.size()); ++i) {
|
||||
if (!response.empty())
|
||||
response += "|"; // Use a delimiter disallowed in file paths.
|
||||
response += file_paths[i];
|
||||
}
|
||||
|
||||
router_callback_->Success(response);
|
||||
router_callback_ = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
CefRefPtr<CefMessageRouterBrowserSide::Callback> router_callback_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(DialogCallback);
|
||||
};
|
||||
|
||||
// Handle messages in the browser process.
|
||||
class Handler : public CefMessageRouterBrowserSide::Handler {
|
||||
public:
|
||||
Handler() {}
|
||||
|
||||
// Called due to cefQuery execution in dialogs.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;
|
||||
|
||||
// Sample file type filter.
|
||||
std::vector<CefString> file_types;
|
||||
file_types.push_back("text/*");
|
||||
file_types.push_back(".log");
|
||||
file_types.push_back(".patch");
|
||||
|
||||
CefRefPtr<DialogCallback> dialog_callback(new DialogCallback(callback));
|
||||
|
||||
const std::string& message_name = request;
|
||||
if (message_name == kFileOpenMessageName) {
|
||||
browser->GetHost()->RunFileDialog(FILE_DIALOG_OPEN, "My Open Dialog",
|
||||
"test.txt", file_types, dialog_callback.get());
|
||||
} else if (message_name == kFileOpenMultipleMessageName) {
|
||||
browser->GetHost()->RunFileDialog(FILE_DIALOG_OPEN_MULTIPLE,
|
||||
"My Open Multiple Dialog", CefString(), file_types,
|
||||
dialog_callback.get());
|
||||
} else if (message_name == kFileSaveMessageName) {
|
||||
browser->GetHost()->RunFileDialog(FILE_DIALOG_SAVE, "My Save Dialog",
|
||||
"test.txt", file_types, dialog_callback.get());
|
||||
} else {
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void CreateMessageHandlers(ClientHandler::MessageHandlerSet& handlers) {
|
||||
handlers.insert(new Handler());
|
||||
}
|
||||
|
||||
} // namespace dialog_test
|
Reference in New Issue
Block a user