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 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 child_window = ::GetWindow(child_window, GW_CHILD); | 1465 child_window = ::GetWindow(child_window, GW_CHILD); |
1471 | 1466 |
1472 ::SetFocus(child_window); | 1467 ::SetFocus(child_window); |
1473 return MA_NOACTIVATE; | 1468 return MA_NOACTIVATE; |
1474 } | 1469 } |
1475 } | 1470 } |
1476 handled = FALSE; | 1471 handled = FALSE; |
1477 return MA_ACTIVATE; | 1472 return MA_ACTIVATE; |
1478 } | 1473 } |
1479 | 1474 |
1480 void RenderWidgetHostViewWin::UpdateAccessibilityTree( | |
1481 const webkit_glue::WebAccessibility& tree) { | |
1482 browser_accessibility_manager_.reset( | |
1483 new BrowserAccessibilityManager(m_hWnd, tree)); | |
1484 } | |
1485 | |
1486 void RenderWidgetHostViewWin::OnAccessibilityFocusChange(int acc_obj_id) { | |
1487 if (browser_accessibility_manager_.get()) { | |
1488 browser_accessibility_manager_->OnAccessibilityFocusChange(acc_obj_id); | |
1489 } | |
1490 } | |
1491 | |
1492 void RenderWidgetHostViewWin::OnAccessibilityObjectStateChange(int acc_obj_id) { | |
1493 if (browser_accessibility_manager_.get()) { | |
1494 browser_accessibility_manager_->OnAccessibilityObjectStateChange( | |
1495 acc_obj_id); | |
1496 } | |
1497 } | |
1498 | |
1499 void RenderWidgetHostViewWin::Observe(NotificationType type, | |
1500 const NotificationSource& source, | |
1501 const NotificationDetails& details) { | |
1502 DCHECK(type == NotificationType::RENDERER_PROCESS_TERMINATED); | |
1503 | |
1504 // Get the RenderProcessHost that posted this notification, and exit | |
1505 // if it's not the one associated with this host view. | |
1506 RenderProcessHost* render_process_host = | |
1507 Source<RenderProcessHost>(source).ptr(); | |
1508 DCHECK(render_process_host); | |
1509 if (!render_widget_host_ || | |
1510 render_process_host != render_widget_host_->process()) | |
1511 return; | |
1512 | |
1513 // If it was our RenderProcessHost that posted the notification, | |
1514 // clear the BrowserAccessibilityManager, because the renderer is | |
1515 // dead and any accessibility information we have is now stale. | |
1516 browser_accessibility_manager_.reset(NULL); | |
1517 } | |
1518 | |
1519 LRESULT RenderWidgetHostViewWin::OnGetObject(UINT message, WPARAM wparam, | 1475 LRESULT RenderWidgetHostViewWin::OnGetObject(UINT message, WPARAM wparam, |
1520 LPARAM lparam, BOOL& handled) { | 1476 LPARAM lparam, BOOL& handled) { |
1521 // TODO(dmazzoni): http://crbug.com/25564 Disabling accessibility in the | 1477 LRESULT reference_result = static_cast<LRESULT>(0L); |
| 1478 // TODO(jcampan): http://b/issue?id=1432077 Disabling accessibility in the |
1522 // renderer is a temporary work-around until that bug is fixed. | 1479 // renderer is a temporary work-around until that bug is fixed. |
1523 if (!renderer_accessible_) { | 1480 if (!renderer_accessible_) |
1524 handled = false; | 1481 return reference_result; |
1525 return static_cast<LRESULT>(0L); | 1482 |
| 1483 // Accessibility readers will send an OBJID_CLIENT message. |
| 1484 if (OBJID_CLIENT == lparam) { |
| 1485 // If our MSAA DOM root is already created, reuse that pointer. Otherwise, |
| 1486 // create a new one. |
| 1487 if (!browser_accessibility_root_) { |
| 1488 // Create a new instance of IAccessible. Root id is 1000, to avoid |
| 1489 // conflicts with the ids used by MSAA. |
| 1490 BrowserAccessibilityManager::GetInstance()->CreateAccessibilityInstance( |
| 1491 IID_IAccessible, 1000, |
| 1492 render_widget_host_->routing_id(), |
| 1493 render_widget_host_->process()->id(), |
| 1494 m_hWnd, |
| 1495 reinterpret_cast<void **>(browser_accessibility_root_.Receive())); |
| 1496 |
| 1497 if (!browser_accessibility_root_) { |
| 1498 // No valid root found, return with failure. |
| 1499 return static_cast<LRESULT>(0L); |
| 1500 } |
| 1501 } |
| 1502 |
| 1503 // Create a reference to BrowserAccessibility which MSAA will marshall to |
| 1504 // the client. |
| 1505 reference_result = LresultFromObject(IID_IAccessible, wparam, |
| 1506 static_cast<IAccessible*>(browser_accessibility_root_)); |
1526 } | 1507 } |
1527 | 1508 return reference_result; |
1528 if (lparam == OBJID_CLIENT && browser_accessibility_manager_.get()) { | |
1529 BrowserAccessibility* root = browser_accessibility_manager_->GetRoot(); | |
1530 if (root) { | |
1531 return LresultFromObject(IID_IAccessible, wparam, | |
1532 static_cast<IAccessible*>(root->NewReference())); | |
1533 } | |
1534 } | |
1535 | |
1536 handled = false; | |
1537 return static_cast<LRESULT>(0L); | |
1538 } | 1509 } |
1539 | 1510 |
1540 void RenderWidgetHostViewWin::OnFinalMessage(HWND window) { | 1511 void RenderWidgetHostViewWin::OnFinalMessage(HWND window) { |
1541 // When the render widget host is being destroyed, it ends up calling | 1512 // When the render widget host is being destroyed, it ends up calling |
1542 // WillDestroyRenderWidget (through the RENDER_WIDGET_HOST_DESTROYED | 1513 // WillDestroyRenderWidget (through the RENDER_WIDGET_HOST_DESTROYED |
1543 // notification) which NULLs render_widget_host_. | 1514 // notification) which NULLs render_widget_host_. |
1544 // Note: the following bug http://crbug.com/24248 seems to report that | 1515 // Note: the following bug http://crbug.com/24248 seems to report that |
1545 // OnFinalMessage is called with a deleted |render_widget_host_|. It is not | 1516 // OnFinalMessage is called with a deleted |render_widget_host_|. It is not |
1546 // clear how this could happen, hence the NULLing of render_widget_host_ | 1517 // clear how this could happen, hence the NULLing of render_widget_host_ |
1547 // above. | 1518 // above. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 1628 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
1658 gfx::NativeView native_view) { | 1629 gfx::NativeView native_view) { |
1659 if (::IsWindow(native_view)) { | 1630 if (::IsWindow(native_view)) { |
1660 HANDLE raw_render_host_view = ::GetProp(native_view, | 1631 HANDLE raw_render_host_view = ::GetProp(native_view, |
1661 kRenderWidgetHostViewKey); | 1632 kRenderWidgetHostViewKey); |
1662 if (raw_render_host_view) | 1633 if (raw_render_host_view) |
1663 return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view); | 1634 return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view); |
1664 } | 1635 } |
1665 return NULL; | 1636 return NULL; |
1666 } | 1637 } |
OLD | NEW |