Add chrome.tabs.create API support (issue #1947)

This commit is contained in:
Marshall Greenblatt
2017-09-28 15:40:26 +02:00
parent 3006329678
commit 607a1d9f49
13 changed files with 658 additions and 9 deletions

View File

@@ -52,12 +52,49 @@ void ZoomModeToZoomSettings(zoom::ZoomController::ZoomMode zoom_mode,
}
}
template <typename T>
void AssignOptionalValue(const std::unique_ptr<T>& source,
std::unique_ptr<T>& destination) {
if (source.get()) {
destination.reset(new T(*source));
}
}
} // namespace
ExtensionFunction::ResponseAction TabsGetFunction::Run() {
return RespondNow(Error(kNotImplementedError));
}
TabsCreateFunction::TabsCreateFunction() : cef_details_(this) {}
ExtensionFunction::ResponseAction TabsCreateFunction::Run() {
std::unique_ptr<tabs::Create::Params> params(
tabs::Create::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
CefExtensionFunctionDetails::OpenTabParams options;
AssignOptionalValue(params->create_properties.window_id, options.window_id);
AssignOptionalValue(params->create_properties.opener_tab_id,
options.opener_tab_id);
AssignOptionalValue(params->create_properties.selected, options.active);
// The 'active' property has replaced the 'selected' property.
AssignOptionalValue(params->create_properties.active, options.active);
AssignOptionalValue(params->create_properties.pinned, options.pinned);
AssignOptionalValue(params->create_properties.index, options.index);
AssignOptionalValue(params->create_properties.url, options.url);
std::string error;
std::unique_ptr<base::DictionaryValue> result(
cef_details_.OpenTab(options, user_gesture(), &error));
if (!result)
return RespondNow(Error(error));
// Return data about the newly created tab.
return RespondNow(has_callback() ? OneArgument(std::move(result))
: NoArguments());
}
ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
: cef_details_(this), execute_tab_id_(-1) {}