| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/render_widget.h" | 5 #include "chrome/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include "app/surface/transport_dib.h" | 7 #include "app/surface/transport_dib.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
| 16 #include "chrome/renderer/render_process.h" | 16 #include "chrome/renderer/render_process.h" |
| 17 #include "chrome/renderer/render_thread.h" | 17 #include "chrome/renderer/render_thread.h" |
| 18 #include "gfx/point.h" | 18 #include "gfx/point.h" |
| 19 #include "gfx/size.h" | 19 #include "gfx/size.h" |
| 20 #include "ipc/ipc_sync_message.h" |
| 20 #include "skia/ext/platform_canvas.h" | 21 #include "skia/ext/platform_canvas.h" |
| 21 #include "third_party/skia/include/core/SkShader.h" | 22 #include "third_party/skia/include/core/SkShader.h" |
| 22 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" | 23 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
| 23 #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h" | 24 #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h" |
| 24 #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenuInfo.h" | 25 #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenuInfo.h" |
| 25 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 26 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 26 #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" | 27 #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" |
| 27 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" | 28 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
| 28 #include "webkit/glue/plugins/webplugin.h" | 29 #include "webkit/glue/plugins/webplugin.h" |
| 29 #include "webkit/glue/webkit_glue.h" | 30 #include "webkit/glue/webkit_glue.h" |
| 30 | 31 |
| 31 #if defined(OS_POSIX) | 32 #if defined(OS_POSIX) |
| 32 #include "ipc/ipc_channel_posix.h" | 33 #include "ipc/ipc_channel_posix.h" |
| 33 #include "third_party/skia/include/core/SkPixelRef.h" | 34 #include "third_party/skia/include/core/SkPixelRef.h" |
| 34 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 35 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
| 35 #endif // defined(OS_POSIX) | 36 #endif // defined(OS_POSIX) |
| 36 | 37 |
| 37 #include "third_party/WebKit/WebKit/chromium/public/WebWidget.h" | 38 #include "third_party/WebKit/WebKit/chromium/public/WebWidget.h" |
| 38 | 39 |
| 39 using WebKit::WebCompositionUnderline; | 40 using WebKit::WebCompositionUnderline; |
| 40 using WebKit::WebCursorInfo; | 41 using WebKit::WebCursorInfo; |
| 41 using WebKit::WebInputEvent; | 42 using WebKit::WebInputEvent; |
| 42 using WebKit::WebNavigationPolicy; | 43 using WebKit::WebNavigationPolicy; |
| 43 using WebKit::WebPopupMenu; | 44 using WebKit::WebPopupMenu; |
| 44 using WebKit::WebPopupMenuInfo; | 45 using WebKit::WebPopupMenuInfo; |
| 46 using WebKit::WebPopupType; |
| 45 using WebKit::WebRect; | 47 using WebKit::WebRect; |
| 46 using WebKit::WebScreenInfo; | 48 using WebKit::WebScreenInfo; |
| 47 using WebKit::WebSize; | 49 using WebKit::WebSize; |
| 48 using WebKit::WebTextDirection; | 50 using WebKit::WebTextDirection; |
| 49 using WebKit::WebTextInputType; | 51 using WebKit::WebTextInputType; |
| 50 using WebKit::WebVector; | 52 using WebKit::WebVector; |
| 53 using WebKit::WebWidget; |
| 51 | 54 |
| 52 RenderWidget::RenderWidget(RenderThreadBase* render_thread, | 55 RenderWidget::RenderWidget(RenderThreadBase* render_thread, |
| 53 WebKit::WebPopupType popup_type) | 56 WebKit::WebPopupType popup_type) |
| 54 : routing_id_(MSG_ROUTING_NONE), | 57 : routing_id_(MSG_ROUTING_NONE), |
| 55 webwidget_(NULL), | 58 webwidget_(NULL), |
| 56 opener_id_(MSG_ROUTING_NONE), | 59 opener_id_(MSG_ROUTING_NONE), |
| 57 render_thread_(render_thread), | 60 render_thread_(render_thread), |
| 58 host_window_(0), | 61 host_window_(0), |
| 59 current_paint_buf_(NULL), | 62 current_paint_buf_(NULL), |
| 60 next_paint_flags_(0), | 63 next_paint_flags_(0), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 77 | 80 |
| 78 RenderWidget::~RenderWidget() { | 81 RenderWidget::~RenderWidget() { |
| 79 DCHECK(!webwidget_) << "Leaking our WebWidget!"; | 82 DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
| 80 if (current_paint_buf_) { | 83 if (current_paint_buf_) { |
| 81 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); | 84 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 82 current_paint_buf_ = NULL; | 85 current_paint_buf_ = NULL; |
| 83 } | 86 } |
| 84 RenderProcess::current()->ReleaseProcess(); | 87 RenderProcess::current()->ReleaseProcess(); |
| 85 } | 88 } |
| 86 | 89 |
| 87 /*static*/ | 90 // static |
| 88 RenderWidget* RenderWidget::Create(int32 opener_id, | 91 RenderWidget* RenderWidget::Create(int32 opener_id, |
| 89 RenderThreadBase* render_thread, | 92 RenderThreadBase* render_thread, |
| 90 WebKit::WebPopupType popup_type) { | 93 WebKit::WebPopupType popup_type) { |
| 91 DCHECK(opener_id != MSG_ROUTING_NONE); | 94 DCHECK(opener_id != MSG_ROUTING_NONE); |
| 92 scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread, | 95 scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread, |
| 93 popup_type); | 96 popup_type); |
| 94 widget->Init(opener_id); // adds reference | 97 widget->Init(opener_id); // adds reference |
| 95 return widget; | 98 return widget; |
| 96 } | 99 } |
| 97 | 100 |
| 101 // static |
| 102 WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) { |
| 103 switch (render_widget->popup_type_) { |
| 104 case WebKit::WebPopupTypeNone: // Nothing to create. |
| 105 break; |
| 106 case WebKit::WebPopupTypeSelect: |
| 107 case WebKit::WebPopupTypeSuggestion: |
| 108 return WebPopupMenu::create(render_widget); |
| 109 default: |
| 110 NOTREACHED(); |
| 111 } |
| 112 return NULL; |
| 113 } |
| 114 |
| 98 void RenderWidget::ConfigureAsExternalPopupMenu(const WebPopupMenuInfo& info) { | 115 void RenderWidget::ConfigureAsExternalPopupMenu(const WebPopupMenuInfo& info) { |
| 99 popup_params_.reset(new ViewHostMsg_ShowPopup_Params); | 116 popup_params_.reset(new ViewHostMsg_ShowPopup_Params); |
| 100 popup_params_->item_height = info.itemHeight; | 117 popup_params_->item_height = info.itemHeight; |
| 101 popup_params_->item_font_size = info.itemFontSize; | 118 popup_params_->item_font_size = info.itemFontSize; |
| 102 popup_params_->selected_item = info.selectedIndex; | 119 popup_params_->selected_item = info.selectedIndex; |
| 103 for (size_t i = 0; i < info.items.size(); ++i) | 120 for (size_t i = 0; i < info.items.size(); ++i) |
| 104 popup_params_->popup_items.push_back(WebMenuItem(info.items[i])); | 121 popup_params_->popup_items.push_back(WebMenuItem(info.items[i])); |
| 105 popup_params_->right_aligned = info.rightAligned; | 122 popup_params_->right_aligned = info.rightAligned; |
| 106 } | 123 } |
| 107 | 124 |
| 108 void RenderWidget::Init(int32 opener_id) { | 125 void RenderWidget::Init(int32 opener_id) { |
| 126 DoInit(opener_id, |
| 127 RenderWidget::CreateWebWidget(this), |
| 128 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_)); |
| 129 } |
| 130 |
| 131 |
| 132 void RenderWidget::DoInit(int32 opener_id, |
| 133 WebKit::WebWidget* web_widget, |
| 134 IPC::SyncMessage* create_widget_message) { |
| 109 DCHECK(!webwidget_); | 135 DCHECK(!webwidget_); |
| 110 | 136 |
| 111 if (opener_id != MSG_ROUTING_NONE) | 137 if (opener_id != MSG_ROUTING_NONE) |
| 112 opener_id_ = opener_id; | 138 opener_id_ = opener_id; |
| 113 | 139 |
| 114 webwidget_ = WebPopupMenu::create(this); | 140 webwidget_ = web_widget; |
| 115 | 141 |
| 116 bool result = render_thread_->Send( | 142 bool result = render_thread_->Send(create_widget_message); |
| 117 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_)); | |
| 118 if (result) { | 143 if (result) { |
| 119 render_thread_->AddRoute(routing_id_, this); | 144 render_thread_->AddRoute(routing_id_, this); |
| 120 // Take a reference on behalf of the RenderThread. This will be balanced | 145 // Take a reference on behalf of the RenderThread. This will be balanced |
| 121 // when we receive ViewMsg_Close. | 146 // when we receive ViewMsg_Close. |
| 122 AddRef(); | 147 AddRef(); |
| 123 } else { | 148 } else { |
| 124 DCHECK(false); | 149 DCHECK(false); |
| 125 } | 150 } |
| 126 } | 151 } |
| 127 | 152 |
| (...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 | 946 |
| 922 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { | 947 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
| 923 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); | 948 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
| 924 i != plugin_window_moves_.end(); ++i) { | 949 i != plugin_window_moves_.end(); ++i) { |
| 925 if (i->window == window) { | 950 if (i->window == window) { |
| 926 plugin_window_moves_.erase(i); | 951 plugin_window_moves_.erase(i); |
| 927 break; | 952 break; |
| 928 } | 953 } |
| 929 } | 954 } |
| 930 } | 955 } |
| OLD | NEW |