| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 7 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
| 8 | 8 |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/common/view_type.h" | 10 #include "chrome/common/view_type.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 | 37 |
| 38 gfx::NativeView ExtensionViewMac::native_view() { | 38 gfx::NativeView ExtensionViewMac::native_view() { |
| 39 return extension_host_->host_contents()->GetView()->GetNativeView(); | 39 return extension_host_->host_contents()->GetView()->GetNativeView(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 content::RenderViewHost* ExtensionViewMac::render_view_host() const { | 42 content::RenderViewHost* ExtensionViewMac::render_view_host() const { |
| 43 return extension_host_->render_view_host(); | 43 return extension_host_->render_view_host(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void ExtensionViewMac::DidStopLoading() { | |
| 47 ShowIfCompletelyLoaded(); | |
| 48 } | |
| 49 | |
| 50 void ExtensionViewMac::SetBackground(const SkBitmap& background) { | 46 void ExtensionViewMac::SetBackground(const SkBitmap& background) { |
| 51 if (!pending_background_.empty() && render_view_host()->GetView()) { | 47 if (!pending_background_.empty() && render_view_host()->GetView()) { |
| 52 render_view_host()->GetView()->SetBackground(background); | 48 render_view_host()->GetView()->SetBackground(background); |
| 53 } else { | 49 } else { |
| 54 pending_background_ = background; | 50 pending_background_ = background; |
| 55 } | 51 } |
| 56 ShowIfCompletelyLoaded(); | 52 ShowIfCompletelyLoaded(); |
| 57 } | 53 } |
| 58 | 54 |
| 55 Browser* ExtensionViewMac::GetBrowser() { |
| 56 return browser_; |
| 57 } |
| 58 |
| 59 const Browser* ExtensionViewMac::GetBrowser() const { |
| 60 return browser_; |
| 61 } |
| 62 |
| 59 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) { | 63 void ExtensionViewMac::ResizeDueToAutoResize(const gfx::Size& new_size) { |
| 60 if (container_) | 64 if (container_) |
| 61 container_->OnExtensionSizeChanged(this, new_size); | 65 container_->OnExtensionSizeChanged(this, new_size); |
| 62 } | 66 } |
| 63 | 67 |
| 64 void ExtensionViewMac::RenderViewCreated() { | 68 void ExtensionViewMac::RenderViewCreated() { |
| 65 if (!pending_background_.empty() && render_view_host()->GetView()) { | 69 if (!pending_background_.empty() && render_view_host()->GetView()) { |
| 66 render_view_host()->GetView()->SetBackground(pending_background_); | 70 render_view_host()->GetView()->SetBackground(pending_background_); |
| 67 pending_background_.reset(); | 71 pending_background_.reset(); |
| 68 } | 72 } |
| 69 | 73 |
| 70 chrome::ViewType host_type = extension_host_->extension_host_type(); | 74 chrome::ViewType host_type = extension_host_->extension_host_type(); |
| 71 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) { | 75 if (host_type == chrome::VIEW_TYPE_EXTENSION_POPUP) { |
| 72 gfx::Size min_size(ExtensionViewMac::kMinWidth, | 76 gfx::Size min_size(ExtensionViewMac::kMinWidth, |
| 73 ExtensionViewMac::kMinHeight); | 77 ExtensionViewMac::kMinHeight); |
| 74 gfx::Size max_size(ExtensionViewMac::kMaxWidth, | 78 gfx::Size max_size(ExtensionViewMac::kMaxWidth, |
| 75 ExtensionViewMac::kMaxHeight); | 79 ExtensionViewMac::kMaxHeight); |
| 76 render_view_host()->EnableAutoResize(min_size, max_size); | 80 render_view_host()->EnableAutoResize(min_size, max_size); |
| 77 } | 81 } |
| 78 } | 82 } |
| 79 | 83 |
| 84 void ExtensionViewMac::DidStopLoading() { |
| 85 ShowIfCompletelyLoaded(); |
| 86 } |
| 87 |
| 80 void ExtensionViewMac::WindowFrameChanged() { | 88 void ExtensionViewMac::WindowFrameChanged() { |
| 81 if (render_view_host()->GetView()) | 89 if (render_view_host()->GetView()) |
| 82 render_view_host()->GetView()->WindowFrameChanged(); | 90 render_view_host()->GetView()->WindowFrameChanged(); |
| 83 } | 91 } |
| 84 | 92 |
| 85 void ExtensionViewMac::CreateWidgetHostView() { | 93 void ExtensionViewMac::CreateWidgetHostView() { |
| 86 extension_host_->CreateRenderViewSoon(); | 94 extension_host_->CreateRenderViewSoon(); |
| 87 } | 95 } |
| 88 | 96 |
| 89 void ExtensionViewMac::ShowIfCompletelyLoaded() { | 97 void ExtensionViewMac::ShowIfCompletelyLoaded() { |
| 90 // We wait to show the ExtensionView until it has loaded, and the view has | 98 // We wait to show the ExtensionView until it has loaded, and the view has |
| 91 // actually been created. These can happen in different orders. | 99 // actually been created. These can happen in different orders. |
| 92 if (extension_host_->did_stop_loading()) { | 100 if (extension_host_->did_stop_loading()) { |
| 93 [native_view() setHidden:NO]; | 101 [native_view() setHidden:NO]; |
| 94 if (container_) | 102 if (container_) |
| 95 container_->OnExtensionViewDidShow(this); | 103 container_->OnExtensionViewDidShow(this); |
| 96 } | 104 } |
| 97 } | 105 } |
| 106 |
| 107 // static |
| 108 ExtensionView* ExtensionView::Create(extensions::ExtensionHost* host, |
| 109 Browser* browser) { |
| 110 ExtensionViewMac* extension_view = new ExtensionViewMac(host, browser); |
| 111 extension_view->Init(); |
| 112 return extension_view; |
| 113 } |
| OLD | NEW |