diff options
author | Ben Murdoch <benm@google.com> | 2010-07-29 17:14:53 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-08-04 14:29:45 +0100 |
commit | c407dc5cd9bdc5668497f21b26b09d988ab439de (patch) | |
tree | 7eaf8707c0309516bdb042ad976feedaf72b0bb1 /webkit/glue/plugins/pepper_webplugin_impl.cc | |
parent | 0998b1cdac5733f299c12d88bc31ef9c8035b8fa (diff) | |
download | external_chromium-c407dc5cd9bdc5668497f21b26b09d988ab439de.zip external_chromium-c407dc5cd9bdc5668497f21b26b09d988ab439de.tar.gz external_chromium-c407dc5cd9bdc5668497f21b26b09d988ab439de.tar.bz2 |
Merge Chromium src@r53293
Change-Id: Ia79acf8670f385cee48c45b0a75371d8e950af34
Diffstat (limited to 'webkit/glue/plugins/pepper_webplugin_impl.cc')
-rw-r--r-- | webkit/glue/plugins/pepper_webplugin_impl.cc | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/webkit/glue/plugins/pepper_webplugin_impl.cc b/webkit/glue/plugins/pepper_webplugin_impl.cc new file mode 100644 index 0000000..df8aae0 --- /dev/null +++ b/webkit/glue/plugins/pepper_webplugin_impl.cc @@ -0,0 +1,196 @@ +// Copyright (c) 2010 The Chromium 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 "webkit/glue/plugins/pepper_webplugin_impl.h" + +#include "base/file_path.h" +#include "base/message_loop.h" +#include "third_party/ppapi/c/pp_var.h" +#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h" +#include "third_party/WebKit/WebKit/chromium/public/WebRect.h" +#include "webkit/glue/plugins/pepper_plugin_instance.h" +#include "webkit/glue/plugins/pepper_plugin_module.h" +#include "webkit/glue/plugins/pepper_url_loader.h" +#include "webkit/glue/plugins/pepper_var.h" + +using WebKit::WebCanvas; +using WebKit::WebPluginContainer; +using WebKit::WebPluginParams; +using WebKit::WebRect; +using WebKit::WebString; +using WebKit::WebVector; + +namespace pepper { + +WebPluginImpl::WebPluginImpl( + PluginModule* plugin_module, + const WebPluginParams& params, + const base::WeakPtr<PluginDelegate>& plugin_delegate) + : init_data_(new InitData()), + full_frame_(params.loadManually) { + DCHECK(plugin_module); + init_data_->module = plugin_module; + init_data_->delegate = plugin_delegate; + for (size_t i = 0; i < params.attributeNames.size(); ++i) { + init_data_->arg_names.push_back(params.attributeNames[i].utf8()); + init_data_->arg_values.push_back(params.attributeValues[i].utf8()); + } +} + +WebPluginImpl::~WebPluginImpl() { +} + +bool WebPluginImpl::initialize(WebPluginContainer* container) { + // The plugin delegate may have gone away. + if (!init_data_->delegate) + return false; + + instance_ = init_data_->module->CreateInstance(init_data_->delegate); + if (!instance_) + return false; + + bool success = instance_->Initialize(container, + init_data_->arg_names, + init_data_->arg_values, + full_frame_); + if (!success) { + instance_->Delete(); + instance_ = NULL; + return false; + } + + init_data_.reset(); + return true; +} + +void WebPluginImpl::destroy() { + if (instance_) { + instance_->Delete(); + instance_ = NULL; + } + + MessageLoop::current()->DeleteSoon(FROM_HERE, this); +} + +NPObject* WebPluginImpl::scriptableObject() { + return GetNPObject(instance_->GetInstanceObject()); +} + +void WebPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) { + instance_->Paint(canvas, plugin_rect_, rect); +} + +void WebPluginImpl::updateGeometry( + const WebRect& window_rect, + const WebRect& clip_rect, + const WebVector<WebRect>& cut_outs_rects, + bool is_visible) { + plugin_rect_ = window_rect; + instance_->ViewChanged(plugin_rect_, clip_rect); +} + +void WebPluginImpl::updateFocus(bool focused) { +} + +void WebPluginImpl::updateVisibility(bool visible) { +} + +bool WebPluginImpl::acceptsInputEvents() { + return true; +} + +bool WebPluginImpl::handleInputEvent(const WebKit::WebInputEvent& event, + WebKit::WebCursorInfo& cursor_info) { + return instance_->HandleInputEvent(event, &cursor_info); +} + +void WebPluginImpl::didReceiveResponse( + const WebKit::WebURLResponse& response) { + DCHECK(!document_loader_); + + document_loader_ = new URLLoader(instance_); + document_loader_->didReceiveResponse(NULL, response); + + if (!instance_->HandleDocumentLoad(document_loader_)) + document_loader_ = NULL; +} + +void WebPluginImpl::didReceiveData(const char* data, int data_length) { + if (document_loader_) + document_loader_->didReceiveData(NULL, data, data_length); +} + +void WebPluginImpl::didFinishLoading() { + if (document_loader_) { + document_loader_->didFinishLoading(NULL); + document_loader_ = NULL; + } +} + +void WebPluginImpl::didFailLoading(const WebKit::WebURLError& error) { + if (document_loader_) { + document_loader_->didFail(NULL, error); + document_loader_ = NULL; + } +} + +void WebPluginImpl::didFinishLoadingFrameRequest(const WebKit::WebURL& url, + void* notify_data) { +} + +void WebPluginImpl::didFailLoadingFrameRequest( + const WebKit::WebURL& url, + void* notify_data, + const WebKit::WebURLError& error) { +} + +bool WebPluginImpl::hasSelection() const { + return !selectionAsText().isEmpty(); +} + +WebKit::WebString WebPluginImpl::selectionAsText() const { + return instance_->GetSelectedText(false); +} + +WebKit::WebString WebPluginImpl::selectionAsMarkup() const { + return instance_->GetSelectedText(true); +} + +void WebPluginImpl::setZoomFactor(float scale, bool text_only) { + instance_->Zoom(scale, text_only); +} + +bool WebPluginImpl::startFind(const WebKit::WebString& search_text, + bool case_sensitive, + int identifier) { + return instance_->StartFind(search_text, case_sensitive, identifier); +} + +void WebPluginImpl::selectFindResult(bool forward) { + instance_->SelectFindResult(forward); +} + +void WebPluginImpl::stopFind() { + instance_->StopFind(); +} + +bool WebPluginImpl::supportsPaginatedPrint() { + return instance_->SupportsPrintInterface(); +} + +int WebPluginImpl::printBegin(const WebKit::WebRect& printable_area, + int printer_dpi) { + return instance_->PrintBegin(printable_area, printer_dpi); +} + +bool WebPluginImpl::printPage(int page_number, + WebKit::WebCanvas* canvas) { + return instance_->PrintPage(page_number, canvas); +} + +void WebPluginImpl::printEnd() { + return instance_->PrintEnd(); +} + +} // namespace pepper |