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/browser/renderer_host/render_widget_host_view_win.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/l10n_util_win.h" | 8 #include "app/l10n_util_win.h" |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/histogram.h" | 11 #include "base/histogram.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/thread.h" | 14 #include "base/thread.h" |
15 #include "base/win_util.h" | 15 #include "base/win_util.h" |
16 #include "chrome/browser/browser_accessibility.h" | |
17 #include "chrome/browser/browser_accessibility_manager.h" | 16 #include "chrome/browser/browser_accessibility_manager.h" |
18 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/browser_trial.h" | 18 #include "chrome/browser/browser_trial.h" |
20 #include "chrome/browser/chrome_thread.h" | 19 #include "chrome/browser/chrome_thread.h" |
21 #include "chrome/browser/plugin_process_host.h" | 20 #include "chrome/browser/plugin_process_host.h" |
22 #include "chrome/browser/renderer_host/backing_store.h" | 21 #include "chrome/browser/renderer_host/backing_store.h" |
23 #include "chrome/browser/renderer_host/backing_store_win.h" | 22 #include "chrome/browser/renderer_host/backing_store_win.h" |
24 #include "chrome/browser/renderer_host/gpu_view_host.h" | 23 #include "chrome/browser/renderer_host/gpu_view_host.h" |
25 #include "chrome/browser/renderer_host/render_process_host.h" | 24 #include "chrome/browser/renderer_host/render_process_host.h" |
26 #include "chrome/browser/renderer_host/render_widget_host.h" | 25 #include "chrome/browser/renderer_host/render_widget_host.h" |
27 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
28 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/native_web_keyboard_event.h" | 28 #include "chrome/common/native_web_keyboard_event.h" |
30 #include "chrome/common/notification_service.h" | |
31 #include "chrome/common/plugin_messages.h" | 29 #include "chrome/common/plugin_messages.h" |
32 #include "chrome/common/render_messages.h" | 30 #include "chrome/common/render_messages.h" |
33 #include "gfx/canvas.h" | 31 #include "gfx/canvas.h" |
34 #include "gfx/gdi_util.h" | 32 #include "gfx/gdi_util.h" |
35 #include "gfx/rect.h" | 33 #include "gfx/rect.h" |
36 #include "grit/webkit_resources.h" | 34 #include "grit/webkit_resources.h" |
37 #include "skia/ext/skia_utils_win.h" | 35 #include "skia/ext/skia_utils_win.h" |
38 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 36 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
39 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h" | 37 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h" |
40 #include "views/accessibility/view_accessibility.h" | 38 #include "views/accessibility/view_accessibility.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 tooltip_hwnd_(NULL), | 278 tooltip_hwnd_(NULL), |
281 tooltip_showing_(false), | 279 tooltip_showing_(false), |
282 shutdown_factory_(this), | 280 shutdown_factory_(this), |
283 parent_hwnd_(NULL), | 281 parent_hwnd_(NULL), |
284 is_loading_(false), | 282 is_loading_(false), |
285 visually_deemphasized_(false) { | 283 visually_deemphasized_(false) { |
286 render_widget_host_->set_view(this); | 284 render_widget_host_->set_view(this); |
287 renderer_accessible_ = | 285 renderer_accessible_ = |
288 CommandLine::ForCurrentProcess()->HasSwitch( | 286 CommandLine::ForCurrentProcess()->HasSwitch( |
289 switches::kEnableRendererAccessibility); | 287 switches::kEnableRendererAccessibility); |
290 registrar_.Add(this, | |
291 NotificationType::RENDERER_PROCESS_TERMINATED, | |
292 NotificationService::AllSources()); | |
293 } | 288 } |
294 | 289 |
295 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { | 290 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { |
296 ResetTooltip(); | 291 ResetTooltip(); |
297 } | 292 } |
298 | 293 |
299 void RenderWidgetHostViewWin::CreateWnd(HWND parent) { | 294 void RenderWidgetHostViewWin::CreateWnd(HWND parent) { |
300 Create(parent); // ATL function to create the window. | 295 Create(parent); // ATL function to create the window. |
301 | 296 |
302 // Add a property indicating that a particular renderer is associated with | 297 // Add a property indicating that a particular renderer is associated with |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 child_window = ::GetWindow(child_window, GW_CHILD); | 1455 child_window = ::GetWindow(child_window, GW_CHILD); |
1461 | 1456 |
1462 ::SetFocus(child_window); | 1457 ::SetFocus(child_window); |
1463 return MA_NOACTIVATE; | 1458 return MA_NOACTIVATE; |
1464 } | 1459 } |
1465 } | 1460 } |
1466 handled = FALSE; | 1461 handled = FALSE; |
1467 return MA_ACTIVATE; | 1462 return MA_ACTIVATE; |
1468 } | 1463 } |
1469 | 1464 |
1470 void RenderWidgetHostViewWin::UpdateAccessibilityTree( | |
1471 const webkit_glue::WebAccessibility& tree) { | |
1472 browser_accessibility_manager_.reset( | |
1473 new BrowserAccessibilityManager(m_hWnd, tree)); | |
1474 } | |
1475 | |
1476 void RenderWidgetHostViewWin::OnAccessibilityFocusChange(int acc_obj_id) { | |
1477 if (browser_accessibility_manager_.get()) { | |
1478 browser_accessibility_manager_->OnAccessibilityFocusChange(acc_obj_id); | |
1479 } | |
1480 } | |
1481 | |
1482 void RenderWidgetHostViewWin::OnAccessibilityObjectStateChange(int acc_obj_id) { | |
1483 if (browser_accessibility_manager_.get()) { | |
1484 browser_accessibility_manager_->OnAccessibilityObjectStateChange( | |
1485 acc_obj_id); | |
1486 } | |
1487 } | |
1488 | |
1489 void RenderWidgetHostViewWin::Observe(NotificationType type, | |
1490 const NotificationSource& source, | |
1491 const NotificationDetails& details) { | |
1492 DCHECK(type == NotificationType::RENDERER_PROCESS_TERMINATED); | |
1493 | |
1494 // Get the RenderProcessHost that posted this notification, and exit | |
1495 // if it's not the one associated with this host view. | |
1496 RenderProcessHost* render_process_host = | |
1497 Source<RenderProcessHost>(source).ptr(); | |
1498 DCHECK(render_process_host); | |
1499 if (render_widget_host_ == NULL || | |
1500 render_process_host != render_widget_host_->process()) { | |
1501 return; | |
1502 } | |
1503 | |
1504 // If it was our RenderProcessHost that posted the notification, | |
1505 // clear the BrowserAccessibilityManager, because the renderer is | |
1506 // dead and any accessibility information we have is now stale. | |
1507 browser_accessibility_manager_.reset(NULL); | |
1508 } | |
1509 | |
1510 LRESULT RenderWidgetHostViewWin::OnGetObject(UINT message, WPARAM wparam, | 1465 LRESULT RenderWidgetHostViewWin::OnGetObject(UINT message, WPARAM wparam, |
1511 LPARAM lparam, BOOL& handled) { | 1466 LPARAM lparam, BOOL& handled) { |
1512 // TODO(dmazzoni): http://crbug.com/25564 Disabling accessibility in the | 1467 LRESULT reference_result = static_cast<LRESULT>(0L); |
| 1468 // TODO(jcampan): http://b/issue?id=1432077 Disabling accessibility in the |
1513 // renderer is a temporary work-around until that bug is fixed. | 1469 // renderer is a temporary work-around until that bug is fixed. |
1514 if (!renderer_accessible_) { | 1470 if (!renderer_accessible_) |
1515 handled = false; | 1471 return reference_result; |
1516 return static_cast<LRESULT>(0L); | 1472 |
| 1473 // Accessibility readers will send an OBJID_CLIENT message. |
| 1474 if (OBJID_CLIENT == lparam) { |
| 1475 // If our MSAA DOM root is already created, reuse that pointer. Otherwise, |
| 1476 // create a new one. |
| 1477 if (!browser_accessibility_root_) { |
| 1478 // Create a new instance of IAccessible. Root id is 1000, to avoid |
| 1479 // conflicts with the ids used by MSAA. |
| 1480 BrowserAccessibilityManager::GetInstance()->CreateAccessibilityInstance( |
| 1481 IID_IAccessible, 1000, |
| 1482 render_widget_host_->routing_id(), |
| 1483 render_widget_host_->process()->id(), |
| 1484 m_hWnd, |
| 1485 reinterpret_cast<void **>(browser_accessibility_root_.Receive())); |
| 1486 |
| 1487 if (!browser_accessibility_root_) { |
| 1488 // No valid root found, return with failure. |
| 1489 return static_cast<LRESULT>(0L); |
| 1490 } |
| 1491 } |
| 1492 |
| 1493 // Create a reference to BrowserAccessibility which MSAA will marshall to |
| 1494 // the client. |
| 1495 reference_result = LresultFromObject(IID_IAccessible, wparam, |
| 1496 static_cast<IAccessible*>(browser_accessibility_root_)); |
1517 } | 1497 } |
1518 | 1498 return reference_result; |
1519 if (lparam == OBJID_CLIENT && browser_accessibility_manager_.get()) { | |
1520 BrowserAccessibility* root = browser_accessibility_manager_->GetRoot(); | |
1521 if (root) { | |
1522 return LresultFromObject(IID_IAccessible, wparam, | |
1523 static_cast<IAccessible*>(root->NewReference())); | |
1524 } | |
1525 } | |
1526 | |
1527 handled = false; | |
1528 return static_cast<LRESULT>(0L); | |
1529 } | 1499 } |
1530 | 1500 |
1531 void RenderWidgetHostViewWin::OnFinalMessage(HWND window) { | 1501 void RenderWidgetHostViewWin::OnFinalMessage(HWND window) { |
1532 // When the render widget host is being destroyed, it ends up calling | 1502 // When the render widget host is being destroyed, it ends up calling |
1533 // WillDestroyRenderWidget (through the RENDER_WIDGET_HOST_DESTROYED | 1503 // WillDestroyRenderWidget (through the RENDER_WIDGET_HOST_DESTROYED |
1534 // notification) which NULLs render_widget_host_. | 1504 // notification) which NULLs render_widget_host_. |
1535 // Note: the following bug http://crbug.com/24248 seems to report that | 1505 // Note: the following bug http://crbug.com/24248 seems to report that |
1536 // OnFinalMessage is called with a deleted |render_widget_host_|. It is not | 1506 // OnFinalMessage is called with a deleted |render_widget_host_|. It is not |
1537 // clear how this could happen, hence the NULLing of render_widget_host_ | 1507 // clear how this could happen, hence the NULLing of render_widget_host_ |
1538 // above. | 1508 // above. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 1618 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
1649 gfx::NativeView native_view) { | 1619 gfx::NativeView native_view) { |
1650 if (::IsWindow(native_view)) { | 1620 if (::IsWindow(native_view)) { |
1651 HANDLE raw_render_host_view = ::GetProp(native_view, | 1621 HANDLE raw_render_host_view = ::GetProp(native_view, |
1652 kRenderWidgetHostViewKey); | 1622 kRenderWidgetHostViewKey); |
1653 if (raw_render_host_view) | 1623 if (raw_render_host_view) |
1654 return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view); | 1624 return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view); |
1655 } | 1625 } |
1656 return NULL; | 1626 return NULL; |
1657 } | 1627 } |
OLD | NEW |