| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/child/npapi/webplugin_delegate_impl.h" | 5 #include "content/child/npapi/webplugin_delegate_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 argc++; | 79 argc++; |
| 80 } | 80 } |
| 81 | 81 |
| 82 creation_succeeded_ = instance_->Start( | 82 creation_succeeded_ = instance_->Start( |
| 83 url, argn.get(), argv.get(), argc, load_manually); | 83 url, argn.get(), argv.get(), argc, load_manually); |
| 84 if (!creation_succeeded_) { | 84 if (!creation_succeeded_) { |
| 85 VLOG(1) << "Couldn't start plugin instance"; | 85 VLOG(1) << "Couldn't start plugin instance"; |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 windowless_ = instance_->windowless(); | |
| 90 if (!windowless_) { | |
| 91 if (!WindowedCreatePlugin()) { | |
| 92 VLOG(1) << "Couldn't create windowed plugin"; | |
| 93 return false; | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 bool should_load = PlatformInitialize(); | 89 bool should_load = PlatformInitialize(); |
| 98 | 90 |
| 99 plugin_url_ = url.spec(); | 91 plugin_url_ = url.spec(); |
| 100 | 92 |
| 101 return should_load; | 93 return should_load; |
| 102 } | 94 } |
| 103 | 95 |
| 104 void WebPluginDelegateImpl::DestroyInstance() { | 96 void WebPluginDelegateImpl::DestroyInstance() { |
| 105 if (instance_.get() && (instance_->npp()->ndata != NULL)) { | 97 if (instance_.get() && (instance_->npp()->ndata != NULL)) { |
| 106 window_.window = NULL; | 98 window_.window = NULL; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 126 if (first_set_window_call_) { | 118 if (first_set_window_call_) { |
| 127 first_set_window_call_ = false; | 119 first_set_window_call_ = false; |
| 128 // Plugins like media player on Windows have a bug where in they handle the | 120 // Plugins like media player on Windows have a bug where in they handle the |
| 129 // first geometry update and ignore the rest resulting in painting issues. | 121 // first geometry update and ignore the rest resulting in painting issues. |
| 130 // This quirk basically ignores the first set window call sequence for | 122 // This quirk basically ignores the first set window call sequence for |
| 131 // these plugins and has been tested for Windows plugins only. | 123 // these plugins and has been tested for Windows plugins only. |
| 132 if (quirks_ & PLUGIN_QUIRK_IGNORE_FIRST_SETWINDOW_CALL) | 124 if (quirks_ & PLUGIN_QUIRK_IGNORE_FIRST_SETWINDOW_CALL) |
| 133 return; | 125 return; |
| 134 } | 126 } |
| 135 | 127 |
| 136 if (windowless_) { | 128 WindowlessUpdateGeometry(window_rect, clip_rect); |
| 137 WindowlessUpdateGeometry(window_rect, clip_rect); | |
| 138 } else { | |
| 139 WindowedUpdateGeometry(window_rect, clip_rect); | |
| 140 } | |
| 141 } | 129 } |
| 142 | 130 |
| 143 void WebPluginDelegateImpl::SetFocus(bool focused) { | 131 void WebPluginDelegateImpl::SetFocus(bool focused) { |
| 144 DCHECK(windowless_); | |
| 145 // This is called when internal WebKit focus (the focused element on the page) | 132 // This is called when internal WebKit focus (the focused element on the page) |
| 146 // changes, but plugins need to know about OS-level focus, so we have an extra | 133 // changes, but plugins need to know about OS-level focus, so we have an extra |
| 147 // layer of focus tracking. | 134 // layer of focus tracking. |
| 148 // | 135 // |
| 149 // On Windows, historically browsers did not set focus events to windowless | 136 // On Windows, historically browsers did not set focus events to windowless |
| 150 // plugins when the toplevel window focus changes. Sending such focus events | 137 // plugins when the toplevel window focus changes. Sending such focus events |
| 151 // breaks full screen mode in Flash because it will come out of full screen | 138 // breaks full screen mode in Flash because it will come out of full screen |
| 152 // mode when it loses focus, and its full screen window causes the browser to | 139 // mode when it loses focus, and its full screen window causes the browser to |
| 153 // lose focus. | 140 // lose focus. |
| 154 has_webkit_focus_ = focused; | 141 has_webkit_focus_ = focused; |
| 155 #if !defined(OS_WIN) | 142 #if !defined(OS_WIN) |
| 156 if (containing_view_has_focus_) | 143 if (containing_view_has_focus_) |
| 157 SetPluginHasFocus(focused); | 144 SetPluginHasFocus(focused); |
| 158 #else | 145 #else |
| 159 SetPluginHasFocus(focused); | 146 SetPluginHasFocus(focused); |
| 160 #endif | 147 #endif |
| 161 } | 148 } |
| 162 | 149 |
| 163 void WebPluginDelegateImpl::SetPluginHasFocus(bool focused) { | 150 void WebPluginDelegateImpl::SetPluginHasFocus(bool focused) { |
| 164 if (focused == plugin_has_focus_) | 151 if (focused == plugin_has_focus_) |
| 165 return; | 152 return; |
| 166 if (PlatformSetPluginHasFocus(focused)) | 153 if (PlatformSetPluginHasFocus(focused)) |
| 167 plugin_has_focus_ = focused; | 154 plugin_has_focus_ = focused; |
| 168 } | 155 } |
| 169 | 156 |
| 170 void WebPluginDelegateImpl::SetContentAreaHasFocus(bool has_focus) { | 157 void WebPluginDelegateImpl::SetContentAreaHasFocus(bool has_focus) { |
| 171 containing_view_has_focus_ = has_focus; | 158 containing_view_has_focus_ = has_focus; |
| 172 if (!windowless_) | |
| 173 return; | |
| 174 #if !defined(OS_WIN) // See SetFocus above. | 159 #if !defined(OS_WIN) // See SetFocus above. |
| 175 SetPluginHasFocus(containing_view_has_focus_ && has_webkit_focus_); | 160 SetPluginHasFocus(containing_view_has_focus_ && has_webkit_focus_); |
| 176 #endif | 161 #endif |
| 177 } | 162 } |
| 178 | 163 |
| 179 NPObject* WebPluginDelegateImpl::GetPluginScriptableObject() { | 164 NPObject* WebPluginDelegateImpl::GetPluginScriptableObject() { |
| 180 return instance_->GetPluginScriptableObject(); | 165 return instance_->GetPluginScriptableObject(); |
| 181 } | 166 } |
| 182 | 167 |
| 183 NPP WebPluginDelegateImpl::GetPluginNPP() { | 168 NPP WebPluginDelegateImpl::GetPluginNPP() { |
| 184 return instance_->npp(); | 169 return instance_->npp(); |
| 185 } | 170 } |
| 186 | 171 |
| 187 bool WebPluginDelegateImpl::GetFormValue(base::string16* value) { | 172 bool WebPluginDelegateImpl::GetFormValue(base::string16* value) { |
| 188 return instance_->GetFormValue(value); | 173 return instance_->GetFormValue(value); |
| 189 } | 174 } |
| 190 | 175 |
| 191 int WebPluginDelegateImpl::GetProcessId() { | 176 int WebPluginDelegateImpl::GetProcessId() { |
| 192 // We are in process, so the plugin pid is this current process pid. | 177 // We are in process, so the plugin pid is this current process pid. |
| 193 return base::GetCurrentProcId(); | 178 return base::GetCurrentProcId(); |
| 194 } | 179 } |
| 195 | 180 |
| 196 base::FilePath WebPluginDelegateImpl::GetPluginPath() { | 181 base::FilePath WebPluginDelegateImpl::GetPluginPath() { |
| 197 return instance()->plugin_lib()->plugin_info().path; | 182 return instance()->plugin_lib()->plugin_info().path; |
| 198 } | 183 } |
| 199 | 184 |
| 200 void WebPluginDelegateImpl::WindowedUpdateGeometry( | |
| 201 const gfx::Rect& window_rect, | |
| 202 const gfx::Rect& clip_rect) { | |
| 203 if (WindowedReposition(window_rect, clip_rect) || | |
| 204 !windowed_did_set_window_) { | |
| 205 // Let the plugin know that it has been moved | |
| 206 WindowedSetWindow(); | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 bool WebPluginDelegateImpl::HandleInputEvent( | 185 bool WebPluginDelegateImpl::HandleInputEvent( |
| 211 const WebInputEvent& event, | 186 const WebInputEvent& event, |
| 212 WebCursor::CursorInfo* cursor_info) { | 187 WebCursor::CursorInfo* cursor_info) { |
| 213 DCHECK(windowless_) << "events should only be received in windowless mode"; | |
| 214 | |
| 215 bool pop_user_gesture = false; | 188 bool pop_user_gesture = false; |
| 216 if (IsUserGesture(event)) { | 189 if (IsUserGesture(event)) { |
| 217 pop_user_gesture = true; | 190 pop_user_gesture = true; |
| 218 instance()->PushPopupsEnabledState(true); | 191 instance()->PushPopupsEnabledState(true); |
| 219 } | 192 } |
| 220 | 193 |
| 221 bool handled = PlatformHandleInputEvent(event, cursor_info); | 194 bool handled = PlatformHandleInputEvent(event, cursor_info); |
| 222 | 195 |
| 223 if (pop_user_gesture) { | 196 if (pop_user_gesture) { |
| 224 instance()->PopPopupsEnabledState(); | 197 instance()->PopPopupsEnabledState(); |
| 225 } | 198 } |
| 226 | 199 |
| 227 return handled; | 200 return handled; |
| 228 } | 201 } |
| 229 | 202 |
| 230 bool WebPluginDelegateImpl::IsUserGesture(const WebInputEvent& event) { | 203 bool WebPluginDelegateImpl::IsUserGesture(const WebInputEvent& event) { |
| 231 switch (event.type) { | 204 switch (event.type) { |
| 232 case WebInputEvent::MouseDown: | 205 case WebInputEvent::MouseDown: |
| 233 case WebInputEvent::MouseUp: | 206 case WebInputEvent::MouseUp: |
| 234 case WebInputEvent::KeyDown: | 207 case WebInputEvent::KeyDown: |
| 235 case WebInputEvent::KeyUp: | 208 case WebInputEvent::KeyUp: |
| 236 return true; | 209 return true; |
| 237 default: | 210 default: |
| 238 return false; | 211 return false; |
| 239 } | 212 } |
| 240 } | 213 } |
| 241 | 214 |
| 242 } // namespace content | 215 } // namespace content |
| OLD | NEW |