Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / apps / native_app_window_cocoa.mm
index 395e1d3..ecd390e 100644 (file)
@@ -18,7 +18,6 @@
 #include "content/public/browser/native_web_keyboard_event.h"
 #include "content/public/browser/render_widget_host_view.h"
 #include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
 #include "extensions/common/extension.h"
 #include "third_party/skia/include/core/SkRegion.h"
 #include "ui/gfx/skia_util.h"
@@ -307,7 +306,7 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
       shows_resize_controls_(true),
       shows_fullscreen_controls_(true),
       attention_request_id_(0) {
-  Observe(web_contents());
+  Observe(WebContents());
 
   base::scoped_nsobject<NSWindow> window;
   Class window_class;
@@ -330,7 +329,12 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
                 styleMask:GetWindowStyleMask()
                   backing:NSBackingStoreBuffered
                     defer:NO]);
-  [window setTitle:base::SysUTF8ToNSString(extension()->name())];
+
+  std::string name;
+  const extensions::Extension* extension = app_window_->GetExtension();
+  if (extension)
+    name = extension->name();
+  [window setTitle:base::SysUTF8ToNSString(name)];
   [[window contentView] cr_setWantsLayer:YES];
 
   if (base::mac::IsOSSnowLeopard() &&
@@ -344,7 +348,7 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
   window_controller_.reset(
       [[NativeAppWindowController alloc] initWithWindow:window.release()]);
 
-  NSView* view = web_contents()->GetView()->GetNativeView();
+  NSView* view = WebContents()->GetNativeView();
   [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
 
   InstallView();
@@ -382,7 +386,7 @@ NSUInteger NativeAppWindowCocoa::GetWindowStyleMask() const {
 }
 
 void NativeAppWindowCocoa::InstallView() {
-  NSView* view = web_contents()->GetView()->GetNativeView();
+  NSView* view = WebContents()->GetNativeView();
   if (has_frame_) {
     [view setFrame:[[window() contentView] bounds]];
     [[window() contentView] addSubview:view];
@@ -415,7 +419,7 @@ void NativeAppWindowCocoa::InstallView() {
 }
 
 void NativeAppWindowCocoa::UninstallView() {
-  NSView* view = web_contents()->GetView()->GetNativeView();
+  NSView* view = WebContents()->GetNativeView();
   [view removeFromSuperview];
 }
 
@@ -661,7 +665,7 @@ void NativeAppWindowCocoa::UpdateDraggableRegionViews() {
   // All ControlRegionViews should be added as children of the WebContentsView,
   // because WebContentsView will be removed and re-added when entering and
   // leaving fullscreen mode.
-  NSView* webView = web_contents()->GetView()->GetNativeView();
+  NSView* webView = WebContents()->GetNativeView();
   NSInteger webViewWidth = NSWidth([webView bounds]);
   NSInteger webViewHeight = NSHeight([webView bounds]);
 
@@ -711,7 +715,7 @@ bool NativeAppWindowCocoa::IsAlwaysOnTop() const {
 
 void NativeAppWindowCocoa::RenderViewCreated(content::RenderViewHost* rvh) {
   if (IsActive())
-    web_contents()->GetView()->RestoreFocus();
+    WebContents()->RestoreFocus();
 }
 
 bool NativeAppWindowCocoa::IsFrameless() const {
@@ -723,7 +727,12 @@ bool NativeAppWindowCocoa::HasFrameColor() const {
   return false;
 }
 
-SkColor NativeAppWindowCocoa::FrameColor() const {
+SkColor NativeAppWindowCocoa::ActiveFrameColor() const {
+  // TODO(benwells): Implement this.
+  return SkColor();
+}
+
+SkColor NativeAppWindowCocoa::InactiveFrameColor() const {
   // TODO(benwells): Implement this.
   return SkColor();
 }
@@ -780,12 +789,12 @@ void NativeAppWindowCocoa::WindowWillClose() {
 
 void NativeAppWindowCocoa::WindowDidBecomeKey() {
   content::RenderWidgetHostView* rwhv =
-      web_contents()->GetRenderWidgetHostView();
+      WebContents()->GetRenderWidgetHostView();
   if (rwhv)
     rwhv->SetActive(true);
   app_window_->OnNativeWindowActivated();
 
-  web_contents()->GetView()->RestoreFocus();
+  WebContents()->RestoreFocus();
 }
 
 void NativeAppWindowCocoa::WindowDidResignKey() {
@@ -796,10 +805,10 @@ void NativeAppWindowCocoa::WindowDidResignKey() {
   if ([NSApp isActive] && ([NSApp keyWindow] == window()))
     return;
 
-  web_contents()->GetView()->StoreFocus();
+  WebContents()->StoreFocus();
 
   content::RenderWidgetHostView* rwhv =
-      web_contents()->GetRenderWidgetHostView();
+      WebContents()->GetRenderWidgetHostView();
   if (rwhv)
     rwhv->SetActive(false);
 }
@@ -935,6 +944,10 @@ ShellNSWindow* NativeAppWindowCocoa::window() const {
   return static_cast<ShellNSWindow*>(window);
 }
 
+content::WebContents* NativeAppWindowCocoa::WebContents() const {
+  return app_window_->web_contents();
+}
+
 void NativeAppWindowCocoa::UpdateRestoredBounds() {
   if (IsRestored(*this))
     restored_bounds_ = [window() frame];