Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/extensions/extension_host_mac.h"
      6 
      7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
      8 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
      9 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
     10 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
     11 #include "content/common/native_web_keyboard_event.h"
     12 
     13 ExtensionHostMac::~ExtensionHostMac() {
     14   // If there is a popup open for this host's extension, close it.
     15   ExtensionPopupController* popup = [ExtensionPopupController popup];
     16   if ([[popup window] isVisible] &&
     17       [popup extensionHost]->extension() == this->extension()) {
     18     InfoBubbleWindow* window = (InfoBubbleWindow*)[popup window];
     19     [window setDelayOnClose:NO];
     20     [popup close];
     21   }
     22 }
     23 
     24 RenderWidgetHostView* ExtensionHostMac::CreateNewWidgetInternal(
     25     int route_id,
     26     WebKit::WebPopupType popup_type) {
     27   // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
     28   // to allow it to survive the trip without being hosed.
     29   RenderWidgetHostView* widget_view =
     30       ExtensionHost::CreateNewWidgetInternal(route_id, popup_type);
     31   RenderWidgetHostViewMac* widget_view_mac =
     32       static_cast<RenderWidgetHostViewMac*>(widget_view);
     33   [widget_view_mac->native_view() retain];
     34 
     35   return widget_view;
     36 }
     37 
     38 void ExtensionHostMac::ShowCreatedWidgetInternal(
     39     RenderWidgetHostView* widget_host_view,
     40     const gfx::Rect& initial_pos) {
     41   ExtensionHost::ShowCreatedWidgetInternal(widget_host_view, initial_pos);
     42 
     43   // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
     44   // properly embedded (or purposefully ignored) we can release the reference we
     45   // took in CreateNewWidgetInternal().
     46   RenderWidgetHostViewMac* widget_view_mac =
     47       static_cast<RenderWidgetHostViewMac*>(widget_host_view);
     48   [widget_view_mac->native_view() release];
     49 }
     50 
     51 void ExtensionHostMac::UnhandledKeyboardEvent(
     52     const NativeWebKeyboardEvent& event) {
     53   if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char ||
     54       extension_host_type() != ViewType::EXTENSION_POPUP) {
     55     return;
     56   }
     57 
     58   ChromeEventProcessingWindow* event_window =
     59       static_cast<ChromeEventProcessingWindow*>([view()->native_view() window]);
     60   DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]);
     61   [event_window redispatchKeyEvent:event.os_event];
     62 }
     63