summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_host_mac.mm
blob: 3a9386f8f7f411013093f0b419f5931de32d595b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/extension_host_mac.h"

#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
#import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
#import "chrome/browser/ui/cocoa/info_bubble_window.h"
#include "content/public/browser/native_web_keyboard_event.h"

using content::NativeWebKeyboardEvent;

namespace extensions {

ExtensionHostMac::~ExtensionHostMac() {
  // If there is a popup open for this host's extension, close it.
  ExtensionPopupController* popup = [ExtensionPopupController popup];
  if ([[popup window] isVisible] &&
      [popup extensionHost]->extension() == this->extension()) {
    InfoBubbleWindow* window = (InfoBubbleWindow*)[popup window];
    [window setAllowedAnimations:info_bubble::kAnimateNone];
    [popup close];
  }
}

void ExtensionHostMac::UnhandledKeyboardEvent(
    content::WebContents* source,
    const NativeWebKeyboardEvent& event) {
  if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char ||
      extension_host_type() != VIEW_TYPE_EXTENSION_POPUP) {
    return;
  }

  ChromeEventProcessingWindow* event_window =
      static_cast<ChromeEventProcessingWindow*>([view()->native_view() window]);
  DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]);
  [event_window redispatchKeyEvent:event.os_event];
}

}  // namespace extensions