| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 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/glue/plugins/webview_plugin.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebSettings.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
| 13 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 14 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
| 16 |
| 17 #if WEBKIT_USING_CG |
| 18 #include <CoreGraphics/CGContext.h> |
| 19 #elif WEBKIT_USING_SKIA |
| 20 #include "skia/ext/platform_canvas.h" |
| 21 #endif |
| 22 |
| 23 using WebKit::WebCanvas; |
| 24 using WebKit::WebCursorInfo; |
| 25 using WebKit::WebDragData; |
| 26 using WebKit::WebDragOperationsMask; |
| 27 using WebKit::WebFrame; |
| 28 using WebKit::WebImage; |
| 29 using WebKit::WebInputEvent; |
| 30 using WebKit::WebPluginContainer; |
| 31 using WebKit::WebPoint; |
| 32 using WebKit::WebRect; |
| 33 using WebKit::WebSize; |
| 34 using WebKit::WebURLError; |
| 35 using WebKit::WebURLRequest; |
| 36 using WebKit::WebVector; |
| 37 using WebKit::WebView; |
| 38 |
| 39 WebViewPlugin::WebViewPlugin(WebViewPlugin::Delegate* delegate) |
| 40 : delegate_(delegate), |
| 41 container_(NULL) { |
| 42 web_view_ = WebView::create(this, NULL); |
| 43 web_view_->initializeMainFrame(this); |
| 44 } |
| 45 |
| 46 WebViewPlugin::~WebViewPlugin() { |
| 47 web_view_->close(); |
| 48 } |
| 49 |
| 50 bool WebViewPlugin::initialize(WebPluginContainer* container) { |
| 51 container_ = container; |
| 52 return true; |
| 53 } |
| 54 |
| 55 void WebViewPlugin::destroy() { |
| 56 delegate_->WillDestroyPlugin(); |
| 57 delegate_ = NULL; |
| 58 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 59 } |
| 60 |
| 61 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { |
| 62 gfx::Rect paintRect(rect_.Intersect(rect)); |
| 63 if (paintRect.IsEmpty()) |
| 64 return; |
| 65 |
| 66 paintRect.Offset(-rect_.x(), -rect_.y()); |
| 67 |
| 68 #if WEBKIT_USING_CG |
| 69 CGContextRef context = canvas; |
| 70 CGContextTranslateCTM(context, rect_.x(), rect_.y()); |
| 71 CGContextSaveGState(context); |
| 72 #elif WEBKIT_USING_SKIA |
| 73 skia::PlatformCanvas* platform_canvas = canvas; |
| 74 platform_canvas->translate(SkIntToScalar(rect_.x()), |
| 75 SkIntToScalar(rect_.y())); |
| 76 platform_canvas->save(); |
| 77 #endif |
| 78 |
| 79 web_view_->layout(); |
| 80 web_view_->paint(canvas, paintRect); |
| 81 |
| 82 #if WEBKIT_USING_SKIA |
| 83 platform_canvas->restore(); |
| 84 #elif WEBKIT_USING_CG |
| 85 CGContextRestoreGState(context); |
| 86 #endif |
| 87 } |
| 88 |
| 89 // Coordinates are relative to the containing window. |
| 90 void WebViewPlugin::updateGeometry( |
| 91 const WebRect& frame_rect, const WebRect& clip_rect, |
| 92 const WebVector<WebRect>& cut_out_rects, bool is_visible) { |
| 93 if (frame_rect != rect_) { |
| 94 rect_ = frame_rect; |
| 95 web_view_->resize(WebSize(frame_rect.width, frame_rect.height)); |
| 96 } |
| 97 } |
| 98 |
| 99 bool WebViewPlugin::handleInputEvent(const WebInputEvent& event, |
| 100 WebCursorInfo& cursor) { |
| 101 current_cursor_ = cursor; |
| 102 bool handled = web_view_->handleInputEvent(event); |
| 103 cursor = current_cursor_; |
| 104 return handled; |
| 105 } |
| 106 |
| 107 void WebViewPlugin::startDragging(const WebDragData&, |
| 108 WebDragOperationsMask, |
| 109 const WebImage&, |
| 110 const WebPoint&) { |
| 111 // Immediately stop dragging. |
| 112 web_view_->dragSourceSystemDragEnded(); |
| 113 } |
| 114 |
| 115 void WebViewPlugin::didInvalidateRect(const WebRect& rect) { |
| 116 if (container_) |
| 117 container_->invalidateRect(WebRect(rect)); |
| 118 } |
| 119 |
| 120 void WebViewPlugin::didChangeCursor(const WebCursorInfo& cursor) { |
| 121 current_cursor_ = cursor; |
| 122 } |
| 123 |
| 124 void WebViewPlugin::didClearWindowObject(WebFrame* frame) { |
| 125 delegate_->BindWebFrame(frame); |
| 126 } |
| 127 |
| 128 bool WebViewPlugin::canHandleRequest(WebFrame* frame, |
| 129 const WebURLRequest& request) { |
| 130 return GURL(request.url()).SchemeIs("chrome"); |
| 131 } |
| 132 |
| 133 WebURLError WebViewPlugin::cancelledError(WebFrame* frame, |
| 134 const WebURLRequest& request) { |
| 135 // Return an error with a non-zero reason so isNull() on the corresponding |
| 136 // ResourceError is false. |
| 137 WebURLError error; |
| 138 error.domain = "WebViewPlugin"; |
| 139 error.reason = -1; |
| 140 error.unreachableURL = request.url(); |
| 141 return error; |
| 142 } |
| OLD | NEW |