Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

133 lines (114 sloc) 5.055 kb
// Copyright (c) 2012 Intel Corp
// Copyright (c) 2012 The Chromium Authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
// pies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in al
// l copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "content/nw/src/api/dispatcher_host.h"
#include "base/logging.h"
#include "base/values.h"
#include "content/nw/src/api/api_messages.h"
#include "content/nw/src/api/base/base.h"
#include "content/nw/src/api/clipboard/clipboard.h"
#include "content/nw/src/api/menu/menu.h"
#include "content/nw/src/api/menuitem/menuitem.h"
#include "content/nw/src/api/tray/tray.h"
#include "content/nw/src/api/window/window.h"
namespace api {
DispatcherHost::DispatcherHost(content::RenderViewHost* render_view_host)
: content::RenderViewHostObserver(render_view_host) {
}
DispatcherHost::~DispatcherHost() {
}
Base* DispatcherHost::GetObject(int id) {
return objects_registry_.Lookup(id);
}
void DispatcherHost::SendEvent(Base* object,
const std::string& event,
const base::ListValue& arguments) {
Send(new ShellViewMsg_Object_On_Event(
routing_id(), object->id(), event, arguments));
}
bool DispatcherHost::Send(IPC::Message* message) {
return content::RenderViewHostObserver::Send(message);
}
bool DispatcherHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(DispatcherHost, message)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_Allocate_Object, OnAllocateObject)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_Deallocate_Object, OnDeallocateObject)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_Call_Object_Method, OnCallObjectMethod)
IPC_MESSAGE_HANDLER(ShellViewHostMsg_Call_Object_Method_Sync,
OnCallObjectMethodSync)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void DispatcherHost::OnAllocateObject(int object_id,
const std::string& type,
const base::DictionaryValue& option) {
DLOG(INFO) << "OnAllocateObject: object_id:" << object_id
<< " type:" << type
<< " option:" << option;
if (type == "Menu") {
objects_registry_.AddWithID(new Menu(object_id, this, option), object_id);
} else if (type == "MenuItem") {
objects_registry_.AddWithID(
new MenuItem(object_id, this, option), object_id);
} else if (type == "Tray") {
objects_registry_.AddWithID(new Tray(object_id, this, option), object_id);
} else if (type == "Clipboard") {
objects_registry_.AddWithID(
new Clipboard(object_id, this, option), object_id);
} else if (type == "Window") {
objects_registry_.AddWithID(new Window(object_id, this, option), object_id);
} else {
LOG(ERROR) << "Allocate an object of unknow type: " << type;
objects_registry_.AddWithID(new Base(object_id, this, option), object_id);
}
}
void DispatcherHost::OnDeallocateObject(int object_id) {
DLOG(INFO) << "OnDeallocateObject: object_id:" << object_id;
objects_registry_.Remove(object_id);
}
void DispatcherHost::OnCallObjectMethod(
int object_id,
const std::string& type,
const std::string& method,
const base::ListValue& arguments) {
DLOG(INFO) << "OnCallObjectMethod: object_id:" << object_id
<< " type:" << type
<< " method:" << method
<< " arguments:" << arguments;
Base* object = GetObject(object_id);
DCHECK(object) << "Unknown object: " << object_id;
object->Call(method, arguments);
}
void DispatcherHost::OnCallObjectMethodSync(
int object_id,
const std::string& type,
const std::string& method,
const base::ListValue& arguments,
base::ListValue* result) {
DLOG(INFO) << "OnCallObjectMethodSync: object_id:" << object_id
<< " type:" << type
<< " method:" << method
<< " arguments:" << arguments;
Base* object = GetObject(object_id);
DCHECK(object) << "Unknown object: " << object_id;
object->CallSync(method, arguments, result);
}
} // namespace api
Jump to Line
Something went wrong with that request. Please try again.