| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback_helpers.h" | |
| 9 #include "base/debug/trace_event.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/linked_ptr.h" | |
| 12 #include "base/message_loop/message_loop.h" | |
| 13 #include "base/stl_util.h" | |
| 14 #include "base/strings/stringprintf.h" | |
| 15 #include "base/strings/utf_offset_string_conversions.h" | |
| 16 #include "base/strings/utf_string_conversions.h" | |
| 17 #include "base/time/time.h" | |
| 18 #include "cc/layers/texture_layer.h" | |
| 19 #include "ppapi/c/dev/ppb_find_dev.h" | |
| 20 #include "ppapi/c/dev/ppb_zoom_dev.h" | |
| 21 #include "ppapi/c/dev/ppp_find_dev.h" | |
| 22 #include "ppapi/c/dev/ppp_selection_dev.h" | |
| 23 #include "ppapi/c/dev/ppp_text_input_dev.h" | |
| 24 #include "ppapi/c/dev/ppp_zoom_dev.h" | |
| 25 #include "ppapi/c/pp_rect.h" | |
| 26 #include "ppapi/c/ppb_audio_config.h" | |
| 27 #include "ppapi/c/ppb_core.h" | |
| 28 #include "ppapi/c/ppb_gamepad.h" | |
| 29 #include "ppapi/c/ppp_input_event.h" | |
| 30 #include "ppapi/c/ppp_instance.h" | |
| 31 #include "ppapi/c/ppp_messaging.h" | |
| 32 #include "ppapi/c/ppp_mouse_lock.h" | |
| 33 #include "ppapi/c/private/ppp_instance_private.h" | |
| 34 #include "ppapi/shared_impl/ppapi_permissions.h" | |
| 35 #include "ppapi/shared_impl/ppapi_preferences.h" | |
| 36 #include "ppapi/shared_impl/ppb_gamepad_shared.h" | |
| 37 #include "ppapi/shared_impl/ppb_input_event_shared.h" | |
| 38 #include "ppapi/shared_impl/ppb_url_util_shared.h" | |
| 39 #include "ppapi/shared_impl/ppb_view_shared.h" | |
| 40 #include "ppapi/shared_impl/ppp_instance_combined.h" | |
| 41 #include "ppapi/shared_impl/resource.h" | |
| 42 #include "ppapi/shared_impl/scoped_pp_resource.h" | |
| 43 #include "ppapi/shared_impl/time_conversion.h" | |
| 44 #include "ppapi/shared_impl/url_request_info_data.h" | |
| 45 #include "ppapi/shared_impl/var.h" | |
| 46 #include "ppapi/thunk/enter.h" | |
| 47 #include "ppapi/thunk/ppb_buffer_api.h" | |
| 48 #include "printing/metafile.h" | |
| 49 #include "printing/metafile_skia_wrapper.h" | |
| 50 #include "printing/units.h" | |
| 51 #include "skia/ext/platform_canvas.h" | |
| 52 #include "skia/ext/platform_device.h" | |
| 53 #include "third_party/WebKit/public/platform/WebGamepads.h" | |
| 54 #include "third_party/WebKit/public/platform/WebString.h" | |
| 55 #include "third_party/WebKit/public/platform/WebURL.h" | |
| 56 #include "third_party/WebKit/public/platform/WebURLError.h" | |
| 57 #include "third_party/WebKit/public/platform/WebURLRequest.h" | |
| 58 #include "third_party/WebKit/public/web/WebBindings.h" | |
| 59 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | |
| 60 #include "third_party/WebKit/public/web/WebCursorInfo.h" | |
| 61 #include "third_party/WebKit/public/web/WebDocument.h" | |
| 62 #include "third_party/WebKit/public/web/WebElement.h" | |
| 63 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 64 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 65 #include "third_party/WebKit/public/web/WebPluginContainer.h" | |
| 66 #include "third_party/WebKit/public/web/WebPrintParams.h" | |
| 67 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" | |
| 68 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | |
| 69 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | |
| 70 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | |
| 71 #include "third_party/WebKit/public/web/WebView.h" | |
| 72 #include "third_party/skia/include/core/SkCanvas.h" | |
| 73 #include "third_party/skia/include/core/SkRect.h" | |
| 74 #include "ui/base/range/range.h" | |
| 75 #include "ui/gfx/image/image_skia.h" | |
| 76 #include "ui/gfx/image/image_skia_rep.h" | |
| 77 #include "ui/gfx/rect_conversions.h" | |
| 78 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | |
| 79 #include "v8/include/v8.h" | |
| 80 #include "webkit/plugins/plugin_constants.h" | |
| 81 #include "webkit/plugins/ppapi/common.h" | |
| 82 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" | |
| 83 #include "webkit/plugins/ppapi/event_conversion.h" | |
| 84 #include "webkit/plugins/ppapi/fullscreen_container.h" | |
| 85 #include "webkit/plugins/ppapi/gfx_conversion.h" | |
| 86 #include "webkit/plugins/ppapi/host_globals.h" | |
| 87 #include "webkit/plugins/ppapi/message_channel.h" | |
| 88 #include "webkit/plugins/ppapi/npapi_glue.h" | |
| 89 #include "webkit/plugins/ppapi/plugin_module.h" | |
| 90 #include "webkit/plugins/ppapi/plugin_object.h" | |
| 91 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | |
| 92 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | |
| 93 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" | |
| 94 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | |
| 95 #include "webkit/plugins/ppapi/ppp_pdf.h" | |
| 96 #include "webkit/plugins/ppapi/url_request_info_util.h" | |
| 97 #include "webkit/plugins/sad_plugin.h" | |
| 98 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" | |
| 99 | |
| 100 #if defined(OS_MACOSX) | |
| 101 #include "printing/metafile_impl.h" | |
| 102 #endif // defined(OS_MACOSX) | |
| 103 | |
| 104 #if defined(OS_WIN) | |
| 105 #include "base/metrics/histogram.h" | |
| 106 #include "base/win/windows_version.h" | |
| 107 #include "skia/ext/platform_canvas.h" | |
| 108 #include "ui/gfx/codec/jpeg_codec.h" | |
| 109 #include "ui/gfx/gdi_util.h" | |
| 110 #endif | |
| 111 | |
| 112 using base::StringPrintf; | |
| 113 using ppapi::InputEventData; | |
| 114 using ppapi::PpapiGlobals; | |
| 115 using ppapi::PPB_InputEvent_Shared; | |
| 116 using ppapi::PPB_View_Shared; | |
| 117 using ppapi::PPP_Instance_Combined; | |
| 118 using ppapi::Resource; | |
| 119 using ppapi::ScopedPPResource; | |
| 120 using ppapi::StringVar; | |
| 121 using ppapi::TrackedCallback; | |
| 122 using ppapi::thunk::EnterResourceNoLock; | |
| 123 using ppapi::thunk::PPB_Buffer_API; | |
| 124 using ppapi::thunk::PPB_Gamepad_API; | |
| 125 using ppapi::thunk::PPB_Graphics2D_API; | |
| 126 using ppapi::thunk::PPB_Graphics3D_API; | |
| 127 using ppapi::thunk::PPB_ImageData_API; | |
| 128 using ppapi::Var; | |
| 129 using ppapi::ArrayBufferVar; | |
| 130 using ppapi::ViewData; | |
| 131 using WebKit::WebBindings; | |
| 132 using WebKit::WebCanvas; | |
| 133 using WebKit::WebCursorInfo; | |
| 134 using WebKit::WebDocument; | |
| 135 using WebKit::WebElement; | |
| 136 using WebKit::WebFrame; | |
| 137 using WebKit::WebInputEvent; | |
| 138 using WebKit::WebPlugin; | |
| 139 using WebKit::WebPluginContainer; | |
| 140 using WebKit::WebPrintParams; | |
| 141 using WebKit::WebPrintScalingOption; | |
| 142 using WebKit::WebScopedUserGesture; | |
| 143 using WebKit::WebString; | |
| 144 using WebKit::WebURLError; | |
| 145 using WebKit::WebURLLoader; | |
| 146 using WebKit::WebURLLoaderClient; | |
| 147 using WebKit::WebURLRequest; | |
| 148 using WebKit::WebURLResponse; | |
| 149 using WebKit::WebUserGestureIndicator; | |
| 150 using WebKit::WebUserGestureToken; | |
| 151 using WebKit::WebView; | |
| 152 | |
| 153 namespace webkit { | |
| 154 namespace ppapi { | |
| 155 | |
| 156 #if defined(OS_WIN) | |
| 157 // Exported by pdf.dll | |
| 158 typedef bool (*RenderPDFPageToDCProc)( | |
| 159 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, | |
| 160 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, | |
| 161 int bounds_width, int bounds_height, bool fit_to_bounds, | |
| 162 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds, | |
| 163 bool autorotate); | |
| 164 | |
| 165 void DrawEmptyRectangle(HDC dc) { | |
| 166 // TODO(sanjeevr): This is a temporary hack. If we output a JPEG | |
| 167 // to the EMF, the EnumEnhMetaFile call fails in the browser | |
| 168 // process. The failure also happens if we output nothing here. | |
| 169 // We need to investigate the reason for this failure and fix it. | |
| 170 // In the meantime this temporary hack of drawing an empty | |
| 171 // rectangle in the DC gets us by. | |
| 172 Rectangle(dc, 0, 0, 0, 0); | |
| 173 } | |
| 174 #endif // defined(OS_WIN) | |
| 175 | |
| 176 namespace { | |
| 177 | |
| 178 // Check PP_TextInput_Type and ui::TextInputType are kept in sync. | |
| 179 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NONE) == \ | |
| 180 int(PP_TEXTINPUT_TYPE_NONE), mismatching_enums); | |
| 181 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TEXT) == \ | |
| 182 int(PP_TEXTINPUT_TYPE_TEXT), mismatching_enums); | |
| 183 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_PASSWORD) == \ | |
| 184 int(PP_TEXTINPUT_TYPE_PASSWORD), mismatching_enums); | |
| 185 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_SEARCH) == \ | |
| 186 int(PP_TEXTINPUT_TYPE_SEARCH), mismatching_enums); | |
| 187 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_EMAIL) == \ | |
| 188 int(PP_TEXTINPUT_TYPE_EMAIL), mismatching_enums); | |
| 189 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_NUMBER) == \ | |
| 190 int(PP_TEXTINPUT_TYPE_NUMBER), mismatching_enums); | |
| 191 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_TELEPHONE) == \ | |
| 192 int(PP_TEXTINPUT_TYPE_TELEPHONE), mismatching_enums); | |
| 193 COMPILE_ASSERT(int(ui::TEXT_INPUT_TYPE_URL) == \ | |
| 194 int(PP_TEXTINPUT_TYPE_URL), mismatching_enums); | |
| 195 | |
| 196 // The default text input type is to regard the plugin always accept text input. | |
| 197 // This is for allowing users to use input methods even on completely-IME- | |
| 198 // unaware plugins (e.g., PPAPI Flash or PDF plugin for M16). | |
| 199 // Plugins need to explicitly opt out the text input mode if they know | |
| 200 // that they don't accept texts. | |
| 201 const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT; | |
| 202 | |
| 203 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ | |
| 204 COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \ | |
| 205 == static_cast<int>(np_name), \ | |
| 206 mismatching_enums) | |
| 207 | |
| 208 #define COMPILE_ASSERT_PRINT_SCALING_MATCHING_ENUM(webkit_name, pp_name) \ | |
| 209 COMPILE_ASSERT(static_cast<int>(webkit_name) \ | |
| 210 == static_cast<int>(pp_name), \ | |
| 211 mismatching_enums) | |
| 212 | |
| 213 // <embed>/<object> attributes. | |
| 214 const char kWidth[] = "width"; | |
| 215 const char kHeight[] = "height"; | |
| 216 const char kBorder[] = "border"; // According to w3c, deprecated. | |
| 217 const char kStyle[] = "style"; | |
| 218 | |
| 219 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_MOUSECURSOR_TYPE_POINTER); | |
| 220 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_MOUSECURSOR_TYPE_CROSS); | |
| 221 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_MOUSECURSOR_TYPE_HAND); | |
| 222 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_MOUSECURSOR_TYPE_IBEAM); | |
| 223 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_MOUSECURSOR_TYPE_WAIT); | |
| 224 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_MOUSECURSOR_TYPE_HELP); | |
| 225 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_MOUSECURSOR_TYPE_EASTRESIZE); | |
| 226 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_MOUSECURSOR_TYPE_NORTHRESIZE); | |
| 227 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastResize, | |
| 228 PP_MOUSECURSOR_TYPE_NORTHEASTRESIZE); | |
| 229 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestResize, | |
| 230 PP_MOUSECURSOR_TYPE_NORTHWESTRESIZE); | |
| 231 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthResize, PP_MOUSECURSOR_TYPE_SOUTHRESIZE); | |
| 232 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastResize, | |
| 233 PP_MOUSECURSOR_TYPE_SOUTHEASTRESIZE); | |
| 234 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestResize, | |
| 235 PP_MOUSECURSOR_TYPE_SOUTHWESTRESIZE); | |
| 236 COMPILE_ASSERT_MATCHING_ENUM(TypeWestResize, PP_MOUSECURSOR_TYPE_WESTRESIZE); | |
| 237 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthSouthResize, | |
| 238 PP_MOUSECURSOR_TYPE_NORTHSOUTHRESIZE); | |
| 239 COMPILE_ASSERT_MATCHING_ENUM(TypeEastWestResize, | |
| 240 PP_MOUSECURSOR_TYPE_EASTWESTRESIZE); | |
| 241 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastSouthWestResize, | |
| 242 PP_MOUSECURSOR_TYPE_NORTHEASTSOUTHWESTRESIZE); | |
| 243 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestSouthEastResize, | |
| 244 PP_MOUSECURSOR_TYPE_NORTHWESTSOUTHEASTRESIZE); | |
| 245 COMPILE_ASSERT_MATCHING_ENUM(TypeColumnResize, | |
| 246 PP_MOUSECURSOR_TYPE_COLUMNRESIZE); | |
| 247 COMPILE_ASSERT_MATCHING_ENUM(TypeRowResize, PP_MOUSECURSOR_TYPE_ROWRESIZE); | |
| 248 COMPILE_ASSERT_MATCHING_ENUM(TypeMiddlePanning, | |
| 249 PP_MOUSECURSOR_TYPE_MIDDLEPANNING); | |
| 250 COMPILE_ASSERT_MATCHING_ENUM(TypeEastPanning, PP_MOUSECURSOR_TYPE_EASTPANNING); | |
| 251 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthPanning, | |
| 252 PP_MOUSECURSOR_TYPE_NORTHPANNING); | |
| 253 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastPanning, | |
| 254 PP_MOUSECURSOR_TYPE_NORTHEASTPANNING); | |
| 255 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestPanning, | |
| 256 PP_MOUSECURSOR_TYPE_NORTHWESTPANNING); | |
| 257 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthPanning, | |
| 258 PP_MOUSECURSOR_TYPE_SOUTHPANNING); | |
| 259 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastPanning, | |
| 260 PP_MOUSECURSOR_TYPE_SOUTHEASTPANNING); | |
| 261 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestPanning, | |
| 262 PP_MOUSECURSOR_TYPE_SOUTHWESTPANNING); | |
| 263 COMPILE_ASSERT_MATCHING_ENUM(TypeWestPanning, PP_MOUSECURSOR_TYPE_WESTPANNING); | |
| 264 COMPILE_ASSERT_MATCHING_ENUM(TypeMove, PP_MOUSECURSOR_TYPE_MOVE); | |
| 265 COMPILE_ASSERT_MATCHING_ENUM(TypeVerticalText, | |
| 266 PP_MOUSECURSOR_TYPE_VERTICALTEXT); | |
| 267 COMPILE_ASSERT_MATCHING_ENUM(TypeCell, PP_MOUSECURSOR_TYPE_CELL); | |
| 268 COMPILE_ASSERT_MATCHING_ENUM(TypeContextMenu, PP_MOUSECURSOR_TYPE_CONTEXTMENU); | |
| 269 COMPILE_ASSERT_MATCHING_ENUM(TypeAlias, PP_MOUSECURSOR_TYPE_ALIAS); | |
| 270 COMPILE_ASSERT_MATCHING_ENUM(TypeProgress, PP_MOUSECURSOR_TYPE_PROGRESS); | |
| 271 COMPILE_ASSERT_MATCHING_ENUM(TypeNoDrop, PP_MOUSECURSOR_TYPE_NODROP); | |
| 272 COMPILE_ASSERT_MATCHING_ENUM(TypeCopy, PP_MOUSECURSOR_TYPE_COPY); | |
| 273 COMPILE_ASSERT_MATCHING_ENUM(TypeNone, PP_MOUSECURSOR_TYPE_NONE); | |
| 274 COMPILE_ASSERT_MATCHING_ENUM(TypeNotAllowed, PP_MOUSECURSOR_TYPE_NOTALLOWED); | |
| 275 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomIn, PP_MOUSECURSOR_TYPE_ZOOMIN); | |
| 276 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomOut, PP_MOUSECURSOR_TYPE_ZOOMOUT); | |
| 277 COMPILE_ASSERT_MATCHING_ENUM(TypeGrab, PP_MOUSECURSOR_TYPE_GRAB); | |
| 278 COMPILE_ASSERT_MATCHING_ENUM(TypeGrabbing, PP_MOUSECURSOR_TYPE_GRABBING); | |
| 279 // Do not assert WebCursorInfo::TypeCustom == PP_CURSORTYPE_CUSTOM; | |
| 280 // PP_CURSORTYPE_CUSTOM is pinned to allow new cursor types. | |
| 281 | |
| 282 COMPILE_ASSERT_PRINT_SCALING_MATCHING_ENUM(WebKit::WebPrintScalingOptionNone, | |
| 283 PP_PRINTSCALINGOPTION_NONE); | |
| 284 COMPILE_ASSERT_PRINT_SCALING_MATCHING_ENUM( | |
| 285 WebKit::WebPrintScalingOptionFitToPrintableArea, | |
| 286 PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA); | |
| 287 COMPILE_ASSERT_PRINT_SCALING_MATCHING_ENUM( | |
| 288 WebKit::WebPrintScalingOptionSourceSize, PP_PRINTSCALINGOPTION_SOURCE_SIZE); | |
| 289 | |
| 290 // Sets |*security_origin| to be the WebKit security origin associated with the | |
| 291 // document containing the given plugin instance. On success, returns true. If | |
| 292 // the instance is invalid, returns false and |*security_origin| will be | |
| 293 // unchanged. | |
| 294 bool SecurityOriginForInstance(PP_Instance instance_id, | |
| 295 WebKit::WebSecurityOrigin* security_origin) { | |
| 296 PluginInstanceImpl* instance = HostGlobals::Get()->GetInstance(instance_id); | |
| 297 if (!instance) | |
| 298 return false; | |
| 299 | |
| 300 WebElement plugin_element = instance->container()->element(); | |
| 301 *security_origin = plugin_element.document().securityOrigin(); | |
| 302 return true; | |
| 303 } | |
| 304 | |
| 305 // Convert the given vector to an array of C-strings. The strings in the | |
| 306 // returned vector are only guaranteed valid so long as the vector of strings | |
| 307 // is not modified. | |
| 308 scoped_ptr<const char*[]> StringVectorToArgArray( | |
| 309 const std::vector<std::string>& vector) { | |
| 310 scoped_ptr<const char*[]> array(new const char*[vector.size()]); | |
| 311 for (size_t i = 0; i < vector.size(); ++i) | |
| 312 array[i] = vector[i].c_str(); | |
| 313 return array.Pass(); | |
| 314 } | |
| 315 | |
| 316 } // namespace | |
| 317 | |
| 318 // static | |
| 319 PluginInstanceImpl* PluginInstanceImpl::Create(PluginDelegate* delegate, | |
| 320 content::RenderView* render_view, | |
| 321 PluginModule* module, | |
| 322 WebPluginContainer* container, | |
| 323 const GURL& plugin_url) { | |
| 324 base::Callback<const void*(const char*)> get_plugin_interface_func = | |
| 325 base::Bind(&PluginModule::GetPluginInterface, module); | |
| 326 PPP_Instance_Combined* ppp_instance_combined = | |
| 327 PPP_Instance_Combined::Create(get_plugin_interface_func); | |
| 328 if (!ppp_instance_combined) | |
| 329 return NULL; | |
| 330 return new PluginInstanceImpl(delegate, render_view, module, | |
| 331 ppp_instance_combined, container, plugin_url); | |
| 332 } | |
| 333 | |
| 334 PluginInstanceImpl::NaClDocumentLoader::NaClDocumentLoader() | |
| 335 : finished_loading_(false) { | |
| 336 } | |
| 337 | |
| 338 PluginInstanceImpl::NaClDocumentLoader::~NaClDocumentLoader(){ | |
| 339 } | |
| 340 | |
| 341 void PluginInstanceImpl::NaClDocumentLoader::ReplayReceivedData( | |
| 342 WebURLLoaderClient* document_loader) { | |
| 343 for (std::list<std::string>::iterator it = data_.begin(); | |
| 344 it != data_.end(); ++it) { | |
| 345 document_loader->didReceiveData(NULL, it->c_str(), it->length(), | |
| 346 0 /* encoded_data_length */); | |
| 347 } | |
| 348 if (finished_loading_) { | |
| 349 document_loader->didFinishLoading(NULL, | |
| 350 0 /* finish_time */); | |
| 351 } | |
| 352 if (error_.get()) { | |
| 353 document_loader->didFail(NULL, *error_); | |
| 354 } | |
| 355 } | |
| 356 | |
| 357 void PluginInstanceImpl::NaClDocumentLoader::didReceiveData( | |
| 358 WebURLLoader* loader, | |
| 359 const char* data, | |
| 360 int data_length, | |
| 361 int encoded_data_length) { | |
| 362 data_.push_back(std::string(data, data_length)); | |
| 363 } | |
| 364 | |
| 365 void PluginInstanceImpl::NaClDocumentLoader::didFinishLoading( | |
| 366 WebURLLoader* loader, | |
| 367 double finish_time) { | |
| 368 DCHECK(!finished_loading_); | |
| 369 finished_loading_ = true; | |
| 370 } | |
| 371 | |
| 372 void PluginInstanceImpl::NaClDocumentLoader::didFail( | |
| 373 WebURLLoader* loader, | |
| 374 const WebURLError& error) { | |
| 375 DCHECK(!error_.get()); | |
| 376 error_.reset(new WebURLError(error)); | |
| 377 } | |
| 378 | |
| 379 PluginInstanceImpl::GamepadImpl::GamepadImpl(PluginDelegate* delegate) | |
| 380 : Resource(::ppapi::Resource::Untracked()), | |
| 381 delegate_(delegate) { | |
| 382 } | |
| 383 | |
| 384 PPB_Gamepad_API* PluginInstanceImpl::GamepadImpl::AsPPB_Gamepad_API() { | |
| 385 return this; | |
| 386 } | |
| 387 | |
| 388 void PluginInstanceImpl::GamepadImpl::Sample(PP_Instance instance, | |
| 389 PP_GamepadsSampleData* data) { | |
| 390 WebKit::WebGamepads webkit_data; | |
| 391 delegate_->SampleGamepads(&webkit_data); | |
| 392 ConvertWebKitGamepadData( | |
| 393 *reinterpret_cast<const ::ppapi::WebKitGamepads*>(&webkit_data), data); | |
| 394 } | |
| 395 | |
| 396 PluginInstanceImpl::PluginInstanceImpl( | |
| 397 PluginDelegate* delegate, | |
| 398 content::RenderView* render_view, | |
| 399 PluginModule* module, | |
| 400 ::ppapi::PPP_Instance_Combined* instance_interface, | |
| 401 WebPluginContainer* container, | |
| 402 const GURL& plugin_url) | |
| 403 : delegate_(delegate), | |
| 404 render_view_(render_view), | |
| 405 module_(module), | |
| 406 instance_interface_(instance_interface), | |
| 407 pp_instance_(0), | |
| 408 container_(container), | |
| 409 layer_bound_to_fullscreen_(false), | |
| 410 plugin_url_(plugin_url), | |
| 411 full_frame_(false), | |
| 412 sent_initial_did_change_view_(false), | |
| 413 view_change_weak_ptr_factory_(this), | |
| 414 bound_graphics_2d_platform_(NULL), | |
| 415 has_webkit_focus_(false), | |
| 416 has_content_area_focus_(false), | |
| 417 find_identifier_(-1), | |
| 418 plugin_find_interface_(NULL), | |
| 419 plugin_input_event_interface_(NULL), | |
| 420 plugin_messaging_interface_(NULL), | |
| 421 plugin_mouse_lock_interface_(NULL), | |
| 422 plugin_pdf_interface_(NULL), | |
| 423 plugin_private_interface_(NULL), | |
| 424 plugin_selection_interface_(NULL), | |
| 425 plugin_textinput_interface_(NULL), | |
| 426 plugin_zoom_interface_(NULL), | |
| 427 checked_for_plugin_input_event_interface_(false), | |
| 428 checked_for_plugin_messaging_interface_(false), | |
| 429 checked_for_plugin_pdf_interface_(false), | |
| 430 gamepad_impl_(new GamepadImpl(delegate)), | |
| 431 plugin_print_interface_(NULL), | |
| 432 plugin_graphics_3d_interface_(NULL), | |
| 433 always_on_top_(false), | |
| 434 fullscreen_container_(NULL), | |
| 435 flash_fullscreen_(false), | |
| 436 desired_fullscreen_state_(false), | |
| 437 sad_plugin_(NULL), | |
| 438 input_event_mask_(0), | |
| 439 filtered_input_event_mask_(0), | |
| 440 text_input_type_(kPluginDefaultTextInputType), | |
| 441 text_input_caret_(0, 0, 0, 0), | |
| 442 text_input_caret_bounds_(0, 0, 0, 0), | |
| 443 text_input_caret_set_(false), | |
| 444 selection_caret_(0), | |
| 445 selection_anchor_(0), | |
| 446 pending_user_gesture_(0.0), | |
| 447 document_loader_(NULL), | |
| 448 nacl_document_load_(false), | |
| 449 npp_(new NPP_t), | |
| 450 isolate_(v8::Isolate::GetCurrent()) { | |
| 451 pp_instance_ = HostGlobals::Get()->AddInstance(this); | |
| 452 | |
| 453 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | |
| 454 DCHECK(delegate); | |
| 455 module_->InstanceCreated(this); | |
| 456 delegate_->InstanceCreated(this); | |
| 457 | |
| 458 view_data_.is_page_visible = delegate->IsPageVisible(); | |
| 459 resource_creation_ = delegate_->CreateResourceCreationAPI(this); | |
| 460 | |
| 461 // TODO(bbudge) remove this when the trusted NaCl plugin has been removed. | |
| 462 // We must defer certain plugin events for NaCl instances since we switch | |
| 463 // from the in-process to the out-of-process proxy after instantiating them. | |
| 464 if (module->name() == "Native Client") | |
| 465 nacl_document_load_ = true; | |
| 466 } | |
| 467 | |
| 468 PluginInstanceImpl::~PluginInstanceImpl() { | |
| 469 DCHECK(!fullscreen_container_); | |
| 470 | |
| 471 // Force-unbind any Graphics. In the case of Graphics2D, if the plugin | |
| 472 // leaks the graphics 2D, it may actually get cleaned up after our | |
| 473 // destruction, so we need its pointers to be up-to-date. | |
| 474 BindGraphics(pp_instance(), 0); | |
| 475 | |
| 476 // Free all the plugin objects. This will automatically clear the back- | |
| 477 // pointer from the NPObject so WebKit can't call into the plugin any more. | |
| 478 // | |
| 479 // Swap out the set so we can delete from it (the objects will try to | |
| 480 // unregister themselves inside the delete call). | |
| 481 PluginObjectSet plugin_object_copy; | |
| 482 live_plugin_objects_.swap(plugin_object_copy); | |
| 483 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); | |
| 484 i != plugin_object_copy.end(); ++i) | |
| 485 delete *i; | |
| 486 | |
| 487 if (TrackedCallback::IsPending(lock_mouse_callback_)) | |
| 488 lock_mouse_callback_->Abort(); | |
| 489 | |
| 490 delegate_->InstanceDeleted(this); | |
| 491 module_->InstanceDeleted(this); | |
| 492 // If we switched from the NaCl plugin module, notify it too. | |
| 493 if (original_module_.get()) | |
| 494 original_module_->InstanceDeleted(this); | |
| 495 | |
| 496 // This should be last since some of the above "instance deleted" calls will | |
| 497 // want to look up in the global map to get info off of our object. | |
| 498 HostGlobals::Get()->InstanceDeleted(pp_instance_); | |
| 499 } | |
| 500 | |
| 501 // NOTE: Any of these methods that calls into the plugin needs to take into | |
| 502 // account that the plugin may use Var to remove the <embed> from the DOM, which | |
| 503 // will make the WebPluginImpl drop its reference, usually the last one. If a | |
| 504 // method needs to access a member of the instance after the call has returned, | |
| 505 // then it needs to keep its own reference on the stack. | |
| 506 | |
| 507 void PluginInstanceImpl::Delete() { | |
| 508 // Keep a reference on the stack. See NOTE above. | |
| 509 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 510 // Force the MessageChannel to release its "passthrough object" which should | |
| 511 // release our last reference to the "InstanceObject" and will probably | |
| 512 // destroy it. We want to do this prior to calling DidDestroy in case the | |
| 513 // destructor of the instance object tries to use the instance. | |
| 514 message_channel_->SetPassthroughObject(NULL); | |
| 515 // If this is a NaCl plugin instance, shut down the NaCl plugin by calling | |
| 516 // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance, | |
| 517 // since there is little that it can do at this point. | |
| 518 if (original_instance_interface_) | |
| 519 original_instance_interface_->DidDestroy(pp_instance()); | |
| 520 else | |
| 521 instance_interface_->DidDestroy(pp_instance()); | |
| 522 // Ensure we don't attempt to call functions on the destroyed instance. | |
| 523 original_instance_interface_.reset(); | |
| 524 instance_interface_.reset(); | |
| 525 | |
| 526 if (fullscreen_container_) { | |
| 527 fullscreen_container_->Destroy(); | |
| 528 fullscreen_container_ = NULL; | |
| 529 } | |
| 530 bound_graphics_3d_ = NULL; | |
| 531 UpdateLayer(); | |
| 532 container_ = NULL; | |
| 533 } | |
| 534 | |
| 535 void PluginInstanceImpl::Paint(WebCanvas* canvas, | |
| 536 const gfx::Rect& plugin_rect, | |
| 537 const gfx::Rect& paint_rect) { | |
| 538 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); | |
| 539 if (module()->is_crashed()) { | |
| 540 // Crashed plugin painting. | |
| 541 if (!sad_plugin_) // Lazily initialize bitmap. | |
| 542 sad_plugin_ = delegate_->GetSadPluginBitmap(); | |
| 543 if (sad_plugin_) | |
| 544 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); | |
| 545 return; | |
| 546 } | |
| 547 | |
| 548 PluginDelegate::PlatformGraphics2D* bound_graphics_2d = GetBoundGraphics2D(); | |
| 549 if (bound_graphics_2d) | |
| 550 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect); | |
| 551 } | |
| 552 | |
| 553 void PluginInstanceImpl::InvalidateRect(const gfx::Rect& rect) { | |
| 554 if (fullscreen_container_) { | |
| 555 if (rect.IsEmpty()) | |
| 556 fullscreen_container_->Invalidate(); | |
| 557 else | |
| 558 fullscreen_container_->InvalidateRect(rect); | |
| 559 } else { | |
| 560 if (!container_ || | |
| 561 view_data_.rect.size.width == 0 || view_data_.rect.size.height == 0) | |
| 562 return; // Nothing to do. | |
| 563 if (rect.IsEmpty()) | |
| 564 container_->invalidate(); | |
| 565 else | |
| 566 container_->invalidateRect(rect); | |
| 567 } | |
| 568 } | |
| 569 | |
| 570 void PluginInstanceImpl::ScrollRect(int dx, int dy, const gfx::Rect& rect) { | |
| 571 if (fullscreen_container_) { | |
| 572 fullscreen_container_->ScrollRect(dx, dy, rect); | |
| 573 } else { | |
| 574 if (full_frame_ && !IsViewAccelerated()) { | |
| 575 container_->scrollRect(dx, dy, rect); | |
| 576 } else { | |
| 577 // Can't do optimized scrolling since there could be other elements on top | |
| 578 // of us or the view renders via the accelerated compositor which is | |
| 579 // incompatible with the move and backfill scrolling model. | |
| 580 InvalidateRect(rect); | |
| 581 } | |
| 582 } | |
| 583 } | |
| 584 | |
| 585 void PluginInstanceImpl::CommitBackingTexture() { | |
| 586 if (texture_layer_.get()) | |
| 587 texture_layer_->SetNeedsDisplay(); | |
| 588 } | |
| 589 | |
| 590 void PluginInstanceImpl::InstanceCrashed() { | |
| 591 // Force free all resources and vars. | |
| 592 HostGlobals::Get()->InstanceCrashed(pp_instance()); | |
| 593 | |
| 594 // Free any associated graphics. | |
| 595 SetFullscreen(false); | |
| 596 FlashSetFullscreen(false, false); | |
| 597 // Unbind current 2D or 3D graphics context. | |
| 598 BindGraphics(pp_instance(), 0); | |
| 599 InvalidateRect(gfx::Rect()); | |
| 600 | |
| 601 delegate()->PluginCrashed(this); | |
| 602 } | |
| 603 | |
| 604 static void SetGPUHistogram(const ::ppapi::Preferences& prefs, | |
| 605 const std::vector<std::string>& arg_names, | |
| 606 const std::vector<std::string>& arg_values) { | |
| 607 // Calculate a histogram to let us determine how likely people are to try to | |
| 608 // run Stage3D content on machines that have it blacklisted. | |
| 609 #if defined(OS_WIN) | |
| 610 bool needs_gpu = false; | |
| 611 bool is_xp = base::win::GetVersion() <= base::win::VERSION_XP; | |
| 612 | |
| 613 for (size_t i = 0; i < arg_names.size(); i++) { | |
| 614 if (arg_names[i] == "wmode") { | |
| 615 // In theory content other than Flash could have a "wmode" argument, | |
| 616 // but that's pretty unlikely. | |
| 617 if (arg_values[i] == "direct" || arg_values[i] == "gpu") | |
| 618 needs_gpu = true; | |
| 619 break; | |
| 620 } | |
| 621 } | |
| 622 // 0 : No 3D content and GPU is blacklisted | |
| 623 // 1 : No 3D content and GPU is not blacklisted | |
| 624 // 2 : 3D content but GPU is blacklisted | |
| 625 // 3 : 3D content and GPU is not blacklisted | |
| 626 // 4 : No 3D content and GPU is blacklisted on XP | |
| 627 // 5 : No 3D content and GPU is not blacklisted on XP | |
| 628 // 6 : 3D content but GPU is blacklisted on XP | |
| 629 // 7 : 3D content and GPU is not blacklisted on XP | |
| 630 UMA_HISTOGRAM_ENUMERATION("Flash.UsesGPU", | |
| 631 is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); | |
| 632 #endif | |
| 633 } | |
| 634 | |
| 635 bool PluginInstanceImpl::Initialize(const std::vector<std::string>& arg_names, | |
| 636 const std::vector<std::string>& arg_values, | |
| 637 bool full_frame) { | |
| 638 message_channel_.reset(new MessageChannel(this)); | |
| 639 | |
| 640 full_frame_ = full_frame; | |
| 641 | |
| 642 UpdateTouchEventRequest(); | |
| 643 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); | |
| 644 | |
| 645 SetGPUHistogram(delegate_->GetPreferences(), arg_names, arg_values); | |
| 646 | |
| 647 argn_ = arg_names; | |
| 648 argv_ = arg_values; | |
| 649 scoped_ptr<const char*[]> argn_array(StringVectorToArgArray(argn_)); | |
| 650 scoped_ptr<const char*[]> argv_array(StringVectorToArgArray(argv_)); | |
| 651 bool success = PP_ToBool(instance_interface_->DidCreate(pp_instance(), | |
| 652 argn_.size(), | |
| 653 argn_array.get(), | |
| 654 argv_array.get())); | |
| 655 if (success) | |
| 656 message_channel_->StopQueueingJavaScriptMessages(); | |
| 657 return success; | |
| 658 } | |
| 659 | |
| 660 bool PluginInstanceImpl::HandleDocumentLoad( | |
| 661 const WebKit::WebURLResponse& response) { | |
| 662 DCHECK(!document_loader_); | |
| 663 if (!nacl_document_load_) { | |
| 664 if (module()->is_crashed()) { | |
| 665 // Don't create a resource for a crashed plugin. | |
| 666 container()->element().document().frame()->stopLoading(); | |
| 667 return false; | |
| 668 } | |
| 669 delegate()->HandleDocumentLoad(this, response); | |
| 670 // If the load was not abandoned, document_loader_ will now be set. It's | |
| 671 // possible that the load was canceled by now and document_loader_ was | |
| 672 // already nulled out. | |
| 673 } else { | |
| 674 // The NaCl proxy isn't available, so save the response and record document | |
| 675 // load notifications for later replay. | |
| 676 nacl_document_response_ = response; | |
| 677 nacl_document_loader_.reset(new NaClDocumentLoader()); | |
| 678 document_loader_ = nacl_document_loader_.get(); | |
| 679 } | |
| 680 return true; | |
| 681 } | |
| 682 | |
| 683 bool PluginInstanceImpl::SendCompositionEventToPlugin( | |
| 684 PP_InputEvent_Type type, const base::string16& text) { | |
| 685 std::vector<WebKit::WebCompositionUnderline> empty; | |
| 686 return SendCompositionEventWithUnderlineInformationToPlugin( | |
| 687 type, text, empty, static_cast<int>(text.size()), | |
| 688 static_cast<int>(text.size())); | |
| 689 } | |
| 690 | |
| 691 bool PluginInstanceImpl::SendCompositionEventWithUnderlineInformationToPlugin( | |
| 692 PP_InputEvent_Type type, | |
| 693 const base::string16& text, | |
| 694 const std::vector<WebKit::WebCompositionUnderline>& underlines, | |
| 695 int selection_start, | |
| 696 int selection_end) { | |
| 697 // Keep a reference on the stack. See NOTE above. | |
| 698 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 699 | |
| 700 if (!LoadInputEventInterface()) | |
| 701 return false; | |
| 702 | |
| 703 PP_InputEvent_Class event_class = PP_INPUTEVENT_CLASS_IME; | |
| 704 if (!(filtered_input_event_mask_ & event_class) && | |
| 705 !(input_event_mask_ & event_class)) | |
| 706 return false; | |
| 707 | |
| 708 ::ppapi::InputEventData event; | |
| 709 event.event_type = type; | |
| 710 event.event_time_stamp = ::ppapi::TimeTicksToPPTimeTicks( | |
| 711 base::TimeTicks::Now()); | |
| 712 | |
| 713 // Convert UTF16 text to UTF8 with offset conversion. | |
| 714 std::vector<size_t> utf16_offsets; | |
| 715 utf16_offsets.push_back(selection_start); | |
| 716 utf16_offsets.push_back(selection_end); | |
| 717 for (size_t i = 0; i < underlines.size(); ++i) { | |
| 718 utf16_offsets.push_back(underlines[i].startOffset); | |
| 719 utf16_offsets.push_back(underlines[i].endOffset); | |
| 720 } | |
| 721 std::vector<size_t> utf8_offsets(utf16_offsets); | |
| 722 event.character_text = base::UTF16ToUTF8AndAdjustOffsets(text, &utf8_offsets); | |
| 723 | |
| 724 // Set the converted selection range. | |
| 725 event.composition_selection_start = (utf8_offsets[0] == std::string::npos ? | |
| 726 event.character_text.size() : utf8_offsets[0]); | |
| 727 event.composition_selection_end = (utf8_offsets[1] == std::string::npos ? | |
| 728 event.character_text.size() : utf8_offsets[1]); | |
| 729 | |
| 730 // Set the converted segmentation points. | |
| 731 // Be sure to add 0 and size(), and remove duplication or errors. | |
| 732 std::set<size_t> offset_set(utf8_offsets.begin()+2, utf8_offsets.end()); | |
| 733 offset_set.insert(0); | |
| 734 offset_set.insert(event.character_text.size()); | |
| 735 offset_set.erase(std::string::npos); | |
| 736 event.composition_segment_offsets.assign(offset_set.begin(), | |
| 737 offset_set.end()); | |
| 738 | |
| 739 // Set the composition target. | |
| 740 for (size_t i = 0; i < underlines.size(); ++i) { | |
| 741 if (underlines[i].thick) { | |
| 742 std::vector<uint32_t>::iterator it = | |
| 743 std::find(event.composition_segment_offsets.begin(), | |
| 744 event.composition_segment_offsets.end(), | |
| 745 utf8_offsets[2*i+2]); | |
| 746 if (it != event.composition_segment_offsets.end()) { | |
| 747 event.composition_target_segment = | |
| 748 it - event.composition_segment_offsets.begin(); | |
| 749 break; | |
| 750 } | |
| 751 } | |
| 752 } | |
| 753 | |
| 754 // Send the event. | |
| 755 bool handled = false; | |
| 756 if (filtered_input_event_mask_ & event_class) | |
| 757 event.is_filtered = true; | |
| 758 else | |
| 759 handled = true; // Unfiltered events are assumed to be handled. | |
| 760 scoped_refptr<PPB_InputEvent_Shared> event_resource( | |
| 761 new PPB_InputEvent_Shared(::ppapi::OBJECT_IS_IMPL, pp_instance(), event)); | |
| 762 handled |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent( | |
| 763 pp_instance(), event_resource->pp_resource())); | |
| 764 return handled; | |
| 765 } | |
| 766 | |
| 767 void PluginInstanceImpl::RequestInputEventsHelper(uint32_t event_classes) { | |
| 768 if (event_classes & PP_INPUTEVENT_CLASS_TOUCH) | |
| 769 UpdateTouchEventRequest(); | |
| 770 if (event_classes & PP_INPUTEVENT_CLASS_WHEEL) | |
| 771 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); | |
| 772 } | |
| 773 | |
| 774 bool PluginInstanceImpl::HandleCompositionStart(const base::string16& text) { | |
| 775 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_START, | |
| 776 text); | |
| 777 } | |
| 778 | |
| 779 bool PluginInstanceImpl::HandleCompositionUpdate( | |
| 780 const base::string16& text, | |
| 781 const std::vector<WebKit::WebCompositionUnderline>& underlines, | |
| 782 int selection_start, | |
| 783 int selection_end) { | |
| 784 return SendCompositionEventWithUnderlineInformationToPlugin( | |
| 785 PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE, | |
| 786 text, underlines, selection_start, selection_end); | |
| 787 } | |
| 788 | |
| 789 bool PluginInstanceImpl::HandleCompositionEnd(const base::string16& text) { | |
| 790 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_COMPOSITION_END, | |
| 791 text); | |
| 792 } | |
| 793 | |
| 794 bool PluginInstanceImpl::HandleTextInput(const base::string16& text) { | |
| 795 return SendCompositionEventToPlugin(PP_INPUTEVENT_TYPE_IME_TEXT, | |
| 796 text); | |
| 797 } | |
| 798 | |
| 799 void PluginInstanceImpl::GetSurroundingText(base::string16* text, | |
| 800 ui::Range* range) const { | |
| 801 std::vector<size_t> offsets; | |
| 802 offsets.push_back(selection_anchor_); | |
| 803 offsets.push_back(selection_caret_); | |
| 804 *text = base::UTF8ToUTF16AndAdjustOffsets(surrounding_text_, &offsets); | |
| 805 range->set_start(offsets[0] == base::string16::npos ? text->size() | |
| 806 : offsets[0]); | |
| 807 range->set_end(offsets[1] == base::string16::npos ? text->size() | |
| 808 : offsets[1]); | |
| 809 } | |
| 810 | |
| 811 bool PluginInstanceImpl::IsPluginAcceptingCompositionEvents() const { | |
| 812 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || | |
| 813 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); | |
| 814 } | |
| 815 | |
| 816 gfx::Rect PluginInstanceImpl::GetCaretBounds() const { | |
| 817 if (!text_input_caret_set_) { | |
| 818 // If it is never set by the plugin, use the bottom left corner. | |
| 819 return gfx::Rect(view_data_.rect.point.x, | |
| 820 view_data_.rect.point.y + view_data_.rect.size.height, | |
| 821 0, 0); | |
| 822 } | |
| 823 | |
| 824 // TODO(kinaba) Take CSS transformation into accont. | |
| 825 // TODO(kinaba) Take bounding_box into account. On some platforms, an | |
| 826 // "exclude rectangle" where candidate window must avoid the region can be | |
| 827 // passed to IME. Currently, we pass only the caret rectangle because | |
| 828 // it is the only information supported uniformly in Chromium. | |
| 829 gfx::Rect caret(text_input_caret_); | |
| 830 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | |
| 831 return caret; | |
| 832 } | |
| 833 | |
| 834 bool PluginInstanceImpl::HandleInputEvent(const WebKit::WebInputEvent& event, | |
| 835 WebCursorInfo* cursor_info) { | |
| 836 TRACE_EVENT0("ppapi", "PluginInstanceImpl::HandleInputEvent"); | |
| 837 | |
| 838 if (WebInputEvent::isMouseEventType(event.type)) | |
| 839 delegate()->DidReceiveMouseEvent(this); | |
| 840 | |
| 841 // Don't dispatch input events to crashed plugins. | |
| 842 if (module()->is_crashed()) | |
| 843 return false; | |
| 844 | |
| 845 // Keep a reference on the stack. See NOTE above. | |
| 846 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 847 | |
| 848 bool rv = false; | |
| 849 if (LoadInputEventInterface()) { | |
| 850 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); | |
| 851 if (!event_class) | |
| 852 return false; | |
| 853 | |
| 854 if ((filtered_input_event_mask_ & event_class) || | |
| 855 (input_event_mask_ & event_class)) { | |
| 856 // Actually send the event. | |
| 857 std::vector< ::ppapi::InputEventData > events; | |
| 858 CreateInputEventData(event, &events); | |
| 859 | |
| 860 // Allow the user gesture to be pending after the plugin handles the | |
| 861 // event. This allows out-of-process plugins to respond to the user | |
| 862 // gesture after processing has finished here. | |
| 863 if (WebUserGestureIndicator::isProcessingUserGesture()) { | |
| 864 pending_user_gesture_ = | |
| 865 ::ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds); | |
| 866 pending_user_gesture_token_ = | |
| 867 WebUserGestureIndicator::currentUserGestureToken(); | |
| 868 pending_user_gesture_token_.setOutOfProcess(); | |
| 869 } | |
| 870 | |
| 871 // Each input event may generate more than one PP_InputEvent. | |
| 872 for (size_t i = 0; i < events.size(); i++) { | |
| 873 if (filtered_input_event_mask_ & event_class) | |
| 874 events[i].is_filtered = true; | |
| 875 else | |
| 876 rv = true; // Unfiltered events are assumed to be handled. | |
| 877 scoped_refptr<PPB_InputEvent_Shared> event_resource( | |
| 878 new PPB_InputEvent_Shared(::ppapi::OBJECT_IS_IMPL, | |
| 879 pp_instance(), events[i])); | |
| 880 | |
| 881 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent( | |
| 882 pp_instance(), event_resource->pp_resource())); | |
| 883 } | |
| 884 } | |
| 885 } | |
| 886 | |
| 887 if (cursor_) | |
| 888 *cursor_info = *cursor_; | |
| 889 return rv; | |
| 890 } | |
| 891 | |
| 892 void PluginInstanceImpl::HandleMessage(PP_Var message) { | |
| 893 TRACE_EVENT0("ppapi", "PluginInstanceImpl::HandleMessage"); | |
| 894 // Keep a reference on the stack. See NOTE above. | |
| 895 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 896 if (!LoadMessagingInterface()) | |
| 897 return; | |
| 898 plugin_messaging_interface_->HandleMessage(pp_instance(), message); | |
| 899 } | |
| 900 | |
| 901 PP_Var PluginInstanceImpl::GetInstanceObject() { | |
| 902 // Keep a reference on the stack. See NOTE above. | |
| 903 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 904 | |
| 905 // If the plugin supports the private instance interface, try to retrieve its | |
| 906 // instance object. | |
| 907 if (LoadPrivateInterface()) | |
| 908 return plugin_private_interface_->GetInstanceObject(pp_instance()); | |
| 909 return PP_MakeUndefined(); | |
| 910 } | |
| 911 | |
| 912 void PluginInstanceImpl::ViewChanged( | |
| 913 const gfx::Rect& position, | |
| 914 const gfx::Rect& clip, | |
| 915 const std::vector<gfx::Rect>& cut_outs_rects) { | |
| 916 // WebKit can give weird (x,y) positions for empty clip rects (since the | |
| 917 // position technically doesn't matter). But we want to make these | |
| 918 // consistent since this is given to the plugin, so force everything to 0 | |
| 919 // in the "everything is clipped" case. | |
| 920 gfx::Rect new_clip; | |
| 921 if (!clip.IsEmpty()) | |
| 922 new_clip = clip; | |
| 923 | |
| 924 cut_outs_rects_ = cut_outs_rects; | |
| 925 | |
| 926 view_data_.rect = PP_FromGfxRect(position); | |
| 927 view_data_.clip_rect = PP_FromGfxRect(clip); | |
| 928 view_data_.device_scale = container_->deviceScaleFactor(); | |
| 929 view_data_.css_scale = container_->pageZoomFactor() * | |
| 930 container_->pageScaleFactor(); | |
| 931 | |
| 932 if (desired_fullscreen_state_ || view_data_.is_fullscreen) { | |
| 933 WebElement element = container_->element(); | |
| 934 WebDocument document = element.document(); | |
| 935 bool is_fullscreen_element = (element == document.fullScreenElement()); | |
| 936 if (!view_data_.is_fullscreen && desired_fullscreen_state_ && | |
| 937 delegate()->IsInFullscreenMode() && is_fullscreen_element) { | |
| 938 // Entered fullscreen. Only possible via SetFullscreen(). | |
| 939 view_data_.is_fullscreen = true; | |
| 940 } else if (view_data_.is_fullscreen && !is_fullscreen_element) { | |
| 941 // Exited fullscreen. Possible via SetFullscreen() or F11/link, | |
| 942 // so desired_fullscreen_state might be out-of-date. | |
| 943 desired_fullscreen_state_ = false; | |
| 944 view_data_.is_fullscreen = false; | |
| 945 | |
| 946 // This operation will cause the plugin to re-layout which will send more | |
| 947 // DidChangeView updates. Schedule an asynchronous update and suppress | |
| 948 // notifications until that completes to avoid sending intermediate sizes | |
| 949 // to the plugins. | |
| 950 ScheduleAsyncDidChangeView(); | |
| 951 | |
| 952 // Reset the size attributes that we hacked to fill in the screen and | |
| 953 // retrigger ViewChanged. Make sure we don't forward duplicates of | |
| 954 // this view to the plugin. | |
| 955 ResetSizeAttributesAfterFullscreen(); | |
| 956 return; | |
| 957 } | |
| 958 } | |
| 959 | |
| 960 UpdateFlashFullscreenState(fullscreen_container_ != NULL); | |
| 961 | |
| 962 SendDidChangeView(); | |
| 963 } | |
| 964 | |
| 965 void PluginInstanceImpl::SetWebKitFocus(bool has_focus) { | |
| 966 if (has_webkit_focus_ == has_focus) | |
| 967 return; | |
| 968 | |
| 969 bool old_plugin_focus = PluginHasFocus(); | |
| 970 has_webkit_focus_ = has_focus; | |
| 971 if (PluginHasFocus() != old_plugin_focus) | |
| 972 SendFocusChangeNotification(); | |
| 973 } | |
| 974 | |
| 975 void PluginInstanceImpl::SetContentAreaFocus(bool has_focus) { | |
| 976 if (has_content_area_focus_ == has_focus) | |
| 977 return; | |
| 978 | |
| 979 bool old_plugin_focus = PluginHasFocus(); | |
| 980 has_content_area_focus_ = has_focus; | |
| 981 if (PluginHasFocus() != old_plugin_focus) | |
| 982 SendFocusChangeNotification(); | |
| 983 } | |
| 984 | |
| 985 void PluginInstanceImpl::PageVisibilityChanged(bool is_visible) { | |
| 986 if (is_visible == view_data_.is_page_visible) | |
| 987 return; // Nothing to do. | |
| 988 view_data_.is_page_visible = is_visible; | |
| 989 | |
| 990 // If the initial DidChangeView notification hasn't been sent to the plugin, | |
| 991 // let it pass the visibility state for us, instead of sending a notification | |
| 992 // immediately. It is possible that PluginInstanceImpl::ViewChanged() hasn't | |
| 993 // been called for the first time. In that case, most of the fields in | |
| 994 // |view_data_| haven't been properly initialized. | |
| 995 if (sent_initial_did_change_view_) | |
| 996 SendDidChangeView(); | |
| 997 } | |
| 998 | |
| 999 void PluginInstanceImpl::ViewWillInitiatePaint() { | |
| 1000 if (GetBoundGraphics2D()) | |
| 1001 GetBoundGraphics2D()->ViewWillInitiatePaint(); | |
| 1002 else if (bound_graphics_3d_.get()) | |
| 1003 bound_graphics_3d_->ViewWillInitiatePaint(); | |
| 1004 } | |
| 1005 | |
| 1006 void PluginInstanceImpl::ViewInitiatedPaint() { | |
| 1007 if (GetBoundGraphics2D()) | |
| 1008 GetBoundGraphics2D()->ViewInitiatedPaint(); | |
| 1009 else if (bound_graphics_3d_.get()) | |
| 1010 bound_graphics_3d_->ViewInitiatedPaint(); | |
| 1011 } | |
| 1012 | |
| 1013 void PluginInstanceImpl::ViewFlushedPaint() { | |
| 1014 // Keep a reference on the stack. See NOTE above. | |
| 1015 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1016 if (GetBoundGraphics2D()) | |
| 1017 GetBoundGraphics2D()->ViewFlushedPaint(); | |
| 1018 else if (bound_graphics_3d_.get()) | |
| 1019 bound_graphics_3d_->ViewFlushedPaint(); | |
| 1020 } | |
| 1021 | |
| 1022 bool PluginInstanceImpl::GetBitmapForOptimizedPluginPaint( | |
| 1023 const gfx::Rect& paint_bounds, | |
| 1024 TransportDIB** dib, | |
| 1025 gfx::Rect* location, | |
| 1026 gfx::Rect* clip, | |
| 1027 float* scale_factor) { | |
| 1028 if (!always_on_top_) | |
| 1029 return false; | |
| 1030 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->IsAlwaysOpaque()) | |
| 1031 return false; | |
| 1032 | |
| 1033 // We specifically want to compare against the area covered by the backing | |
| 1034 // store when seeing if we cover the given paint bounds, since the backing | |
| 1035 // store could be smaller than the declared plugin area. | |
| 1036 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->ImageData(); | |
| 1037 // ImageDatas created by NaCl don't have a PlatformImage, so can't be | |
| 1038 // optimized this way. | |
| 1039 if (!image_data->PlatformImage()) | |
| 1040 return false; | |
| 1041 | |
| 1042 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); | |
| 1043 gfx::Vector2d plugin_offset = plugin_origin.OffsetFromOrigin(); | |
| 1044 // Convert |paint_bounds| to be relative to the left-top corner of the plugin. | |
| 1045 gfx::Rect relative_paint_bounds(paint_bounds); | |
| 1046 relative_paint_bounds.Offset(-plugin_offset); | |
| 1047 | |
| 1048 gfx::Rect pixel_plugin_backing_store_rect( | |
| 1049 0, 0, image_data->width(), image_data->height()); | |
| 1050 float scale = GetBoundGraphics2D()->GetScale(); | |
| 1051 gfx::Rect plugin_backing_store_rect = gfx::ToEnclosedRect( | |
| 1052 gfx::ScaleRect(pixel_plugin_backing_store_rect, scale)); | |
| 1053 | |
| 1054 gfx::Rect clip_page = PP_ToGfxRect(view_data_.clip_rect); | |
| 1055 gfx::Rect plugin_paint_rect = | |
| 1056 gfx::IntersectRects(plugin_backing_store_rect, clip_page); | |
| 1057 if (!plugin_paint_rect.Contains(relative_paint_bounds)) | |
| 1058 return false; | |
| 1059 | |
| 1060 // Don't do optimized painting if the area to paint intersects with the | |
| 1061 // cut-out rects, otherwise we will paint over them. | |
| 1062 for (std::vector<gfx::Rect>::const_iterator iter = cut_outs_rects_.begin(); | |
| 1063 iter != cut_outs_rects_.end(); ++iter) { | |
| 1064 if (relative_paint_bounds.Intersects(*iter)) | |
| 1065 return false; | |
| 1066 } | |
| 1067 | |
| 1068 *dib = image_data->PlatformImage()->GetTransportDIB(); | |
| 1069 plugin_backing_store_rect.Offset(plugin_offset); | |
| 1070 *location = plugin_backing_store_rect; | |
| 1071 clip_page.Offset(plugin_offset); | |
| 1072 *clip = clip_page; | |
| 1073 // The plugin scale factor is inverted, e.g. for a device scale factor of 2x | |
| 1074 // the plugin scale factor is 0.5. | |
| 1075 *scale_factor = 1.0 / scale; | |
| 1076 return true; | |
| 1077 } | |
| 1078 | |
| 1079 base::string16 PluginInstanceImpl::GetSelectedText(bool html) { | |
| 1080 // Keep a reference on the stack. See NOTE above. | |
| 1081 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1082 if (!LoadSelectionInterface()) | |
| 1083 return base::string16(); | |
| 1084 | |
| 1085 PP_Var rv = plugin_selection_interface_->GetSelectedText(pp_instance(), | |
| 1086 PP_FromBool(html)); | |
| 1087 StringVar* string = StringVar::FromPPVar(rv); | |
| 1088 base::string16 selection; | |
| 1089 if (string) | |
| 1090 selection = UTF8ToUTF16(string->value()); | |
| 1091 // Release the ref the plugin transfered to us. | |
| 1092 HostGlobals::Get()->GetVarTracker()->ReleaseVar(rv); | |
| 1093 return selection; | |
| 1094 } | |
| 1095 | |
| 1096 base::string16 PluginInstanceImpl::GetLinkAtPosition(const gfx::Point& point) { | |
| 1097 // Keep a reference on the stack. See NOTE above. | |
| 1098 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1099 if (!LoadPdfInterface()) | |
| 1100 return base::string16(); | |
| 1101 | |
| 1102 PP_Point p; | |
| 1103 p.x = point.x(); | |
| 1104 p.y = point.y(); | |
| 1105 PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); | |
| 1106 StringVar* string = StringVar::FromPPVar(rv); | |
| 1107 base::string16 link; | |
| 1108 if (string) | |
| 1109 link = UTF8ToUTF16(string->value()); | |
| 1110 // Release the ref the plugin transfered to us. | |
| 1111 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(rv); | |
| 1112 return link; | |
| 1113 } | |
| 1114 | |
| 1115 void PluginInstanceImpl::RequestSurroundingText( | |
| 1116 size_t desired_number_of_characters) { | |
| 1117 // Keep a reference on the stack. See NOTE above. | |
| 1118 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1119 if (!LoadTextInputInterface()) | |
| 1120 return; | |
| 1121 plugin_textinput_interface_->RequestSurroundingText( | |
| 1122 pp_instance(), desired_number_of_characters); | |
| 1123 } | |
| 1124 | |
| 1125 void PluginInstanceImpl::Zoom(double factor, bool text_only) { | |
| 1126 // Keep a reference on the stack. See NOTE above. | |
| 1127 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1128 if (!LoadZoomInterface()) | |
| 1129 return; | |
| 1130 plugin_zoom_interface_->Zoom(pp_instance(), factor, PP_FromBool(text_only)); | |
| 1131 } | |
| 1132 | |
| 1133 bool PluginInstanceImpl::StartFind(const base::string16& search_text, | |
| 1134 bool case_sensitive, | |
| 1135 int identifier) { | |
| 1136 // Keep a reference on the stack. See NOTE above. | |
| 1137 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1138 if (!LoadFindInterface()) | |
| 1139 return false; | |
| 1140 find_identifier_ = identifier; | |
| 1141 return PP_ToBool( | |
| 1142 plugin_find_interface_->StartFind( | |
| 1143 pp_instance(), | |
| 1144 UTF16ToUTF8(search_text.c_str()).c_str(), | |
| 1145 PP_FromBool(case_sensitive))); | |
| 1146 } | |
| 1147 | |
| 1148 void PluginInstanceImpl::SelectFindResult(bool forward) { | |
| 1149 // Keep a reference on the stack. See NOTE above. | |
| 1150 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1151 if (LoadFindInterface()) | |
| 1152 plugin_find_interface_->SelectFindResult(pp_instance(), | |
| 1153 PP_FromBool(forward)); | |
| 1154 } | |
| 1155 | |
| 1156 void PluginInstanceImpl::StopFind() { | |
| 1157 // Keep a reference on the stack. See NOTE above. | |
| 1158 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1159 if (!LoadFindInterface()) | |
| 1160 return; | |
| 1161 find_identifier_ = -1; | |
| 1162 plugin_find_interface_->StopFind(pp_instance()); | |
| 1163 } | |
| 1164 | |
| 1165 bool PluginInstanceImpl::LoadFindInterface() { | |
| 1166 if (!plugin_find_interface_) { | |
| 1167 plugin_find_interface_ = | |
| 1168 static_cast<const PPP_Find_Dev*>(module_->GetPluginInterface( | |
| 1169 PPP_FIND_DEV_INTERFACE)); | |
| 1170 } | |
| 1171 | |
| 1172 return !!plugin_find_interface_; | |
| 1173 } | |
| 1174 | |
| 1175 bool PluginInstanceImpl::LoadInputEventInterface() { | |
| 1176 if (!checked_for_plugin_input_event_interface_) { | |
| 1177 checked_for_plugin_input_event_interface_ = true; | |
| 1178 plugin_input_event_interface_ = | |
| 1179 static_cast<const PPP_InputEvent*>(module_->GetPluginInterface( | |
| 1180 PPP_INPUT_EVENT_INTERFACE)); | |
| 1181 } | |
| 1182 return !!plugin_input_event_interface_; | |
| 1183 } | |
| 1184 | |
| 1185 bool PluginInstanceImpl::LoadMessagingInterface() { | |
| 1186 if (!checked_for_plugin_messaging_interface_) { | |
| 1187 checked_for_plugin_messaging_interface_ = true; | |
| 1188 plugin_messaging_interface_ = | |
| 1189 static_cast<const PPP_Messaging*>(module_->GetPluginInterface( | |
| 1190 PPP_MESSAGING_INTERFACE)); | |
| 1191 } | |
| 1192 return !!plugin_messaging_interface_; | |
| 1193 } | |
| 1194 | |
| 1195 bool PluginInstanceImpl::LoadMouseLockInterface() { | |
| 1196 if (!plugin_mouse_lock_interface_) { | |
| 1197 plugin_mouse_lock_interface_ = | |
| 1198 static_cast<const PPP_MouseLock*>(module_->GetPluginInterface( | |
| 1199 PPP_MOUSELOCK_INTERFACE)); | |
| 1200 } | |
| 1201 | |
| 1202 return !!plugin_mouse_lock_interface_; | |
| 1203 } | |
| 1204 | |
| 1205 bool PluginInstanceImpl::LoadPdfInterface() { | |
| 1206 if (!checked_for_plugin_pdf_interface_) { | |
| 1207 checked_for_plugin_pdf_interface_ = true; | |
| 1208 plugin_pdf_interface_ = | |
| 1209 static_cast<const PPP_Pdf_1*>(module_->GetPluginInterface( | |
| 1210 PPP_PDF_INTERFACE_1)); | |
| 1211 } | |
| 1212 | |
| 1213 return !!plugin_pdf_interface_; | |
| 1214 } | |
| 1215 | |
| 1216 bool PluginInstanceImpl::LoadPrintInterface() { | |
| 1217 // Only check for the interface if the plugin has dev permission. | |
| 1218 if (!module_->permissions().HasPermission(::ppapi::PERMISSION_DEV)) | |
| 1219 return false; | |
| 1220 if (!plugin_print_interface_) { | |
| 1221 plugin_print_interface_ = static_cast<const PPP_Printing_Dev*>( | |
| 1222 module_->GetPluginInterface(PPP_PRINTING_DEV_INTERFACE)); | |
| 1223 } | |
| 1224 return !!plugin_print_interface_; | |
| 1225 } | |
| 1226 | |
| 1227 bool PluginInstanceImpl::LoadPrivateInterface() { | |
| 1228 // Only check for the interface if the plugin has private permission. | |
| 1229 if (!module_->permissions().HasPermission(::ppapi::PERMISSION_PRIVATE)) | |
| 1230 return false; | |
| 1231 if (!plugin_private_interface_) { | |
| 1232 plugin_private_interface_ = static_cast<const PPP_Instance_Private*>( | |
| 1233 module_->GetPluginInterface(PPP_INSTANCE_PRIVATE_INTERFACE)); | |
| 1234 } | |
| 1235 | |
| 1236 return !!plugin_private_interface_; | |
| 1237 } | |
| 1238 | |
| 1239 bool PluginInstanceImpl::LoadSelectionInterface() { | |
| 1240 if (!plugin_selection_interface_) { | |
| 1241 plugin_selection_interface_ = | |
| 1242 static_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface( | |
| 1243 PPP_SELECTION_DEV_INTERFACE)); | |
| 1244 } | |
| 1245 return !!plugin_selection_interface_; | |
| 1246 } | |
| 1247 | |
| 1248 bool PluginInstanceImpl::LoadTextInputInterface() { | |
| 1249 if (!plugin_textinput_interface_) { | |
| 1250 plugin_textinput_interface_ = | |
| 1251 static_cast<const PPP_TextInput_Dev*>(module_->GetPluginInterface( | |
| 1252 PPP_TEXTINPUT_DEV_INTERFACE)); | |
| 1253 } | |
| 1254 | |
| 1255 return !!plugin_textinput_interface_; | |
| 1256 } | |
| 1257 | |
| 1258 bool PluginInstanceImpl::LoadZoomInterface() { | |
| 1259 if (!plugin_zoom_interface_) { | |
| 1260 plugin_zoom_interface_ = | |
| 1261 static_cast<const PPP_Zoom_Dev*>(module_->GetPluginInterface( | |
| 1262 PPP_ZOOM_DEV_INTERFACE)); | |
| 1263 } | |
| 1264 | |
| 1265 return !!plugin_zoom_interface_; | |
| 1266 } | |
| 1267 | |
| 1268 bool PluginInstanceImpl::PluginHasFocus() const { | |
| 1269 return flash_fullscreen_ || (has_webkit_focus_ && has_content_area_focus_); | |
| 1270 } | |
| 1271 | |
| 1272 void PluginInstanceImpl::SendFocusChangeNotification() { | |
| 1273 // This call can happen during PluginInstanceImpl destruction, because WebKit | |
| 1274 // informs the plugin it's losing focus. See crbug.com/236574 | |
| 1275 if (!delegate_ || !instance_interface_) | |
| 1276 return; | |
| 1277 bool has_focus = PluginHasFocus(); | |
| 1278 delegate()->PluginFocusChanged(this, has_focus); | |
| 1279 instance_interface_->DidChangeFocus(pp_instance(), PP_FromBool(has_focus)); | |
| 1280 } | |
| 1281 | |
| 1282 void PluginInstanceImpl::UpdateTouchEventRequest() { | |
| 1283 bool raw_touch = (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_TOUCH) || | |
| 1284 (input_event_mask_ & PP_INPUTEVENT_CLASS_TOUCH); | |
| 1285 container_->requestTouchEventType(raw_touch ? | |
| 1286 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : | |
| 1287 WebKit::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse); | |
| 1288 } | |
| 1289 | |
| 1290 bool PluginInstanceImpl::IsAcceptingWheelEvents() const { | |
| 1291 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_WHEEL) || | |
| 1292 (input_event_mask_ & PP_INPUTEVENT_CLASS_WHEEL); | |
| 1293 } | |
| 1294 | |
| 1295 void PluginInstanceImpl::ScheduleAsyncDidChangeView() { | |
| 1296 if (view_change_weak_ptr_factory_.HasWeakPtrs()) | |
| 1297 return; // Already scheduled. | |
| 1298 base::MessageLoop::current()->PostTask( | |
| 1299 FROM_HERE, | |
| 1300 base::Bind(&PluginInstanceImpl::SendAsyncDidChangeView, | |
| 1301 view_change_weak_ptr_factory_.GetWeakPtr())); | |
| 1302 } | |
| 1303 | |
| 1304 void PluginInstanceImpl::SendAsyncDidChangeView() { | |
| 1305 // The bound callback that owns the weak pointer is still valid until after | |
| 1306 // this function returns. SendDidChangeView checks HasWeakPtrs, so we need to | |
| 1307 // invalidate them here. | |
| 1308 // NOTE: If we ever want to have more than one pending callback, it should | |
| 1309 // use a different factory, or we should have a different strategy here. | |
| 1310 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 1311 SendDidChangeView(); | |
| 1312 } | |
| 1313 | |
| 1314 void PluginInstanceImpl::SendDidChangeView() { | |
| 1315 // Don't send DidChangeView to crashed plugins. | |
| 1316 if (module()->is_crashed()) | |
| 1317 return; | |
| 1318 | |
| 1319 if (view_change_weak_ptr_factory_.HasWeakPtrs() || | |
| 1320 (sent_initial_did_change_view_ && | |
| 1321 last_sent_view_data_.Equals(view_data_))) | |
| 1322 return; // Nothing to update. | |
| 1323 | |
| 1324 const PP_Size& size = view_data_.rect.size; | |
| 1325 // Avoid sending a notification with a huge rectangle. | |
| 1326 if (size.width < 0 || size.width > kMaxPluginSideLength || | |
| 1327 size.height < 0 || size.height > kMaxPluginSideLength || | |
| 1328 // We know this won't overflow due to above checks. | |
| 1329 static_cast<uint32>(size.width) * static_cast<uint32>(size.height) > | |
| 1330 kMaxPluginSize) { | |
| 1331 return; | |
| 1332 } | |
| 1333 | |
| 1334 sent_initial_did_change_view_ = true; | |
| 1335 last_sent_view_data_ = view_data_; | |
| 1336 ScopedPPResource resource( | |
| 1337 ScopedPPResource::PassRef(), | |
| 1338 (new PPB_View_Shared(::ppapi::OBJECT_IS_IMPL, | |
| 1339 pp_instance(), view_data_))->GetReference()); | |
| 1340 | |
| 1341 instance_interface_->DidChangeView(pp_instance(), resource, | |
| 1342 &view_data_.rect, | |
| 1343 &view_data_.clip_rect); | |
| 1344 } | |
| 1345 | |
| 1346 void PluginInstanceImpl::ReportGeometry() { | |
| 1347 // If this call was delayed, we may have transitioned back to fullscreen in | |
| 1348 // the mean time, so only report the geometry if we are actually in normal | |
| 1349 // mode. | |
| 1350 if (container_ && !fullscreen_container_ && !flash_fullscreen_) | |
| 1351 container_->reportGeometry(); | |
| 1352 } | |
| 1353 | |
| 1354 bool PluginInstanceImpl::GetPreferredPrintOutputFormat( | |
| 1355 PP_PrintOutputFormat_Dev* format) { | |
| 1356 // Keep a reference on the stack. See NOTE above. | |
| 1357 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1358 if (!LoadPrintInterface()) | |
| 1359 return false; | |
| 1360 uint32_t supported_formats = | |
| 1361 plugin_print_interface_->QuerySupportedFormats(pp_instance()); | |
| 1362 if (supported_formats & PP_PRINTOUTPUTFORMAT_PDF) { | |
| 1363 *format = PP_PRINTOUTPUTFORMAT_PDF; | |
| 1364 return true; | |
| 1365 } | |
| 1366 return false; | |
| 1367 } | |
| 1368 | |
| 1369 bool PluginInstanceImpl::SupportsPrintInterface() { | |
| 1370 PP_PrintOutputFormat_Dev format; | |
| 1371 return GetPreferredPrintOutputFormat(&format); | |
| 1372 } | |
| 1373 | |
| 1374 bool PluginInstanceImpl::IsPrintScalingDisabled() { | |
| 1375 DCHECK(plugin_print_interface_); | |
| 1376 if (!plugin_print_interface_) | |
| 1377 return false; | |
| 1378 return plugin_print_interface_->IsScalingDisabled(pp_instance()) == PP_TRUE; | |
| 1379 } | |
| 1380 | |
| 1381 int PluginInstanceImpl::PrintBegin(const WebPrintParams& print_params) { | |
| 1382 // Keep a reference on the stack. See NOTE above. | |
| 1383 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1384 PP_PrintOutputFormat_Dev format; | |
| 1385 if (!GetPreferredPrintOutputFormat(&format)) { | |
| 1386 // PrintBegin should not have been called since SupportsPrintInterface | |
| 1387 // would have returned false; | |
| 1388 NOTREACHED(); | |
| 1389 return 0; | |
| 1390 } | |
| 1391 int num_pages = 0; | |
| 1392 PP_PrintSettings_Dev print_settings; | |
| 1393 print_settings.printable_area = PP_FromGfxRect(print_params.printableArea); | |
| 1394 print_settings.content_area = PP_FromGfxRect(print_params.printContentArea); | |
| 1395 print_settings.paper_size = PP_FromGfxSize(print_params.paperSize); | |
| 1396 print_settings.dpi = print_params.printerDPI; | |
| 1397 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; | |
| 1398 print_settings.grayscale = PP_FALSE; | |
| 1399 print_settings.print_scaling_option = static_cast<PP_PrintScalingOption_Dev>( | |
| 1400 print_params.printScalingOption); | |
| 1401 print_settings.format = format; | |
| 1402 num_pages = plugin_print_interface_->Begin(pp_instance(), | |
| 1403 &print_settings); | |
| 1404 if (!num_pages) | |
| 1405 return 0; | |
| 1406 current_print_settings_ = print_settings; | |
| 1407 canvas_.clear(); | |
| 1408 ranges_.clear(); | |
| 1409 return num_pages; | |
| 1410 } | |
| 1411 | |
| 1412 bool PluginInstanceImpl::PrintPage(int page_number, WebKit::WebCanvas* canvas) { | |
| 1413 #if defined(ENABLE_PRINTING) | |
| 1414 DCHECK(plugin_print_interface_); | |
| 1415 PP_PrintPageNumberRange_Dev page_range; | |
| 1416 page_range.first_page_number = page_range.last_page_number = page_number; | |
| 1417 // The canvas only has a metafile on it for print preview. | |
| 1418 bool save_for_later = | |
| 1419 (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL); | |
| 1420 #if defined(OS_MACOSX) || defined(OS_WIN) | |
| 1421 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); | |
| 1422 #endif | |
| 1423 if (save_for_later) { | |
| 1424 ranges_.push_back(page_range); | |
| 1425 canvas_ = skia::SharePtr(canvas); | |
| 1426 return true; | |
| 1427 } else { | |
| 1428 return PrintPageHelper(&page_range, 1, canvas); | |
| 1429 } | |
| 1430 #else // defined(ENABLED_PRINTING) | |
| 1431 return false; | |
| 1432 #endif | |
| 1433 } | |
| 1434 | |
| 1435 bool PluginInstanceImpl::PrintPageHelper( | |
| 1436 PP_PrintPageNumberRange_Dev* page_ranges, | |
| 1437 int num_ranges, | |
| 1438 WebKit::WebCanvas* canvas) { | |
| 1439 // Keep a reference on the stack. See NOTE above. | |
| 1440 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1441 DCHECK(plugin_print_interface_); | |
| 1442 if (!plugin_print_interface_) | |
| 1443 return false; | |
| 1444 PP_Resource print_output = plugin_print_interface_->PrintPages( | |
| 1445 pp_instance(), page_ranges, num_ranges); | |
| 1446 if (!print_output) | |
| 1447 return false; | |
| 1448 | |
| 1449 bool ret = false; | |
| 1450 | |
| 1451 if (current_print_settings_.format == PP_PRINTOUTPUTFORMAT_PDF) | |
| 1452 ret = PrintPDFOutput(print_output, canvas); | |
| 1453 | |
| 1454 // Now we need to release the print output resource. | |
| 1455 PluginModule::GetCore()->ReleaseResource(print_output); | |
| 1456 | |
| 1457 return ret; | |
| 1458 } | |
| 1459 | |
| 1460 void PluginInstanceImpl::PrintEnd() { | |
| 1461 // Keep a reference on the stack. See NOTE above. | |
| 1462 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1463 if (!ranges_.empty()) | |
| 1464 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get()); | |
| 1465 canvas_.clear(); | |
| 1466 ranges_.clear(); | |
| 1467 | |
| 1468 DCHECK(plugin_print_interface_); | |
| 1469 if (plugin_print_interface_) | |
| 1470 plugin_print_interface_->End(pp_instance()); | |
| 1471 | |
| 1472 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | |
| 1473 #if defined(OS_MACOSX) | |
| 1474 last_printed_page_ = NULL; | |
| 1475 #endif // defined(OS_MACOSX) | |
| 1476 } | |
| 1477 | |
| 1478 bool PluginInstanceImpl::CanRotateView() { | |
| 1479 if (!LoadPdfInterface()) | |
| 1480 return false; | |
| 1481 | |
| 1482 return true; | |
| 1483 } | |
| 1484 | |
| 1485 void PluginInstanceImpl::SetBoundGraphics2DForTest( | |
| 1486 PluginDelegate::PlatformGraphics2D* graphics) { | |
| 1487 BindGraphics(pp_instance(), 0); // Unbind any old stuff. | |
| 1488 if (graphics) { | |
| 1489 bound_graphics_2d_platform_ = graphics; | |
| 1490 bound_graphics_2d_platform_->BindToInstance(this); | |
| 1491 } | |
| 1492 } | |
| 1493 | |
| 1494 void PluginInstanceImpl::RotateView(WebPlugin::RotationType type) { | |
| 1495 if (!LoadPdfInterface()) | |
| 1496 return; | |
| 1497 PP_PrivatePageTransformType transform_type = | |
| 1498 type == WebPlugin::RotationType90Clockwise ? | |
| 1499 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW : | |
| 1500 PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW; | |
| 1501 plugin_pdf_interface_->Transform(pp_instance(), transform_type); | |
| 1502 // NOTE: plugin instance may have been deleted. | |
| 1503 } | |
| 1504 | |
| 1505 bool PluginInstanceImpl::FlashIsFullscreenOrPending() { | |
| 1506 return fullscreen_container_ != NULL; | |
| 1507 } | |
| 1508 | |
| 1509 bool PluginInstanceImpl::IsFullscreenOrPending() { | |
| 1510 return desired_fullscreen_state_; | |
| 1511 } | |
| 1512 | |
| 1513 bool PluginInstanceImpl::SetFullscreen(bool fullscreen) { | |
| 1514 // Keep a reference on the stack. See NOTE above. | |
| 1515 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1516 | |
| 1517 // Check whether we are trying to switch to the state we're already going | |
| 1518 // to (i.e. if we're already switching to fullscreen but the fullscreen | |
| 1519 // container isn't ready yet, don't do anything more). | |
| 1520 if (fullscreen == IsFullscreenOrPending()) | |
| 1521 return false; | |
| 1522 | |
| 1523 // Check whether we are trying to switch while the state is in transition. | |
| 1524 // The 2nd request gets dropped while messing up the internal state, so | |
| 1525 // disallow this. | |
| 1526 if (view_data_.is_fullscreen != desired_fullscreen_state_) | |
| 1527 return false; | |
| 1528 | |
| 1529 if (fullscreen && !IsProcessingUserGesture()) | |
| 1530 return false; | |
| 1531 | |
| 1532 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); | |
| 1533 desired_fullscreen_state_ = fullscreen; | |
| 1534 | |
| 1535 if (fullscreen) { | |
| 1536 // Create the user gesture in case we're processing one that's pending. | |
| 1537 WebScopedUserGesture user_gesture(CurrentUserGestureToken()); | |
| 1538 // WebKit does not resize the plugin to fill the screen in fullscreen mode, | |
| 1539 // so we will tweak plugin's attributes to support the expected behavior. | |
| 1540 KeepSizeAttributesBeforeFullscreen(); | |
| 1541 SetSizeAttributesForFullscreen(); | |
| 1542 container_->element().requestFullScreen(); | |
| 1543 } else { | |
| 1544 container_->element().document().cancelFullScreen(); | |
| 1545 } | |
| 1546 return true; | |
| 1547 } | |
| 1548 | |
| 1549 void PluginInstanceImpl::UpdateFlashFullscreenState(bool flash_fullscreen) { | |
| 1550 bool is_mouselock_pending = TrackedCallback::IsPending(lock_mouse_callback_); | |
| 1551 | |
| 1552 if (flash_fullscreen == flash_fullscreen_) { | |
| 1553 // Manually clear callback when fullscreen fails with mouselock pending. | |
| 1554 if (!flash_fullscreen && is_mouselock_pending) | |
| 1555 lock_mouse_callback_->Run(PP_ERROR_FAILED); | |
| 1556 return; | |
| 1557 } | |
| 1558 | |
| 1559 PPB_Graphics3D_Impl* graphics_3d = bound_graphics_3d_.get(); | |
| 1560 if (graphics_3d) | |
| 1561 UpdateLayer(); | |
| 1562 | |
| 1563 bool old_plugin_focus = PluginHasFocus(); | |
| 1564 flash_fullscreen_ = flash_fullscreen; | |
| 1565 if (is_mouselock_pending && !delegate()->IsMouseLocked(this)) { | |
| 1566 if (!IsProcessingUserGesture() && | |
| 1567 !module_->permissions().HasPermission( | |
| 1568 ::ppapi::PERMISSION_BYPASS_USER_GESTURE)) { | |
| 1569 lock_mouse_callback_->Run(PP_ERROR_NO_USER_GESTURE); | |
| 1570 } else { | |
| 1571 // Open a user gesture here so the Webkit user gesture checks will succeed | |
| 1572 // for out-of-process plugins. | |
| 1573 WebScopedUserGesture user_gesture(CurrentUserGestureToken()); | |
| 1574 if (!delegate()->LockMouse(this)) | |
| 1575 lock_mouse_callback_->Run(PP_ERROR_FAILED); | |
| 1576 } | |
| 1577 } | |
| 1578 | |
| 1579 if (PluginHasFocus() != old_plugin_focus) | |
| 1580 SendFocusChangeNotification(); | |
| 1581 } | |
| 1582 | |
| 1583 bool PluginInstanceImpl::IsViewAccelerated() { | |
| 1584 if (!container_) | |
| 1585 return false; | |
| 1586 | |
| 1587 WebDocument document = container_->element().document(); | |
| 1588 WebFrame* frame = document.frame(); | |
| 1589 if (!frame) | |
| 1590 return false; | |
| 1591 WebView* view = frame->view(); | |
| 1592 if (!view) | |
| 1593 return false; | |
| 1594 | |
| 1595 return view->isAcceleratedCompositingActive(); | |
| 1596 } | |
| 1597 | |
| 1598 PluginDelegate::PlatformContext3D* PluginInstanceImpl::CreateContext3D() { | |
| 1599 return delegate_->CreateContext3D(); | |
| 1600 } | |
| 1601 | |
| 1602 bool PluginInstanceImpl::PrintPDFOutput(PP_Resource print_output, | |
| 1603 WebKit::WebCanvas* canvas) { | |
| 1604 #if defined(ENABLE_PRINTING) | |
| 1605 ::ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> enter(print_output, true); | |
| 1606 if (enter.failed()) | |
| 1607 return false; | |
| 1608 | |
| 1609 BufferAutoMapper mapper(enter.object()); | |
| 1610 if (!mapper.data() || !mapper.size()) { | |
| 1611 NOTREACHED(); | |
| 1612 return false; | |
| 1613 } | |
| 1614 #if defined(OS_WIN) | |
| 1615 // For Windows, we need the PDF DLL to render the output PDF to a DC. | |
| 1616 HMODULE pdf_module = GetModuleHandle(L"pdf.dll"); | |
| 1617 if (!pdf_module) | |
| 1618 return false; | |
| 1619 RenderPDFPageToDCProc render_proc = | |
| 1620 reinterpret_cast<RenderPDFPageToDCProc>( | |
| 1621 GetProcAddress(pdf_module, "RenderPDFPageToDC")); | |
| 1622 if (!render_proc) | |
| 1623 return false; | |
| 1624 #endif // defined(OS_WIN) | |
| 1625 | |
| 1626 bool ret = false; | |
| 1627 #if defined(OS_LINUX) || defined(OS_MACOSX) | |
| 1628 // On Linux we just set the final bits in the native metafile | |
| 1629 // (NativeMetafile and PreviewMetafile must have compatible formats, | |
| 1630 // i.e. both PDF for this to work). | |
| 1631 printing::Metafile* metafile = | |
| 1632 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); | |
| 1633 DCHECK(metafile != NULL); | |
| 1634 if (metafile) | |
| 1635 ret = metafile->InitFromData(mapper.data(), mapper.size()); | |
| 1636 #elif defined(OS_WIN) | |
| 1637 printing::Metafile* metafile = | |
| 1638 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); | |
| 1639 if (metafile) { | |
| 1640 // We only have a metafile when doing print preview, so we just want to | |
| 1641 // pass the PDF off to preview. | |
| 1642 ret = metafile->InitFromData(mapper.data(), mapper.size()); | |
| 1643 } else { | |
| 1644 // On Windows, we now need to render the PDF to the DC that backs the | |
| 1645 // supplied canvas. | |
| 1646 HDC dc = skia::BeginPlatformPaint(canvas); | |
| 1647 DrawEmptyRectangle(dc); | |
| 1648 gfx::Size size_in_pixels; | |
| 1649 size_in_pixels.set_width(printing::ConvertUnit( | |
| 1650 current_print_settings_.printable_area.size.width, | |
| 1651 static_cast<int>(printing::kPointsPerInch), | |
| 1652 current_print_settings_.dpi)); | |
| 1653 size_in_pixels.set_height(printing::ConvertUnit( | |
| 1654 current_print_settings_.printable_area.size.height, | |
| 1655 static_cast<int>(printing::kPointsPerInch), | |
| 1656 current_print_settings_.dpi)); | |
| 1657 // We need to scale down DC to fit an entire page into DC available area. | |
| 1658 // First, we'll try to use default scaling based on the 72dpi that is | |
| 1659 // used in webkit for printing. | |
| 1660 // If default scaling is not enough to fit the entire PDF without | |
| 1661 // Current metafile is based on screen DC and have current screen size. | |
| 1662 // Writing outside of those boundaries will result in the cut-off output. | |
| 1663 // On metafiles (this is the case here), scaling down will still record | |
| 1664 // original coordinates and we'll be able to print in full resolution. | |
| 1665 // Before playback we'll need to counter the scaling up that will happen | |
| 1666 // in the browser (printed_document_win.cc). | |
| 1667 double dynamic_scale = gfx::CalculatePageScale(dc, size_in_pixels.width(), | |
| 1668 size_in_pixels.height()); | |
| 1669 double page_scale = static_cast<double>(printing::kPointsPerInch) / | |
| 1670 static_cast<double>(current_print_settings_.dpi); | |
| 1671 | |
| 1672 if (dynamic_scale < page_scale) { | |
| 1673 page_scale = dynamic_scale; | |
| 1674 printing::MetafileSkiaWrapper::SetCustomScaleOnCanvas(*canvas, | |
| 1675 page_scale); | |
| 1676 } | |
| 1677 | |
| 1678 gfx::ScaleDC(dc, page_scale); | |
| 1679 | |
| 1680 ret = render_proc(static_cast<unsigned char*>(mapper.data()), mapper.size(), | |
| 1681 0, dc, current_print_settings_.dpi, | |
| 1682 current_print_settings_.dpi, 0, 0, size_in_pixels.width(), | |
| 1683 size_in_pixels.height(), true, false, true, true, true); | |
| 1684 skia::EndPlatformPaint(canvas); | |
| 1685 } | |
| 1686 #endif // defined(OS_WIN) | |
| 1687 | |
| 1688 return ret; | |
| 1689 #else // defined(ENABLE_PRINTING) | |
| 1690 return false; | |
| 1691 #endif | |
| 1692 } | |
| 1693 | |
| 1694 PluginDelegate::PlatformGraphics2D* | |
| 1695 PluginInstanceImpl::GetBoundGraphics2D() const { | |
| 1696 return bound_graphics_2d_platform_; | |
| 1697 } | |
| 1698 | |
| 1699 static void IgnoreCallback(unsigned, bool) {} | |
| 1700 | |
| 1701 void PluginInstanceImpl::UpdateLayer() { | |
| 1702 if (!container_) | |
| 1703 return; | |
| 1704 | |
| 1705 gpu::Mailbox mailbox; | |
| 1706 if (bound_graphics_3d_.get()) { | |
| 1707 PluginDelegate::PlatformContext3D* context = | |
| 1708 bound_graphics_3d_->platform_context(); | |
| 1709 context->GetBackingMailbox(&mailbox); | |
| 1710 } | |
| 1711 bool want_layer = !mailbox.IsZero(); | |
| 1712 | |
| 1713 if (want_layer == !!texture_layer_.get() && | |
| 1714 layer_bound_to_fullscreen_ == !!fullscreen_container_) | |
| 1715 return; | |
| 1716 | |
| 1717 if (texture_layer_.get()) { | |
| 1718 if (!layer_bound_to_fullscreen_) | |
| 1719 container_->setWebLayer(NULL); | |
| 1720 else if (fullscreen_container_) | |
| 1721 fullscreen_container_->SetLayer(NULL); | |
| 1722 web_layer_.reset(); | |
| 1723 texture_layer_ = NULL; | |
| 1724 } | |
| 1725 if (want_layer) { | |
| 1726 DCHECK(bound_graphics_3d_.get()); | |
| 1727 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); | |
| 1728 web_layer_.reset(new webkit::WebLayerImpl(texture_layer_)); | |
| 1729 if (fullscreen_container_) { | |
| 1730 fullscreen_container_->SetLayer(web_layer_.get()); | |
| 1731 // Ignore transparency in fullscreen, since that's what Flash always | |
| 1732 // wants to do, and that lets it not recreate a context if | |
| 1733 // wmode=transparent was specified. | |
| 1734 texture_layer_->SetContentsOpaque(true); | |
| 1735 } else { | |
| 1736 container_->setWebLayer(web_layer_.get()); | |
| 1737 texture_layer_->SetContentsOpaque(bound_graphics_3d_->IsOpaque()); | |
| 1738 } | |
| 1739 texture_layer_->SetTextureMailbox( | |
| 1740 cc::TextureMailbox(mailbox, base::Bind(&IgnoreCallback), 0)); | |
| 1741 } | |
| 1742 layer_bound_to_fullscreen_ = !!fullscreen_container_; | |
| 1743 } | |
| 1744 | |
| 1745 void PluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) { | |
| 1746 DCHECK(live_plugin_objects_.find(plugin_object) == | |
| 1747 live_plugin_objects_.end()); | |
| 1748 live_plugin_objects_.insert(plugin_object); | |
| 1749 } | |
| 1750 | |
| 1751 void PluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) { | |
| 1752 // Don't actually verify that the object is in the set since during module | |
| 1753 // deletion we'll be in the process of freeing them. | |
| 1754 live_plugin_objects_.erase(plugin_object); | |
| 1755 } | |
| 1756 | |
| 1757 bool PluginInstanceImpl::IsProcessingUserGesture() { | |
| 1758 PP_TimeTicks now = | |
| 1759 ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); | |
| 1760 // Give a lot of slack so tests won't be flaky. | |
| 1761 const PP_TimeTicks kUserGestureDurationInSeconds = 10.0; | |
| 1762 return pending_user_gesture_token_.hasGestures() && | |
| 1763 (now - pending_user_gesture_ < kUserGestureDurationInSeconds); | |
| 1764 } | |
| 1765 | |
| 1766 WebUserGestureToken PluginInstanceImpl::CurrentUserGestureToken() { | |
| 1767 if (!IsProcessingUserGesture()) | |
| 1768 pending_user_gesture_token_ = WebUserGestureToken(); | |
| 1769 return pending_user_gesture_token_; | |
| 1770 } | |
| 1771 | |
| 1772 void PluginInstanceImpl::OnLockMouseACK(bool succeeded) { | |
| 1773 if (TrackedCallback::IsPending(lock_mouse_callback_)) | |
| 1774 lock_mouse_callback_->Run(succeeded ? PP_OK : PP_ERROR_FAILED); | |
| 1775 } | |
| 1776 | |
| 1777 void PluginInstanceImpl::OnMouseLockLost() { | |
| 1778 if (LoadMouseLockInterface()) | |
| 1779 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); | |
| 1780 } | |
| 1781 | |
| 1782 void PluginInstanceImpl::HandleMouseLockedInputEvent( | |
| 1783 const WebKit::WebMouseEvent& event) { | |
| 1784 // |cursor_info| is ignored since it is hidden when the mouse is locked. | |
| 1785 WebKit::WebCursorInfo cursor_info; | |
| 1786 HandleInputEvent(event, &cursor_info); | |
| 1787 } | |
| 1788 | |
| 1789 void PluginInstanceImpl::SimulateInputEvent(const InputEventData& input_event) { | |
| 1790 WebView* web_view = container()->element().document().frame()->view(); | |
| 1791 if (!web_view) { | |
| 1792 NOTREACHED(); | |
| 1793 return; | |
| 1794 } | |
| 1795 | |
| 1796 bool handled = SimulateIMEEvent(input_event); | |
| 1797 if (handled) | |
| 1798 return; | |
| 1799 | |
| 1800 std::vector<linked_ptr<WebInputEvent> > events = | |
| 1801 CreateSimulatedWebInputEvents( | |
| 1802 input_event, | |
| 1803 view_data_.rect.point.x + view_data_.rect.size.width / 2, | |
| 1804 view_data_.rect.point.y + view_data_.rect.size.height / 2); | |
| 1805 for (std::vector<linked_ptr<WebInputEvent> >::iterator it = events.begin(); | |
| 1806 it != events.end(); ++it) { | |
| 1807 web_view->handleInputEvent(*it->get()); | |
| 1808 } | |
| 1809 } | |
| 1810 | |
| 1811 bool PluginInstanceImpl::SimulateIMEEvent(const InputEventData& input_event) { | |
| 1812 switch (input_event.event_type) { | |
| 1813 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_START: | |
| 1814 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE: | |
| 1815 SimulateImeSetCompositionEvent(input_event); | |
| 1816 break; | |
| 1817 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_END: | |
| 1818 DCHECK(input_event.character_text.empty()); | |
| 1819 SimulateImeSetCompositionEvent(input_event); | |
| 1820 break; | |
| 1821 case PP_INPUTEVENT_TYPE_IME_TEXT: | |
| 1822 delegate()->SimulateImeConfirmComposition( | |
| 1823 UTF8ToUTF16(input_event.character_text)); | |
| 1824 break; | |
| 1825 default: | |
| 1826 return false; | |
| 1827 } | |
| 1828 return true; | |
| 1829 } | |
| 1830 | |
| 1831 void PluginInstanceImpl::SimulateImeSetCompositionEvent( | |
| 1832 const InputEventData& input_event) { | |
| 1833 std::vector<size_t> offsets; | |
| 1834 offsets.push_back(input_event.composition_selection_start); | |
| 1835 offsets.push_back(input_event.composition_selection_end); | |
| 1836 offsets.insert(offsets.end(), | |
| 1837 input_event.composition_segment_offsets.begin(), | |
| 1838 input_event.composition_segment_offsets.end()); | |
| 1839 | |
| 1840 base::string16 utf16_text = | |
| 1841 base::UTF8ToUTF16AndAdjustOffsets(input_event.character_text, &offsets); | |
| 1842 | |
| 1843 std::vector<WebKit::WebCompositionUnderline> underlines; | |
| 1844 for (size_t i = 2; i + 1 < offsets.size(); ++i) { | |
| 1845 WebKit::WebCompositionUnderline underline; | |
| 1846 underline.startOffset = offsets[i]; | |
| 1847 underline.endOffset = offsets[i + 1]; | |
| 1848 if (input_event.composition_target_segment == static_cast<int32_t>(i - 2)) | |
| 1849 underline.thick = true; | |
| 1850 underlines.push_back(underline); | |
| 1851 } | |
| 1852 | |
| 1853 delegate()->SimulateImeSetComposition( | |
| 1854 utf16_text, underlines, offsets[0], offsets[1]); | |
| 1855 } | |
| 1856 | |
| 1857 ContentDecryptorDelegate* PluginInstanceImpl::GetContentDecryptorDelegate() { | |
| 1858 if (content_decryptor_delegate_) | |
| 1859 return content_decryptor_delegate_.get(); | |
| 1860 | |
| 1861 const PPP_ContentDecryptor_Private* plugin_decryption_interface = | |
| 1862 static_cast<const PPP_ContentDecryptor_Private*>( | |
| 1863 module_->GetPluginInterface( | |
| 1864 PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE)); | |
| 1865 if (!plugin_decryption_interface) | |
| 1866 return NULL; | |
| 1867 | |
| 1868 content_decryptor_delegate_.reset( | |
| 1869 new ContentDecryptorDelegate(pp_instance_, plugin_decryption_interface)); | |
| 1870 return content_decryptor_delegate_.get(); | |
| 1871 } | |
| 1872 | |
| 1873 PP_Bool PluginInstanceImpl::BindGraphics(PP_Instance instance, | |
| 1874 PP_Resource device) { | |
| 1875 TRACE_EVENT0("ppapi", "PluginInstanceImpl::BindGraphics"); | |
| 1876 // The Graphics3D instance can't be destroyed until we call | |
| 1877 // UpdateLayer(). | |
| 1878 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_3d_.get(); | |
| 1879 if (bound_graphics_3d_.get()) { | |
| 1880 bound_graphics_3d_->BindToInstance(false); | |
| 1881 bound_graphics_3d_ = NULL; | |
| 1882 } | |
| 1883 if (bound_graphics_2d_platform_) { | |
| 1884 GetBoundGraphics2D()->BindToInstance(NULL); | |
| 1885 bound_graphics_2d_platform_ = NULL; | |
| 1886 } | |
| 1887 | |
| 1888 // Special-case clearing the current device. | |
| 1889 if (!device) { | |
| 1890 UpdateLayer(); | |
| 1891 InvalidateRect(gfx::Rect()); | |
| 1892 return PP_TRUE; | |
| 1893 } | |
| 1894 | |
| 1895 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or | |
| 1896 // to/from fullscreen with PPB_Fullscreen. | |
| 1897 if ((fullscreen_container_ && !flash_fullscreen_) || | |
| 1898 desired_fullscreen_state_ != view_data_.is_fullscreen) | |
| 1899 return PP_FALSE; | |
| 1900 | |
| 1901 PluginDelegate::PlatformGraphics2D* graphics_2d = | |
| 1902 delegate_->GetGraphics2D(this, device); | |
| 1903 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); | |
| 1904 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? | |
| 1905 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; | |
| 1906 | |
| 1907 if (graphics_2d) { | |
| 1908 if (graphics_2d->BindToInstance(this)) { | |
| 1909 bound_graphics_2d_platform_ = graphics_2d; | |
| 1910 UpdateLayer(); | |
| 1911 return PP_TRUE; | |
| 1912 } | |
| 1913 } else if (graphics_3d) { | |
| 1914 // Make sure graphics can only be bound to the instance it is | |
| 1915 // associated with. | |
| 1916 if (graphics_3d->pp_instance() == pp_instance() && | |
| 1917 graphics_3d->BindToInstance(true)) { | |
| 1918 bound_graphics_3d_ = graphics_3d; | |
| 1919 UpdateLayer(); | |
| 1920 return PP_TRUE; | |
| 1921 } | |
| 1922 } | |
| 1923 | |
| 1924 // The instance cannot be bound or the device is not a valid resource type. | |
| 1925 return PP_FALSE; | |
| 1926 } | |
| 1927 | |
| 1928 PP_Bool PluginInstanceImpl::IsFullFrame(PP_Instance instance) { | |
| 1929 return PP_FromBool(full_frame()); | |
| 1930 } | |
| 1931 | |
| 1932 const ViewData* PluginInstanceImpl::GetViewData(PP_Instance instance) { | |
| 1933 return &view_data_; | |
| 1934 } | |
| 1935 | |
| 1936 PP_Bool PluginInstanceImpl::FlashIsFullscreen(PP_Instance instance) { | |
| 1937 return PP_FromBool(flash_fullscreen_); | |
| 1938 } | |
| 1939 | |
| 1940 PP_Var PluginInstanceImpl::GetWindowObject(PP_Instance instance) { | |
| 1941 if (!container_) | |
| 1942 return PP_MakeUndefined(); | |
| 1943 | |
| 1944 WebFrame* frame = container_->element().document().frame(); | |
| 1945 if (!frame) | |
| 1946 return PP_MakeUndefined(); | |
| 1947 | |
| 1948 return NPObjectToPPVar(this, frame->windowObject()); | |
| 1949 } | |
| 1950 | |
| 1951 PP_Var PluginInstanceImpl::GetOwnerElementObject(PP_Instance instance) { | |
| 1952 if (!container_) | |
| 1953 return PP_MakeUndefined(); | |
| 1954 return NPObjectToPPVar(this, container_->scriptableObjectForElement()); | |
| 1955 } | |
| 1956 | |
| 1957 PP_Var PluginInstanceImpl::ExecuteScript(PP_Instance instance, | |
| 1958 PP_Var script, | |
| 1959 PP_Var* exception) { | |
| 1960 // Executing the script may remove the plugin from the DOM, so we need to keep | |
| 1961 // a reference to ourselves so that we can still process the result after the | |
| 1962 // WebBindings::evaluate() below. | |
| 1963 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 1964 TryCatch try_catch(exception); | |
| 1965 if (try_catch.has_exception()) | |
| 1966 return PP_MakeUndefined(); | |
| 1967 | |
| 1968 // Convert the script into an inconvenient NPString object. | |
| 1969 StringVar* script_string = StringVar::FromPPVar(script); | |
| 1970 if (!script_string) { | |
| 1971 try_catch.SetException("Script param to ExecuteScript must be a string."); | |
| 1972 return PP_MakeUndefined(); | |
| 1973 } | |
| 1974 NPString np_script; | |
| 1975 np_script.UTF8Characters = script_string->value().c_str(); | |
| 1976 np_script.UTF8Length = script_string->value().length(); | |
| 1977 | |
| 1978 // Get the current frame to pass to the evaluate function. | |
| 1979 WebFrame* frame = container_->element().document().frame(); | |
| 1980 if (!frame) { | |
| 1981 try_catch.SetException("No frame to execute script in."); | |
| 1982 return PP_MakeUndefined(); | |
| 1983 } | |
| 1984 | |
| 1985 NPVariant result; | |
| 1986 bool ok = false; | |
| 1987 if (IsProcessingUserGesture()) { | |
| 1988 WebKit::WebScopedUserGesture user_gesture(CurrentUserGestureToken()); | |
| 1989 ok = WebBindings::evaluate(NULL, frame->windowObject(), &np_script, | |
| 1990 &result); | |
| 1991 } else { | |
| 1992 ok = WebBindings::evaluate(NULL, frame->windowObject(), &np_script, | |
| 1993 &result); | |
| 1994 } | |
| 1995 if (!ok) { | |
| 1996 // TryCatch doesn't catch the exceptions properly. Since this is only for | |
| 1997 // a trusted API, just set to a general exception message. | |
| 1998 try_catch.SetException("Exception caught"); | |
| 1999 WebBindings::releaseVariantValue(&result); | |
| 2000 return PP_MakeUndefined(); | |
| 2001 } | |
| 2002 | |
| 2003 PP_Var ret = NPVariantToPPVar(this, &result); | |
| 2004 WebBindings::releaseVariantValue(&result); | |
| 2005 return ret; | |
| 2006 } | |
| 2007 | |
| 2008 uint32_t PluginInstanceImpl::GetAudioHardwareOutputSampleRate( | |
| 2009 PP_Instance instance) { | |
| 2010 return delegate()->GetAudioHardwareOutputSampleRate(); | |
| 2011 } | |
| 2012 | |
| 2013 uint32_t PluginInstanceImpl::GetAudioHardwareOutputBufferSize( | |
| 2014 PP_Instance instance) { | |
| 2015 return delegate()->GetAudioHardwareOutputBufferSize(); | |
| 2016 } | |
| 2017 | |
| 2018 PP_Var PluginInstanceImpl::GetDefaultCharSet(PP_Instance instance) { | |
| 2019 std::string encoding = delegate()->GetDefaultEncoding(); | |
| 2020 return StringVar::StringToPPVar(encoding); | |
| 2021 } | |
| 2022 | |
| 2023 // These PPB_ContentDecryptor_Private calls are responses to | |
| 2024 // PPP_ContentDecryptor_Private calls made on |content_decryptor_delegate_|. | |
| 2025 // Therefore, |content_decryptor_delegate_| must have been initialized when | |
| 2026 // the following methods are called. | |
| 2027 void PluginInstanceImpl::NeedKey(PP_Instance instance, | |
| 2028 PP_Var key_system_var, | |
| 2029 PP_Var session_id_var, | |
| 2030 PP_Var init_data_var) { | |
| 2031 content_decryptor_delegate_->NeedKey( | |
| 2032 key_system_var, session_id_var, init_data_var); | |
| 2033 } | |
| 2034 | |
| 2035 void PluginInstanceImpl::KeyAdded(PP_Instance instance, | |
| 2036 PP_Var key_system_var, | |
| 2037 PP_Var session_id_var) { | |
| 2038 content_decryptor_delegate_->KeyAdded(key_system_var, session_id_var); | |
| 2039 } | |
| 2040 | |
| 2041 void PluginInstanceImpl::KeyMessage(PP_Instance instance, | |
| 2042 PP_Var key_system_var, | |
| 2043 PP_Var session_id_var, | |
| 2044 PP_Var message_var, | |
| 2045 PP_Var default_url_var) { | |
| 2046 content_decryptor_delegate_->KeyMessage( | |
| 2047 key_system_var, session_id_var, message_var, default_url_var); | |
| 2048 } | |
| 2049 | |
| 2050 void PluginInstanceImpl::KeyError(PP_Instance instance, | |
| 2051 PP_Var key_system_var, | |
| 2052 PP_Var session_id_var, | |
| 2053 int32_t media_error, | |
| 2054 int32_t system_code) { | |
| 2055 content_decryptor_delegate_->KeyError( | |
| 2056 key_system_var, session_id_var, media_error, system_code); | |
| 2057 } | |
| 2058 | |
| 2059 void PluginInstanceImpl::DeliverBlock(PP_Instance instance, | |
| 2060 PP_Resource decrypted_block, | |
| 2061 const PP_DecryptedBlockInfo* block_info) { | |
| 2062 content_decryptor_delegate_->DeliverBlock(decrypted_block, block_info); | |
| 2063 } | |
| 2064 | |
| 2065 void PluginInstanceImpl::DecoderInitializeDone( | |
| 2066 PP_Instance instance, | |
| 2067 PP_DecryptorStreamType decoder_type, | |
| 2068 uint32_t request_id, | |
| 2069 PP_Bool success) { | |
| 2070 content_decryptor_delegate_->DecoderInitializeDone( | |
| 2071 decoder_type, request_id, success); | |
| 2072 } | |
| 2073 | |
| 2074 void PluginInstanceImpl::DecoderDeinitializeDone( | |
| 2075 PP_Instance instance, | |
| 2076 PP_DecryptorStreamType decoder_type, | |
| 2077 uint32_t request_id) { | |
| 2078 content_decryptor_delegate_->DecoderDeinitializeDone(decoder_type, | |
| 2079 request_id); | |
| 2080 } | |
| 2081 | |
| 2082 void PluginInstanceImpl::DecoderResetDone(PP_Instance instance, | |
| 2083 PP_DecryptorStreamType decoder_type, | |
| 2084 uint32_t request_id) { | |
| 2085 content_decryptor_delegate_->DecoderResetDone(decoder_type, request_id); | |
| 2086 } | |
| 2087 | |
| 2088 | |
| 2089 void PluginInstanceImpl::DeliverFrame(PP_Instance instance, | |
| 2090 PP_Resource decrypted_frame, | |
| 2091 const PP_DecryptedFrameInfo* frame_info) { | |
| 2092 content_decryptor_delegate_->DeliverFrame(decrypted_frame, frame_info); | |
| 2093 } | |
| 2094 | |
| 2095 void PluginInstanceImpl::DeliverSamples( | |
| 2096 PP_Instance instance, | |
| 2097 PP_Resource audio_frames, | |
| 2098 const PP_DecryptedBlockInfo* block_info) { | |
| 2099 content_decryptor_delegate_->DeliverSamples(audio_frames, block_info); | |
| 2100 } | |
| 2101 | |
| 2102 void PluginInstanceImpl::NumberOfFindResultsChanged(PP_Instance instance, | |
| 2103 int32_t total, | |
| 2104 PP_Bool final_result) { | |
| 2105 DCHECK_NE(find_identifier_, -1); | |
| 2106 delegate_->NumberOfFindResultsChanged(find_identifier_, total, | |
| 2107 PP_ToBool(final_result)); | |
| 2108 } | |
| 2109 | |
| 2110 void PluginInstanceImpl::SelectedFindResultChanged(PP_Instance instance, | |
| 2111 int32_t index) { | |
| 2112 DCHECK_NE(find_identifier_, -1); | |
| 2113 delegate_->SelectedFindResultChanged(find_identifier_, index); | |
| 2114 } | |
| 2115 | |
| 2116 PP_Bool PluginInstanceImpl::IsFullscreen(PP_Instance instance) { | |
| 2117 return PP_FromBool(view_data_.is_fullscreen); | |
| 2118 } | |
| 2119 | |
| 2120 PP_Bool PluginInstanceImpl::SetFullscreen(PP_Instance instance, | |
| 2121 PP_Bool fullscreen) { | |
| 2122 return PP_FromBool(SetFullscreen(PP_ToBool(fullscreen))); | |
| 2123 } | |
| 2124 | |
| 2125 PP_Bool PluginInstanceImpl::GetScreenSize(PP_Instance instance, PP_Size* size) { | |
| 2126 gfx::Size screen_size = delegate()->GetScreenSize(); | |
| 2127 *size = PP_MakeSize(screen_size.width(), screen_size.height()); | |
| 2128 return PP_TRUE; | |
| 2129 } | |
| 2130 | |
| 2131 ::ppapi::Resource* PluginInstanceImpl::GetSingletonResource( | |
| 2132 PP_Instance instance, | |
| 2133 ::ppapi::SingletonResourceID id) { | |
| 2134 // Flash APIs and some others aren't implemented in-process. | |
| 2135 switch (id) { | |
| 2136 case ::ppapi::BROKER_SINGLETON_ID: | |
| 2137 case ::ppapi::BROWSER_FONT_SINGLETON_ID: | |
| 2138 case ::ppapi::CRX_FILESYSTEM_SINGLETON_ID: | |
| 2139 case ::ppapi::EXTENSIONS_COMMON_SINGLETON_ID: | |
| 2140 case ::ppapi::FLASH_CLIPBOARD_SINGLETON_ID: | |
| 2141 case ::ppapi::FLASH_FILE_SINGLETON_ID: | |
| 2142 case ::ppapi::FLASH_FULLSCREEN_SINGLETON_ID: | |
| 2143 case ::ppapi::FLASH_SINGLETON_ID: | |
| 2144 case ::ppapi::NETWORK_PROXY_SINGLETON_ID: | |
| 2145 case ::ppapi::PDF_SINGLETON_ID: | |
| 2146 case ::ppapi::TRUETYPE_FONT_SINGLETON_ID: | |
| 2147 NOTIMPLEMENTED(); | |
| 2148 return NULL; | |
| 2149 case ::ppapi::GAMEPAD_SINGLETON_ID: | |
| 2150 return gamepad_impl_.get(); | |
| 2151 } | |
| 2152 | |
| 2153 NOTREACHED(); | |
| 2154 return NULL; | |
| 2155 } | |
| 2156 | |
| 2157 int32_t PluginInstanceImpl::RequestInputEvents(PP_Instance instance, | |
| 2158 uint32_t event_classes) { | |
| 2159 input_event_mask_ |= event_classes; | |
| 2160 filtered_input_event_mask_ &= ~(event_classes); | |
| 2161 RequestInputEventsHelper(event_classes); | |
| 2162 return ValidateRequestInputEvents(false, event_classes); | |
| 2163 } | |
| 2164 | |
| 2165 int32_t PluginInstanceImpl::RequestFilteringInputEvents( | |
| 2166 PP_Instance instance, | |
| 2167 uint32_t event_classes) { | |
| 2168 filtered_input_event_mask_ |= event_classes; | |
| 2169 input_event_mask_ &= ~(event_classes); | |
| 2170 RequestInputEventsHelper(event_classes); | |
| 2171 return ValidateRequestInputEvents(true, event_classes); | |
| 2172 } | |
| 2173 | |
| 2174 void PluginInstanceImpl::ClearInputEventRequest(PP_Instance instance, | |
| 2175 uint32_t event_classes) { | |
| 2176 input_event_mask_ &= ~(event_classes); | |
| 2177 filtered_input_event_mask_ &= ~(event_classes); | |
| 2178 RequestInputEventsHelper(event_classes); | |
| 2179 } | |
| 2180 | |
| 2181 void PluginInstanceImpl::ZoomChanged(PP_Instance instance, double factor) { | |
| 2182 // We only want to tell the page to change its zoom if the whole page is the | |
| 2183 // plugin. If we're in an iframe, then don't do anything. | |
| 2184 if (!IsFullPagePlugin()) | |
| 2185 return; | |
| 2186 container()->zoomLevelChanged(WebView::zoomFactorToZoomLevel(factor)); | |
| 2187 } | |
| 2188 | |
| 2189 void PluginInstanceImpl::ZoomLimitsChanged(PP_Instance instance, | |
| 2190 double minimum_factor, | |
| 2191 double maximium_factor) { | |
| 2192 if (minimum_factor > maximium_factor) { | |
| 2193 NOTREACHED(); | |
| 2194 return; | |
| 2195 } | |
| 2196 delegate()->ZoomLimitsChanged(minimum_factor, maximium_factor); | |
| 2197 } | |
| 2198 | |
| 2199 void PluginInstanceImpl::PostMessage(PP_Instance instance, PP_Var message) { | |
| 2200 message_channel_->PostMessageToJavaScript(message); | |
| 2201 } | |
| 2202 | |
| 2203 PP_Bool PluginInstanceImpl::SetCursor(PP_Instance instance, | |
| 2204 PP_MouseCursor_Type type, | |
| 2205 PP_Resource image, | |
| 2206 const PP_Point* hot_spot) { | |
| 2207 if (!ValidateSetCursorParams(type, image, hot_spot)) | |
| 2208 return PP_FALSE; | |
| 2209 | |
| 2210 if (type != PP_MOUSECURSOR_TYPE_CUSTOM) { | |
| 2211 DoSetCursor(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); | |
| 2212 return PP_TRUE; | |
| 2213 } | |
| 2214 | |
| 2215 EnterResourceNoLock<PPB_ImageData_API> enter(image, true); | |
| 2216 if (enter.failed()) | |
| 2217 return PP_FALSE; | |
| 2218 PPB_ImageData_Impl* image_data = | |
| 2219 static_cast<PPB_ImageData_Impl*>(enter.object()); | |
| 2220 | |
| 2221 ImageDataAutoMapper auto_mapper(image_data); | |
| 2222 if (!auto_mapper.is_valid()) | |
| 2223 return PP_FALSE; | |
| 2224 | |
| 2225 scoped_ptr<WebCursorInfo> custom_cursor( | |
| 2226 new WebCursorInfo(WebCursorInfo::TypeCustom)); | |
| 2227 custom_cursor->hotSpot.x = hot_spot->x; | |
| 2228 custom_cursor->hotSpot.y = hot_spot->y; | |
| 2229 | |
| 2230 const SkBitmap* bitmap = image_data->GetMappedBitmap(); | |
| 2231 // Make a deep copy, so that the cursor remains valid even after the original | |
| 2232 // image data gets freed. | |
| 2233 if (!bitmap->copyTo(&custom_cursor->customImage.getSkBitmap(), | |
| 2234 bitmap->config())) { | |
| 2235 return PP_FALSE; | |
| 2236 } | |
| 2237 | |
| 2238 DoSetCursor(custom_cursor.release()); | |
| 2239 return PP_TRUE; | |
| 2240 } | |
| 2241 | |
| 2242 int32_t PluginInstanceImpl::LockMouse(PP_Instance instance, | |
| 2243 scoped_refptr<TrackedCallback> callback) { | |
| 2244 if (TrackedCallback::IsPending(lock_mouse_callback_)) | |
| 2245 return PP_ERROR_INPROGRESS; | |
| 2246 | |
| 2247 if (delegate()->IsMouseLocked(this)) | |
| 2248 return PP_OK; | |
| 2249 | |
| 2250 if (!CanAccessMainFrame()) | |
| 2251 return PP_ERROR_NOACCESS; | |
| 2252 | |
| 2253 if (!IsProcessingUserGesture()) | |
| 2254 return PP_ERROR_NO_USER_GESTURE; | |
| 2255 | |
| 2256 // Attempt mouselock only if Flash isn't waiting on fullscreen, otherwise | |
| 2257 // we wait and call LockMouse() in UpdateFlashFullscreenState(). | |
| 2258 if (!FlashIsFullscreenOrPending() || flash_fullscreen()) { | |
| 2259 // Open a user gesture here so the Webkit user gesture checks will succeed | |
| 2260 // for out-of-process plugins. | |
| 2261 WebScopedUserGesture user_gesture(CurrentUserGestureToken()); | |
| 2262 if (!delegate()->LockMouse(this)) | |
| 2263 return PP_ERROR_FAILED; | |
| 2264 } | |
| 2265 | |
| 2266 // Either mouselock succeeded or a Flash fullscreen is pending. | |
| 2267 lock_mouse_callback_ = callback; | |
| 2268 return PP_OK_COMPLETIONPENDING; | |
| 2269 } | |
| 2270 | |
| 2271 void PluginInstanceImpl::UnlockMouse(PP_Instance instance) { | |
| 2272 delegate()->UnlockMouse(this); | |
| 2273 } | |
| 2274 | |
| 2275 void PluginInstanceImpl::SetTextInputType(PP_Instance instance, | |
| 2276 PP_TextInput_Type type) { | |
| 2277 int itype = type; | |
| 2278 if (itype < 0 || itype > ui::TEXT_INPUT_TYPE_URL) | |
| 2279 itype = ui::TEXT_INPUT_TYPE_NONE; | |
| 2280 text_input_type_ = static_cast<ui::TextInputType>(itype); | |
| 2281 delegate()->PluginTextInputTypeChanged(this); | |
| 2282 } | |
| 2283 | |
| 2284 void PluginInstanceImpl::UpdateCaretPosition(PP_Instance instance, | |
| 2285 const PP_Rect& caret, | |
| 2286 const PP_Rect& bounding_box) { | |
| 2287 text_input_caret_ = PP_ToGfxRect(caret); | |
| 2288 text_input_caret_bounds_ = PP_ToGfxRect(bounding_box); | |
| 2289 text_input_caret_set_ = true; | |
| 2290 delegate()->PluginCaretPositionChanged(this); | |
| 2291 } | |
| 2292 | |
| 2293 void PluginInstanceImpl::CancelCompositionText(PP_Instance instance) { | |
| 2294 delegate()->PluginRequestedCancelComposition(this); | |
| 2295 } | |
| 2296 | |
| 2297 void PluginInstanceImpl::SelectionChanged(PP_Instance instance) { | |
| 2298 // TODO(kinaba): currently the browser always calls RequestSurroundingText. | |
| 2299 // It can be optimized so that it won't call it back until the information | |
| 2300 // is really needed. | |
| 2301 | |
| 2302 // Avoid calling in nested context or else this will reenter the plugin. This | |
| 2303 // uses a weak pointer rather than exploiting the fact that this class is | |
| 2304 // refcounted because we don't actually want this operation to affect the | |
| 2305 // lifetime of the instance. | |
| 2306 base::MessageLoop::current()->PostTask( | |
| 2307 FROM_HERE, | |
| 2308 base::Bind(&PluginInstanceImpl::RequestSurroundingText, | |
| 2309 AsWeakPtr(), | |
| 2310 static_cast<size_t>(kExtraCharsForTextInput))); | |
| 2311 } | |
| 2312 | |
| 2313 void PluginInstanceImpl::UpdateSurroundingText(PP_Instance instance, | |
| 2314 const char* text, | |
| 2315 uint32_t caret, | |
| 2316 uint32_t anchor) { | |
| 2317 surrounding_text_ = text; | |
| 2318 selection_caret_ = caret; | |
| 2319 selection_anchor_ = anchor; | |
| 2320 delegate()->PluginSelectionChanged(this); | |
| 2321 } | |
| 2322 | |
| 2323 PP_Var PluginInstanceImpl::ResolveRelativeToDocument( | |
| 2324 PP_Instance instance, | |
| 2325 PP_Var relative, | |
| 2326 PP_URLComponents_Dev* components) { | |
| 2327 StringVar* relative_string = StringVar::FromPPVar(relative); | |
| 2328 if (!relative_string) | |
| 2329 return PP_MakeNull(); | |
| 2330 | |
| 2331 WebElement plugin_element = container()->element(); | |
| 2332 GURL document_url = plugin_element.document().baseURL(); | |
| 2333 return ::ppapi::PPB_URLUtil_Shared::GenerateURLReturn( | |
| 2334 document_url.Resolve(relative_string->value()), | |
| 2335 components); | |
| 2336 } | |
| 2337 | |
| 2338 PP_Bool PluginInstanceImpl::DocumentCanRequest(PP_Instance instance, | |
| 2339 PP_Var url) { | |
| 2340 StringVar* url_string = StringVar::FromPPVar(url); | |
| 2341 if (!url_string) | |
| 2342 return PP_FALSE; | |
| 2343 | |
| 2344 WebKit::WebSecurityOrigin security_origin; | |
| 2345 if (!SecurityOriginForInstance(instance, &security_origin)) | |
| 2346 return PP_FALSE; | |
| 2347 | |
| 2348 GURL gurl(url_string->value()); | |
| 2349 if (!gurl.is_valid()) | |
| 2350 return PP_FALSE; | |
| 2351 | |
| 2352 return BoolToPPBool(security_origin.canRequest(gurl)); | |
| 2353 } | |
| 2354 | |
| 2355 PP_Bool PluginInstanceImpl::DocumentCanAccessDocument(PP_Instance instance, | |
| 2356 PP_Instance target) { | |
| 2357 WebKit::WebSecurityOrigin our_origin; | |
| 2358 if (!SecurityOriginForInstance(instance, &our_origin)) | |
| 2359 return PP_FALSE; | |
| 2360 | |
| 2361 WebKit::WebSecurityOrigin target_origin; | |
| 2362 if (!SecurityOriginForInstance(instance, &target_origin)) | |
| 2363 return PP_FALSE; | |
| 2364 | |
| 2365 return BoolToPPBool(our_origin.canAccess(target_origin)); | |
| 2366 } | |
| 2367 | |
| 2368 PP_Var PluginInstanceImpl::GetDocumentURL(PP_Instance instance, | |
| 2369 PP_URLComponents_Dev* components) { | |
| 2370 WebKit::WebDocument document = container()->element().document(); | |
| 2371 return ::ppapi::PPB_URLUtil_Shared::GenerateURLReturn(document.url(), | |
| 2372 components); | |
| 2373 } | |
| 2374 | |
| 2375 PP_Var PluginInstanceImpl::GetPluginInstanceURL( | |
| 2376 PP_Instance instance, | |
| 2377 PP_URLComponents_Dev* components) { | |
| 2378 return ::ppapi::PPB_URLUtil_Shared::GenerateURLReturn(plugin_url_, | |
| 2379 components); | |
| 2380 } | |
| 2381 | |
| 2382 PP_ExternalPluginResult PluginInstanceImpl::ResetAsProxied( | |
| 2383 scoped_refptr<PluginModule> module) { | |
| 2384 // Save the original module and switch over to the new one now that this | |
| 2385 // plugin is using the IPC-based proxy. | |
| 2386 original_module_ = module_; | |
| 2387 module_ = module; | |
| 2388 | |
| 2389 // Don't send any messages to the plugin until DidCreate() has finished. | |
| 2390 message_channel_->QueueJavaScriptMessages(); | |
| 2391 | |
| 2392 // For NaCl instances, remember the NaCl plugin instance interface, so we | |
| 2393 // can shut it down by calling its DidDestroy in our Delete() method. | |
| 2394 original_instance_interface_.reset(instance_interface_.release()); | |
| 2395 | |
| 2396 base::Callback<const void*(const char*)> get_plugin_interface_func = | |
| 2397 base::Bind(&PluginModule::GetPluginInterface, module_.get()); | |
| 2398 PPP_Instance_Combined* ppp_instance_combined = | |
| 2399 PPP_Instance_Combined::Create(get_plugin_interface_func); | |
| 2400 if (!ppp_instance_combined) { | |
| 2401 // The proxy must support at least one usable PPP_Instance interface. | |
| 2402 // While this could be a failure to implement the interface in the NaCl | |
| 2403 // module, it is more likely that the NaCl process has crashed. Either | |
| 2404 // way, report that module initialization failed. | |
| 2405 return PP_EXTERNAL_PLUGIN_ERROR_MODULE; | |
| 2406 } | |
| 2407 | |
| 2408 instance_interface_.reset(ppp_instance_combined); | |
| 2409 // Clear all PPP interfaces we may have cached. | |
| 2410 plugin_find_interface_ = NULL; | |
| 2411 plugin_input_event_interface_ = NULL; | |
| 2412 checked_for_plugin_input_event_interface_ = false; | |
| 2413 plugin_messaging_interface_ = NULL; | |
| 2414 checked_for_plugin_messaging_interface_ = false; | |
| 2415 plugin_mouse_lock_interface_ = NULL; | |
| 2416 plugin_pdf_interface_ = NULL; | |
| 2417 checked_for_plugin_pdf_interface_ = false; | |
| 2418 plugin_private_interface_ = NULL; | |
| 2419 plugin_selection_interface_ = NULL; | |
| 2420 plugin_textinput_interface_ = NULL; | |
| 2421 plugin_zoom_interface_ = NULL; | |
| 2422 | |
| 2423 // Re-send the DidCreate event via the proxy. | |
| 2424 scoped_ptr<const char*[]> argn_array(StringVectorToArgArray(argn_)); | |
| 2425 scoped_ptr<const char*[]> argv_array(StringVectorToArgArray(argv_)); | |
| 2426 if (!instance_interface_->DidCreate(pp_instance(), argn_.size(), | |
| 2427 argn_array.get(), argv_array.get())) | |
| 2428 return PP_EXTERNAL_PLUGIN_ERROR_INSTANCE; | |
| 2429 message_channel_->StopQueueingJavaScriptMessages(); | |
| 2430 | |
| 2431 // Clear sent_initial_did_change_view_ and cancel any pending DidChangeView | |
| 2432 // event. This way, SendDidChangeView will send the "current" view | |
| 2433 // immediately (before other events like HandleDocumentLoad). | |
| 2434 sent_initial_did_change_view_ = false; | |
| 2435 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 2436 SendDidChangeView(); | |
| 2437 | |
| 2438 DCHECK(nacl_document_load_); | |
| 2439 nacl_document_load_ = false; | |
| 2440 if (!nacl_document_response_.isNull()) { | |
| 2441 document_loader_ = NULL; | |
| 2442 // Pass the response to the new proxy. | |
| 2443 HandleDocumentLoad(nacl_document_response_); | |
| 2444 nacl_document_response_ = WebKit::WebURLResponse(); | |
| 2445 // Replay any document load events we've received to the real loader. | |
| 2446 nacl_document_loader_->ReplayReceivedData(document_loader_); | |
| 2447 nacl_document_loader_.reset(NULL); | |
| 2448 } | |
| 2449 | |
| 2450 return PP_EXTERNAL_PLUGIN_OK; | |
| 2451 } | |
| 2452 | |
| 2453 bool PluginInstanceImpl::IsValidInstanceOf(PluginModule* module) { | |
| 2454 DCHECK(module); | |
| 2455 return module == module_.get() || | |
| 2456 module == original_module_.get(); | |
| 2457 } | |
| 2458 | |
| 2459 NPP PluginInstanceImpl::instanceNPP() { | |
| 2460 return npp_.get(); | |
| 2461 } | |
| 2462 | |
| 2463 v8::Isolate* PluginInstanceImpl::GetIsolate() const { | |
| 2464 return isolate_; | |
| 2465 } | |
| 2466 | |
| 2467 PluginInstance* PluginInstance::Get(PP_Instance instance_id) { | |
| 2468 return HostGlobals::Get()->GetInstance(instance_id); | |
| 2469 } | |
| 2470 | |
| 2471 content::RenderView* PluginInstanceImpl::GetRenderView() { | |
| 2472 return render_view_; | |
| 2473 } | |
| 2474 | |
| 2475 WebKit::WebPluginContainer* PluginInstanceImpl::GetContainer() { | |
| 2476 return container_; | |
| 2477 } | |
| 2478 | |
| 2479 ::ppapi::VarTracker* PluginInstanceImpl::GetVarTracker() { | |
| 2480 return HostGlobals::Get()->GetVarTracker(); | |
| 2481 } | |
| 2482 | |
| 2483 const GURL& PluginInstanceImpl::GetPluginURL() { | |
| 2484 return plugin_url_; | |
| 2485 } | |
| 2486 | |
| 2487 base::FilePath PluginInstanceImpl::GetModulePath() { | |
| 2488 return module_->path(); | |
| 2489 } | |
| 2490 | |
| 2491 PP_Resource PluginInstanceImpl::CreateExternalFileReference( | |
| 2492 const base::FilePath& external_file_path) { | |
| 2493 webkit::ppapi::PPB_FileRef_Impl* ref = | |
| 2494 webkit::ppapi::PPB_FileRef_Impl::CreateExternal( | |
| 2495 pp_instance(), external_file_path, ""); | |
| 2496 return ref->GetReference(); | |
| 2497 } | |
| 2498 | |
| 2499 PP_Resource PluginInstanceImpl::CreateImage(gfx::ImageSkia* source_image, | |
| 2500 float scale) { | |
| 2501 ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale); | |
| 2502 gfx::ImageSkiaRep image_skia_rep = source_image->GetRepresentation( | |
| 2503 scale_factor); | |
| 2504 | |
| 2505 if (image_skia_rep.is_null() || image_skia_rep.scale_factor() != scale_factor) | |
| 2506 return 0; | |
| 2507 | |
| 2508 scoped_refptr<webkit::ppapi::PPB_ImageData_Impl> image_data( | |
| 2509 new webkit::ppapi::PPB_ImageData_Impl( | |
| 2510 pp_instance(), | |
| 2511 webkit::ppapi::PPB_ImageData_Impl::PLATFORM)); | |
| 2512 if (!image_data->Init( | |
| 2513 webkit::ppapi::PPB_ImageData_Impl::GetNativeImageDataFormat(), | |
| 2514 image_skia_rep.pixel_width(), | |
| 2515 image_skia_rep.pixel_height(), | |
| 2516 false)) { | |
| 2517 return 0; | |
| 2518 } | |
| 2519 | |
| 2520 webkit::ppapi::ImageDataAutoMapper mapper(image_data.get()); | |
| 2521 if (!mapper.is_valid()) | |
| 2522 return 0; | |
| 2523 | |
| 2524 skia::PlatformCanvas* canvas = image_data->GetPlatformCanvas(); | |
| 2525 // Note: Do not SkBitmap::copyTo the canvas bitmap directly because it will | |
| 2526 // ignore the allocated pixels in shared memory and re-allocate a new buffer. | |
| 2527 canvas->writePixels(image_skia_rep.sk_bitmap(), 0, 0); | |
| 2528 | |
| 2529 return image_data->GetReference(); | |
| 2530 } | |
| 2531 | |
| 2532 PP_ExternalPluginResult PluginInstanceImpl::SwitchToOutOfProcessProxy( | |
| 2533 const base::FilePath& file_path, | |
| 2534 ::ppapi::PpapiPermissions permissions, | |
| 2535 const IPC::ChannelHandle& channel_handle, | |
| 2536 base::ProcessId plugin_pid, | |
| 2537 int plugin_child_id) { | |
| 2538 // Create a new module for each instance of the external plugin that is using | |
| 2539 // the IPC based out-of-process proxy. We can't use the existing module, | |
| 2540 // because it is configured for the in-process plugin, and we must keep it | |
| 2541 // that way to allow the page to create other instances. | |
| 2542 scoped_refptr<webkit::ppapi::PluginModule> external_plugin_module( | |
| 2543 module_->CreateModuleForExternalPluginInstance()); | |
| 2544 | |
| 2545 content::RendererPpapiHost* renderer_ppapi_host = | |
| 2546 delegate_->CreateExternalPluginModule( | |
| 2547 external_plugin_module, | |
| 2548 file_path, | |
| 2549 permissions, | |
| 2550 channel_handle, | |
| 2551 plugin_pid, | |
| 2552 plugin_child_id); | |
| 2553 if (!renderer_ppapi_host) { | |
| 2554 DLOG(ERROR) << "CreateExternalPluginModule() failed"; | |
| 2555 return PP_EXTERNAL_PLUGIN_ERROR_MODULE; | |
| 2556 } | |
| 2557 | |
| 2558 // Finally, switch the instance to the proxy. | |
| 2559 return external_plugin_module->InitAsProxiedExternalPlugin(this); | |
| 2560 } | |
| 2561 | |
| 2562 void PluginInstanceImpl::SetAlwaysOnTop(bool on_top) { | |
| 2563 always_on_top_ = on_top; | |
| 2564 } | |
| 2565 | |
| 2566 void PluginInstanceImpl::DoSetCursor(WebCursorInfo* cursor) { | |
| 2567 cursor_.reset(cursor); | |
| 2568 if (fullscreen_container_) { | |
| 2569 fullscreen_container_->DidChangeCursor(*cursor); | |
| 2570 } else { | |
| 2571 delegate()->DidChangeCursor(this, *cursor); | |
| 2572 } | |
| 2573 } | |
| 2574 | |
| 2575 bool PluginInstanceImpl::IsFullPagePlugin() { | |
| 2576 WebFrame* frame = container()->element().document().frame(); | |
| 2577 return frame->view()->mainFrame()->document().isPluginDocument(); | |
| 2578 } | |
| 2579 | |
| 2580 void PluginInstanceImpl::FlashSetFullscreen(bool fullscreen, | |
| 2581 bool delay_report) { | |
| 2582 TRACE_EVENT0("ppapi", "PluginInstanceImpl::FlashSetFullscreen"); | |
| 2583 // Keep a reference on the stack. See NOTE above. | |
| 2584 scoped_refptr<PluginInstanceImpl> ref(this); | |
| 2585 | |
| 2586 // We check whether we are trying to switch to the state we're already going | |
| 2587 // to (i.e. if we're already switching to fullscreen but the fullscreen | |
| 2588 // container isn't ready yet, don't do anything more). | |
| 2589 if (fullscreen == FlashIsFullscreenOrPending()) | |
| 2590 return; | |
| 2591 | |
| 2592 // Unbind current 2D or 3D graphics context. | |
| 2593 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); | |
| 2594 if (fullscreen) { | |
| 2595 DCHECK(!fullscreen_container_); | |
| 2596 fullscreen_container_ = delegate_->CreateFullscreenContainer(this); | |
| 2597 UpdateLayer(); | |
| 2598 } else { | |
| 2599 DCHECK(fullscreen_container_); | |
| 2600 fullscreen_container_->Destroy(); | |
| 2601 fullscreen_container_ = NULL; | |
| 2602 UpdateFlashFullscreenState(false); | |
| 2603 if (!delay_report) { | |
| 2604 ReportGeometry(); | |
| 2605 } else { | |
| 2606 base::MessageLoop::current()->PostTask( | |
| 2607 FROM_HERE, base::Bind(&PluginInstanceImpl::ReportGeometry, this)); | |
| 2608 } | |
| 2609 } | |
| 2610 } | |
| 2611 | |
| 2612 bool PluginInstanceImpl::IsRectTopmost(const gfx::Rect& rect) { | |
| 2613 if (flash_fullscreen_) | |
| 2614 return true; | |
| 2615 | |
| 2616 return container_->isRectTopmost(rect); | |
| 2617 } | |
| 2618 | |
| 2619 int32_t PluginInstanceImpl::Navigate(const ::ppapi::URLRequestInfoData& request, | |
| 2620 const char* target, | |
| 2621 bool from_user_action) { | |
| 2622 if (!container_) | |
| 2623 return PP_ERROR_FAILED; | |
| 2624 | |
| 2625 WebDocument document = container_->element().document(); | |
| 2626 WebFrame* frame = document.frame(); | |
| 2627 if (!frame) | |
| 2628 return PP_ERROR_FAILED; | |
| 2629 | |
| 2630 ::ppapi::URLRequestInfoData completed_request = request; | |
| 2631 | |
| 2632 WebURLRequest web_request; | |
| 2633 if (!CreateWebURLRequest(&completed_request, frame, &web_request)) | |
| 2634 return PP_ERROR_FAILED; | |
| 2635 web_request.setFirstPartyForCookies(document.firstPartyForCookies()); | |
| 2636 web_request.setHasUserGesture(from_user_action); | |
| 2637 | |
| 2638 GURL gurl(web_request.url()); | |
| 2639 if (gurl.SchemeIs("javascript")) { | |
| 2640 // In imitation of the NPAPI implementation, only |target_frame == frame| is | |
| 2641 // allowed for security reasons. | |
| 2642 WebFrame* target_frame = | |
| 2643 frame->view()->findFrameByName(WebString::fromUTF8(target), frame); | |
| 2644 if (target_frame != frame) | |
| 2645 return PP_ERROR_NOACCESS; | |
| 2646 | |
| 2647 // TODO(viettrungluu): NPAPI sends the result back to the plugin -- do we | |
| 2648 // need that? | |
| 2649 WebString result = container_->executeScriptURL(gurl, from_user_action); | |
| 2650 return result.isNull() ? PP_ERROR_FAILED : PP_OK; | |
| 2651 } | |
| 2652 | |
| 2653 // Only GETs and POSTs are supported. | |
| 2654 if (web_request.httpMethod() != "GET" && | |
| 2655 web_request.httpMethod() != "POST") | |
| 2656 return PP_ERROR_BADARGUMENT; | |
| 2657 | |
| 2658 WebString target_str = WebString::fromUTF8(target); | |
| 2659 container_->loadFrameRequest(web_request, target_str, false, NULL); | |
| 2660 return PP_OK; | |
| 2661 } | |
| 2662 | |
| 2663 bool PluginInstanceImpl::CanAccessMainFrame() const { | |
| 2664 if (!container_) | |
| 2665 return false; | |
| 2666 WebKit::WebDocument containing_document = container_->element().document(); | |
| 2667 | |
| 2668 if (!containing_document.frame() || | |
| 2669 !containing_document.frame()->view() || | |
| 2670 !containing_document.frame()->view()->mainFrame()) { | |
| 2671 return false; | |
| 2672 } | |
| 2673 WebKit::WebDocument main_document = | |
| 2674 containing_document.frame()->view()->mainFrame()->document(); | |
| 2675 | |
| 2676 return containing_document.securityOrigin().canAccess( | |
| 2677 main_document.securityOrigin()); | |
| 2678 } | |
| 2679 | |
| 2680 void PluginInstanceImpl::KeepSizeAttributesBeforeFullscreen() { | |
| 2681 WebElement element = container_->element(); | |
| 2682 width_before_fullscreen_ = element.getAttribute(WebString::fromUTF8(kWidth)); | |
| 2683 height_before_fullscreen_ = | |
| 2684 element.getAttribute(WebString::fromUTF8(kHeight)); | |
| 2685 border_before_fullscreen_ = | |
| 2686 element.getAttribute(WebString::fromUTF8(kBorder)); | |
| 2687 style_before_fullscreen_ = element.getAttribute(WebString::fromUTF8(kStyle)); | |
| 2688 } | |
| 2689 | |
| 2690 void PluginInstanceImpl::SetSizeAttributesForFullscreen() { | |
| 2691 screen_size_for_fullscreen_ = delegate()->GetScreenSize(); | |
| 2692 std::string width = StringPrintf("%d", screen_size_for_fullscreen_.width()); | |
| 2693 std::string height = StringPrintf("%d", screen_size_for_fullscreen_.height()); | |
| 2694 | |
| 2695 WebElement element = container_->element(); | |
| 2696 element.setAttribute(WebString::fromUTF8(kWidth), WebString::fromUTF8(width)); | |
| 2697 element.setAttribute(WebString::fromUTF8(kHeight), | |
| 2698 WebString::fromUTF8(height)); | |
| 2699 element.setAttribute(WebString::fromUTF8(kBorder), WebString::fromUTF8("0")); | |
| 2700 | |
| 2701 // There should be no style settings that matter in fullscreen mode, | |
| 2702 // so just replace them instead of appending. | |
| 2703 // NOTE: "position: fixed" and "display: block" reset the plugin and | |
| 2704 // using %% settings might not work without them (e.g. if the plugin is a | |
| 2705 // child of a container element). | |
| 2706 std::string style; | |
| 2707 style += StringPrintf("width: %s !important; ", width.c_str()); | |
| 2708 style += StringPrintf("height: %s !important; ", height.c_str()); | |
| 2709 style += "margin: 0 !important; padding: 0 !important; border: 0 !important"; | |
| 2710 container_->element().setAttribute(kStyle, WebString::fromUTF8(style)); | |
| 2711 } | |
| 2712 | |
| 2713 void PluginInstanceImpl::ResetSizeAttributesAfterFullscreen() { | |
| 2714 screen_size_for_fullscreen_ = gfx::Size(); | |
| 2715 WebElement element = container_->element(); | |
| 2716 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | |
| 2717 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | |
| 2718 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | |
| 2719 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | |
| 2720 } | |
| 2721 | |
| 2722 } // namespace ppapi | |
| 2723 } // namespace webkit | |
| OLD | NEW |