[Ozone-Gbm] Explicitly crash if trying software rendering on GBM
[chromium-blink-merge.git] / content / renderer / pepper / pepper_webplugin_impl.cc
bloba92c83cbc7abde00b08ca06eb829133d245d3f21
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/pepper/pepper_webplugin_impl.h"
7 #include <cmath>
9 #include "base/debug/crash_logging.h"
10 #include "base/message_loop/message_loop.h"
11 #include "content/public/common/page_zoom.h"
12 #include "content/public/renderer/content_renderer_client.h"
13 #include "content/renderer/pepper/message_channel.h"
14 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
15 #include "content/renderer/pepper/plugin_instance_throttler_impl.h"
16 #include "content/renderer/pepper/plugin_module.h"
17 #include "content/renderer/pepper/v8object_var.h"
18 #include "content/renderer/render_frame_impl.h"
19 #include "ppapi/shared_impl/ppapi_globals.h"
20 #include "ppapi/shared_impl/var_tracker.h"
21 #include "third_party/WebKit/public/platform/WebPoint.h"
22 #include "third_party/WebKit/public/platform/WebRect.h"
23 #include "third_party/WebKit/public/platform/WebSize.h"
24 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
25 #include "third_party/WebKit/public/web/WebBindings.h"
26 #include "third_party/WebKit/public/web/WebDocument.h"
27 #include "third_party/WebKit/public/web/WebElement.h"
28 #include "third_party/WebKit/public/web/WebFrame.h"
29 #include "third_party/WebKit/public/web/WebPluginContainer.h"
30 #include "third_party/WebKit/public/web/WebPluginParams.h"
31 #include "third_party/WebKit/public/web/WebPrintParams.h"
32 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h"
33 #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
34 #include "url/gurl.h"
36 using ppapi::V8ObjectVar;
37 using blink::WebCanvas;
38 using blink::WebPlugin;
39 using blink::WebPluginContainer;
40 using blink::WebPluginParams;
41 using blink::WebPoint;
42 using blink::WebPrintParams;
43 using blink::WebRect;
44 using blink::WebSize;
45 using blink::WebString;
46 using blink::WebURL;
47 using blink::WebVector;
49 namespace content {
51 struct PepperWebPluginImpl::InitData {
52 scoped_refptr<PluginModule> module;
53 RenderFrameImpl* render_frame;
54 std::vector<std::string> arg_names;
55 std::vector<std::string> arg_values;
56 GURL url;
59 PepperWebPluginImpl::PepperWebPluginImpl(
60 PluginModule* plugin_module,
61 const WebPluginParams& params,
62 RenderFrameImpl* render_frame,
63 scoped_ptr<PluginInstanceThrottlerImpl> throttler)
64 : init_data_(new InitData()),
65 full_frame_(params.loadManually),
66 throttler_(throttler.Pass()),
67 instance_object_(PP_MakeUndefined()),
68 container_(NULL) {
69 DCHECK(plugin_module);
70 init_data_->module = plugin_module;
71 init_data_->render_frame = render_frame;
72 for (size_t i = 0; i < params.attributeNames.size(); ++i) {
73 init_data_->arg_names.push_back(params.attributeNames[i].utf8());
74 init_data_->arg_values.push_back(params.attributeValues[i].utf8());
76 init_data_->url = params.url;
78 // Set subresource URL for crash reporting.
79 base::debug::SetCrashKeyValue("subresource_url", init_data_->url.spec());
81 if (throttler_)
82 throttler_->SetWebPlugin(this);
85 PepperWebPluginImpl::~PepperWebPluginImpl() {}
87 blink::WebPluginContainer* PepperWebPluginImpl::container() const {
88 return container_;
91 bool PepperWebPluginImpl::initialize(WebPluginContainer* container) {
92 // The plugin delegate may have gone away.
93 instance_ = init_data_->module->CreateInstance(
94 init_data_->render_frame, container, init_data_->url);
95 if (!instance_.get())
96 return false;
98 // Enable script objects for this plugin.
99 container->allowScriptObjects();
101 bool success =
102 instance_->Initialize(init_data_->arg_names, init_data_->arg_values,
103 full_frame_, throttler_.Pass());
104 if (!success) {
105 instance_->Delete();
106 instance_ = NULL;
108 blink::WebPlugin* replacement_plugin =
109 GetContentClient()->renderer()->CreatePluginReplacement(
110 init_data_->render_frame, init_data_->module->path());
111 if (!replacement_plugin || !replacement_plugin->initialize(container))
112 return false;
114 container->setPlugin(replacement_plugin);
115 return true;
118 init_data_.reset();
119 container_ = container;
120 return true;
123 void PepperWebPluginImpl::destroy() {
124 // Tell |container_| to clear references to this plugin's script objects.
125 if (container_)
126 container_->clearScriptObjects();
128 if (instance_.get()) {
129 ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(instance_object_);
130 instance_object_ = PP_MakeUndefined();
131 instance_->Delete();
132 instance_ = NULL;
135 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
138 v8::Local<v8::Object> PepperWebPluginImpl::v8ScriptableObject(
139 v8::Isolate* isolate) {
140 // Call through the plugin to get its instance object. The plugin should pass
141 // us a reference which we release in destroy().
142 if (instance_object_.type == PP_VARTYPE_UNDEFINED)
143 instance_object_ = instance_->GetInstanceObject(isolate);
144 // GetInstanceObject talked to the plugin which may have removed the instance
145 // from the DOM, in which case instance_ would be NULL now.
146 if (!instance_.get())
147 return v8::Local<v8::Object>();
149 scoped_refptr<V8ObjectVar> object_var(
150 V8ObjectVar::FromPPVar(instance_object_));
151 // If there's an InstanceObject, tell the Instance's MessageChannel to pass
152 // any non-postMessage calls to it.
153 if (object_var.get()) {
154 MessageChannel* message_channel = instance_->message_channel();
155 if (message_channel)
156 message_channel->SetPassthroughObject(object_var->GetHandle());
159 v8::Handle<v8::Object> result = instance_->GetMessageChannelObject();
160 return result;
163 bool PepperWebPluginImpl::getFormValue(WebString& value) { return false; }
165 void PepperWebPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) {
166 if (!instance_->FlashIsFullscreenOrPending())
167 instance_->Paint(canvas, plugin_rect_, rect);
170 void PepperWebPluginImpl::updateGeometry(
171 const WebRect& window_rect,
172 const WebRect& clip_rect,
173 const WebVector<WebRect>& cut_outs_rects,
174 bool is_visible) {
175 plugin_rect_ = window_rect;
176 if (!instance_->FlashIsFullscreenOrPending()) {
177 std::vector<gfx::Rect> cut_outs;
178 for (size_t i = 0; i < cut_outs_rects.size(); ++i)
179 cut_outs.push_back(cut_outs_rects[i]);
180 instance_->ViewChanged(plugin_rect_, clip_rect, cut_outs);
184 void PepperWebPluginImpl::updateFocus(bool focused,
185 blink::WebFocusType focus_type) {
186 instance_->SetWebKitFocus(focused);
189 void PepperWebPluginImpl::updateVisibility(bool visible) {}
191 bool PepperWebPluginImpl::acceptsInputEvents() { return true; }
193 bool PepperWebPluginImpl::handleInputEvent(const blink::WebInputEvent& event,
194 blink::WebCursorInfo& cursor_info) {
195 if (instance_->FlashIsFullscreenOrPending())
196 return false;
197 return instance_->HandleInputEvent(event, &cursor_info);
200 void PepperWebPluginImpl::didReceiveResponse(
201 const blink::WebURLResponse& response) {
202 DCHECK(!instance_->document_loader());
203 instance_->HandleDocumentLoad(response);
206 void PepperWebPluginImpl::didReceiveData(const char* data, int data_length) {
207 blink::WebURLLoaderClient* document_loader = instance_->document_loader();
208 if (document_loader)
209 document_loader->didReceiveData(NULL, data, data_length, 0);
212 void PepperWebPluginImpl::didFinishLoading() {
213 blink::WebURLLoaderClient* document_loader = instance_->document_loader();
214 if (document_loader)
215 document_loader->didFinishLoading(
216 NULL, 0.0, blink::WebURLLoaderClient::kUnknownEncodedDataLength);
219 void PepperWebPluginImpl::didFailLoading(const blink::WebURLError& error) {
220 blink::WebURLLoaderClient* document_loader = instance_->document_loader();
221 if (document_loader)
222 document_loader->didFail(NULL, error);
225 void PepperWebPluginImpl::didFinishLoadingFrameRequest(const blink::WebURL& url,
226 void* notify_data) {}
228 void PepperWebPluginImpl::didFailLoadingFrameRequest(
229 const blink::WebURL& url,
230 void* notify_data,
231 const blink::WebURLError& error) {}
233 bool PepperWebPluginImpl::hasSelection() const {
234 return !selectionAsText().isEmpty();
237 WebString PepperWebPluginImpl::selectionAsText() const {
238 return instance_->GetSelectedText(false);
241 WebString PepperWebPluginImpl::selectionAsMarkup() const {
242 return instance_->GetSelectedText(true);
245 WebURL PepperWebPluginImpl::linkAtPosition(const WebPoint& position) const {
246 return GURL(instance_->GetLinkAtPosition(position));
249 void PepperWebPluginImpl::setZoomLevel(double level, bool text_only) {
250 instance_->Zoom(content::ZoomLevelToZoomFactor(level), text_only);
253 bool PepperWebPluginImpl::startFind(const blink::WebString& search_text,
254 bool case_sensitive,
255 int identifier) {
256 return instance_->StartFind(search_text, case_sensitive, identifier);
259 void PepperWebPluginImpl::selectFindResult(bool forward) {
260 instance_->SelectFindResult(forward);
263 void PepperWebPluginImpl::stopFind() { instance_->StopFind(); }
265 bool PepperWebPluginImpl::supportsPaginatedPrint() {
266 return instance_->SupportsPrintInterface();
269 bool PepperWebPluginImpl::isPrintScalingDisabled() {
270 return instance_->IsPrintScalingDisabled();
273 int PepperWebPluginImpl::printBegin(const WebPrintParams& print_params) {
274 return instance_->PrintBegin(print_params);
277 bool PepperWebPluginImpl::printPage(int page_number, blink::WebCanvas* canvas) {
278 return instance_->PrintPage(page_number, canvas);
281 void PepperWebPluginImpl::printEnd() { return instance_->PrintEnd(); }
283 bool PepperWebPluginImpl::getPrintPresetOptionsFromDocument(
284 blink::WebPrintPresetOptions* preset_options) {
285 return instance_->GetPrintPresetOptionsFromDocument(preset_options);
288 bool PepperWebPluginImpl::canRotateView() { return instance_->CanRotateView(); }
290 void PepperWebPluginImpl::rotateView(RotationType type) {
291 instance_->RotateView(type);
294 bool PepperWebPluginImpl::isPlaceholder() { return false; }
296 } // namespace content