Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / components / plugins / renderer / webview_plugin.cc
index dfee291..5beb333 100644 (file)
@@ -7,7 +7,8 @@
 #include "base/message_loop/message_loop.h"
 #include "base/metrics/histogram.h"
 #include "base/numerics/safe_conversions.h"
-#include "content/public/renderer/web_preferences.h"
+#include "content/public/common/web_preferences.h"
+#include "content/public/renderer/render_view.h"
 #include "skia/ext/platform_canvas.h"
 #include "third_party/WebKit/public/platform/WebSize.h"
 #include "third_party/WebKit/public/platform/WebURL.h"
 #include "third_party/WebKit/public/platform/WebURLResponse.h"
 #include "third_party/WebKit/public/web/WebDocument.h"
 #include "third_party/WebKit/public/web/WebElement.h"
-#include "third_party/WebKit/public/web/WebFrame.h"
 #include "third_party/WebKit/public/web/WebInputEvent.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
 #include "third_party/WebKit/public/web/WebPluginContainer.h"
 #include "third_party/WebKit/public/web/WebView.h"
-#include "webkit/common/webpreferences.h"
 
 using blink::WebCanvas;
 using blink::WebCursorInfo;
 using blink::WebDragData;
 using blink::WebDragOperationsMask;
-using blink::WebFrame;
 using blink::WebImage;
 using blink::WebInputEvent;
+using blink::WebLocalFrame;
 using blink::WebMouseEvent;
 using blink::WebPlugin;
 using blink::WebPluginContainer;
@@ -40,13 +40,19 @@ using blink::WebURLRequest;
 using blink::WebURLResponse;
 using blink::WebVector;
 using blink::WebView;
+using content::WebPreferences;
 
-WebViewPlugin::WebViewPlugin(WebViewPlugin::Delegate* delegate)
+WebViewPlugin::WebViewPlugin(WebViewPlugin::Delegate* delegate,
+                             const WebPreferences& preferences)
     : delegate_(delegate),
       container_(NULL),
       web_view_(WebView::create(this)),
-      web_frame_(WebFrame::create(this)),
-      finished_loading_(false) {
+      finished_loading_(false),
+      focused_(false) {
+  // ApplyWebPreferences before making a WebLocalFrame so that the frame sees a
+  // consistent view of our preferences.
+  content::RenderView::ApplyWebPreferences(preferences, web_view_);
+  web_frame_ = WebLocalFrame::create(this);
   web_view_->setMainFrame(web_frame_);
 }
 
@@ -55,10 +61,8 @@ WebViewPlugin* WebViewPlugin::Create(WebViewPlugin::Delegate* delegate,
                                      const WebPreferences& preferences,
                                      const std::string& html_data,
                                      const GURL& url) {
-  WebViewPlugin* plugin = new WebViewPlugin(delegate);
-  WebView* web_view = plugin->web_view();
-  content::ApplyWebPreferences(preferences, web_view);
-  web_view->mainFrame()->loadHTMLString(html_data, url);
+  WebViewPlugin* plugin = new WebViewPlugin(delegate, preferences);
+  plugin->web_view()->mainFrame()->loadHTMLString(html_data, url);
   return plugin;
 }
 
@@ -84,6 +88,10 @@ void WebViewPlugin::ReplayReceivedData(WebPlugin* plugin) {
         "PluginDocument.NumChunks",
         (base::checked_cast<int, size_t>(data_.size())));
   }
+  // We need to transfer the |focused_| to new plugin after it loaded.
+  if (focused_) {
+    plugin->updateFocus(true);
+  }
   if (finished_loading_) {
     plugin->didFinishLoading();
   }
@@ -145,11 +153,14 @@ void WebViewPlugin::updateGeometry(const WebRect& frame_rect,
   if (static_cast<gfx::Rect>(frame_rect) != rect_) {
     rect_ = frame_rect;
     WebSize newSize(frame_rect.width, frame_rect.height);
-    web_view_->setFixedLayoutSize(newSize);
     web_view_->resize(newSize);
   }
 }
 
+void WebViewPlugin::updateFocus(bool focused) {
+  focused_ = focused;
+}
+
 bool WebViewPlugin::acceptsInputEvents() { return true; }
 
 bool WebViewPlugin::handleInputEvent(const WebInputEvent& event,
@@ -201,7 +212,7 @@ void WebViewPlugin::setToolTipText(const WebString& text,
     container_->element().setAttribute("title", text);
 }
 
-void WebViewPlugin::startDragging(WebFrame*,
+void WebViewPlugin::startDragging(WebLocalFrame*,
                                   const WebDragData&,
                                   WebDragOperationsMask,
                                   const WebImage&,
@@ -210,6 +221,10 @@ void WebViewPlugin::startDragging(WebFrame*,
   web_view_->dragSourceSystemDragEnded();
 }
 
+bool WebViewPlugin::allowsBrokenNullLayerTreeView() const {
+  return true;
+}
+
 void WebViewPlugin::didInvalidateRect(const WebRect& rect) {
   if (container_)
     container_->invalidateRect(rect);
@@ -219,12 +234,17 @@ void WebViewPlugin::didChangeCursor(const WebCursorInfo& cursor) {
   current_cursor_ = cursor;
 }
 
-void WebViewPlugin::didClearWindowObject(WebFrame* frame, int world_id) {
+void WebViewPlugin::scheduleAnimation() {
+  if (container_)
+    container_->invalidate();
+}
+
+void WebViewPlugin::didClearWindowObject(WebLocalFrame* frame) {
   if (delegate_)
     delegate_->BindWebFrame(frame);
 }
 
-void WebViewPlugin::didReceiveResponse(WebFrame* frame,
+void WebViewPlugin::didReceiveResponse(WebLocalFrame* frame,
                                        unsigned identifier,
                                        const WebURLResponse& response) {
   WebFrameClient::didReceiveResponse(frame, identifier, response);